From 326da967c630f8bb00d5d83c574f676bf3f7108e Mon Sep 17 00:00:00 2001 From: ttr3dp Date: Thu, 4 Feb 2021 23:06:31 +0100 Subject: [PATCH] PATCH: xresources URL: https://github.com/dudik/herbe/pull/11 --- config.def.h | 14 ++++---- herbe.c | 33 ++++++++++++++++- patches/11.diff | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 patches/11.diff diff --git a/config.def.h b/config.def.h index 86b7e76..d545925 100644 --- a/config.def.h +++ b/config.def.h @@ -2,18 +2,18 @@ static const char *background_color = "#3e3e3e"; static const char *border_color = "#ececec"; 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 unsigned line_spacing = 5; +static unsigned int padding = 15; -static const unsigned int width = 450; -static const unsigned int border_size = 2; -static const unsigned int pos_x = 30; -static const unsigned int pos_y = 60; +static unsigned int width = 450; +static unsigned int border_size = 2; +static unsigned int pos_x = 30; +static unsigned int pos_y = 60; enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; enum corners corner = TOP_RIGHT; -static const unsigned int duration = 5; /* in seconds */ +static unsigned int duration = 5; /* in seconds */ #define DISMISS_BUTTON Button1 #define ACTION_BUTTON Button3 diff --git a/herbe.c b/herbe.c index 51d3990..574e967 100644 --- a/herbe.c +++ b/herbe.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,6 +16,13 @@ #define EXIT_FAIL 1 #define EXIT_DISMISS 2 +#define XRES_STR(name) \ + if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \ + name = val.addr +#define XRES_INT(name) \ + if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \ + name = strtoul(val.addr, 0, 10) + Display *display; Window window; int exit_code = EXIT_DISMISS; @@ -107,6 +115,28 @@ int main(int argc, char *argv[]) if (!(display = XOpenDisplay(0))) die("Cannot open display"); + XrmInitialize(); + + char *res_man = XResourceManagerString(display); + XrmDatabase db = XrmGetStringDatabase(res_man); + + char *type; + XrmValue val; + + XRES_STR(background_color); + XRES_STR(border_color); + XRES_STR(font_color); + XRES_STR(font_pattern); + + XRES_INT(line_spacing); + XRES_INT(padding); + XRES_INT(width); + XRES_INT(border_size); + XRES_INT(pos_x); + XRES_INT(pos_y); + XRES_INT(corner); + XRES_INT(duration); + int screen = DefaultScreen(display); Visual *visual = DefaultVisual(display, screen); Colormap colormap = DefaultColormap(display, screen); @@ -214,7 +244,8 @@ int main(int argc, char *argv[]) XftDrawDestroy(draw); XftColorFree(display, visual, colormap, &color); XftFontClose(display, font); + XrmDestroyDatabase(db); XCloseDisplay(display); return exit_code; -} \ No newline at end of file +} diff --git a/patches/11.diff b/patches/11.diff new file mode 100644 index 0000000..2c9e9b1 --- /dev/null +++ b/patches/11.diff @@ -0,0 +1,95 @@ +diff --git a/config.def.h b/config.def.h +index 86b7e76..d545925 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -2,18 +2,18 @@ static const char *background_color = "#3e3e3e"; + static const char *border_color = "#ececec"; + 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 unsigned line_spacing = 5; ++static unsigned int padding = 15; + +-static const unsigned int width = 450; +-static const unsigned int border_size = 2; +-static const unsigned int pos_x = 30; +-static const unsigned int pos_y = 60; ++static unsigned int width = 450; ++static unsigned int border_size = 2; ++static unsigned int pos_x = 30; ++static unsigned int pos_y = 60; + + enum corners { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; + enum corners corner = TOP_RIGHT; + +-static const unsigned int duration = 5; /* in seconds */ ++static unsigned int duration = 5; /* in seconds */ + + #define DISMISS_BUTTON Button1 + #define ACTION_BUTTON Button3 +diff --git a/herbe.c b/herbe.c +index 51d3990..574e967 100644 +--- a/herbe.c ++++ b/herbe.c +@@ -1,5 +1,6 @@ + #include + #include ++#include + #include + #include + #include +@@ -15,6 +16,13 @@ + #define EXIT_FAIL 1 + #define EXIT_DISMISS 2 + ++#define XRES_STR(name) \ ++ if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \ ++ name = val.addr ++#define XRES_INT(name) \ ++ if (XrmGetResource(db, "herbe." #name, "*", &type, &val)) \ ++ name = strtoul(val.addr, 0, 10) ++ + Display *display; + Window window; + int exit_code = EXIT_DISMISS; +@@ -107,6 +115,28 @@ int main(int argc, char *argv[]) + if (!(display = XOpenDisplay(0))) + die("Cannot open display"); + ++ XrmInitialize(); ++ ++ char *res_man = XResourceManagerString(display); ++ XrmDatabase db = XrmGetStringDatabase(res_man); ++ ++ char *type; ++ XrmValue val; ++ ++ XRES_STR(background_color); ++ XRES_STR(border_color); ++ XRES_STR(font_color); ++ XRES_STR(font_pattern); ++ ++ XRES_INT(line_spacing); ++ XRES_INT(padding); ++ XRES_INT(width); ++ XRES_INT(border_size); ++ XRES_INT(pos_x); ++ XRES_INT(pos_y); ++ XRES_INT(corner); ++ XRES_INT(duration); ++ + int screen = DefaultScreen(display); + Visual *visual = DefaultVisual(display, screen); + Colormap colormap = DefaultColormap(display, screen); +@@ -214,7 +244,8 @@ int main(int argc, char *argv[]) + XftDrawDestroy(draw); + XftColorFree(display, visual, colormap, &color); + XftFontClose(display, font); ++ XrmDestroyDatabase(db); + XCloseDisplay(display); + + return exit_code; +-} +\ No newline at end of file ++}