dwm

Dynamic Window Manager by suckless.org (fork)
git clone git://git.ckyln.com/dwm.git
Log | Files | Refs | README | LICENSE

commit 61c1513d7fea622443eeee7c6a19195f94a56c24
parent b6f377c550c9781176c7a90f137f66caf6f3cc70
Author: Cem Keylan <cem@ckyln.com>
Date:   Thu,  5 Sep 2019 21:52:11 +0300

Lots of changes man, idk

Diffstat:
Mconfig.def.h | 23+++++++++++++----------
Mconfig.h | 118+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mdrw.c | 2+-
Mdrw.h | 2+-
Mdwm.c | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 147 insertions(+), 60 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -8,15 +8,16 @@ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; -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] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, +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] = { normfgcolor, normbgcolor, normbordercolor }, + [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, }; /* tagging */ @@ -60,7 +61,7 @@ static const Layout layouts[] = { /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; static Key keys[] = { @@ -68,6 +69,7 @@ static Key keys[] = { { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_b, toggleextrabar, {0} }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, @@ -88,6 +90,7 @@ static Key keys[] = { { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + { MODKEY, XK_F5, xrdb, {.v = NULL } }, { MODKEY, XK_minus, setgaps, {.i = -1 } }, { MODKEY, XK_equal, setgaps, {.i = +1 } }, { MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } }, diff --git a/config.h b/config.h @@ -13,10 +13,16 @@ 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 char normbgcolor[] = "#222222"; +static char normbordercolor[] = "#444444"; +static char normfgcolor[] = "#bbbbbb"; +static char selfgcolor[] = "#eeeeee"; +static char selbordercolor[] = "#005577"; +static char selbgcolor[] = "#005577"; static const 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 */ @@ -53,8 +59,6 @@ static const Layout layouts[] = { /* key definitions */ #define MODKEY Mod1Mask #define WINKEY Mod4Mask -#define BrightnessDown 0x1008ff03 -#define BrightnessUp 0x1008ff02 #define TAGKEYS(KEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ @@ -64,9 +68,10 @@ static const Layout layouts[] = { /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } +#include <X11/XF86keysym.h> /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; static const char *browcmd[] = { "qutebrowser", NULL }; static const char *surfcmd[] = { "surf", NULL }; @@ -82,51 +87,69 @@ static const char *music[] = { "st", "zsh", "-c", "ncmpcpp", NULL }; static const char *mail[] = { "st", "zsh", "-c", "neomutt", NULL }; static const char *fm[] = { "st", "zsh", "-c", "lf", NULL}; static const char *whatsapp[] = { "surf", "web.whatsapp.com", NULL}; +static const char *volup[] = { "pactl", "set-sink-volume", "0", "+5%", NULL}; +static const char *voldown[] = { "pactl", "set-sink-volume", "0", "-5%", NULL}; +static const char *volmute[] = { "pactl", "set-sink-mute", "0", "toggle", NULL}; +static const char *audioplay[] = { "mpctoggle", NULL}; +static const char *audionext[] = { "mpc", "next", NULL}; +static const char *audioprev[] = { "mpc", "prev", NULL }; +static const char *dmenumount[] = { "dmenumount", NULL }; +static const char *dmenuumount[] = { "dmenuumount", NULL }; static Key keys[] = { /* modifier key function argument */ - { MODKEY, XK_u, spawn, {.v = dmenucmd } }, - { WINKEY, XK_e, spawn, {.v = nighttog } }, - { WINKEY|ShiftMask, XK_e, spawn, {.v = nightdis } }, - { WINKEY|ShiftMask, XK_n, spawn, {.v = shutdown } }, - { WINKEY|ShiftMask, XK_r, spawn, {.v = reboot } }, - { WINKEY|ShiftMask, XK_s, spawn, {.v = suspend } }, - { MODKEY, XK_m, spawn, {.v = music } }, - { MODKEY, XK_n, spawn, {.v = fm } }, - { MODKEY|ShiftMask, XK_m, spawn, {.v = mail } }, - { MODKEY, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_o, spawn, {.v = browcmd } }, - { MODKEY, XK_p, spawn, {.v = surfcmd } }, - { MODKEY, XK_d, spawn, {.v = rofiapp } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, spawn, {.v = whatsapp } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY, XK_Return, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY|ShiftMask, XK_q, killclient, {0} }, - { WINKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { WINKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { WINKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { WINKEY, XK_s, setlayout, {.v = &layouts[3]} }, - { WINKEY, XK_d, setlayout, {.v = &layouts[4]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY|ControlMask, XK_u, focusmon, {.i = -1 } }, - { MODKEY|ControlMask, XK_d, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - { WINKEY, XK_j, setgaps, {.i = +1 } }, - { WINKEY, XK_k, setgaps, {.i = -1 } }, - { WINKEY, XK_h, setgaps, {.i = 0 } }, - { WINKEY, XK_i, incnmaster, {.i = +1 } }, - { WINKEY, XK_l, incnmaster, {.i = -1 } }, - { 0, BrightnessUp, spawn, {.v = brup } }, - { 0, BrightnessDown, spawn, {.v = brdown } }, + { MODKEY, XK_u, spawn, {.v = dmenucmd } }, + { WINKEY, XK_e, spawn, {.v = nighttog } }, + { WINKEY|ShiftMask, XK_e, spawn, {.v = nightdis } }, + { WINKEY|ShiftMask, XK_n, spawn, {.v = shutdown } }, + { WINKEY|ShiftMask, XK_r, spawn, {.v = reboot } }, + { WINKEY|ShiftMask, XK_s, spawn, {.v = suspend } }, + { MODKEY, XK_m, spawn, {.v = music } }, + { MODKEY, XK_n, spawn, {.v = fm } }, + { MODKEY|ShiftMask, XK_m, spawn, {.v = mail } }, + { MODKEY, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_o, spawn, {.v = browcmd } }, + { MODKEY, XK_p, spawn, {.v = surfcmd } }, + { MODKEY, XK_d, spawn, {.v = rofiapp } }, + { WINKEY|ShiftMask, XK_m, spawn, {.v = dmenumount } }, + { WINKEY|ShiftMask, XK_u, spawn, {.v = dmenuumount } }, + { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY, XK_i, spawn, {.v = whatsapp } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_q, killclient, {0} }, + { WINKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { WINKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { WINKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { WINKEY, XK_s, setlayout, {.v = &layouts[3]} }, + { WINKEY, XK_d, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, + { MODKEY|ControlMask, XK_u, focusmon, {.i = -1 } }, + { MODKEY|ControlMask, XK_d, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, + { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, + { WINKEY, XK_j, setgaps, {.i = +1 } }, + { WINKEY, XK_k, setgaps, {.i = -1 } }, + { WINKEY, XK_h, setgaps, {.i = 0 } }, + { WINKEY, XK_i, incnmaster, {.i = +1 } }, + { WINKEY, XK_l, incnmaster, {.i = -1 } }, + { 0, XF86XK_MonBrightnessUp, spawn, {.v = brup } }, + { 0, XF86XK_MonBrightnessDown, spawn, {.v = brdown } }, + { 0, XF86XK_AudioRaiseVolume, spawn, {.v = volup } }, + { 0, XF86XK_AudioLowerVolume, spawn, {.v = voldown } }, + { 0, XF86XK_AudioMute, spawn, {.v = volmute } }, + { 0, XF86XK_AudioPlay, spawn, {.v = audioplay } }, + { 0, XF86XK_AudioNext, spawn, {.v = audionext } }, + { 0, XF86XK_AudioPrev, spawn, {.v = audioprev } }, + { MODKEY|ShiftMask, XK_e, quit, {0} }, + { WINKEY, XK_5, xrdb, {.v = NULL } }, TAGKEYS( XK_1, 0) TAGKEYS( XK_2, 1) TAGKEYS( XK_3, 2) @@ -136,7 +159,6 @@ static Key keys[] = { TAGKEYS( XK_7, 6) TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) - { MODKEY|ShiftMask, XK_e, quit, {0} }, }; /* button definitions */ diff --git a/drw.c b/drw.c @@ -207,7 +207,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; diff --git a/drw.h b/drw.h @@ -39,7 +39,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); diff --git a/dwm.c b/dwm.c @@ -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 */ @@ -178,6 +194,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); @@ -235,6 +252,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 */ @@ -1019,6 +1037,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) { Client *c, *t = NULL; @@ -2130,6 +2179,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee) } 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) { Client *c = selmon->sel; @@ -2155,6 +2215,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)