commit 208f6d48b51c38713da01157e00b898a7ec57184
parent 0725ebc23d5e2e565c43d870331e92327a1b3587
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date: Sun, 5 Nov 2023 20:35:38 +0000
Added dynamic positioning
Diffstat:
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
@@ -7,6 +7,7 @@ Simple notification system for X that works without a daemon. This is mainly for
+ Freetype scalable fonts
+ UTF-8 support
+ Configurable & scriptable
++ Dynamic screen positioning
+ Dynamic box sizing
## Dependencies
@@ -31,8 +32,7 @@ $ ./sxalert -b 5 -t FFFFFF -g 000000 -r FFFFFF "First line" "Second line"
These will overwrite the defaults written in `config.h`
## TODOs:
-+ Dynamic screen positioning
-+ Exit by event (perhaps as a path)
++ Exit by event (perhaps as a patch)
+ Titles (perhaps as a patch)
+ (?) optional daemon for positinioning
diff --git a/config.h b/config.h
@@ -21,5 +21,8 @@ static int text_x_padding = 10;
static int min_width = 300;
static int max_width = 1100;
+static int x_offset = 20; /* pixels from right */
+static int y_offset = 50; /* pixels from top */
+
const char *fontname = "DejaVu Sans Mono:size=12:antialias=true";
static int text_height = 10;
diff --git a/sxalert.c b/sxalert.c
@@ -159,18 +159,16 @@ draw(int border, int duration, char **lines, int length)
int width = get_width(dpy, font, lines, length);
int height = length * (text_height * 2) + text_height;
- //if (length > 0) {
- // XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[0], strlen(lines[0]), &extents);
- // text_height = extents.height;
- // height = length * (text_height * 2) + text_height;
- //} else {
- // text_height = text_x_padding;
- // height = text_height;
- //}
- //printf("text_height: %d\n", text_height);
+
+ int count_screens = ScreenCount(dpy);
+ Screen *screen = ScreenOfDisplay(dpy, 0);
+
+ printf("Screen %d: %dX%d\n", 0, screen->width, screen->height);
+ int x = screen->width - width - x_offset; // - (width - 400);
+ printf("x: %d\n", x);
/* TODO: calculate position dynamically */
- Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 1500-(width-400), 50, width, height, border, hex2int(border_color), hex2int(bg_color));
+ Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), x, y_offset, width, height, border, hex2int(border_color), hex2int(bg_color));
XSetWindowAttributes attributes;
attributes.override_redirect = True;
XChangeWindowAttributes(dpy, win, CWOverrideRedirect, &attributes);