birde

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 061a8c4a049e1d385be20901d7aaba42e782ca1b
parent 46fba36b170796752b24562137f7fcbba995f90e
Author: mrgrouse <mrgrouse@mrgrouse.com>
Date:   Sat, 31 Aug 2024 14:10:44 -0400

birde.c: patched in vertical stacking, but currently does not work with the notify.sh script

Diffstat:
Mbirde.c | 39++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/birde.c b/birde.c @@ -9,7 +9,8 @@ #include <string.h> #include <stdarg.h> #include <fcntl.h> -#include <semaphore.h> +#include <sys/ipc.h> +#include <sys/shm.h> #include "config.h" @@ -88,13 +89,23 @@ void expire(int sig) XFlush(display); } +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[]) { if (argc == 1) - { - sem_unlink("/birde"); die("Usage: %s body", argv[0]); - } struct sigaction act_expire, act_ignore; @@ -196,16 +207,22 @@ int main(int argc, char *argv[]) } } - unsigned int x = screen_x + pos_x; - unsigned int y = screen_y + pos_y; + int y_offset_id; + unsigned int *y_offset; + read_y_offset(&y_offset, &y_offset_id); + 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 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) - x = screen_x + screen_width - width - border_size * 2 - pos_x; + x = screen_x + screen_width - width - border_size * 2 - x; if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT) - y = screen_y + screen_height - height - border_size * 2 - pos_y; + y = screen_y + screen_height - height - border_size * 2 - y; window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen), CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); @@ -216,9 +233,6 @@ int main(int argc, char *argv[]) XSelectInput(display, window, ExposureMask | ButtonPress); XMapWindow(display, window); - sem_t *mutex = sem_open("/birde", O_CREAT, 0644, 1); - sem_wait(mutex); - sigaction(SIGUSR1, &act_expire, 0); sigaction(SIGUSR2, &act_expire, 0); @@ -249,12 +263,11 @@ int main(int argc, char *argv[]) } } - sem_post(mutex); - sem_close(mutex); for (int i = 0; i < num_of_lines; i++) free(lines[i]); + if (used_y_offset == *y_offset) free_y_offset(y_offset_id); free(lines); XftDrawDestroy(draw); XftColorFree(display, visual, colormap, &color);