diff options
author | joe <rbo@gmx.us> | 2025-09-29 17:24:54 +0200 |
---|---|---|
committer | joe <rbo@gmx.us> | 2025-09-29 17:24:54 +0200 |
commit | 09d2f68e3f2d6ed0e8333ac920385bc373b33816 (patch) | |
tree | eaa3efeb61896f2e5e2740f0d96ad944e4b0d5af /applied | |
download | herbe-09d2f68e3f2d6ed0e8333ac920385bc373b33816.tar.gz herbe-09d2f68e3f2d6ed0e8333ac920385bc373b33816.tar.bz2 herbe-09d2f68e3f2d6ed0e8333ac920385bc373b33816.tar.xz herbe-09d2f68e3f2d6ed0e8333ac920385bc373b33816.tar.zst herbe-09d2f68e3f2d6ed0e8333ac920385bc373b33816.zip |
config
Diffstat (limited to 'applied')
-rw-r--r-- | applied/19.diff | 100 | ||||
-rw-r--r-- | applied/21.diff | 80 |
2 files changed, 180 insertions, 0 deletions
diff --git a/applied/19.diff b/applied/19.diff new file mode 100644 index 0000000..2ece3fb --- /dev/null +++ b/applied/19.diff @@ -0,0 +1,100 @@ +diff --git a/herbe.c b/herbe.c +index 51d3990..8bfdbc1 100644 +--- a/herbe.c ++++ b/herbe.c +@@ -7,7 +7,8 @@ + #include <string.h> + #include <stdarg.h> + #include <fcntl.h> +-#include <semaphore.h> ++#include <sys/ipc.h> ++#include <sys/shm.h> + + #include "config.h" + +@@ -79,13 +80,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("/herbe"); +- die("Usage: %s body", argv[0]); +- } ++ die("Usage: %s body", argv[0]); + + struct sigaction act_expire, act_ignore; + +@@ -151,16 +162,22 @@ int main(int argc, char *argv[]) + } + } + +- unsigned int x = pos_x; +- unsigned int 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_width - width - border_size * 2 - pos_x; ++ x = screen_width - width - border_size * 2 - x; + + 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), + CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); +@@ -171,9 +188,6 @@ int main(int argc, char *argv[]) + XSelectInput(display, window, ExposureMask | ButtonPress); + XMapWindow(display, window); + +- sem_t *mutex = sem_open("/herbe", O_CREAT, 0644, 1); +- sem_wait(mutex); +- + sigaction(SIGUSR1, &act_expire, 0); + sigaction(SIGUSR2, &act_expire, 0); + +@@ -204,12 +218,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); +@@ -217,4 +230,4 @@ int main(int argc, char *argv[]) + XCloseDisplay(display); + + return exit_code; +-} +\ No newline at end of file ++} diff --git a/applied/21.diff b/applied/21.diff new file mode 100644 index 0000000..412c034 --- /dev/null +++ b/applied/21.diff @@ -0,0 +1,80 @@ +diff --git a/Makefile b/Makefile +index 3225e36..55509cf 100644 +--- a/Makefile ++++ b/Makefile +@@ -9,7 +9,7 @@ config.h: config.def.h + cp config.def.h config.h + + herbe: herbe.c config.h +- $(CC) herbe.c $(CFLAGS) -o herbe ++ $(CC) herbe.c $(CFLAGS) -o herbe -lXrandr + + install: herbe + mkdir -p ${DESTDIR}${PREFIX}/bin +diff --git a/config.def.h b/config.def.h +index 86b7e76..f8bf499 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -4,6 +4,7 @@ static const char *font_color = "#ececec"; + static const char *font_pattern = "monospace:size=10"; + static const unsigned line_spacing = 5; + static const unsigned int padding = 15; ++static const int use_primary_monitor = 0; + + static const unsigned int width = 450; + static const unsigned int border_size = 2; +diff --git a/herbe.c b/herbe.c +index 51d3990..a2277f0 100644 +--- a/herbe.c ++++ b/herbe.c +@@ -1,5 +1,6 @@ + #include <X11/Xlib.h> + #include <X11/Xft/Xft.h> ++#include <X11/extensions/Xrandr.h> + #include <stdio.h> + #include <stdlib.h> + #include <signal.h> +@@ -111,8 +112,22 @@ int main(int argc, char *argv[]) + Visual *visual = DefaultVisual(display, screen); + Colormap colormap = DefaultColormap(display, screen); + ++ int screen_x = 0; ++ int screen_y = 0; + int screen_width = DisplayWidth(display, screen); + int screen_height = DisplayHeight(display, screen); ++ if(use_primary_monitor) { ++ int nMonitors; ++ XRRMonitorInfo* info = XRRGetMonitors(display, RootWindow(display, screen), 1, &nMonitors); ++ for(int i = 0; i < nMonitors; i++) { ++ if(info[i].primary) { ++ screen_x = info[i].x; ++ screen_y = info[i].y; ++ screen_width = info[i].width; ++ screen_height = info[i].height; ++ } ++ } ++ } + + XSetWindowAttributes attributes; + attributes.override_redirect = True; +@@ -151,16 +166,16 @@ int main(int argc, char *argv[]) + } + } + +- unsigned int x = pos_x; +- unsigned int y = pos_y; ++ unsigned int x = screen_x + pos_x; ++ unsigned int y = screen_y + pos_y; + unsigned int text_height = font->ascent - font->descent; + unsigned int height = (num_of_lines - 1) * line_spacing + num_of_lines * text_height + 2 * padding; + + if (corner == TOP_RIGHT || corner == BOTTOM_RIGHT) +- x = screen_width - width - border_size * 2 - pos_x; ++ x = screen_x + screen_width - width - border_size * 2 - pos_x; + + if (corner == BOTTOM_LEFT || corner == BOTTOM_RIGHT) +- y = screen_height - height - border_size * 2 - pos_y; ++ y = screen_y + screen_height - height - border_size * 2 - pos_y; + + window = XCreateWindow(display, RootWindow(display, screen), x, y, width, height, border_size, DefaultDepth(display, screen), + CopyFromParent, visual, CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes); |