[wiki] [sites] [sent][patch][xresources] add xresources support || Fikri Rahmat Nurhidayat

From: <git_AT_suckless.org>
Date: Mon, 07 Aug 2023 17:51:32 +0200

commit 7908b2e1741541de3e13a4d07f2df8d173c8de36
Author: Fikri Rahmat Nurhidayat <fikrirnurhidayat_AT_gmail.com>
Date: Mon Aug 7 22:49:43 2023 +0700

    [sent][patch][xresources] add xresources support

diff --git a/tools.suckless.org/dmenu/patches/xresources/index.md b/tools.suckless.org/dmenu/patches/xresources/index.md
index 4a638371..a1ef7962 100644
--- a/tools.suckless.org/dmenu/patches/xresources/index.md
+++ b/tools.suckless.org/dmenu/patches/xresources/index.md
_AT_@ -18,7 +18,6 @@ resources that can be changed and what they change:
 
 Note: Values in Xresources will override values in config.h, but will be
 overridden by command line arguments.
-
 Download
 --------
 * [dmenu-xresources-4.9.diff](dmenu-xresources-4.9.diff)
diff --git a/tools.suckless.org/sent/patches/xresources/index.md b/tools.suckless.org/sent/patches/xresources/index.md
new file mode 100644
index 00000000..38d02bd6
--- /dev/null
+++ b/tools.suckless.org/sent/patches/xresources/index.md
_AT_@ -0,0 +1,25 @@
+Xresources
+===============
+
+Description
+-----------
+This patch was a port of [dmenu xresources](https://tools.suckless.org/dmenu/patches/xresources/)
+for sent.
+
+This patch adds the ability to configure sent via Xresources. At startup,
+sent will read and apply the change to the applicable resource. Below are the
+resources that can be changed and what they change:
+
+- `sent.font`: font being used on sent, support multiple fonts to define the fallbacks.
+- `sent.foreground`: foreground color
+- `sent.background`: background color
+
+Note: Values in Xresources will override values in config.h.
+
+Download
+--------
+* [sent-xresources-20230807-fb4dab3.diff](sent-xresources-20230807-fb4dab3.diff)
+
+Authors
+-------
+* Fikri Rahmat Nurhidayat <fikrirnurhidayat_AT_gmail.com>
\ No newline at end of file
diff --git a/tools.suckless.org/sent/patches/xresources/sent-xresources-20230807-fb4dab3.diff b/tools.suckless.org/sent/patches/xresources/sent-xresources-20230807-fb4dab3.diff
new file mode 100644
index 00000000..716f0077
--- /dev/null
+++ b/tools.suckless.org/sent/patches/xresources/sent-xresources-20230807-fb4dab3.diff
_AT_@ -0,0 +1,91 @@
+From a09330410518e8baa127493aa79704f7726c27c7 Mon Sep 17 00:00:00 2001
+From: Fikri Rahmat Nurhidayat <fikrirnurhidayat_AT_gmail.com>
+Date: Mon, 7 Aug 2023 15:59:57 +0700
+Subject: [PATCH] use xrdb value for fontfallbacks, and colors
+
+---
+ config.def.h | 4 ++--
+ sent.c | 33 +++++++++++++++++++++++++++++++++
+ 2 files changed, 35 insertions(+), 2 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 60eb376..50a9808 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -1,6 +1,6 @@
+ /* See LICENSE file for copyright and license details. */
+-
+-static char *fontfallbacks[] = {
++#define MAXFONTS 10
++static char *fontfallbacks[MAXFONTS] = {
+ "dejavu sans",
+ "roboto",
+ "ubuntu",
+diff --git a/sent.c b/sent.c
+index dfadd3a..5875f5e 100644
+--- a/sent.c
++++ b/sent.c
+_AT_@ -18,6 +18,7 @@
+ #include <X11/Xlib.h>
+ #include <X11/Xutil.h>
+ #include <X11/Xft/Xft.h>
++#include <X11/Xresource.h>
+
+ #include "arg.h"
+ #include "util.h"
+_AT_@ -105,6 +106,7 @@ static void xdraw(void);
+ static void xhints(void);
+ static void xinit(void);
+ static void xloadfonts(void);
++static void xresources(void);
+
+ static void bpress(XEvent *);
+ static void cmessage(XEvent *);
+_AT_@ -573,6 +575,7 @@ xinit(void)
+
+ if (!(xw.dpy = XOpenDisplay(NULL)))
+ die("sent: Unable to open display");
++ xresources();
+ xw.scr = XDefaultScreen(xw.dpy);
+ xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+ resize(DisplayWidth(xw.dpy, xw.scr), DisplayHeight(xw.dpy, xw.scr));
+_AT_@ -632,6 +635,36 @@ xloadfonts(void)
+ free(fstrs[j]);
+ }
+
++void
++xresources(void) {
++ XrmInitialize();
++ char* xrm;
++ if ((xrm = XResourceManagerString(xw.dpy))) {
++ char *type;
++ XrmDatabase xdb = XrmGetStringDatabase(xrm);
++ XrmValue xval;
++ if (XrmGetResource(xdb, "sent.font", "*", &type, &xval)) {
++ int fc = 0;
++ char *token;
++ char *delimiter = ",";
++ char *font_string = (char *)xval.addr;
++
++ // Tokenize the font names and store them in the array
++ token = strtok(font_string, delimiter);
++ while (token != NULL && fc < MAXFONTS) {
++ fontfallbacks[fc] = strdup(token);
++ fc++;
++ token = strtok(NULL, delimiter);
++ }
++ }
++ if (XrmGetResource(xdb, "sent.foreground", "*", &type, &xval))
++ colors[0] = strdup(xval.addr);
++ if (XrmGetResource(xdb, "sent.background", "*", &type, &xval))
++ colors[1] = strdup(xval.addr);
++ XrmDestroyDatabase(xdb);
++ }
++}
++
+ void
+ bpress(XEvent *e)
+ {
+--
+2.41.0
+
Received on Mon Aug 07 2023 - 17:51:32 CEST

This archive was generated by hypermail 2.3.0 : Mon Aug 07 2023 - 18:01:08 CEST