commit bf81f5736fc3c8a7c3c22fc70b0ccfa147130454
parent 2c599de6da29595b238d875c658e0e2033e8522d
Author: Michael Constantine Dimopoulos <mk@mcdim.xyz>
Date: Sun, 5 Nov 2023 03:19:32 +0000
Fixed no argument bug, needs refactoring
Diffstat:
2 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/config.h b/config.h
@@ -21,6 +21,4 @@ static int text_x_padding = 10;
static int min_width = 400;
static int max_width = 600;
-static int line_spacing = 2; /* factor in relation to text height */
-
const char *fontname = "DejaVu Sans Mono:size=12:antialias=true";
diff --git a/sxalert.c b/sxalert.c
@@ -100,26 +100,41 @@ draw(int border, int duration, char **lines, int length)
if (!XftColorAllocName(dpy, visual, cmap, text_color_pnd, &color))
die("Cannot allocate Xft color\n", EXIT_FAILURE);
- int width_lines[length];
- int j = 0;
- for (int i = 0; i < length; i++) {
- XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[i], strlen(lines[i]), &extents);
- width_lines[i] = extents.xOff;
- printf("text_width[%d]=%d\n", j, width_lines[j]);
- j++;
- }
+ printf("ok\n");
+ int width;
+ if (length > 0) {
+ int width_lines[length];
+ int j = 0;
+ for (int i = 0; i < length; i++) {
+ XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[i], strlen(lines[i]), &extents);
+ width_lines[i] = extents.xOff;
+ printf("text_width[%d]=%d\n", j, width_lines[j]);
+ j++;
+ }
- int text_width = get_max(width_lines, length);
- printf("text_width=%d\n", text_width);
- int width = (text_x_padding * 2) + text_width;
+ int text_width = get_max(width_lines, length);
+ printf("text_width=%d\n", text_width);
+ width = (text_x_padding * 2) + text_width;
+ } else {
+ width = 0;
+ }
+ printf("ok\n");
if (width < min_width)
width = min_width;
if (width > max_width)
width = max_width;
- XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[0], strlen(lines[0]), &extents);
- int text_height = extents.height;
- int height = length * (text_height * 2) + text_height;
+ printf("susok\n");
+ int text_height, height;
+ if (length > 0) {
+ XftTextExtentsUtf8(dpy, font, (XftChar8*)lines[0], strlen(lines[0]), &extents);
+ printf("susok2\n");
+ text_height = extents.height;
+ height = length * (text_height * 2) + text_height;
+ } else {
+ int text_height = text_x_padding;
+ height = text_height;
+ }
/* TODO: calculate position dynamically */
Window win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 1500, 50, width, height, border, hex2int(border_color), hex2int(bg_color));
@@ -150,7 +165,8 @@ draw(int border, int duration, char **lines, int length)
if (ev.type == Expose) {
int spacing = text_height * 2;
for (int i = 0; i < length; i++) {
- XftDrawStringUtf8(draw, &color, font, text_x_padding, spacing, (XftChar8 *)lines[i], strlen(lines[i]));
+ if (length != 0)
+ XftDrawStringUtf8(draw, &color, font, text_x_padding, spacing, (XftChar8 *)lines[i], strlen(lines[i]));
spacing += text_height * 2;
}
} else if (ev.type == ButtonPress) { //&& ev.xbutton.button == 1) {
@@ -201,6 +217,7 @@ main(int argc, char **argv)
int lines_len=argc-optind;
char** lines = argv + optind; /* get lines to print */
+ printf("ok\n");
draw(border_width, duration, lines, lines_len);