Adding the xresources patch
This commit is contained in:
@@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
|
||||
|
||||
### Changelog:
|
||||
|
||||
2025-02-25 - Added the xresources patch
|
||||
|
||||
2024-10-30 - Added the border rule patch
|
||||
|
||||
2024-07-11 - Added variant of the launcher patch
|
||||
@@ -887,6 +889,9 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
|
||||
- [xrdb](http://dwm.suckless.org/patches/xrdb/)
|
||||
- allows dwm to read colors from xrdb (.Xresources) during runtime
|
||||
|
||||
- [xresources](https://dwm.suckless.org/patches/xresources/)
|
||||
- allows dwm to read strings, integers and float values from xrdb (.Xresources) during runtime
|
||||
|
||||
- [zoomfloating](https://www.reddit.com/r/suckless/comments/ie5fe3/zoomfloating_my_own_simple_original_patch/)
|
||||
- a simple patch that allows floating windows to be zoomed into the master stack position
|
||||
|
||||
|
||||
114
config.def.h
114
config.def.h
@@ -906,6 +906,108 @@ static const Key on_empty_keys[] = {
|
||||
};
|
||||
#endif // ON_EMPTY_KEYS_PATCH
|
||||
|
||||
#if XRESOURCES_PATCH
|
||||
/*
|
||||
* Xresources preferences to load at startup.
|
||||
*
|
||||
* Name Type Address
|
||||
* ------------------------------------------------
|
||||
* "nmaster" INTEGER &nmaster
|
||||
* "mfact" FLOAT &mfact
|
||||
* "color1" STRING &color1
|
||||
*
|
||||
* In the Xresources file setting resources shoud be prefixed with "dwm.", e.g.
|
||||
*
|
||||
* dwm.nmaster: 1
|
||||
* dwm.mfact: 0.50
|
||||
* dwm.color1: #FA6EFA
|
||||
*
|
||||
* Note that the const qualifier must be removed from the variables if you plan on
|
||||
* overriding them with values from Xresources. While resources can be reloaded
|
||||
* using the xrdb function some changes may only take effect following a restart.
|
||||
*/
|
||||
ResourcePref resources[] = {
|
||||
/* Resource name Type Address */
|
||||
{ "normfgcolor", STRING, &normfgcolor },
|
||||
{ "normbgcolor", STRING, &normbgcolor },
|
||||
{ "normbordercolor", STRING, &normbordercolor },
|
||||
{ "normfloatcolor", STRING, &normfloatcolor },
|
||||
{ "selfgcolor", STRING, &selfgcolor },
|
||||
{ "selbgcolor", STRING, &selbgcolor },
|
||||
{ "selbordercolor", STRING, &selbordercolor },
|
||||
{ "selfloatcolor", STRING, &selfloatcolor },
|
||||
{ "titlenormfgcolor", STRING, &titlenormfgcolor },
|
||||
{ "titlenormbgcolor", STRING, &titlenormbgcolor },
|
||||
{ "titlenormbordercolor", STRING, &titlenormbordercolor },
|
||||
{ "titlenormfloatcolor", STRING, &titlenormfloatcolor },
|
||||
{ "titleselfgcolor", STRING, &titleselfgcolor },
|
||||
{ "titleselbgcolor", STRING, &titleselbgcolor },
|
||||
{ "titleselbordercolor", STRING, &titleselbordercolor },
|
||||
{ "titleselfloatcolor", STRING, &titleselfloatcolor },
|
||||
{ "tagsnormfgcolor", STRING, &tagsnormfgcolor },
|
||||
{ "tagsnormbgcolor", STRING, &tagsnormbgcolor },
|
||||
{ "tagsnormbordercolor", STRING, &tagsnormbordercolor },
|
||||
{ "tagsnormfloatcolor", STRING, &tagsnormfloatcolor },
|
||||
{ "tagsselfgcolor", STRING, &tagsselfgcolor },
|
||||
{ "tagsselbgcolor", STRING, &tagsselbgcolor },
|
||||
{ "tagsselbordercolor", STRING, &tagsselbordercolor },
|
||||
{ "tagsselfloatcolor", STRING, &tagsselfloatcolor },
|
||||
{ "hidnormfgcolor", STRING, &hidnormfgcolor },
|
||||
{ "hidnormbgcolor", STRING, &hidnormbgcolor },
|
||||
{ "hidselfgcolor", STRING, &hidselfgcolor },
|
||||
{ "hidselbgcolor", STRING, &hidselbgcolor },
|
||||
{ "urgfgcolor", STRING, &urgfgcolor },
|
||||
{ "urgbgcolor", STRING, &urgbgcolor },
|
||||
{ "urgbordercolor", STRING, &urgbordercolor },
|
||||
{ "urgfloatcolor", STRING, &urgfloatcolor },
|
||||
#if RENAMED_SCRATCHPADS_PATCH
|
||||
{ "scratchselfgcolor", STRING, &scratchselfgcolor },
|
||||
{ "scratchselbgcolor", STRING, &scratchselbgcolor },
|
||||
{ "scratchselbordercolor", STRING, &scratchselbordercolor },
|
||||
{ "scratchselfloatcolor", STRING, &scratchselfloatcolor },
|
||||
{ "scratchnormfgcolor", STRING, &scratchnormfgcolor },
|
||||
{ "scratchnormbgcolor", STRING, &scratchnormbgcolor },
|
||||
{ "scratchnormbordercolor", STRING, &scratchnormbordercolor },
|
||||
{ "scratchnormfloatcolor", STRING, &scratchnormfloatcolor },
|
||||
#endif // RENAMED_SCRATCHPADS_PATCH
|
||||
#if BAR_FLEXWINTITLE_PATCH
|
||||
{ "normTTBbgcolor", STRING, &normTTBbgcolor },
|
||||
{ "normLTRbgcolor", STRING, &normLTRbgcolor },
|
||||
{ "normMONObgcolor", STRING, &normMONObgcolor },
|
||||
{ "normGRIDbgcolor", STRING, &normGRIDbgcolor },
|
||||
{ "normGRD1bgcolor", STRING, &normGRD1bgcolor },
|
||||
{ "normGRD2bgcolor", STRING, &normGRD2bgcolor },
|
||||
{ "normGRDMbgcolor", STRING, &normGRDMbgcolor },
|
||||
{ "normHGRDbgcolor", STRING, &normHGRDbgcolor },
|
||||
{ "normDWDLbgcolor", STRING, &normDWDLbgcolor },
|
||||
{ "normSPRLbgcolor", STRING, &normSPRLbgcolor },
|
||||
{ "normfloatbgcolor", STRING, &normfloatbgcolor },
|
||||
{ "actTTBbgcolor", STRING, &actTTBbgcolor },
|
||||
{ "actLTRbgcolor", STRING, &actLTRbgcolor },
|
||||
{ "actMONObgcolor", STRING, &actMONObgcolor },
|
||||
{ "actGRIDbgcolor", STRING, &actGRIDbgcolor },
|
||||
{ "actGRD1bgcolor", STRING, &actGRD1bgcolor },
|
||||
{ "actGRD2bgcolor", STRING, &actGRD2bgcolor },
|
||||
{ "actGRDMbgcolor", STRING, &actGRDMbgcolor },
|
||||
{ "actHGRDbgcolor", STRING, &actHGRDbgcolor },
|
||||
{ "actDWDLbgcolor", STRING, &actDWDLbgcolor },
|
||||
{ "actSPRLbgcolor", STRING, &actSPRLbgcolor },
|
||||
{ "actfloatbgcolor", STRING, &actfloatbgcolor },
|
||||
{ "selTTBbgcolor", STRING, &selTTBbgcolor },
|
||||
{ "selLTRbgcolor", STRING, &selLTRbgcolor },
|
||||
{ "selMONObgcolor", STRING, &selMONObgcolor },
|
||||
{ "selGRIDbgcolor", STRING, &selGRIDbgcolor },
|
||||
{ "selGRD1bgcolor", STRING, &selGRD1bgcolor },
|
||||
{ "selGRD2bgcolor", STRING, &selGRD2bgcolor },
|
||||
{ "selGRDMbgcolor", STRING, &selGRDMbgcolor },
|
||||
{ "selHGRDbgcolor", STRING, &selHGRDbgcolor },
|
||||
{ "selDWDLbgcolor", STRING, &selDWDLbgcolor },
|
||||
{ "selSPRLbgcolor", STRING, &selSPRLbgcolor },
|
||||
{ "selfloatbgcolor", STRING, &selfloatbgcolor },
|
||||
#endif // BAR_FLEXWINTITLE_PATCH
|
||||
};
|
||||
#endif // XRESOURCES_PATCH
|
||||
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
#if KEYMODES_PATCH
|
||||
@@ -1084,9 +1186,9 @@ static const Key keys[] = {
|
||||
#if WINVIEW_PATCH
|
||||
{ MODKEY, XK_o, winview, {0} },
|
||||
#endif // WINVIEW_PATCH
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRDB_PATCH || XRESOURCES_PATCH
|
||||
{ MODKEY|ShiftMask, XK_F5, xrdb, {.v = NULL } },
|
||||
#endif // XRDB_PATCH
|
||||
#endif // XRDB_PATCH | XRESOURCES_PATCH
|
||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||
@@ -1586,9 +1688,9 @@ static const Signal signals[] = {
|
||||
#if WINVIEW_PATCH
|
||||
{ "winview", winview },
|
||||
#endif // WINVIEW_PATCH
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRDB_PATCH || XRESOURCES_PATCH
|
||||
{ "xrdb", xrdb },
|
||||
#endif // XRDB_PATCH
|
||||
#endif // XRDB_PATCH | XRESOURCES_PATCH
|
||||
#if TAGOTHERMONITOR_PATCH
|
||||
{ "tagnextmonex", tagnextmonex },
|
||||
{ "tagprevmonex", tagprevmonex },
|
||||
@@ -1786,8 +1888,8 @@ static IPCCommand ipccommands[] = {
|
||||
#if WINVIEW_PATCH
|
||||
IPCCOMMAND( winview, 1, {ARG_TYPE_NONE} ),
|
||||
#endif // WINVIEW_PATCH
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRDB_PATCH || XRESOURCES_PATCH
|
||||
IPCCOMMAND( xrdb, 1, {ARG_TYPE_NONE} ),
|
||||
#endif // XRDB_PATCH
|
||||
#endif // XRDB_PATCH | XRESOURCES_PATCH
|
||||
};
|
||||
#endif // IPC_PATCH
|
||||
|
||||
6
dwm.c
6
dwm.c
@@ -5354,10 +5354,10 @@ main(int argc, char *argv[])
|
||||
die("dwm: cannot get xcb connection\n");
|
||||
#endif // SWALLOW_PATCH
|
||||
checkotherwm();
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRESOURCES_PATCH || XRDB_PATCH
|
||||
XrmInitialize();
|
||||
loadxrdb();
|
||||
#endif // XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
load_xresources();
|
||||
#endif // XRESOURCES_PATCH | XRDB_PATCH
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
autostart_exec();
|
||||
#endif // COOL_AUTOSTART_PATCH
|
||||
|
||||
@@ -346,7 +346,9 @@
|
||||
#if XKB_PATCH
|
||||
#include "xkb.c"
|
||||
#endif
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRESOURCES_PATCH
|
||||
#include "xresources.c"
|
||||
#elif XRDB_PATCH
|
||||
#include "xrdb.c"
|
||||
#endif
|
||||
#if DRAGMFACT_PATCH
|
||||
|
||||
@@ -348,7 +348,9 @@
|
||||
#if XKB_PATCH
|
||||
#include "xkb.h"
|
||||
#endif
|
||||
#if XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
#if XRESOURCES_PATCH
|
||||
#include "xresources.h"
|
||||
#elif XRDB_PATCH
|
||||
#include "xrdb.h"
|
||||
#endif
|
||||
/* Layouts */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
void
|
||||
loadxrdb()
|
||||
load_xresources()
|
||||
{
|
||||
Display *display;
|
||||
char * resm;
|
||||
@@ -123,7 +123,7 @@ loadxrdb()
|
||||
void
|
||||
xrdb(const Arg *arg)
|
||||
{
|
||||
loadxrdb();
|
||||
load_xresources();
|
||||
int i;
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
scheme[i] = drw_scm_create(drw, colors[i],
|
||||
|
||||
@@ -16,7 +16,5 @@
|
||||
} \
|
||||
}
|
||||
|
||||
static void loadxrdb(void);
|
||||
static void load_xresources(void);
|
||||
static void xrdb(const Arg *arg);
|
||||
|
||||
|
||||
|
||||
74
patch/xresources.c
Normal file
74
patch/xresources.c
Normal file
@@ -0,0 +1,74 @@
|
||||
void
|
||||
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
{
|
||||
char *sdst = NULL;
|
||||
int *idst = NULL;
|
||||
float *fdst = NULL;
|
||||
|
||||
sdst = dst;
|
||||
idst = dst;
|
||||
fdst = dst;
|
||||
|
||||
char fullname[256];
|
||||
char *type;
|
||||
XrmValue ret;
|
||||
|
||||
snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
|
||||
fullname[sizeof(fullname) - 1] = '\0';
|
||||
|
||||
XrmGetResource(db, fullname, "*", &type, &ret);
|
||||
if (!(ret.addr == NULL || strncmp("String", type, 64)))
|
||||
{
|
||||
switch (rtype) {
|
||||
case STRING:
|
||||
strcpy(sdst, ret.addr);
|
||||
break;
|
||||
case INTEGER:
|
||||
*idst = strtoul(ret.addr, NULL, 10);
|
||||
break;
|
||||
case FLOAT:
|
||||
*fdst = strtof(ret.addr, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
load_xresources(void)
|
||||
{
|
||||
Display *display;
|
||||
char *resm;
|
||||
XrmDatabase db;
|
||||
ResourcePref *p;
|
||||
|
||||
display = XOpenDisplay(NULL);
|
||||
resm = XResourceManagerString(display);
|
||||
if (!resm)
|
||||
return;
|
||||
|
||||
db = XrmGetStringDatabase(resm);
|
||||
for (p = resources; p < resources + LENGTH(resources); p++)
|
||||
resource_load(db, p->name, p->type, p->dst);
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
|
||||
void
|
||||
xrdb(const Arg *arg)
|
||||
{
|
||||
int i;
|
||||
load_xresources();
|
||||
for (i = 0; i < LENGTH(colors); i++)
|
||||
scheme[i] = drw_scm_create(drw, colors[i],
|
||||
#if BAR_ALPHA_PATCH
|
||||
alphas[i],
|
||||
#endif // BAR_ALPHA_PATCH
|
||||
ColCount
|
||||
);
|
||||
#if BAR_SYSTRAY_PATCH && !BAR_ALPHA_PATCH
|
||||
if (systray) {
|
||||
XMoveWindow(dpy, systray->win, -32000, -32000);
|
||||
}
|
||||
#endif // BAR_SYSTRAY_PATCH
|
||||
arrange(NULL);
|
||||
focus(NULL);
|
||||
}
|
||||
18
patch/xresources.h
Normal file
18
patch/xresources.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
/* Xresources preferences */
|
||||
enum resource_type {
|
||||
STRING = 0,
|
||||
INTEGER = 1,
|
||||
FLOAT = 2
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
enum resource_type type;
|
||||
void *dst;
|
||||
} ResourcePref;
|
||||
|
||||
static void load_xresources(void);
|
||||
static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
|
||||
static void xrdb(const Arg *arg);
|
||||
@@ -1433,6 +1433,12 @@
|
||||
*/
|
||||
#define XRDB_PATCH 0
|
||||
|
||||
/* This patch allows for integer, float and string settings to be loaded from Xresources.
|
||||
* Xresources takes precedence over xrdb.
|
||||
* https://dwm.suckless.org/patches/xresources/
|
||||
*/
|
||||
#define XRESOURCES_PATCH 0
|
||||
|
||||
/* Simple patch that allows floating windows to be zoomed into the master stack position.
|
||||
* https://www.reddit.com/r/suckless/comments/ie5fe3/zoomfloating_my_own_simple_original_patch/
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user