[wiki] [sites] [tabbed][patch] xresources patch || 6d6f7274686f6e

From: <git_AT_suckless.org>
Date: Wed, 17 Mar 2021 12:10:13 +0100

commit fd438a751e76df014278f91a29c56c1f846d52b1
Author: 6d6f7274686f6e <4648531+6d6f7274686f6e_AT_users.noreply.github.com>
Date: Wed Mar 17 11:44:28 2021 +0100

    [tabbed][patch] xresources patch
    
    imported from the st patch of the same name

diff --git a/tools.suckless.org/tabbed/patches/xresources/index.md b/tools.suckless.org/tabbed/patches/xresources/index.md
new file mode 100644
index 00000000..9cbaf313
--- /dev/null
+++ b/tools.suckless.org/tabbed/patches/xresources/index.md
_AT_@ -0,0 +1,17 @@
+xresources
+==========
+
+Description
+-----------
+This patch adds the ability to configure tabbed via Xresources. At startup, tabbed
+will read and apply the resources named in the `resources[]` array in config.h.
+
+Most of the code has been copied from the [st patch of the same name](https://st.suckless.org/patches/xresources).
+
+Download
+--------
+* [tabbed-xresources-20210317-dabf6a2.diff](tabbed-xresources-20210317-dabf6a2.diff)
+
+Author
+-------
+* _AT_6d6f7274686f6e on [Github](https://github.com/6d6f7274686f6e/tabbed-xresources)
diff --git a/tools.suckless.org/tabbed/patches/xresources/tabbed-xresources-20210317-dabf6a2.diff b/tools.suckless.org/tabbed/patches/xresources/tabbed-xresources-20210317-dabf6a2.diff
new file mode 100644
index 00000000..15610a77
--- /dev/null
+++ b/tools.suckless.org/tabbed/patches/xresources/tabbed-xresources-20210317-dabf6a2.diff
_AT_@ -0,0 +1,178 @@
+From 8c48f1564c555bbd21758a3a70a9984e61c34a35 Mon Sep 17 00:00:00 2001
+From: 6d6f7274686f6e <4648531+6d6f7274686f6e_AT_users.noreply.github.com>
+Date: Wed, 17 Mar 2021 10:59:18 +0100
+Subject: [PATCH] xresources support
+
+---
+ config.def.h | 27 ++++++++++++++------
+ tabbed.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 89 insertions(+), 7 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index defa426..244e288 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -1,13 +1,13 @@
+ /* See LICENSE file for copyright and license details. */
+
+ /* appearance */
+-static const char font[] = "monospace:size=9";
+-static const char* normbgcolor = "#222222";
+-static const char* normfgcolor = "#cccccc";
+-static const char* selbgcolor = "#555555";
+-static const char* selfgcolor = "#ffffff";
+-static const char* urgbgcolor = "#111111";
+-static const char* urgfgcolor = "#cc0000";
++static char font[] = "monospace:size=9";
++static char* normbgcolor = "#222222";
++static char* normfgcolor = "#cccccc";
++static char* selbgcolor = "#555555";
++static char* selfgcolor = "#ffffff";
++static char* urgbgcolor = "#111111";
++static char* urgfgcolor = "#cc0000";
+ static const char before[] = "<";
+ static const char after[] = ">";
+ static const char titletrim[] = "...";
+_AT_@ -33,6 +33,19 @@ static Bool npisrelative = False;
+ } \
+ }
+
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "font", STRING, &font },
++ { "color0", STRING, &normbgcolor },
++ { "color4", STRING, &normfgcolor },
++ { "color4", STRING, &selbgcolor },
++ { "color7", STRING, &selfgcolor },
++ { "color2", STRING, &urgbgcolor },
++ { "color3", STRING, &urgfgcolor },
++};
++
+ #define MODKEY ControlMask
+ static Key keys[] = {
+ /* modifier key function argument */
+diff --git a/tabbed.c b/tabbed.c
+index eafe28a..c5bffc7 100644
+--- a/tabbed.c
++++ b/tabbed.c
+_AT_@ -13,6 +13,7 @@
+ #include <X11/Xatom.h>
+ #include <X11/Xlib.h>
+ #include <X11/Xproto.h>
++#include <X11/Xresource.h>
+ #include <X11/Xutil.h>
+ #include <X11/XKBlib.h>
+ #include <X11/Xft/Xft.h>
+_AT_@ -85,11 +86,26 @@ typedef struct {
+ Bool urgent;
+ Bool closed;
+ } Client;
++
++/* Xresources preferences */
++enum resource_type {
++ STRING = 0,
++ INTEGER = 1,
++ FLOAT = 2
++};
++
++typedef struct {
++ char *name;
++ enum resource_type type;
++ void *dst;
++} ResourcePref;
++
+
+ /* function declarations */
+ static void buttonpress(const XEvent *e);
+ static void cleanup(void);
+ static void clientmessage(const XEvent *e);
++static void config_init(void);
+ static void configurenotify(const XEvent *e);
+ static void configurerequest(const XEvent *e);
+ static void createnotify(const XEvent *e);
+_AT_@ -120,6 +136,7 @@ static void move(const Arg *arg);
+ static void movetab(const Arg *arg);
+ static void propertynotify(const XEvent *e);
+ static void resize(int c, int w, int h);
++static int resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
+ static void rotate(const Arg *arg);
+ static void run(void);
+ static void sendxembed(int c, long msg, long detail, long d1, long d2);
+_AT_@ -245,6 +262,23 @@ clientmessage(const XEvent *e)
+ }
+ }
+
++void
++config_init(void)
++{
++ char *resm;
++ XrmDatabase db;
++ ResourcePref *p;
++
++ XrmInitialize();
++ resm = XResourceManagerString(dpy);
++ if (!resm)
++ return;
++
++ db = XrmGetStringDatabase(resm);
++ for (p = resources; p < resources + LENGTH(resources); p++)
++ resource_load(db, p->name, p->type, p->dst);
++}
++
+ void
+ configurenotify(const XEvent *e)
+ {
+_AT_@ -897,6 +931,40 @@ resize(int c, int w, int h)
+ (XEvent *)&ce);
+ }
+
++int
++resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
++{
++ char **sdst = dst;
++ int *idst = dst;
++ float *fdst = dst;
++
++ char fullname[256];
++ char fullclass[256];
++ char *type;
++ XrmValue ret;
++
++ snprintf(fullname, sizeof(fullname), "%s.%s", "tabbed", name);
++ snprintf(fullclass, sizeof(fullclass), "%s.%s", "tabbed", name);
++ fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '++
++ XrmGetResource(db, fullname, fullclass, &type, &ret);
++ if (ret.addr == NULL || strncmp("String", type, 64))
++ return 1;
++
++ switch (rtype) {
++ case STRING:
++ *sdst = ret.addr;
++ break;
++ case INTEGER:
++ *idst = strtoul(ret.addr, NULL, 10);
++ break;
++ case FLOAT:
++ *fdst = strtof(ret.addr, NULL);
++ break;
++ }
++ return 0;
++}
++
+ void
+ rotate(const Arg *arg)
+ {
+_AT_@ -1354,6 +1422,7 @@ main(int argc, char *argv[])
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("%s: cannot open display
", argv0);
+
++ config_init();
+ setup();
+ printf("0x%lx
", win);
+ fflush(NULL);
+--
+2.30.2
+
Received on Wed Mar 17 2021 - 12:10:13 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 17 2021 - 12:12:45 CET