diff options
author | Philip Wittamore <philip@wittamore.com> | 2025-05-21 17:45:02 +0200 |
---|---|---|
committer | Philip Wittamore <philip@wittamore.com> | 2025-05-21 17:45:02 +0200 |
commit | ed58bff91b2d872a3c5db3db2e86015640d7c3db (patch) | |
tree | 673dfd1961495e35cf4b366e5c79f34dbe56ab4f | |
parent | 85bae18bde133934db189edf020ef43d38ccbdc6 (diff) | |
download | dwm-ed58bff91b2d872a3c5db3db2e86015640d7c3db.tar.gz dwm-ed58bff91b2d872a3c5db3db2e86015640d7c3db.tar.bz2 dwm-ed58bff91b2d872a3c5db3db2e86015640d7c3db.zip |
update
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | config.def.h | 106 | ||||
-rw-r--r-- | config.h | 82 | ||||
-rw-r--r-- | config.mk | 3 | ||||
-rw-r--r-- | drw.c | 2 | ||||
-rw-r--r-- | drw.h | 2 | ||||
-rw-r--r-- | dwm.c | 379 |
7 files changed, 458 insertions, 130 deletions
@@ -1,12 +1,6 @@ -# The DWM 6.5 window manager with my modifications +# The DWM 6.5 window manager with the following patches -## dwm.c -- A function has been added for circulating from tag to tag +- xrdb +- swallow +- rotatestack -## config.h -- The key bindings are adapted to a French keyboard -- Thinkpad keys are taken into account -- The colours are grabbed from Pywal16 -- Super+Shift+Right/Left enables tag circulation -- Super+Right/Left enables window circulation within a tag -- Other key bindings diff --git a/config.def.h b/config.def.h index 9efa774..d8e7992 100644 --- a/config.def.h +++ b/config.def.h @@ -1,34 +1,39 @@ /* See LICENSE file for copyright and license details. */ +#include <X11/XF86keysym.h> /* appearance */ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ +static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ 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 const char *fonts[] = { "JetBrainsMono Nerd Font Mono:size=11" }; +static const char dmenufont[] = "JetBrainsMono Nerd Font Mono:size=11"; +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 */ -static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *tags[] = { "Ⅰ" ,"Ⅱ", "Ⅲ", "Ⅳ"}; //, "5", "6", "7", "8", "9" }; static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating monitor */ - { "Gimp", NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + /* class instance title tags mask isfloating isterminal noswallow monitor */ + { "Gimp", NULL, NULL, 0, 1, 0, 0, -1 }, + { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, + { "St", NULL, NULL, 0, 0, 1, 0, -1 }, + { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ }; /* layout(s) */ @@ -39,13 +44,13 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win static const Layout layouts[] = { /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ - { "><>", NULL }, /* no layout function means floating behavior */ - { "[M]", monocle }, + { "Ƭ", tile }, /* first entry is default */ + { "Φ", NULL }, /* no layout function means floating behavior */ + { "µ", monocle }, /* everything is maximised */ }; /* key definitions */ -#define MODKEY Mod1Mask +#define MODKEY Mod4Mask #define TAGKEYS(KEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ @@ -57,44 +62,57 @@ 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", selbgcolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; static const Key keys[] = { /* modifier key function argument */ - { MODKEY, XK_p, spawn, {.v = dmenucmd } }, - { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_i, incnmaster, {.i = +1 } }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, - { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { 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, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - 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, XK_semicolon, focusmon, {.i = +1 } }, + { MODKEY, XK_F5, xrdb, {.v = NULL } }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, + { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, { MODKEY|ShiftMask, XK_q, quit, {0} }, + { MODKEY|ShiftMask, XK_x, spawn, SHCMD("rofi -show power-menu -modi power-menu:rofi-power-menu") }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY|ShiftMask, XK_agrave, tag, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, + { MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } }, + { 0, XF86XK_AudioMute, spawn, SHCMD("dwm-audio voltoggle") }, + { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("dwm-audio volquieter") }, + { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("dwm-audio vollouder") }, + { 0, XF86XK_AudioMicMute, spawn, SHCMD("dwm-audio mictoggle") }, + { 0, XF86XK_MonBrightnessDown, spawn, SHCMD("brightnessctl set 10%-") }, + { 0, XF86XK_MonBrightnessUp, spawn, SHCMD("brightnessctl set 10%+") }, + { 0, XF86XK_Launch1, spawn, SHCMD("dpower") }, + { 0, XK_Menu, spawn, SHCMD("dpower") }, + { 0, XK_Print, spawn, SHCMD("screenshot.sh") }, + TAGKEYS( XK_ampersand, 0) + TAGKEYS( XK_eacute, 1) + TAGKEYS( XK_quotedbl, 2) + TAGKEYS( XK_apostrophe, 3) + TAGKEYS( XK_parenleft, 4) + TAGKEYS( XK_minus, 5) + TAGKEYS( XK_egrave, 6) + TAGKEYS( XK_underscore, 7) + TAGKEYS( XK_ccedilla, 8) + TAGKEYS( XK_agrave, 9) }; /* button definitions */ @@ -4,13 +4,22 @@ /* appearance */ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ +static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "JetBrainsMono Nerd Font Mono:size=11" }; static const char dmenufont[] = "JetBrainsMono Nerd Font Mono:size=11"; - -/* Pywal16 */ -#include "/home/philip/.cache/wal/colors-wal-dwm.h" +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 */ static const char *tags[] = { "Ⅰ" ,"Ⅱ", "Ⅲ", "Ⅳ"}; //, "5", "6", "7", "8", "9" }; @@ -20,13 +29,11 @@ static const Rule rules[] = { * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating monitor */ - { "ghostty", NULL, NULL, 1 << 0, 0, -1 }, - { "librewolf", NULL, NULL, 1 << 1, 0, -1 }, - { "Chromium", NULL, NULL, 1 << 1, 0, -1 }, - { "Gimp", NULL, NULL, 1 << 2, 1, -1 }, - { "gThumb", NULL, NULL, 1 << 2, 1, -1 }, - { "Galculator", NULL, NULL, 1 << 8, 1, -1 }, + /* class instance title tags mask isfloating isterminal noswallow monitor */ + { "Gimp", NULL, NULL, 0, 1, 0, 0, -1 }, + { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, + { "St", NULL, NULL, 0, 0, 1, 0, -1 }, + { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ }; /* layout(s) */ @@ -43,7 +50,6 @@ static const Layout layouts[] = { }; /* key definitions */ -/* modifiers are ShiftMask, LockMask, ControlMask, Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask and Mod5Mask */ #define MODKEY Mod4Mask #define TAGKEYS(KEY,TAG) \ { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ @@ -56,55 +62,47 @@ 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", norm_bg, "-nf", norm_fg, "-sb", sel_bg, "-sf", sel_fg, NULL }; -static const char *termcmd[] = { "ghostty", NULL }; -static const char *wwwcmd[] = { "librewolf", NULL }; -static const char *brighter[] = { "brightnessctl", "set", "10%+", NULL }; -static const char *dimmer[] = { "brightnessctl", "set", "10%-", NULL }; -static const char *bluetooth[] = { "blueman-manager", NULL }; -static const char *scrotcmd[] = { "screenshot.sh", NULL}; +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; +static const char *termcmd[] = { "st", NULL }; static const Key keys[] = { /* modifier key function argument */ - { 0, XF86XK_AudioMute, spawn, SHCMD("~/.local/bin/dwm-audio voltoggle") }, - { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("~/.local/bin/dwm-audio volquieter") }, - { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("~/.local/bin/dwm-audio vollouder") }, - { 0, XF86XK_AudioMicMute, spawn, SHCMD("~/.local/bin/dwm-audio mictoggle") }, - { 0, XF86XK_MonBrightnessDown, spawn, {.v = dimmer } }, - { 0, XF86XK_MonBrightnessUp, spawn, {.v = brighter } }, - { 0, XF86XK_Launch1, spawn, SHCMD("rofi -show power-menu -modi power-menu:rofi-power-menu") }, - { 0, XK_Menu, spawn, SHCMD("rofi -show power-menu -modi power-menu:rofi-power-menu") }, - { 0, XK_Print, spawn, {.v = scrotcmd } }, { MODKEY, XK_b, togglebar, {0} }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_i, incnmaster, {.i = +1 } }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_r, spawn, SHCMD("rofi -show run") }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_p, spawn, {.v = dmenucmd } }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_w, spawn, {.v = wwwcmd } }, - { MODKEY, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_Right, focusstack, {.i = +1 } }, - { MODKEY, XK_Left, focusstack, {.i = -1 } }, + { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_space, setlayout, {0} }, - { MODKEY, XK_agrave, view, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_semicolon, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_b, spawn, {.v = bluetooth } }, + { MODKEY, XK_semicolon, focusmon, {.i = +1 } }, + { MODKEY, XK_F5, xrdb, {.v = NULL } }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, - { MODKEY|ShiftMask, XK_Right, view_adjacent, {.i = +1 } }, - { MODKEY|ShiftMask, XK_Left, view_adjacent, {.i = -1 } }, - { MODKEY|ShiftMask, XK_Return, zoom, {0} }, + { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, + { MODKEY|ShiftMask, XK_q, quit, {0} }, + { MODKEY|ShiftMask, XK_x, spawn, SHCMD("rofi -show power-menu -modi power-menu:rofi-power-menu") }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY|ShiftMask, XK_agrave, tag, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_q, quit, {0} }, - { MODKEY|ShiftMask, XK_x, spawn, SHCMD("rofi -show power-menu -modi power-menu:rofi-power-menu") }, + { MODKEY|ShiftMask, XK_semicolon, tagmon, {.i = +1 } }, + { 0, XF86XK_AudioMute, spawn, SHCMD("dwm-audio voltoggle") }, + { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("dwm-audio volquieter") }, + { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("dwm-audio vollouder") }, + { 0, XF86XK_AudioMicMute, spawn, SHCMD("dwm-audio mictoggle") }, + { 0, XF86XK_MonBrightnessDown, spawn, SHCMD("brightnessctl set 10%-") }, + { 0, XF86XK_MonBrightnessUp, spawn, SHCMD("brightnessctl set 10%+") }, + { 0, XF86XK_Launch1, spawn, SHCMD("dpower") }, + { 0, XK_Menu, spawn, SHCMD("dpower") }, + { 0, XK_Print, spawn, SHCMD("screenshot.sh") }, TAGKEYS( XK_ampersand, 0) TAGKEYS( XK_eacute, 1) TAGKEYS( XK_quotedbl, 2) @@ -132,7 +130,5 @@ static const Button buttons[] = { { ClkTagBar, 0, Button3, toggleview, {0} }, { ClkTagBar, MODKEY, Button1, tag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, - { ClkTagBar, 0, Button4, view_adjacent, {.i = -1 } }, - { ClkTagBar, 0, Button5, view_adjacent, {.i = +1 } }, }; @@ -20,10 +20,11 @@ FREETYPEINC = /usr/include/freetype2 # OpenBSD (uncomment) #FREETYPEINC = ${X11INC}/freetype2 #MANPREFIX = ${PREFIX}/man +#KVMLIB = -lkvm # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res ${KVMLIB} # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} @@ -181,7 +181,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; @@ -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); @@ -35,11 +35,18 @@ #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> #endif /* XINERAMA */ #include <X11/Xft/Xft.h> +#include <X11/Xlib-xcb.h> +#include <xcb/res.h> +#ifdef __OpenBSD__ +#include <sys/sysctl.h> +#include <kvm.h> +#endif /* __OpenBSD */ #include "drw.h" #include "util.h" @@ -55,10 +62,25 @@ #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 */ -enum { SchemeNorm, SchemeSel, SchemeWarn, SchemeUrgent }; /* color schemes */ +enum { SchemeNorm, SchemeSel }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ @@ -91,9 +113,11 @@ struct Client { int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid; int bw, oldbw; unsigned int tags; - int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow; + pid_t pid; Client *next; Client *snext; + Client *swallowing; Monitor *mon; Window win; }; @@ -137,6 +161,8 @@ typedef struct { const char *title; unsigned int tags; int isfloating; + int isterminal; + int noswallow; int monitor; } Rule; @@ -162,6 +188,8 @@ static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); +static void enqueue(Client *c); +static void enqueuestack(Client *c); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -177,6 +205,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); @@ -192,6 +221,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void restack(Monitor *m); +static void rotatestack(const Arg *arg); static void run(void); static void scan(void); static int sendevent(Client *c, Atom proto); @@ -231,8 +261,14 @@ 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); -static void view_adjacent(const Arg *arg); + +static pid_t getparentprocess(pid_t p); +static int isdescprocess(pid_t p, pid_t c); +static Client *swallowingclient(Window w); +static Client *termforwin(const Client *c); +static pid_t winpid(Window w); /* variables */ static const char broken[] = "broken"; @@ -268,6 +304,8 @@ static Drw *drw; static Monitor *mons, *selmon; static Window root, wmcheckwin; +static xcb_connection_t *xcon; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -297,6 +335,8 @@ applyrules(Client *c) && (!r->class || strstr(class, r->class)) && (!r->instance || strstr(instance, r->instance))) { + c->isterminal = r->isterminal; + c->noswallow = r->noswallow; c->isfloating = r->isfloating; c->tags |= r->tags; for (m = mons; m && m->num != r->monitor; m = m->next); @@ -416,6 +456,53 @@ attachstack(Client *c) } void +swallow(Client *p, Client *c) +{ + + if (c->noswallow || c->isterminal) + return; + if (c->noswallow && !swallowfloating && c->isfloating) + return; + + detach(c); + detachstack(c); + + setclientstate(c, WithdrawnState); + XUnmapWindow(dpy, p->win); + + p->swallowing = c; + c->mon = p->mon; + + Window w = p->win; + p->win = c->win; + c->win = w; + updatetitle(p); + XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h); + arrange(p->mon); + configure(p); + updateclientlist(); +} + +void +unswallow(Client *c) +{ + c->win = c->swallowing->win; + + free(c->swallowing); + c->swallowing = NULL; + + /* unfullscreen the client */ + setfullscreen(c, 0); + updatetitle(c); + arrange(c->mon); + XMapWindow(dpy, c->win); + XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); + setclientstate(c, NormalState); + focus(NULL); + arrange(c->mon); +} + +void buttonpress(XEvent *e) { unsigned int i, x, click; @@ -655,6 +742,9 @@ destroynotify(XEvent *e) if ((c = wintoclient(ev->window))) unmanage(c, 1); + + else if ((c = swallowingclient(ev->window))) + unmanage(c->swallowing, 1); } void @@ -758,6 +848,28 @@ drawbars(void) } void +enqueue(Client *c) +{ + Client *l; + for (l = c->mon->clients; l && l->next; l = l->next); + if (l) { + l->next = c; + c->next = NULL; + } +} + +void +enqueuestack(Client *c) +{ + Client *l; + for (l = c->mon->stack; l && l->snext; l = l->snext); + if (l) { + l->snext = c; + c->snext = NULL; + } +} + +void enternotify(XEvent *e) { Client *c; @@ -1029,14 +1141,46 @@ 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; + Client *c, *t = NULL, *term = NULL; Window trans = None; XWindowChanges wc; c = ecalloc(1, sizeof(Client)); c->win = w; + c->pid = winpid(w); /* geometry */ c->x = c->oldx = wa->x; c->y = c->oldy = wa->y; @@ -1051,6 +1195,7 @@ manage(Window w, XWindowAttributes *wa) } else { c->mon = selmon; applyrules(c); + term = termforwin(c); } if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww) @@ -1085,6 +1230,8 @@ manage(Window w, XWindowAttributes *wa) c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); + if (term) + swallow(term, c); focus(NULL); } @@ -1380,6 +1527,38 @@ restack(Monitor *m) } void +rotatestack(const Arg *arg) +{ + Client *c = NULL, *f; + + if (!selmon->sel) + return; + f = selmon->sel; + if (arg->i > 0) { + for (c = nexttiled(selmon->clients); c && nexttiled(c->next); c = nexttiled(c->next)); + if (c){ + detach(c); + attach(c); + detachstack(c); + attachstack(c); + } + } else { + if ((c = nexttiled(selmon->clients))){ + detach(c); + enqueue(c); + detachstack(c); + enqueuestack(c); + } + } + if (c){ + arrange(selmon); + //unfocus(f, 1); + focus(f); + restack(selmon); + } +} + +void run(void) { XEvent ev; @@ -1781,6 +1960,20 @@ unmanage(Client *c, int destroyed) Monitor *m = c->mon; XWindowChanges wc; + if (c->swallowing) { + unswallow(c); + return; + } + + Client *s = swallowingclient(c->win); + if (s) { + free(s->swallowing); + s->swallowing = NULL; + arrange(m); + focus(NULL); + return; + } + detach(c); detachstack(c); if (!destroyed) { @@ -1796,9 +1989,12 @@ unmanage(Client *c, int destroyed) XUngrabServer(dpy); } free(c); - focus(NULL); - updateclientlist(); - arrange(m); + + if (!s) { + arrange(m); + focus(NULL); + updateclientlist(); + } } void @@ -2062,6 +2258,136 @@ view(const Arg *arg) arrange(selmon); } +pid_t +winpid(Window w) +{ + + pid_t result = 0; + +#ifdef __linux__ + xcb_res_client_id_spec_t spec = {0}; + spec.client = w; + spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID; + + xcb_generic_error_t *e = NULL; + xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec); + xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e); + + if (!r) + return (pid_t)0; + + xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r); + for (; i.rem; xcb_res_client_id_value_next(&i)) { + spec = i.data->spec; + if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) { + uint32_t *t = xcb_res_client_id_value_value(i.data); + result = *t; + break; + } + } + + free(r); + + if (result == (pid_t)-1) + result = 0; + +#endif /* __linux__ */ + +#ifdef __OpenBSD__ + Atom type; + int format; + unsigned long len, bytes; + unsigned char *prop; + pid_t ret; + + if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 0), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop) + return 0; + + ret = *(pid_t*)prop; + XFree(prop); + result = ret; + +#endif /* __OpenBSD__ */ + return result; +} + +pid_t +getparentprocess(pid_t p) +{ + unsigned int v = 0; + +#ifdef __linux__ + FILE *f; + char buf[256]; + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); + + if (!(f = fopen(buf, "r"))) + return 0; + + fscanf(f, "%*u %*s %*c %u", &v); + fclose(f); +#endif /* __linux__*/ + +#ifdef __OpenBSD__ + int n; + kvm_t *kd; + struct kinfo_proc *kp; + + kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL); + if (!kd) + return 0; + + kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n); + v = kp->p_ppid; +#endif /* __OpenBSD__ */ + + return (pid_t)v; +} + +int +isdescprocess(pid_t p, pid_t c) +{ + while (p != c && c != 0) + c = getparentprocess(c); + + return (int)c; +} + +Client * +termforwin(const Client *w) +{ + Client *c; + Monitor *m; + + if (!w->pid || w->isterminal) + return NULL; + + for (m = mons; m; m = m->next) { + for (c = m->clients; c; c = c->next) { + if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid)) + return c; + } + } + + return NULL; +} + +Client * +swallowingclient(Window w) +{ + Client *c; + Monitor *m; + + for (m = mons; m; m = m->next) { + for (c = m->clients; c; c = c->next) { + if (c->swallowing && c->swallowing->win == w) + return c; + } + } + + return NULL; +} + Client * wintoclient(Window w) { @@ -2129,6 +2455,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; @@ -2140,28 +2477,6 @@ zoom(const Arg *arg) pop(c); } -void -view_adjacent(const Arg *arg) -{ - int i, curtags; - int seltag = 0; - Arg a; - - curtags = selmon->tagset[selmon->seltags]; - for(i = 0; i < LENGTH(tags); i++) - if(curtags & (1 << i)){ - seltag = i; - break; - } - - seltag = (seltag + arg->i) % (int)LENGTH(tags); - if(seltag < 0) - seltag += LENGTH(tags); - - a.i = (1 << seltag); - view(&a); -} - int main(int argc, char *argv[]) { @@ -2173,10 +2488,14 @@ main(int argc, char *argv[]) fputs("warning: no locale support\n", stderr); if (!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display"); + if (!(xcon = XGetXCBConnection(dpy))) + die("dwm: cannot get xcb connection\n"); checkotherwm(); + XrmInitialize(); + loadxrdb(); setup(); #ifdef __OpenBSD__ - if (pledge("stdio rpath proc exec", NULL) == -1) + if (pledge("stdio rpath proc exec ps", NULL) == -1) die("pledge"); #endif /* __OpenBSD__ */ scan(); |