sent-xresources-20230807-fb4dab3.diff (2376B)
1 From a09330410518e8baa127493aa79704f7726c27c7 Mon Sep 17 00:00:00 2001 2 From: Fikri Rahmat Nurhidayat <fikrirnurhidayat@gmail.com> 3 Date: Mon, 7 Aug 2023 15:59:57 +0700 4 Subject: [PATCH] use xrdb value for fontfallbacks, and colors 5 6 --- 7 config.def.h | 4 ++-- 8 sent.c | 33 +++++++++++++++++++++++++++++++++ 9 2 files changed, 35 insertions(+), 2 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index 60eb376..50a9808 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -1,6 +1,6 @@ 16 /* See LICENSE file for copyright and license details. */ 17 - 18 -static char *fontfallbacks[] = { 19 +#define MAXFONTS 10 20 +static char *fontfallbacks[MAXFONTS] = { 21 "dejavu sans", 22 "roboto", 23 "ubuntu", 24 diff --git a/sent.c b/sent.c 25 index dfadd3a..5875f5e 100644 26 --- a/sent.c 27 +++ b/sent.c 28 @@ -18,6 +18,7 @@ 29 #include <X11/Xlib.h> 30 #include <X11/Xutil.h> 31 #include <X11/Xft/Xft.h> 32 +#include <X11/Xresource.h> 33 34 #include "arg.h" 35 #include "util.h" 36 @@ -105,6 +106,7 @@ static void xdraw(void); 37 static void xhints(void); 38 static void xinit(void); 39 static void xloadfonts(void); 40 +static void xresources(void); 41 42 static void bpress(XEvent *); 43 static void cmessage(XEvent *); 44 @@ -573,6 +575,7 @@ xinit(void) 45 46 if (!(xw.dpy = XOpenDisplay(NULL))) 47 die("sent: Unable to open display"); 48 + xresources(); 49 xw.scr = XDefaultScreen(xw.dpy); 50 xw.vis = XDefaultVisual(xw.dpy, xw.scr); 51 resize(DisplayWidth(xw.dpy, xw.scr), DisplayHeight(xw.dpy, xw.scr)); 52 @@ -632,6 +635,36 @@ xloadfonts(void) 53 free(fstrs[j]); 54 } 55 56 +void 57 +xresources(void) { 58 + XrmInitialize(); 59 + char* xrm; 60 + if ((xrm = XResourceManagerString(xw.dpy))) { 61 + char *type; 62 + XrmDatabase xdb = XrmGetStringDatabase(xrm); 63 + XrmValue xval; 64 + if (XrmGetResource(xdb, "sent.font", "*", &type, &xval)) { 65 + int fc = 0; 66 + char *token; 67 + char *delimiter = ","; 68 + char *font_string = (char *)xval.addr; 69 + 70 + // Tokenize the font names and store them in the array 71 + token = strtok(font_string, delimiter); 72 + while (token != NULL && fc < MAXFONTS) { 73 + fontfallbacks[fc] = strdup(token); 74 + fc++; 75 + token = strtok(NULL, delimiter); 76 + } 77 + } 78 + if (XrmGetResource(xdb, "sent.foreground", "*", &type, &xval)) 79 + colors[0] = strdup(xval.addr); 80 + if (XrmGetResource(xdb, "sent.background", "*", &type, &xval)) 81 + colors[1] = strdup(xval.addr); 82 + XrmDestroyDatabase(xdb); 83 + } 84 +} 85 + 86 void 87 bpress(XEvent *e) 88 { 89 -- 90 2.41.0 91