apply stacking patch
parent
91de526006
commit
cf94686974
41
herbe.c
41
herbe.c
|
|
@ -8,7 +8,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <semaphore.h>
|
#include <sys/ipc.h>
|
||||||
|
#include <sys/shm.h>
|
||||||
|
|
||||||
#define EXIT_ACTION 0
|
#define EXIT_ACTION 0
|
||||||
#define EXIT_FAIL 1
|
#define EXIT_FAIL 1
|
||||||
|
|
@ -144,13 +145,23 @@ void config_init(Display *dpy)
|
||||||
resource_load(db, p->name, p->type, p->dst);
|
resource_load(db, p->name, p->type, p->dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void read_y_offset(unsigned int **offset, int *id) {
|
||||||
|
int shm_id = shmget(8432, sizeof(unsigned int), IPC_CREAT | 0660);
|
||||||
|
if (shm_id == -1) die("shmget failed");
|
||||||
|
|
||||||
|
*offset = (unsigned int *)shmat(shm_id, 0, 0);
|
||||||
|
if (*offset == (unsigned int *)-1) die("shmat failed\n");
|
||||||
|
*id = shm_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_y_offset(int id) {
|
||||||
|
shmctl(id, IPC_RMID, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
die("Usage: %s body", argv[0]);
|
||||||
sem_unlink("/herbe");
|
|
||||||
die("Usage: %s body", argv[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sigaction act_expire, act_ignore;
|
struct sigaction act_expire, act_ignore;
|
||||||
|
|
||||||
|
|
@ -218,16 +229,22 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int x = pos_x;
|
int y_offset_id;
|
||||||
unsigned int y = pos_y;
|
unsigned int *y_offset;
|
||||||
|
read_y_offset(&y_offset, &y_offset_id);
|
||||||
|
|
||||||
unsigned int text_height = font->ascent - font->descent;
|
unsigned int text_height = font->ascent - font->descent;
|
||||||
unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;
|
unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding;
|
||||||
|
unsigned int x = pos_x;
|
||||||
|
unsigned int y = pos_y + *y_offset;
|
||||||
|
|
||||||
|
unsigned int used_y_offset = (*y_offset) += height + padding;
|
||||||
|
|
||||||
if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
|
if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT)
|
||||||
x = screen_width - width - border_size * 2 - pos_x;
|
x = screen_width - width - border_size * 2 - x;
|
||||||
|
|
||||||
if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
|
if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT)
|
||||||
y = screen_height - height - border_size * 2 - pos_y;
|
y = screen_height - height - border_size * 2 - y;
|
||||||
|
|
||||||
window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen),
|
window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen),
|
||||||
CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
|
||||||
|
|
@ -238,9 +255,6 @@ int main(int argc, char *argv[])
|
||||||
XSelectInput(display, window, ExposureMask | ButtonPress);
|
XSelectInput(display, window, ExposureMask | ButtonPress);
|
||||||
XMapWindow(display, window);
|
XMapWindow(display, window);
|
||||||
|
|
||||||
sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1);
|
|
||||||
sem_wait(mutex);
|
|
||||||
|
|
||||||
sigaction(SIGUSR1, &act_expire, 0);
|
sigaction(SIGUSR1, &act_expire, 0);
|
||||||
sigaction(SIGUSR2, &act_expire, 0);
|
sigaction(SIGUSR2, &act_expire, 0);
|
||||||
|
|
||||||
|
|
@ -271,12 +285,11 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_post(mutex);
|
|
||||||
sem_close(mutex);
|
|
||||||
|
|
||||||
for (int i = 0; i < num_of_lines; i++)
|
for (int i = 0; i < num_of_lines; i++)
|
||||||
free(lines[i]);
|
free(lines[i]);
|
||||||
|
|
||||||
|
if (used_y_offset == *y_offset) free_y_offset(y_offset_id);
|
||||||
free(lines);
|
free(lines);
|
||||||
XftDrawDestroy(draw);
|
XftDrawDestroy(draw);
|
||||||
XftColorFree(display, visual, colormap, &color);
|
XftColorFree(display, visual, colormap, &color);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue