added xresources patch

This commit is contained in:
Victor Ișan 2026-05-18 12:45:45 +02:00
parent 1c0de94714
commit 2e819b2be0
6 changed files with 127 additions and 40 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
*.o *.o
*.orig
*.rej
dwm

View File

@ -1,21 +1,23 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
/* appearance */ /* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */ static unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */ static unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */ static int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */ static int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "monospace:size=10" }; static char font[] = "monospace:size=10";
static const char dmenufont[] = "monospace:size=10"; static char dmenufont[] = "monospace:size=10";
static const char col_gray1[] = "#222222"; static const char *fonts[] = { font };
static const char col_gray2[] = "#444444"; static char normbgcolor[] = "#222222";
static const char col_gray3[] = "#bbbbbb"; static char normbordercolor[] = "#444444";
static const char col_gray4[] = "#eeeeee"; static char normfgcolor[] = "#bbbbbb";
static const char col_cyan[] = "#005577"; static char selfgcolor[] = "#eeeeee";
static const char *colors[][3] = { static char selbordercolor[] = "#005577";
/* fg bg border */ static char selbgcolor[] = "#005577";
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, static char *colors[][3] = {
[SchemeSel] = { col_gray4, col_cyan, col_cyan }, /* fg bg border */
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
}; };
/* tagging */ /* tagging */
@ -32,9 +34,9 @@ static const Rule rules[] = {
}; };
/* layout(s) */ /* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */ static int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */ static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */

View File

@ -1,8 +1,8 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
/* Constants */ /* Constants */
#define TERMINAL "st" #define TERMINAL "alacritty"
#define TERMCLASS "St" #define TERMCLASS "Alacritty"
#define BROWSER "firefox" #define BROWSER "firefox"
/* appearance */ /* appearance */
@ -12,6 +12,7 @@ static int swallowfloating = 0; /* 1 means swallow floating wind
static int showbar = 1; /* 0 means no bar */ static int showbar = 1; /* 0 means no bar */
static int topbar = 1; /* 0 means bottom bar */ static int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "IntoneMonoNerdFontMono:size=13", "NotoColorEmoji:pixelsize=10:antialias=true:autohint=true", "font-awesome" }; static const char *fonts[] = { "IntoneMonoNerdFontMono:size=13", "NotoColorEmoji:pixelsize=10:antialias=true:autohint=true", "font-awesome" };
static char font[] = "IntoneMonoNerdFontMono:size=13";
static char dmenufont[] = "IntoneMonoNerdFontMono:size=13"; static char dmenufont[] = "IntoneMonoNerdFontMono:size=13";
static char normbgcolor[] = "#222222"; static char normbgcolor[] = "#222222";
static char normbordercolor[] = "#444444"; static char normbordercolor[] = "#444444";
@ -19,7 +20,7 @@ static char normfgcolor[] = "#bbbbbb";
static char selfgcolor[] = "#eeeeee"; static char selfgcolor[] = "#eeeeee";
static char selbordercolor[] = "#770000"; static char selbordercolor[] = "#770000";
static char selbgcolor[] = "#005577"; static char selbgcolor[] = "#005577";
static const char *colors[][3] = { static char *colors[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
@ -78,23 +79,23 @@ static const char *termcmd[] = { TERMINAL, NULL };
/* /*
* Xresources preferences to load at startup * Xresources preferences to load at startup
*/ */
//ResourcePref resources[] = { ResourcePref resources[] = {
// { "font", STRING, &font }, { "font", STRING, &font },
// { "dmenufont", STRING, &dmenufont }, { "dmenufont", STRING, &dmenufont },
// { "normbgcolor", STRING, &normbgcolor }, { "normbgcolor", STRING, &normbgcolor },
// { "normbordercolor", STRING, &normbordercolor }, { "normbordercolor", STRING, &normbordercolor },
// { "normfgcolor", STRING, &normfgcolor }, { "normfgcolor", STRING, &normfgcolor },
// { "selbgcolor", STRING, &selbgcolor }, { "selbgcolor", STRING, &selbgcolor },
// { "selbordercolor", STRING, &selbordercolor }, { "selbordercolor", STRING, &selbordercolor },
// { "selfgcolor", STRING, &selfgcolor }, { "selfgcolor", STRING, &selfgcolor },
// { "borderpx", INTEGER, &borderpx }, { "borderpx", INTEGER, &borderpx },
// { "snap", INTEGER, &snap }, { "snap", INTEGER, &snap },
// { "showbar", INTEGER, &showbar }, { "showbar", INTEGER, &showbar },
// { "topbar", INTEGER, &topbar }, { "topbar", INTEGER, &topbar },
// { "nmaster", INTEGER, &nmaster }, { "nmaster", INTEGER, &nmaster },
// { "resizehints", INTEGER, &resizehints }, { "resizehints", INTEGER, &resizehints },
// { "mfact", FLOAT, &mfact }, { "mfact", FLOAT, &mfact },
//}; };
static const Key keys[] = { static const Key keys[] = {
/* modifier key function argument */ /* modifier key function argument */
@ -125,6 +126,15 @@ static const Key keys[] = {
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = +1 } },
{ MODKEY, XK_space, zoom, {0} }, { MODKEY, XK_space, zoom, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
TAGKEYS( XK_4, 3)
TAGKEYS( XK_5, 4)
TAGKEYS( XK_6, 5)
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} }, { MODKEY|ShiftMask, XK_q, quit, {0} },
}; };

2
drw.c
View File

@ -180,7 +180,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
/* Create color schemes. */ /* Create color schemes. */
Clr * Clr *
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
{ {
size_t i; size_t i;
Clr *ret; Clr *ret;

2
drw.h
View File

@ -41,7 +41,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */ /* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
void drw_clr_free(Drw *drw, Clr *c); void drw_clr_free(Drw *drw, Clr *c);
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
void drw_scm_free(Drw *drw, Clr *scm, size_t clrcount); void drw_scm_free(Drw *drw, Clr *scm, size_t clrcount);
/* Cursor abstraction */ /* Cursor abstraction */

72
dwm.c
View File

@ -36,6 +36,7 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Xproto.h> #include <X11/Xproto.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xresource.h>
#ifdef XINERAMA #ifdef XINERAMA
#include <X11/extensions/Xinerama.h> #include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */ #endif /* XINERAMA */
@ -140,6 +141,19 @@ typedef struct {
int monitor; int monitor;
} Rule; } Rule;
/* Xresources preferences */
enum resource_type {
STRING = 0,
INTEGER = 1,
FLOAT = 2
};
typedef struct {
char *name;
enum resource_type type;
void *dst;
} ResourcePref;
/* function declarations */ /* function declarations */
static void applyrules(Client *c); static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@ -232,6 +246,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
static void load_xresources(void);
static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
@ -2140,6 +2156,60 @@ zoom(const Arg *arg)
pop(c); pop(c);
} }
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);
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -2152,6 +2222,8 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL))) if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display"); die("dwm: cannot open display");
checkotherwm(); checkotherwm();
XrmInitialize();
load_xresources();
setup(); setup();
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1) if (pledge("stdio rpath proc exec", NULL) == -1)