Add xrdb patch

This commit is contained in:
BitHeaven-Official 2023-03-08 09:50:09 +05:00
parent f811e03254
commit d803aa3963
7 changed files with 90 additions and 24 deletions

View File

@ -19,16 +19,17 @@ static const char *fonts[] = {
"Font Awesome 6 Free Solid:style=Solid:size=12:antialias=true:autohint=true",
"Font Awesome 6 Brands Regular:style=Regular:size=12:antialias=true:autohint=true"
};
static const char dmenufont[] = "Ubuntu Mono:size=12";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char *colors[][3] = {
static char dmenufont[] = "Ubuntu Mono:size=12";
static char normbgcolor[] = "#222222";
static char normbordercolor[] = "#444444";
static char normfgcolor[] = "#bbbbbb";
static char selfgcolor[] = "#eeeeee";
static char selbordercolor[] = "#005577";
static char selbgcolor[] = "#005577";
static char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
};
/* tagging */
@ -96,7 +97,7 @@ static const char *volmute[] = { "pactl", "set-sink-mute", "0", "toggle", NULL }
static const char *backlightup[] = { "s", "set-sink-mute", "0", "toggle", NULL };
static const char *dmenucmd[] = { "dmenu_run", "-g", "15", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *dmenucmd[] = { "dmenu_run", "-g", "15", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
static const char *termcmd[] = { "st", NULL };
static Key keys[] = {
@ -137,6 +138,7 @@ static Key keys[] = {
{ SUPERKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
{ SUPERKEY|ShiftMask, XK_t, togglealwaysontop, {0} },
{ SUPERKEY|ShiftMask, XK_f, togglefullscr, {0} },
{ SUPERKEY, XK_F5, xrdb, {.v = NULL } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)

View File

@ -19,16 +19,17 @@ static const char *fonts[] = {
"Font Awesome 6 Free Solid:style=Solid:size=12:antialias=true:autohint=true",
"Font Awesome 6 Brands Regular:style=Regular:size=12:antialias=true:autohint=true"
};
static const char dmenufont[] = "Ubuntu Mono:size=12";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char *colors[][3] = {
static char dmenufont[] = "Ubuntu Mono:size=12";
static char normbgcolor[] = "#222222";
static char normbordercolor[] = "#444444";
static char normfgcolor[] = "#bbbbbb";
static char selfgcolor[] = "#eeeeee";
static char selbordercolor[] = "#005577";
static char selbgcolor[] = "#005577";
static char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
[SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
};
/* tagging */
@ -96,7 +97,7 @@ static const char *volmute[] = { "pactl", "set-sink-mute", "0", "toggle", NULL }
static const char *backlightup[] = { "s", "set-sink-mute", "0", "toggle", NULL };
static const char *dmenucmd[] = { "dmenu_run", "-g", "15", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *dmenucmd[] = { "dmenu_run", "-g", "15", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL };
static const char *termcmd[] = { "st", NULL };
static Key keys[] = {
@ -137,6 +138,7 @@ static Key keys[] = {
{ SUPERKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
{ SUPERKEY|ShiftMask, XK_t, togglealwaysontop, {0} },
{ SUPERKEY|ShiftMask, XK_f, togglefullscr, {0} },
{ SUPERKEY, XK_F5, xrdb, {.v = NULL } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)

2
drw.c
View File

@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
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;
Clr *ret;

2
drw.h
View File

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

BIN
dwm

Binary file not shown.

62
dwm.c
View File

@ -35,6 +35,7 @@
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
@ -56,6 +57,21 @@
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \
if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \
int i = 1; \
for (; i <= 6; i++) { \
if (value.addr[i] < 48) break; \
if (value.addr[i] > 57 && value.addr[i] < 65) break; \
if (value.addr[i] > 70 && value.addr[i] < 97) break; \
if (value.addr[i] > 102) break; \
} \
if (i == 7) { \
strncpy(V, value.addr, 7); \
V[7] = '\0'; \
} \
} \
}
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@ -188,6 +204,7 @@ static void grabkeys(void);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
static void loadxrdb(void);
static void manage(Window w, XWindowAttributes *wa);
static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
@ -246,6 +263,7 @@ static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xrdb(const Arg *arg);
static void zoom(const Arg *arg);
/* variables */
@ -1291,6 +1309,37 @@ killclient(const Arg *arg)
}
}
void
loadxrdb()
{
Display *display;
char * resm;
XrmDatabase xrdb;
char *type;
XrmValue value;
display = XOpenDisplay(NULL);
if (display != NULL) {
resm = XResourceManagerString(display);
if (resm != NULL) {
xrdb = XrmGetStringDatabase(resm);
if (xrdb != NULL) {
XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor);
XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor);
XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor);
XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor);
XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor);
XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor);
}
}
}
XCloseDisplay(display);
}
void
manage(Window w, XWindowAttributes *wa)
{
@ -2501,6 +2550,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
return -1;
}
void
xrdb(const Arg *arg)
{
loadxrdb();
int i;
for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3);
focus(NULL);
arrange(NULL);
}
void
zoom(const Arg *arg)
{
@ -2525,6 +2585,8 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
checkotherwm();
XrmInitialize();
loadxrdb();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1)

BIN
dwm.o

Binary file not shown.