Add usage information, more error checking
authorSamuel Dudik <redacted>
Thu, 30 Jul 2020 13:23:32 +0000 (15:23 +0200)
committerSamuel Dudik <redacted>
Thu, 30 Jul 2020 13:23:32 +0000 (15:23 +0200)
config.h
main.c

index f49865bd824d3ef48d872304aebb165011d37012..a72c9a7994ea7af24f14103319d4ff20d432cd22 100644 (file)
--- a/config.h
+++ b/config.h
@@ -1,14 +1,14 @@
-const static char *background_color = "#FFFFFF";
-const static char *border_color = "#FF0000";
+const static char *background_color = "#3e3e3e";
+const static char *border_color = "#ececec";
 
 const static char *font_style = "Inconsolata:style=Medium:size=15";
-const static char *font_color = "#00FF00";
+const static char *font_color = "#ececec";
 const static unsigned short text_padding = 10;
 
 const static unsigned short width = 300;
-const static unsigned short border_size = 5;
-const static unsigned short pos_x = 30;
-const static unsigned short pos_y = 30;
+const static unsigned short border_size = 2;
+const static unsigned short pos_x = 40;
+const static unsigned short pos_y = 50;
 
 enum corners { top_left, top_right, down_right, down_left };
 enum corners corner = top_right;
diff --git a/main.c b/main.c
index 4c29b15728133233b0e1bab5d99746d7cd6f5b6e..3888ec241f35cfbe677f1f799704f5730822e481 100644 (file)
--- a/main.c
+++ b/main.c
@@ -20,6 +20,11 @@ void expire()
 
 int main(int argc, char *argv[])
 {
+       if (argc != 2) {
+               fprintf(stderr, "Usage: herbe message\n");
+               exit(EXIT_FAILURE);
+       }
+
        signal(SIGALRM, expire);
        alarm(duration);
 
@@ -53,21 +58,21 @@ int main(int argc, char *argv[])
        int height = font->ascent - font->descent + text_padding * 2;
        switch (corner)
        {
-       case down_right:
-               y = window_height - height - border_size * 2 - pos_y;
-       case top_right:
-               x = window_width - width - border_size * 2 - pos_x;
-               break;
-       case down_left:
-               y = window_height - height - border_size * 2 - pos_y;
+               case down_right:
+                       y = window_height - height - border_size * 2 - pos_y;
+               case top_right:
+                       x = window_width - width - border_size * 2 - pos_x;
+                       break;
+               case down_left:
+                       y = window_height - height - border_size * 2 - pos_y;
        }
 
        window = XCreateWindow(
-               display, root, x,
-               y, width, height, border_size,
-               DefaultDepth(display, screen), CopyFromParent,
-               DefaultVisual(display, screen),
-               CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
+                       display, root, x,
+                       y, width, height, border_size,
+                       DefaultDepth(display, screen), CopyFromParent,
+                       DefaultVisual(display, screen),
+                       CWOverrideRedirect | CWBackPixel | CWBorderPixel, &attributes);
 
        XftDraw *draw = XftDrawCreate(display, window, DefaultVisual(display, screen), DefaultColormap(display, screen));
        XftColorAllocName(display, DefaultVisual(display, screen), DefaultColormap(display, screen), font_color, &color);
@@ -76,8 +81,6 @@ int main(int argc, char *argv[])
 
        XMapWindow(display, window);
 
-       // TODO free xftcolor
-
        XEvent event;
 
        while (1)
@@ -93,6 +96,10 @@ int main(int argc, char *argv[])
                        break;
        }
 
+       XftDrawDestroy(draw);
+       XftColorFree(display, DefaultVisual(display, screen), DefaultColormap(display, screen), &color);
+       XftFontClose(display, font);
+
        XCloseDisplay(display);
        return 0;
 }