diff options
32 files changed, 4143 insertions, 207 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c7f6a97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Patch files +*.orig +*.rej + +# C files +*.o +dwm +config.h @@ -38,7 +38,7 @@ dist: clean install: all mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f dwm ${DESTDIR}${PREFIX}/bin + cp -f dwm dwmc ${DESTDIR}${PREFIX}/bin chmod 755 ${DESTDIR}${PREFIX}/bin/dwm mkdir -p ${DESTDIR}${MANPREFIX}/man1 sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 @@ -1,48 +0,0 @@ -dwm - dynamic window manager -============================ -dwm is an extremely fast, small, and dynamic window manager for X. - - -Requirements ------------- -In order to build dwm you need the Xlib header files. - - -Installation ------------- -Edit config.mk to match your local setup (dwm is installed into -the /usr/local namespace by default). - -Afterwards enter the following command to build and install dwm (if -necessary as root): - - make clean install - - -Running dwm ------------ -Add the following line to your .xinitrc to start dwm using startx: - - exec dwm - -In order to connect dwm to a specific display, make sure that -the DISPLAY environment variable is set correctly, e.g.: - - DISPLAY=foo.bar:1 exec dwm - -(This will start dwm on display :1 of the host foo.bar.) - -In order to display status info in the bar, you can do something -like this in your .xinitrc: - - while xsetroot -name "`date` `uptime | sed 's/.*,//'`" - do - sleep 1 - done & - exec dwm - - -Configuration -------------- -The configuration of dwm is done by creating a custom config.h -and (re)compiling the source code. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4353403 --- /dev/null +++ b/README.md @@ -0,0 +1,243 @@ +My dwm +--- +A Dynamic Window Manager + +dwm is an extremely fast, small, and dynamic window manager for X. +It is written with the [suckless philosophy][15] +in mind and is objectively one of the best window managers out there. + +## What my build has to offer +I have patched dwm extensively using official patches but also with the +awesome patches [Floris Laporte][16] makes for his own build to +make the experience more enjoyable. Here are the following patches which I +installed: + +- [dwm-activetagindicatorbar-6.2][1] +- [dwm-alpha-20180613-b69c870][2] +- [dwm-bar-height-6.2][3] +- [dwm-centeredmaster-6.1][4] +- [dwm-dwmc-6.2][5] +- [dwm-focusmaster][6] +- [dwm-fullscreen][7] +- [dwm-gaplessgrid-20160731-56a31dc][8] +- [dwm-libxft-bgra][9] +- [dwm-movestack-6.1][10] +- [dwm-rotatestack-20161021-ab9571b][11] +- [dwm-statuscmd-signal-6.2][21] +- [dwm-tilegap][12] +- [dwm-zoomswap-6.2][13] +- [flaport-center][14] +- [flaport-mastermon][14] +- [flaport-swallow][14] + +So that's a nice list... But what does it actually mean? Here are the main +points that make my build stand out. + +**Decentralized keybindings:** + +So if I have a piece of software that does one thing and does it well, why +would I use anything else. I personally use the *Simple X Hotkey Daemon* +([SXHKD][17]) to manage all my keybindings and dwm should be no exception. +That's why I use the [dwmc][5] patch to allow sxhkd to control dwm. + +For this reason, I highly recommend you take a look at my [dotfiles][18] +repository as it contains my current configuration for sxhkd. **This build +of dwm is basically unusable until you have sxhkd setup for it.** This also +means sxhkd should be launched along dwm inside your `.xinitrc`. As a bonus, +if you install this build of dwm with my dotfiles using [archer][19], you +can press `super + alt + shift + h` to view a procedurally generated pdf of +all my keybindings. + +**Window swallowing:** + +This is a feature which allows terminals to "transform" themselves into the +software they are launching (essentially saving screen real estate). For +example: If I were to open a video inside mpv from my terminal, the terminal +window would disapear and where it once was, mpv would appear. + +**Aesthetics:** + +I love transparency and that's why I added the [alpha][2] patch to my build. +While I was at it, I switched the standard corner square bar indicator for a +centered rectangle on each tag using the [activetagindicatorbar][1] patch. +Most fonts don't play well with it so I added the [bar-height][3] patch to make +the bar taller. I don't like to have gaps everywhere, but I don't dislike them +either. Therefore, I only added them to the tiling layout (which is where they +make the most sense). + +**Emoji Compatibility:** + +Some Suckless software have a frustrating tendency of crashing when +encountering color emoji. This got fixed with the [libxft-bgra][9] patch. I'm +not the greatest fan of emojis (I personally prefer the fontawesome fonts for +icons), but in the unlikely event that one makes it's way to my statusbar, it +will not crash. + +**dwmblocks compatibility:** + +I personnally have a personal build of [dwmblocks][20] which is capable of +handling click events. For that to work, I had to add the +[statuscmd-signal][21] patch. + +**Accessible stack navigation and manipulation:** + +I don't want to spend half an hour placing a window where I want in in the +stack. I need a suite of functions aiding me to do certain motions +either to position windows or navigate through them: + +- [Rotatestack][11]: Rotate the entire stack (clockwise/couterclockwise). +- [Movestack][10]: Move the current window up or down the stack. +- [FocusMaster][6]: Focus the master window (the last spawned window). +- [ZoomSwap][13]: Swap the master window with the currently focused one. + +**Diverse but consise tiling modes:** + +I'm not a fan of having so many tiling modes I need a patch just to switch +through all of them. I only included those I found usefull on a day to day +basis. The following schematics will showcase these (1 being the newest +spawned window): + +``` + Tile (Regular): +┌───────────────────────────────┐┌────────────────────────────────┐ +│ 1 ││ 2 │ +│ ││ │ +│ │└────────────────────────────────┘ +│ │┌────────────────────────────────┐ +│ ││ 3 │ +│ ││ │ +│ │└────────────────────────────────┘ +│ │┌────────────────────────────────┐ +│ ││ 4 │ +│ ││ │ +│ │└────────────────────────────────┘ +│ │┌────────────────────────────────┐ +│ ││ 5 │ +│ ││ │ +│ │└────────────────────────────────┘ +│ │┌────────────────────────────────┐ +│ ││ 6 │ +│ ││ │ +└───────────────────────────────┘└────────────────────────────────┘ + + Centered Master: +┌───────────────┐┌───────────────────────────────┐┌───────────────┐ +│ 3 ││ 1 ││ 2 │ +│ ││ ││ │ +└───────────────┘│ │└───────────────┘ +┌───────────────┐│ │┌───────────────┐ +│ 5 ││ ││ 4 │ +│ ││ ││ │ +└───────────────┘│ │└───────────────┘ +┌───────────────┐│ │┌───────────────┐ +│ 7 ││ ││ 6 │ +│ ││ ││ │ +└───────────────┘│ │└───────────────┘ +┌───────────────┐│ │┌───────────────┐ +│ 9 ││ ││ 8 │ +│ ││ ││ │ +└───────────────┘│ │└───────────────┘ +┌───────────────┐│ │┌───────────────┐ +│ 11 ││ ││ 10 │ +│ ││ ││ │ +└───────────────┘└───────────────────────────────┘└───────────────┘ + + Floating Centered Master: +┌───────────────┐┌───────────────┐┌───────────────┐┌───────────────┐ +│ 2 ││ 3 ││ 4 ││ 5 │ +│ ││ ││ ││ │ +│ ┌──────────────────────────────────────┐ │ +│ │ 1 │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ │ │ │ +│ └──────────────────────────────────────┘ │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +└───────────────┘└───────────────┘└───────────────┘└───────────────┘ + + Gappless Grid: +┌───────────────┐┌───────────────┐┌───────────────┐┌───────────────┐ +│ 1 ││ 5 ││ 9 ││ 13 │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +└───────────────┘└───────────────┘└───────────────┘└───────────────┘ +┌───────────────┐┌───────────────┐┌───────────────┐┌───────────────┐ +│ 2 ││ 6 ││ 10 ││ 14 │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +└───────────────┘└───────────────┘└───────────────┘└───────────────┘ +┌───────────────┐┌───────────────┐┌───────────────┐┌───────────────┐ +│ 3 ││ 7 ││ 11 ││ 15 │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +└───────────────┘└───────────────┘└───────────────┘└───────────────┘ +┌───────────────┐┌───────────────┐┌───────────────┐┌───────────────┐ +│ 4 ││ 8 ││ 12 ││ 16 │ +│ ││ ││ ││ │ +│ ││ ││ ││ │ +└───────────────┘└───────────────┘└───────────────┘└───────────────┘ + +``` +There are 3 more layout which don't require drawings: +- Fullscreen +- Monocle: Windows are stacked one over the over in "fullscreen" + (the statusbar remains). +- Floating: Windows don't respond to any tiling function and simply + spawn in the top left corner (they remain in place coming from + another tiling function). + +## Requirements +In order to build dwm you need the Xlib header files. + + +## Installation +Edit config.mk to match your local setup (dwm is installed into +the /usr/local namespace by default). + +Afterwards enter the following command to build and install dwm (if +necessary as root): +``` + make clean install +``` + +## Running dwm +Add the following line to your .xinitrc to start dwm using startx: +``` + exec dwm +``` + +## Configuration +The configuration of dwm is done by creating a custom config.h +and (re)compiling the source code. + + +[1]: https://dwm.suckless.org/patches/activetagindicatorbar/ +[2]: https://dwm.suckless.org/patches/alpha/ +[3]: https://dwm.suckless.org/patches/bar_height/ +[4]: https://dwm.suckless.org/patches/centeredmaster/ +[5]: https://dwm.suckless.org/patches/dwmc/ +[6]: https://dwm.suckless.org/patches/focusmaster/ +[7]: https://dwm.suckless.org/patches/fullscreen/ +[8]: https://dwm.suckless.org/patches/gaplessgrid/ +[9]: https://youtu.be/f9qNXV01yzg +[10]: https://dwm.suckless.org/patches/movestack/ +[11]: https://dwm.suckless.org/patches/rotatestack/ +[12]: https://dwm.suckless.org/patches/tilegap/ +[13]: https://dwm.suckless.org/patches/zoomswap/ +[14]: https://github.com/flaport/dwm +[15]: https://suckless.org/philosophy/ +[16]: https://github.com/flaport +[17]: https://github.com/baskerville/sxhkd +[18]: https://git.chausse.xyz/dotfiles/ +[19]: https://git.chausse.xyz/archer/ +[20]: https://git.chausse.xyz/dwmblocks/ +[21]: https://dwm.suckless.org/patches/statuscmd/ diff --git a/config.def.h b/config.def.h index a2ac963..2c53956 100644 --- a/config.def.h +++ b/config.def.h @@ -1,100 +1,131 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -static const unsigned int borderpx = 1; /* border pixel of windows */ -static const unsigned int snap = 32; /* snap pixel */ +static const unsigned int borderpx = 0; /* border pixel of windows */ +static const unsigned int gappx = 3; /* gap pixel between windows */ +static const unsigned int snap = 15; /* snap pixel */ +static const int swallowfloating = 1; /* 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 int user_bh = 28; /* 0 means that dwm will calculate bar height, >= 1 means dwm will user_bh as bar height */ +static const char *fonts[] = { "monospace:size=12" }; +static const char dmenufont[] = "monospace:size=12"; +static const char col_norm_fg[] = "#447a6c"; +/* static const char col_norm_fg[] = "#83969D"; */ +static const char col_norm_bg[] = "#1b1d1b"; +static const char col_sel_fg[] = "#1b1d1b"; +static const char col_sel_bg[] = "#7D4B23"; +static const char col_norm_border[] = "#C0FFEE"; +static const char col_sel_border[] = "#BADA55"; + +/* static const char col_gray1[] = "#222d32"; */ +/* static const char col_gray2[] = "#343e42"; */ +/* static const char col_white[] = "#f2f1f0"; */ +/* static const char col_gray4[] = "#aaccbb"; */ +/* static const char col_cyan[] = "#42717b"; */ + +#define baralpha 0xd0 +#define borderalpha OPAQUE + static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, + /* fg bg border */ + [SchemeNorm] = { col_norm_fg, col_norm_bg, col_norm_border }, + [SchemeSel] = { col_sel_fg, col_sel_bg, col_sel_border }, +}; +/* static const char *colors[][3] = { */ +/* /1* fg bg border *1/ */ +/* [SchemeNorm] = { col_white, col_gray1, col_gray2 }, */ +/* [SchemeSel] = { col_gray4, col_cyan, col_cyan }, */ +/* }; */ +static const unsigned int alphas[][3] = { + /* fg bg border */ + [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, + [SchemeSel] = { OPAQUE, baralpha, borderalpha }, }; /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *montags[] = { " I ", "II", "III", "IV"}; 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 iscentered isfloating isterminal noswallow monitor canfocus */ + /* { "Gimp", NULL, NULL, 0, 0, 1, 0, 0, -1, 1 }, */ + /* { "Firefox", NULL, NULL, 1 << 8, 0, 0, 0, 0, -1, 1 }, */ + { NULL, NULL, "Picture-in-Picture",1, 0, 0, 0, 0, -1, 1 }, + { "St", NULL, NULL, 0, 0, 0, 1, 0, -1, 1 }, + { "dropdown",NULL, NULL, 0, 1, 1, 0, 0, -1, 1 }, + { NULL, NULL, "Color Picker", 0, 1, 1, 0, 0, -1, 1 }, + { "youtube", NULL, NULL, 0, 1, 1, 1, 0, -1, 1 }, + { "Nvim-R", NULL, NULL, 0, 0, 0, 1, 1, -1, 1 }, + /* { NULL, NULL, "Event Tester", 0, 0, 1, 0, 1, -1, 1 }, /1* xev *1/ */ + /* { "R_x11", NULL, NULL, 0, 0, 1, 0, 1, -1, 0 }, /1* R popup *1/ */ + /* { "Matplotlib",NULL, NULL, 0, 1, 1, 0, 1, -1, 0 }, /1* Python popups *1/ */ + /* { NULL,NULL,"Subplot Configuration Tool",0, 1, 1, 0, 1, -1, 0 }, /1* Python popups *1/ */ + + /* { "Dropbox-cli",NULL, NULL, 0, 0, 1, 0, 1, -1, 1 }, */ + /* { NULL, NULL, "Kite", 0, 0, 0, 0, 1, -1, 1 }, */ + /* { "Arandr", NULL, NULL, 0, 1, 1, 0, 0, -1, 1 }, */ + /* { "Surf", NULL, NULL, 0, 1, 0, 0, 1, -1, 1 }, */ + /* { "Zathura", NULL, NULL, 0, 0, 0, 0, 1, -1, 1 }, */ }; +/* include functions */ +#include "gaplessgrid.c" +#include "focusmaster.c" + /* layout(s) */ -static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ +static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ +<<<<<<< HEAD +static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ +======= static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ +>>>>>>> origin/master static const Layout layouts[] = { - /* symbol arrange function */ - { "[]=", tile }, /* first entry is default */ - { "><>", NULL }, /* no layout function means floating behavior */ - { "[M]", monocle }, + /* symbol arrange function */ + { " []= ", tile }, /* first entry is default */ + { " ", NULL }, /* no layout function means floating behavior */ + { " <o> ", monocle }, + { " |_| ", centeredmaster }, + { " |=| ", centeredfloatingmaster }, + { " [+] ", gaplessgrid }, }; /* 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} }, \ { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, +#define MONKEYS(KEY,TAG) \ + { MODKEY, KEY, focusmon, {.i = TAG+1} }, \ + { MODKEY|ShiftMask, KEY, tagmon, {.i = TAG+1} }, \ + { MODKEY|ControlMask, KEY, swapmon, {.i = TAG+1} }, /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* 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 *termcmd[] = { "st", NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_norm_bg, "-nf", col_norm_fg, "-sb", col_sel_fg, "-sf", col_sel_bg, NULL }; +/* static const char *termcmd[] = { "st", NULL }; */ +#include "movestack.c" static Key keys[] = { + + /* All keybindings are managed by sxhkd. */ + /* The only reason a keybinding is uncommented is to prevent + * dwm from handling an empty array.*/ + /* 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_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_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|ShiftMask, XK_q, quit, {0} }, }; /* button definitions */ @@ -104,7 +135,10 @@ static Button buttons[] = { { ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, { ClkWinTitle, 0, Button2, zoom, {0} }, - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, + { ClkStatusText, 0, Button1, sigdwmblocks, {.i = 1} }, + { ClkStatusText, 0, Button2, sigdwmblocks, {.i = 2} }, + { ClkStatusText, 0, Button3, sigdwmblocks, {.i = 3} }, + { ClkStatusText, ShiftMask, Button3, sigdwmblocks, {.i = 6} }, { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, @@ -114,3 +148,79 @@ static Button buttons[] = { { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; +void +setlayoutex(const Arg *arg) +{ + setlayout(&((Arg) { .v = &layouts[arg->i] })); +} + +void +viewex(const Arg *arg) +{ + view(&((Arg) { .ui = 1 << arg->ui })); +} + +void +viewall(const Arg *arg) +{ + view(&((Arg){.ui = ~0})); +} + +void +toggleviewex(const Arg *arg) +{ + toggleview(&((Arg) { .ui = 1 << arg->ui })); +} + +void +tagex(const Arg *arg) +{ + tag(&((Arg) { .ui = 1 << arg->ui })); +} + +void +toggletagex(const Arg *arg) +{ + toggletag(&((Arg) { .ui = 1 << arg->ui })); +} + +void +tagall(const Arg *arg) +{ + tag(&((Arg){.ui = ~0})); +} + +/* signal definitions */ +/* signum must be greater than 0 */ +/* trigger signals using `xsetroot -name "fsignal:<signame> [<type> <value>]"` */ +static Signal signals[] = { + /* signum function */ + { "focusstack", focusstack }, + { "rotatestack", rotatestack }, + { "setmfact", setmfact }, + { "togglebar", togglebar }, + { "incnmaster", incnmaster }, + { "togglefloating", togglefloating }, + { "focusmon", focusmon }, + { "focusmaster", focusmaster }, + { "fullscreen", fullscreen }, + { "movestack", movestack }, + { "tagmon", tagmon }, + { "swapmon", swapmon }, + { "zoom", zoom }, + { "view", view }, + { "viewall", viewall }, + { "viewex", viewex }, + { "toggleview", view }, + { "toggleviewex", toggleviewex }, + { "tag", tag }, + { "tagall", tagall }, + { "tagex", tagex }, + { "toggletag", tag }, + { "toggletagex", toggletagex }, + { "killclient", killclient }, + { "quit", quit }, + { "setmastermon", setmastermon }, + { "setlayout", setlayout }, + { "setlayoutex", setlayoutex }, +}; @@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2 # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender -lX11-xcb -lxcb -lxcb-res # flags CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} @@ -35,4 +35,4 @@ LDFLAGS = ${LIBS} #LDFLAGS = ${LIBS} # compiler and linker -CC = cc +CC = clang @@ -11,6 +11,8 @@ #define UTF_INVALID 0xFFFD #define UTF_SIZ 4 +int has_libxft_bgra = 0; + static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; @@ -61,7 +63,7 @@ utf8decode(const char *c, long *u, size_t clen) } Drw * -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) +drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap) { Drw *drw = ecalloc(1, sizeof(Drw)); @@ -70,8 +72,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h drw->root = root; drw->w = w; drw->h = h; - drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); - drw->gc = XCreateGC(dpy, root, 0, NULL); + drw->visual = visual; + drw->depth = depth; + drw->cmap = cmap; + drw->drawable = XCreatePixmap(dpy, root, w, h, depth); + drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL); XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); return drw; @@ -87,7 +92,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h) drw->h = h; if (drw->drawable) XFreePixmap(drw->dpy, drw->drawable); - drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); + drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth); } void @@ -140,11 +145,13 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 * and lots more all over the internet. */ - FcBool iscol; - if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { - XftFontClose(drw->dpy, xfont); - return NULL; - } + if (!has_libxft_bgra){ + FcBool iscol; + if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { + XftFontClose(drw->dpy, xfont); + return NULL; + } + } font = ecalloc(1, sizeof(Fnt)); font->xfont = xfont; @@ -175,6 +182,8 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) if (!drw || !fonts) return NULL; + has_libxft_bgra = !system("pacman -Q libxft | grep bgra > /dev/null 2> /dev/null"); + for (i = 1; i <= fontcount; i++) { if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { cur->next = ret; @@ -194,21 +203,22 @@ drw_fontset_free(Fnt *font) } void -drw_clr_create(Drw *drw, Clr *dest, const char *clrname) +drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha) { if (!drw || !dest || !clrname) return; - if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), - DefaultColormap(drw->dpy, drw->screen), + if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, clrname, dest)) die("error, cannot allocate color '%s'", clrname); + + dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); } /* 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, const char *clrnames[], const unsigned int alphas[], size_t clrcount) { size_t i; Clr *ret; @@ -218,7 +228,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) return NULL; for (i = 0; i < clrcount; i++) - drw_clr_create(drw, &ret[i], clrnames[i]); + drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]); return ret; } @@ -274,9 +284,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp } else { XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); - d = XftDrawCreate(drw->dpy, drw->drawable, - DefaultVisual(drw->dpy, drw->screen), - DefaultColormap(drw->dpy, drw->screen)); + d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap); x += lpad; w -= lpad; } @@ -20,6 +20,9 @@ typedef struct { Display *dpy; int screen; Window root; + Visual *visual; + unsigned int depth; + Colormap cmap; Drawable drawable; GC gc; Clr *scheme; @@ -27,7 +30,7 @@ typedef struct { } Drw; /* Drawable abstraction */ -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); +Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); void drw_resize(Drw *drw, unsigned int w, unsigned int h); void drw_free(Drw *drw); @@ -38,8 +41,8 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); /* 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); +void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha); +Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount); /* Cursor abstraction */ Cur *drw_cur_create(Drw *drw, int shape); @@ -40,6 +40,8 @@ #include <X11/extensions/Xinerama.h> #endif /* XINERAMA */ #include <X11/Xft/Xft.h> +#include <X11/Xlib-xcb.h> +#include <xcb/res.h> #include "drw.h" #include "util.h" @@ -57,9 +59,11 @@ #define TAGMASK ((1 << LENGTH(tags)) - 1) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) +#define OPAQUE 0xffU + /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ -enum { SchemeNorm, SchemeSel }; /* color schemes */ +enum { SchemeNorm, SchemeSel, SchemeInactive }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ @@ -92,9 +96,11 @@ struct Client { int basew, baseh, incw, inch, maxw, maxh, minw, minh; int bw, oldbw; unsigned int tags; - int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + int isfixed, iscentered, isurgent, neverfocus, oldstate, isfullscreen, isfloating, isterminal, noswallow, canfocus; + pid_t pid; Client *next; Client *snext; + Client *swallowing; Monitor *mon; Window win; }; @@ -107,6 +113,11 @@ typedef struct { } Key; typedef struct { + const char * sig; + void (*func)(const Arg *); +} Signal; + +typedef struct { const char *symbol; void (*arrange)(Monitor *); } Layout; @@ -137,8 +148,12 @@ typedef struct { const char *instance; const char *title; unsigned int tags; + int iscentered; int isfloating; + int isterminal; + int noswallow; int monitor; + int canfocus; } Rule; /* function declarations */ @@ -148,6 +163,7 @@ static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); static void attachstack(Client *c); +static int fake_signal(void); static void buttonpress(XEvent *e); static void checkotherwm(void); static void cleanup(void); @@ -156,6 +172,7 @@ static void clientmessage(XEvent *e); static void configure(Client *c); static void configurenotify(XEvent *e); static void configurerequest(XEvent *e); +static void copyvalidchars(char *text, char *rawtext); static Monitor *createmon(void); static void destroynotify(XEvent *e); static void detach(Client *c); @@ -163,12 +180,16 @@ 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 Client *findbefore(Client *c); static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static int getdwmblockspid(); static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); @@ -178,14 +199,16 @@ static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); +static void makemastermon(Monitor *m); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static Monitor *numtomon(const unsigned int num); static Client *nexttiled(Client *c); -static void pop(Client *); +/* static void pop(Client *); */ static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); @@ -193,6 +216,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); @@ -200,13 +224,17 @@ static void sendmon(Client *c, Monitor *m); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); +static void fullscreen(const Arg *arg); static void setlayout(const Arg *arg); +static void setmastermon(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void sigchld(int unused); -static void spawn(const Arg *arg); +static void sigdwmblocks(const Arg *arg); +/* static void spawn(const Arg *arg); */ +static void swapmon(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *); @@ -233,11 +261,25 @@ 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 xinitvisual(); static void zoom(const Arg *arg); +static void centeredmaster(Monitor *m); +static void centeredfloatingmaster(Monitor *m); + +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 Client *prevzoom = NULL; static const char broken[] = "broken"; static char stext[256]; +static char rawstext[256]; +static int dwmblockssig; +pid_t dwmblockspid = 0; +static int scanner; static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh, blw = 0; /* bar geometry */ @@ -266,8 +308,17 @@ static Cur *cursor[CurLast]; static Clr **scheme; static Display *dpy; static Drw *drw; -static Monitor *mons, *selmon; +static Monitor *mons, *selmon, *mastermon; static Window root, wmcheckwin; +static Layout *last_layout; + + +static int useargb = 0; +static Visual *visual; +static int depth; +static Colormap cmap; + +static xcb_connection_t *xcon; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -286,7 +337,9 @@ applyrules(Client *c) XClassHint ch = { NULL, NULL }; /* rule matching */ + c->noswallow = -1; c->isfloating = 0; + c->canfocus = 1; c->tags = 0; XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; @@ -298,7 +351,11 @@ applyrules(Client *c) && (!r->class || strstr(class, r->class)) && (!r->instance || strstr(instance, r->instance))) { + c->isterminal = r->isterminal; + c->noswallow = r->noswallow; + c->iscentered = r->iscentered; c->isfloating = r->isfloating; + c->canfocus = r->canfocus; c->tags |= r->tags; for (m = mons; m && m->num != r->monitor; m = m->next); if (m) @@ -415,6 +472,61 @@ attachstack(Client *c) } void +swallow(Client *p, Client *c) +{ + Client *s; + + if (c->noswallow > 0 || c->isterminal) + return; + if (c->noswallow < 0 && !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; + + XChangeProperty(dpy, c->win, netatom[NetClientList], XA_WINDOW, 32, PropModeReplace, + (unsigned char *) &(p->win), 1); + + updatetitle(p); + s = scanner ? c : p; + XMoveResizeWindow(dpy, p->win, s->x, s->y, s->w, s->h); + arrange(p->mon); + configure(p); + updateclientlist(); +} + +void +unswallow(Client *c) +{ + c->win = c->swallowing->win; + + free(c->swallowing); + c->swallowing = NULL; + + XDeleteProperty(dpy, c->win, netatom[NetClientList]); + + /* 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; @@ -432,17 +544,50 @@ buttonpress(XEvent *e) } if (ev->window == selmon->barwin) { i = x = 0; - do - x += TEXTW(tags[i]); - while (ev->x >= x && ++i < LENGTH(tags)); - if (i < LENGTH(tags)) { + if (mons->next){ + x += TEXTW(montags[m->num]); + if (ev->x < x){ + if (ev->button == 1){ + makemastermon(selmon); + } + return; + } + x += TEXTW(" "); + if (ev->x < x) + return; + } + + if (selmon == mastermon){ + do + x += TEXTW(tags[i]); + while (ev->x >= x && ++i < LENGTH(tags)); + } + + if ((i < LENGTH(tags)) && (selmon == mastermon)) { click = ClkTagBar; arg.ui = 1 << i; - } else if (ev->x < x + blw) + } else if (ev->x < x + TEXTW(selmon->ltsymbol)) click = ClkLtSymbol; - else if (ev->x > selmon->ww - (int)TEXTW(stext)) + else if (ev->x > (x = selmon->ww - (int)TEXTW(stext) + lrpad)) { click = ClkStatusText; - else + + char *text = rawstext; + int i = -1; + char ch; + dwmblockssig = 0; + while (text[++i]) { + if ((unsigned char)text[i] < ' ') { + ch = text[i]; + text[i] = '\0'; + x += (int)TEXTW(text) - lrpad; + text[i] = ch; + text += i+1; + i = -1; + if (x >= ev->x) break; + dwmblockssig = ch; + } + } + } else click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { focus(c); @@ -505,6 +650,13 @@ cleanupmon(Monitor *mon) for (m = mons; m && m->next != mon; m = m->next); m->next = mon->next; } + if (mon == mastermon){ + mastermon = mon->next; + if (!mastermon){ + mastermon = mons; // do not use makemastermon here. + } + drawbars(); + } XUnmapWindow(dpy, mon->barwin); XDestroyWindow(dpy, mon->barwin); free(mon); @@ -628,6 +780,19 @@ configurerequest(XEvent *e) XSync(dpy, False); } +void +copyvalidchars(char *text, char *rawtext) +{ + int i = -1, j = 0; + + while(rawtext[++i]) { + if ((unsigned char)rawtext[i] >= ' ') { + text[j++] = rawtext[i]; + } + } + text[j] = '\0'; +} + Monitor * createmon(void) { @@ -653,6 +818,9 @@ destroynotify(XEvent *e) if ((c = wintoclient(ev->window))) unmanage(c, 1); + + else if ((c = swallowingclient(ev->window))) + unmanage(c->swallowing, 1); } void @@ -717,17 +885,30 @@ drawbar(Monitor *m) if (c->isurgent) urg |= c->tags; } + x = 0; - for (i = 0; i < LENGTH(tags); i++) { - w = TEXTW(tags[i]); - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); - if (occ & 1 << i) - drw_rect(drw, x + boxs, boxs, boxw, boxw, - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, - urg & 1 << i); - x += w; - } + + if (mons->next){ + w = blw = TEXTW(montags[m->num]); + drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeInactive]); + x = drw_text(drw, x, 0, w, bh, lrpad / 2, montags[m->num], 0); + drw_setscheme(drw, scheme[SchemeNorm]); + x = drw_text(drw, x, 0, w, bh, lrpad / 2, " ", 0); + } + + if (m == mastermon){ + for (i = 0; i < LENGTH(tags); i++) { + w = TEXTW(tags[i]); + drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? ( m == selmon ? SchemeSel : SchemeInactive) : SchemeNorm]); + drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); + if (occ & 1 << i) + drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, + m == selmon && selmon->sel && selmon->sel->tags & 1 << i, + urg & 1 << i); + + x += w; + } + } w = blw = TEXTW(m->ltsymbol); drw_setscheme(drw, scheme[SchemeNorm]); x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); @@ -756,6 +937,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; @@ -784,14 +987,27 @@ expose(XEvent *e) drawbar(m); } +Client * +findbefore(Client *c) +{ + Client *tmp; + if (c == selmon->clients) + return NULL; + for (tmp = selmon->clients; tmp && tmp->next != c; tmp = tmp->next); + return tmp; +} + void focus(Client *c) { + XWindowChanges wc; if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); if (selmon->sel && selmon->sel != c) unfocus(selmon->sel, 0); if (c) { + if (!c->canfocus) + return; if (c->mon != selmon) selmon = c->mon; if (c->isurgent) @@ -799,6 +1015,9 @@ focus(Client *c) detachstack(c); attachstack(c); grabbuttons(c, 1); + c->bw = borderpx; + wc.border_width = c->bw; + XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); setfocus(c); } else { @@ -823,11 +1042,18 @@ void focusmon(const Arg *arg) { Monitor *m; - - if (!mons->next) - return; - if ((m = dirtomon(arg->i)) == selmon) - return; + if (arg->i > 1){ + m = numtomon(arg->i-2); + if (!m) + return; + } else if ((arg->i == -1) || (arg->i == 1)){ + if (!mons->next) + return; + if ((m = dirtomon(arg->i)) == selmon) + return; + } else { + return; + } unfocus(selmon->sel, 0); selmon = m; focus(NULL); @@ -841,16 +1067,16 @@ focusstack(const Arg *arg) if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) return; if (arg->i > 0) { - for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); + for (c = selmon->sel->next; c && (!ISVISIBLE(c) || !c->canfocus); c = c->next); if (!c) - for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); + for (c = selmon->clients; c && (!ISVISIBLE(c) || !c->canfocus); c = c->next); } else { for (i = selmon->clients; i != selmon->sel; i = i->next) - if (ISVISIBLE(i)) + if (ISVISIBLE(i) && i->canfocus) c = i; if (!c) for (; i; i = i->next) - if (ISVISIBLE(i)) + if (ISVISIBLE(i) && i->canfocus) c = i; } if (c) { @@ -876,6 +1102,18 @@ getatomprop(Client *c, Atom prop) } int +getdwmblockspid() +{ + char buf[16]; + FILE *fp = popen("pidof -s dwmblocks", "r"); + fgets(buf, sizeof(buf), fp); + pid_t pid = strtoul(buf, NULL, 10); + pclose(fp); + dwmblockspid = pid; + return pid != 0 ? 0 : -1; +} + +int getrootptr(int *x, int *y) { int di; @@ -1002,6 +1240,49 @@ keypress(XEvent *e) keys[i].func(&(keys[i].arg)); } +int +fake_signal(void) +{ + char fsignal[256]; + char indicator[9] = "fsignal:"; + char str_sig[50]; + char param[16]; + int i, len_str_sig, n, paramn; + size_t len_fsignal, len_indicator = strlen(indicator); + Arg arg; + + // Get root name property + if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) { + len_fsignal = strlen(fsignal); + + // Check if this is indeed a fake signal + if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) { + paramn = sscanf(fsignal+len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n); + + if (paramn == 1) arg = (Arg) {0}; + else if (paramn > 2) return 1; + else if (strncmp(param, "i", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%i", &(arg.i)); + else if (strncmp(param, "ui", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%u", &(arg.ui)); + else if (strncmp(param, "f", n - len_str_sig) == 0) + sscanf(fsignal + len_indicator + n, "%f", &(arg.f)); + else return 1; + + // Check if a signal was found, and if so handle it + for (i = 0; i < LENGTH(signals); i++) + if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func) + signals[i].func(&(arg)); + + // A fake signal was sent + return 1; + } + } + + // No fake signal was sent, so proceed with update + return 0; +} + void killclient(const Arg *arg) { @@ -1019,14 +1300,85 @@ killclient(const Arg *arg) } void +makemastermon(Monitor *m){ + Monitor *mon; + + for (mon=mons; (mon && mon!=mastermon) ; mon=mon->next); + + if (mon != mastermon){ + mastermon = m; + drawbars(); + return; + } + + if (m == mastermon){ + m = m->next ? m->next : mons; + } + + unsigned int mastertagset, N, n, p; + Client *clients, *otherclients, *masterclients; + + masterclients = mastermon->clients; + mastertagset = mastermon->tagset[mastermon->seltags]; + + otherclients = m->clients; + unfocus(otherclients, 1); + + if (otherclients){ + for (N=1, clients=otherclients; clients->next; clients=clients->next, N++); + for (n=N; n>0; n--){ + for (p=1, clients=otherclients; p<n; p++, clients=clients->next); + detach(clients); + detachstack(clients); + clients->mon = mastermon; + clients->tags = 1; + attach(clients); + attachstack(clients); + } + } + + if (masterclients){ + for (N=1, clients=masterclients; clients->next; clients=clients->next, N++); + for (n=N; n>0; n--){ + for (p=1, clients=masterclients; p<n; p++, clients=clients->next); + detach(clients); + detachstack(clients); + clients->mon = m; + attach(clients); + attachstack(clients); + } + } + + if (masterclients || otherclients){ + focus(NULL); + arrange(NULL); + } + + m->tagset[m->seltags] = mastertagset; + mastermon->tagset[mastermon->seltags] = 1; + arrange(m); + arrange(mastermon); + if (masterclients){ + if (otherclients) + unfocus(otherclients, 1); + focus(masterclients); + arrange(masterclients->mon); + } + mastermon = m; + drawbars(); +} + +void manage(Window w, XWindowAttributes *wa) { - Client *c, *t = NULL; + Monitor *m; + 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; @@ -1041,6 +1393,7 @@ manage(Window w, XWindowAttributes *wa) } else { c->mon = selmon; applyrules(c); + term = termforwin(c); } if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) @@ -1051,7 +1404,7 @@ manage(Window w, XWindowAttributes *wa) /* only fix client y-offset, if the client center might cover the bar */ c->y = MAX(c->y, ((c->mon->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx) && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); - c->bw = borderpx; + c->bw = 0; // borderpx wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); @@ -1064,8 +1417,15 @@ manage(Window w, XWindowAttributes *wa) grabbuttons(c, 0); if (!c->isfloating) c->isfloating = c->oldstate = trans != None || c->isfixed; - if (c->isfloating) + if (c->isfloating){ XRaiseWindow(dpy, c->win); + if(c->iscentered) { + c->x = (c->mon->mw - WIDTH(c)) / 2; + c->y = (c->mon->mh - HEIGHT(c)) / 2; + for (m=mons; m != c->mon; m = m->next) + c->x += m->mw; + } + } attach(c); attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, @@ -1077,6 +1437,8 @@ manage(Window w, XWindowAttributes *wa) c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); + if (term) + swallow(term, c); focus(NULL); } @@ -1203,15 +1565,32 @@ nexttiled(Client *c) return c; } -void -pop(Client *c) -{ - detach(c); - attach(c); - focus(c); - arrange(c->mon); + +Monitor +*numtomon(const unsigned int num){ + Monitor *m; + if (num == selmon->num) + return selmon; + for (m = mons; m->next; m = m->next); + if (num > m->num){ + return NULL; + } + if (num == m->num){ + return m; + } + for (m=mons; m->next->num <= num; m = m->next); + return m; } +/* void */ +/* pop(Client *c) */ +/* { */ +/* detach(c); */ +/* attach(c); */ +/* focus(c); */ +/* arrange(c->mon); */ +/* } */ + void propertynotify(XEvent *e) { @@ -1220,7 +1599,8 @@ propertynotify(XEvent *e) XPropertyEvent *ev = &e->xproperty; if ((ev->window == root) && (ev->atom == XA_WM_NAME)) - updatestatus(); + if (!fake_signal()) + updatestatus(); else if (ev->state == PropertyDelete) return; /* ignore */ else if ((c = wintoclient(ev->window))) { @@ -1295,9 +1675,14 @@ void resizemouse(const Arg *arg) { int ocx, ocy, nw, nh; + int ocx2, ocy2, nx, ny; Client *c; Monitor *m; XEvent ev; + int horizcorner, vertcorner; + int di; + unsigned int dui; + Window dummy; Time lasttime = 0; if (!(c = selmon->sel)) @@ -1307,10 +1692,18 @@ resizemouse(const Arg *arg) restack(selmon); ocx = c->x; ocy = c->y; + ocx2 = c->x + c->w; + ocy2 = c->y + c->h; if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) return; - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); + if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui)) + return; + horizcorner = nx < c->w / 2; + vertcorner = ny < c->h / 2; + XWarpPointer (dpy, None, c->win, 0, 0, 0, 0, + horizcorner ? (-c->bw) : (c->w + c->bw -1), + vertcorner ? (-c->bw) : (c->h + c->bw -1)); do { XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch(ev.type) { @@ -1326,6 +1719,11 @@ resizemouse(const Arg *arg) nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); + nx = horizcorner ? ev.xmotion.x : c->x; + ny = vertcorner ? ev.xmotion.y : c->y; + nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1); + nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1); + if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) { @@ -1334,11 +1732,13 @@ resizemouse(const Arg *arg) togglefloating(NULL); } if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) - resize(c, c->x, c->y, nw, nh, 1); + resize(c, nx, ny, nw, nh, 1); break; } } while (ev.type != ButtonRelease); - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, + horizcorner ? (-c->bw) : (c->w + c->bw - 1), + vertcorner ? (-c->bw) : (c->h + c->bw - 1)); XUngrabPointer(dpy, CurrentTime); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { @@ -1374,6 +1774,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; @@ -1387,7 +1819,9 @@ run(void) void scan(void) { + scanner = 1; unsigned int i, num; + char swin[256]; Window d1, d2, *wins = NULL; XWindowAttributes wa; @@ -1398,6 +1832,8 @@ scan(void) continue; if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState) manage(wins[i], &wa); + else if (gettextprop(wins[i], netatom[NetClientList], swin, sizeof swin)) + manage(wins[i], &wa); } for (i = 0; i < num; i++) { /* now the transients */ if (!XGetWindowAttributes(dpy, wins[i], &wa)) @@ -1409,6 +1845,7 @@ scan(void) if (wins) XFree(wins); } + scanner = 0; } void @@ -1502,6 +1939,28 @@ setfullscreen(Client *c, int fullscreen) } void +fullscreen(const Arg *arg) +{ + XWindowChanges wc; + if (selmon->showbar) { + for(last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++); + setlayout(&((Arg) { .v = &layouts[2] })); + selmon->sel->bw = 0; + selmon->showbar = 0; + } else { + setlayout(&((Arg) { .v = last_layout })); + selmon->sel->bw = borderpx; + selmon->showbar = 1; + } + updatebarpos(selmon); + wc.border_width = selmon->sel->bw; + XConfigureWindow(dpy, selmon->sel->win, CWBorderWidth, &wc); + XSetWindowBorder(dpy, selmon->sel->win, scheme[SchemeNorm][ColBorder].pixel); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); + arrange(selmon); +} + +void setlayout(const Arg *arg) { if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) @@ -1515,6 +1974,29 @@ setlayout(const Arg *arg) drawbar(selmon); } +void +setmastermon(const Arg *arg) { + + if ((selmon != mastermon)){ + makemastermon(selmon); + return; + } + + if (arg->i != -1 && arg->i != +1) + return; + + Monitor *m; + if (arg->i == -1){ + for (m=mons; (m->next && m->next==selmon); m=m->next); + } else { + m = selmon->next ? selmon->next : mons; + } + makemastermon(m); + unfocus(selmon->sel, 0); + selmon = m; + focus(NULL); +} + /* arg > 1.0 will set mfact absolutely */ void setmfact(const Arg *arg) @@ -1545,11 +2027,12 @@ setup(void) sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); - drw = drw_create(dpy, screen, root, sw, sh); + xinitvisual(); + drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap); if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); lrpad = drw->fonts->h; - bh = drw->fonts->h + 2; + bh = user_bh ? user_bh : drw->fonts->h + 2; updategeom(); /* init atoms */ utf8string = XInternAtom(dpy, "UTF8_STRING", False); @@ -1573,7 +2056,7 @@ setup(void) /* init appearance */ scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); for (i = 0; i < LENGTH(colors); i++) - scheme[i] = drw_scm_create(drw, colors[i], 3); + scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); /* init bars */ updatebars(); updatestatus(); @@ -1641,6 +2124,23 @@ sigchld(int unused) } void +sigdwmblocks(const Arg *arg) +{ + union sigval sv; + sv.sival_int = (dwmblockssig << 8) | arg->i; + if (!dwmblockspid) + if (getdwmblockspid() == -1) + return; + + if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) { + if (errno == ESRCH) { + if (!getdwmblockspid()) + sigqueue(dwmblockspid, SIGUSR1, sv); + } + } +} + +void spawn(const Arg *arg) { if (arg->v == dmenucmd) @@ -1657,19 +2157,122 @@ spawn(const Arg *arg) } void +swapmon(const Arg *arg) +{ + if (!mons->next) + return; + + if (arg->i < -1 || arg->i > 1) + return; + + Monitor *m1, *m2; + Client *c, *c1, *c2; + unsigned int N, n, p; + + m1 = selmon; + if (arg->i == -1) + for (m2=mons; (m2->next && m2->next==m1); m2=m2->next); + else if (arg->i == +1) + m2 = m1->next ? m1->next : mons; + else if (mastermon && (mastermon != selmon)) + m2 = mastermon; + else if (selmon->next) + m2 = selmon->next; + else + m2 = mons; + + + unfocus(m1->sel, 1); + unfocus(m2->sel, 1); + + c1 = c = m1->clients; + c2 = m2->clients; + unfocus(c1, 1); + + if (c1){ + for (N=1, c=c1; c->next; c=c->next, N++); + for (n=N; n>0; n--){ + for (p=1, c=c1; p<n; p++, c=c->next); + if ISVISIBLE(c){ + detach(c); + detachstack(c); + c->mon = m2; + c->tags = m2->tagset[m2->seltags]; /* assign tags of target monitor */ + attach(c); + attachstack(c); + } + } + } + + if (c2){ + for (N=1, c=c2; c->next; c=c->next, N++); + for (n=N; n>0; n--){ + for (p=1, c=c2; p<n; p++, c=c->next); + if ISVISIBLE(c){ + detach(c); + detachstack(c); + c->mon = m1; + c->tags = m1->tagset[m1->seltags]; /* assign tags of target monitor */ + attach(c); + attachstack(c); + } + } + } + + if (c1 || c2){ + focus(NULL); + arrange(NULL); + } + + if (c2){ + if (c1) + unfocus(c1, 1); + focus(c2); + arrange(c2->mon); + } + + arrange(selmon); + focus(c); +} + +void tag(const Arg *arg) { - if (selmon->sel && arg->ui & TAGMASK) { - selmon->sel->tags = arg->ui & TAGMASK; - focus(NULL); - arrange(selmon); - } + if (!selmon->sel || !(arg->ui & TAGMASK)) + return; + + if (selmon == mastermon){ + selmon->sel->tags = arg->ui & TAGMASK; + focus(NULL); + arrange(selmon); + return; + } + + Client *c = selmon->sel; + unfocus(c, 1); + detach(c); + detachstack(c); + c->mon = mastermon; + c->tags = arg->ui & TAGMASK; + attach(c); + attachstack(c); + focus(NULL); + arrange(NULL); } void tagmon(const Arg *arg) { - if (!selmon->sel || !mons->next) + Monitor *m; + if (!selmon->sel) + return; + if (arg->i > 1){ + m=numtomon(arg->ui-2); + if (m) + sendmon(selmon->sel, m); + return; + } + if (!mons->next) return; sendmon(selmon->sel, dirtomon(arg->i)); } @@ -1677,28 +2280,31 @@ tagmon(const Arg *arg) void tile(Monitor *m) { - unsigned int i, n, h, mw, my, ty; + unsigned int i, n, h, mw, my, ty, ns; Client *c; for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; - if (n > m->nmaster) + if (n > m->nmaster) { mw = m->nmaster ? m->ww * m->mfact : 0; - else + ns = m->nmaster > 0 ? 2 : 1; + } else { mw = m->ww; - for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + ns = 1; + } + for(i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) if (i < m->nmaster) { - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); + h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gappx; + resize(c, m->wx + gappx, m->wy + my, mw - (2*c->bw) - gappx*(5-ns)/2, h - (2*c->bw), False); if (my + HEIGHT(c) < m->wh) - my += HEIGHT(c); + my += HEIGHT(c) + gappx; } else { - h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); + h = (m->wh - ty) / (n - i) - gappx; + resize(c, m->wx + mw + gappx/ns, m->wy + ty, m->ww - mw - (2*c->bw) - gappx*(5-ns)/2, h - (2*c->bw), False); if (ty + HEIGHT(c) < m->wh) - ty += HEIGHT(c); + ty += HEIGHT(c) + gappx; } } @@ -1755,9 +2361,13 @@ toggleview(const Arg *arg) void unfocus(Client *c, int setfocus) { + XWindowChanges wc; if (!c) return; grabbuttons(c, 0); + c->bw = 0; // borderpx + wc.border_width = c->bw; + XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); @@ -1771,6 +2381,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) { @@ -1785,9 +2409,12 @@ unmanage(Client *c, int destroyed) XUngrabServer(dpy); } free(c); - focus(NULL); - updateclientlist(); - arrange(m); + + if (!s) { + arrange(m); + focus(NULL); + updateclientlist(); + } } void @@ -1810,16 +2437,18 @@ updatebars(void) Monitor *m; XSetWindowAttributes wa = { .override_redirect = True, - .background_pixmap = ParentRelative, + .background_pixel = 0, + .border_pixel = 0, + .colormap = cmap, .event_mask = ButtonPressMask|ExposureMask }; XClassHint ch = {"dwm", "dwm"}; for (m = mons; m; m = m->next) { if (m->barwin) continue; - m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), - CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth, + InputOutput, visual, + CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XMapRaised(dpy, m->barwin); XSetClassHint(dpy, m->barwin, &ch); @@ -1893,6 +2522,7 @@ updategeom(void) m->my = m->wy = unique[i].y_org; m->mw = m->ww = unique[i].width; m->mh = m->wh = unique[i].height; + mastermon = m; // do not use makemastermon here. updatebarpos(m); } } else { /* less monitors available nn < n */ @@ -1907,7 +2537,7 @@ updategeom(void) attachstack(c); } if (m == selmon) - selmon = mons; + selmon = mons; cleanupmon(m); } } @@ -1993,8 +2623,10 @@ updatesizehints(Client *c) void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) strcpy(stext, "dwm-"VERSION); + else + copyvalidchars(stext, rawstext); drawbar(selmon); } @@ -2041,13 +2673,119 @@ updatewmhints(Client *c) void view(const Arg *arg) { - if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) + if ((selmon == mastermon) && ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])) return; + if (selmon != mastermon) + selmon = mastermon; selmon->seltags ^= 1; /* toggle sel tagset */ if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; - focus(NULL); - arrange(selmon); + arrange(selmon); + focus(selmon->sel); +} + +pid_t +winpid(Window w) +{ + pid_t result = 0; + + 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; + return result; +} + +pid_t +getparentprocess(pid_t p) +{ + unsigned int v = 0; + +#if defined(__linux__) + FILE *f; + char buf[256]; + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); + + if (!(f = fopen(buf, "r"))) + return (pid_t)0; + + if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1) + v = (pid_t)0; + fclose(f); +#elif defined(__FreeBSD__) + struct kinfo_proc *proc = kinfo_getproc(p); + if (!proc) + return (pid_t)0; + + v = proc->ki_ppid; + free(proc); +#endif + 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 * @@ -2117,17 +2855,78 @@ xerrorstart(Display *dpy, XErrorEvent *ee) } void +xinitvisual() +{ + XVisualInfo *infos; + XRenderPictFormat *fmt; + int nitems; + int i; + + XVisualInfo tpl = { + .screen = screen, + .depth = 32, + .class = TrueColor + }; + long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; + + infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); + visual = NULL; + for(i = 0; i < nitems; i ++) { + fmt = XRenderFindVisualFormat(dpy, infos[i].visual); + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { + visual = infos[i].visual; + depth = infos[i].depth; + cmap = XCreateColormap(dpy, root, visual, AllocNone); + useargb = 1; + break; + } + } + + XFree(infos); + + if (! visual) { + visual = DefaultVisual(dpy, screen); + depth = DefaultDepth(dpy, screen); + cmap = DefaultColormap(dpy, screen); + } +} + +void zoom(const Arg *arg) { Client *c = selmon->sel; + Client *at = NULL, *cold, *cprevious = NULL; if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating)) return; - if (c == nexttiled(selmon->clients)) - if (!c || !(c = nexttiled(c->next))) - return; - pop(c); + if (c == nexttiled(selmon->clients)) { + at = findbefore(prevzoom); + if (at) + cprevious = nexttiled(at->next); + if (!cprevious || cprevious != prevzoom) { + prevzoom = NULL; + if (!c || !(c = nexttiled(c->next))) + return; + } else + c = cprevious; + } + cold = nexttiled(selmon->clients); + if (c != cold && !at) + at = findbefore(c); + detach(c); + attach(c); + /* swap windows instead of pushing the previous one down */ + if (c != cold && at) { + prevzoom = cold; + if (cold && at != cold) { + detach(cold); + cold->next = at->next; + at->next = cold; + } + } + focus(c); + arrange(c->mon); } int @@ -2141,6 +2940,8 @@ 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(); setup(); #ifdef __OpenBSD__ @@ -2153,3 +2954,106 @@ main(int argc, char *argv[]) XCloseDisplay(dpy); return EXIT_SUCCESS; } + +void +centeredmaster(Monitor *m) +{ + unsigned int i, n, h, mw, mx, my, oty, ety, tw; + Client *c; + + /* count number of clients in the selected monitor */ + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + + /* initialize areas */ + mw = m->ww; + mx = 0; + my = 0; + tw = mw; + + if (n > m->nmaster) { + /* go mfact box in the center if more than nmaster clients */ + mw = m->nmaster ? m->ww * m->mfact : 0; + tw = m->ww - mw; + + if (n - m->nmaster > 1) { + /* only one client */ + mx = (m->ww - mw) / 2; + tw = (m->ww - mw) / 2; + } + } + + oty = 0; + ety = 0; + for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + /* nmaster clients are stacked vertically, in the center + * of the screen */ + h = (m->wh - my) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), + h - (2*c->bw), 0); + my += HEIGHT(c); + } else { + /* stack clients are stacked vertically */ + if ((i - m->nmaster) % 2 ) { + h = (m->wh - ety) / ( (1 + n - i) / 2); + resize(c, m->wx, m->wy + ety, tw - (2*c->bw), + h - (2*c->bw), 0); + ety += HEIGHT(c); + } else { + h = (m->wh - oty) / ((1 + n - i) / 2); + resize(c, m->wx + mx + mw, m->wy + oty, + tw - (2*c->bw), h - (2*c->bw), 0); + oty += HEIGHT(c); + } + } +} + +void +centeredfloatingmaster(Monitor *m) +{ + unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx; + Client *c; + + /* count number of clients in the selected monitor */ + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + + /* initialize nmaster area */ + if (n > m->nmaster) { + /* go mfact box in the center if more than nmaster clients */ + if (m->ww > m->wh) { + mw = m->nmaster ? m->ww * m->mfact : 0; + mh = m->nmaster ? m->wh * 0.9 : 0; + } else { + mh = m->nmaster ? m->wh * m->mfact : 0; + mw = m->nmaster ? m->ww * 0.9 : 0; + } + mx = mxo = (m->ww - mw) / 2; + my = myo = (m->wh - mh) / 2; + } else { + /* go fullscreen if all clients are in the master area */ + mh = m->wh; + mw = m->ww; + mx = mxo = 0; + my = myo = 0; + } + + for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + /* nmaster clients are stacked horizontally, in the center + * of the screen */ + w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i); + resize(c, m->wx + mx, m->wy + my, w - (2*c->bw), + mh - (2*c->bw), 0); + mx += WIDTH(c); + } else { + /* stack clients are stacked horizontally */ + w = (m->ww - tx) / (n - i); + resize(c, m->wx + tx, m->wy, w - (2*c->bw), + m->wh - (2*c->bw), 0); + tx += WIDTH(c); + } +} @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +signal() { + xsetroot -name "fsignal:$*" +} + +case $# in +1) + case $1 in + setlayout | fullscreen | view | viewall | togglebar | togglefloating | zoom | killclient | quit | focusmaster | zoomswap) + signal $1 + ;; + *) + echo "Unknown command or missing one argument." + exit 1 + ;; + esac + ;; +2) + case $1 in + view) + signal $1 ui $2 + ;; + viewex | toggleviewex | tagex | toggletagex | setlayoutex | focusstack | incnmaster | focusmon | tagmon | rotatestack | setmastermon | movestack) + signal $1 i $2 + ;; + setmfact) + signal $1 f $2 + ;; + *) + echo "Unknown command or one too many arguments." + exit 1 + ;; + esac + ;; +*) + echo "Too many arguments." + exit 1 + ;; +esac diff --git a/focusmaster.c b/focusmaster.c new file mode 100644 index 0000000..9b397c7 --- /dev/null +++ b/focusmaster.c @@ -0,0 +1,4 @@ +static void +focusmaster(const Arg *arg) { + focus(nexttiled(selmon->clients)); +} diff --git a/gaplessgrid.c b/gaplessgrid.c new file mode 100644 index 0000000..10808c5 --- /dev/null +++ b/gaplessgrid.c @@ -0,0 +1,35 @@ +void +gaplessgrid(Monitor *m) { + unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; + Client *c; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; + if(n == 0) + return; + + /* grid dimensions */ + for(cols = 0; cols <= n/2; cols++) + if(cols*cols >= n) + break; + if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ + cols = 2; + rows = n/cols; + + /* window geometries */ + cw = cols ? m->ww / cols : m->ww; + cn = 0; /* current column number */ + rn = 0; /* current row number */ + for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { + if(i/rows + 1 > cols - n%cols) + rows = n/cols + 1; + ch = rows ? m->wh / rows : m->wh; + cx = m->wx + cn*cw; + cy = m->wy + rn*ch; + resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); + rn++; + if(rn >= rows) { + rn = 0; + cn++; + } + } +} diff --git a/movestack.c b/movestack.c new file mode 100644 index 0000000..c040462 --- /dev/null +++ b/movestack.c @@ -0,0 +1,49 @@ +void +movestack(const Arg *arg) { + Client *c = NULL, *p = NULL, *pc = NULL, *i; + + if(arg->i > 0) { + /* find the client after selmon->sel */ + for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); + if(!c) + for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); + + } + else { + /* find the client before selmon->sel */ + for(i = selmon->clients; i != selmon->sel; i = i->next) + if(ISVISIBLE(i) && !i->isfloating) + c = i; + if(!c) + for(; i; i = i->next) + if(ISVISIBLE(i) && !i->isfloating) + c = i; + } + /* find the client before selmon->sel and c */ + for(i = selmon->clients; i && (!p || !pc); i = i->next) { + if(i->next == selmon->sel) + p = i; + if(i->next == c) + pc = i; + } + + /* swap c and selmon->sel selmon->clients in the selmon->clients list */ + if(c && c != selmon->sel) { + Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; + selmon->sel->next = c->next==selmon->sel?c:c->next; + c->next = temp; + + if(p && p != c) + p->next = c; + if(pc && pc != selmon->sel) + pc->next = selmon->sel; + + if(selmon->sel == selmon->clients) + selmon->clients = c; + else if(c == selmon->clients) + selmon->clients = selmon->sel; + + arrange(selmon); + } +} + diff --git a/patches/dwm-activetagindicatorbar-6.2.diff b/patches/dwm-activetagindicatorbar-6.2.diff new file mode 100644 index 0000000..4450099 --- /dev/null +++ b/patches/dwm-activetagindicatorbar-6.2.diff @@ -0,0 +1,17 @@ +diff -up dwm-a/dwm.c dwm-b/dwm.c +--- dwm-a/dwm.c 2019-02-02 06:55:28.000000000 -0600 ++++ dwm-b/dwm.c 2019-02-23 21:43:13.359179100 -0600 +@@ -719,9 +719,10 @@ drawbar(Monitor *m) + drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); + drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); + if (occ & 1 << i) +- drw_rect(drw, x + boxs, boxs, boxw, boxw, +- m == selmon && selmon->sel && selmon->sel->tags & 1 << i, +- urg & 1 << i); ++ drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, ++ m == selmon && selmon->sel && selmon->sel->tags & 1 << i, ++ urg & 1 << i); ++ + x += w; + } + w = blw = TEXTW(m->ltsymbol); diff --git a/patches/dwm-alpha-20180613-b69c870.diff b/patches/dwm-alpha-20180613-b69c870.diff new file mode 100644 index 0000000..558b2f3 --- /dev/null +++ b/patches/dwm-alpha-20180613-b69c870.diff @@ -0,0 +1,289 @@ +From f699934b8c8a9c15988ad359bf8fedd6c55abd53 Mon Sep 17 00:00:00 2001 +From: Thomas Oltmann <thomas.oltmann.hhg@gmail.com> +Date: Wed, 13 Jun 2018 19:46:26 +0200 +Subject: [PATCH] Allow dwm to have translucent bars, while keeping all the + text on it opaque, just like the alpha-patch for st. Updated for b69c870. + +--- + config.def.h | 7 ++++++ + config.mk | 2 +- + drw.c | 26 ++++++++++++----------- + drw.h | 9 +++++--- + dwm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ + 5 files changed, 82 insertions(+), 22 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..4f68fe8 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -12,11 +12,18 @@ 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 unsigned int baralpha = 0xd0; ++static const unsigned int borderalpha = OPAQUE; + static const char *colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, + [SchemeSel] = { col_gray4, col_cyan, col_cyan }, + }; ++static const unsigned int alphas[][3] = { ++ /* fg bg border */ ++ [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, ++ [SchemeSel] = { OPAQUE, baralpha, borderalpha }, ++}; + + /* tagging */ + static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +diff --git a/config.mk b/config.mk +index 25e2685..bef8de0 100644 +--- a/config.mk ++++ b/config.mk +@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2 + + # includes and libs + INCS = -I${X11INC} -I${FREETYPEINC} +-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} ++LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXrender + + # flags + CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +diff --git a/drw.c b/drw.c +index c638323..77fc113 100644 +--- a/drw.c ++++ b/drw.c +@@ -61,7 +61,7 @@ utf8decode(const char *c, long *u, size_t clen) + } + + Drw * +-drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) ++drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap) + { + Drw *drw = ecalloc(1, sizeof(Drw)); + +@@ -70,8 +70,11 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h + drw->root = root; + drw->w = w; + drw->h = h; +- drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); +- drw->gc = XCreateGC(dpy, root, 0, NULL); ++ drw->visual = visual; ++ drw->depth = depth; ++ drw->cmap = cmap; ++ drw->drawable = XCreatePixmap(dpy, root, w, h, depth); ++ drw->gc = XCreateGC(dpy, drw->drawable, 0, NULL); + XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); + + return drw; +@@ -87,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h) + drw->h = h; + if (drw->drawable) + XFreePixmap(drw->dpy, drw->drawable); +- drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); ++ drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, drw->depth); + } + + void +@@ -180,21 +183,22 @@ drw_fontset_free(Fnt *font) + } + + void +-drw_clr_create(Drw *drw, Clr *dest, const char *clrname) ++drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha) + { + if (!drw || !dest || !clrname) + return; + +- if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), +- DefaultColormap(drw->dpy, drw->screen), ++ if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, + clrname, dest)) + die("error, cannot allocate color '%s'", clrname); ++ ++ dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); + } + + /* 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, const char *clrnames[], const unsigned int alphas[], size_t clrcount) + { + size_t i; + Clr *ret; +@@ -204,7 +208,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) + return NULL; + + for (i = 0; i < clrcount; i++) +- drw_clr_create(drw, &ret[i], clrnames[i]); ++ drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]); + return ret; + } + +@@ -260,9 +264,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp + } else { + XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); + XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); +- d = XftDrawCreate(drw->dpy, drw->drawable, +- DefaultVisual(drw->dpy, drw->screen), +- DefaultColormap(drw->dpy, drw->screen)); ++ d = XftDrawCreate(drw->dpy, drw->drawable, drw->visual, drw->cmap); + x += lpad; + w -= lpad; + } +diff --git a/drw.h b/drw.h +index 4bcd5ad..a56f523 100644 +--- a/drw.h ++++ b/drw.h +@@ -20,6 +20,9 @@ typedef struct { + Display *dpy; + int screen; + Window root; ++ Visual *visual; ++ unsigned int depth; ++ Colormap cmap; + Drawable drawable; + GC gc; + Clr *scheme; +@@ -27,7 +30,7 @@ typedef struct { + } Drw; + + /* Drawable abstraction */ +-Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); ++Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); + void drw_resize(Drw *drw, unsigned int w, unsigned int h); + void drw_free(Drw *drw); + +@@ -38,8 +41,8 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text); + void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); + + /* 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); ++void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha); ++Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount); + + /* Cursor abstraction */ + Cur *drw_cur_create(Drw *drw, int shape); +diff --git a/dwm.c b/dwm.c +index 4465af1..20f8309 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -57,6 +57,8 @@ + #define TAGMASK ((1 << LENGTH(tags)) - 1) + #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) + ++#define OPAQUE 0xffU ++ + /* enums */ + enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ + enum { SchemeNorm, SchemeSel }; /* color schemes */ +@@ -232,6 +234,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 xinitvisual(); + static void zoom(const Arg *arg); + + /* variables */ +@@ -268,6 +271,11 @@ static Drw *drw; + static Monitor *mons, *selmon; + static Window root, wmcheckwin; + ++static int useargb = 0; ++static Visual *visual; ++static int depth; ++static Colormap cmap; ++ + /* configuration, allows nested code to access above variables */ + #include "config.h" + +@@ -1541,7 +1549,8 @@ setup(void) + sw = DisplayWidth(dpy, screen); + sh = DisplayHeight(dpy, screen); + root = RootWindow(dpy, screen); +- drw = drw_create(dpy, screen, root, sw, sh); ++ xinitvisual(); ++ drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap); + if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) + die("no fonts could be loaded."); + lrpad = drw->fonts->h; +@@ -1569,7 +1578,7 @@ setup(void) + /* init appearance */ + scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); + for (i = 0; i < LENGTH(colors); i++) +- scheme[i] = drw_scm_create(drw, colors[i], 3); ++ scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 3); + /* init bars */ + updatebars(); + updatestatus(); +@@ -1804,16 +1813,18 @@ updatebars(void) + Monitor *m; + XSetWindowAttributes wa = { + .override_redirect = True, +- .background_pixmap = ParentRelative, ++ .background_pixel = 0, ++ .border_pixel = 0, ++ .colormap = cmap, + .event_mask = ButtonPressMask|ExposureMask + }; + XClassHint ch = {"dwm", "dwm"}; + for (m = mons; m; m = m->next) { + if (m->barwin) + continue; +- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), +- CopyFromParent, DefaultVisual(dpy, screen), +- CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); ++ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, depth, ++ InputOutput, visual, ++ CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); + XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); + XMapRaised(dpy, m->barwin); + XSetClassHint(dpy, m->barwin, &ch); +@@ -2110,6 +2121,43 @@ xerrorstart(Display *dpy, XErrorEvent *ee) + return -1; + } + ++void ++xinitvisual() ++{ ++ XVisualInfo *infos; ++ XRenderPictFormat *fmt; ++ int nitems; ++ int i; ++ ++ XVisualInfo tpl = { ++ .screen = screen, ++ .depth = 32, ++ .class = TrueColor ++ }; ++ long masks = VisualScreenMask | VisualDepthMask | VisualClassMask; ++ ++ infos = XGetVisualInfo(dpy, masks, &tpl, &nitems); ++ visual = NULL; ++ for(i = 0; i < nitems; i ++) { ++ fmt = XRenderFindVisualFormat(dpy, infos[i].visual); ++ if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { ++ visual = infos[i].visual; ++ depth = infos[i].depth; ++ cmap = XCreateColormap(dpy, root, visual, AllocNone); ++ useargb = 1; ++ break; ++ } ++ } ++ ++ XFree(infos); ++ ++ if (! visual) { ++ visual = DefaultVisual(dpy, screen); ++ depth = DefaultDepth(dpy, screen); ++ cmap = DefaultColormap(dpy, screen); ++ } ++} ++ + void + zoom(const Arg *arg) + { +-- +2.17.0 + diff --git a/patches/dwm-bar-height-6.2.diff b/patches/dwm-bar-height-6.2.diff new file mode 100644 index 0000000..a576111 --- /dev/null +++ b/patches/dwm-bar-height-6.2.diff @@ -0,0 +1,25 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..9814500 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ + static const unsigned int snap = 32; /* snap pixel */ + static const int showbar = 1; /* 0 means no bar */ + static const int topbar = 1; /* 0 means bottom bar */ ++static const int user_bh = 0; /* 0 means that dwm will calculate bar height, >= 1 means dwm will user_bh as bar height */ + static const char *fonts[] = { "monospace:size=10" }; + static const char dmenufont[] = "monospace:size=10"; + static const char col_gray1[] = "#222222"; +diff --git a/dwm.c b/dwm.c +index 4465af1..2c27cb3 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -1545,7 +1545,7 @@ setup(void) + if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) + die("no fonts could be loaded."); + lrpad = drw->fonts->h; +- bh = drw->fonts->h + 2; ++ bh = user_bh ? user_bh : drw->fonts->h + 2; + updategeom(); + /* init atoms */ + utf8string = XInternAtom(dpy, "UTF8_STRING", False); diff --git a/patches/dwm-canfocusrule-20200702-f709b19.diff b/patches/dwm-canfocusrule-20200702-f709b19.diff new file mode 100644 index 0000000..8917836 --- /dev/null +++ b/patches/dwm-canfocusrule-20200702-f709b19.diff @@ -0,0 +1,98 @@ +From f709b1910af85d8ff2fdd5c38215c204f8bb34e7 Mon Sep 17 00:00:00 2001 +From: Danil Demchenko <mail@d-demchenko.ru> +Date: Fri, 7 Feb 2020 00:11:53 +0300 +Subject: [PATCH] Add rule to remove the opportunity to focus certain windows. + May be useful for tray applications. + +--- + config.def.h | 6 +++--- + dwm.c | 15 ++++++++++----- + 2 files changed, 13 insertions(+), 8 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..a4468eb 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -26,9 +26,9 @@ static const Rule rules[] = { + * 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 canfocus monitor */ ++ { "Gimp", NULL, NULL, 0, 1, 1, -1 }, ++ { "Firefox", NULL, NULL, 1 << 8, 0, 1, -1 }, + }; + + /* layout(s) */ +diff --git a/dwm.c b/dwm.c +index 4465af1..c678e90 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -92,7 +92,7 @@ struct Client { + int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int bw, oldbw; + unsigned int tags; +- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; ++ int isfixed, isfloating, canfocus, isurgent, neverfocus, oldstate, isfullscreen; + Client *next; + Client *snext; + Monitor *mon; +@@ -138,6 +138,7 @@ typedef struct { + const char *title; + unsigned int tags; + int isfloating; ++ int canfocus; + int monitor; + } Rule; + +@@ -286,6 +287,7 @@ applyrules(Client *c) + + /* rule matching */ + c->isfloating = 0; ++ c->canfocus = 1; + c->tags = 0; + XGetClassHint(dpy, c->win, &ch); + class = ch.res_class ? ch.res_class : broken; +@@ -298,6 +300,7 @@ applyrules(Client *c) + && (!r->instance || strstr(instance, r->instance))) + { + c->isfloating = r->isfloating; ++ c->canfocus = r->canfocus; + c->tags |= r->tags; + for (m = mons; m && m->num != r->monitor; m = m->next); + if (m) +@@ -788,6 +791,8 @@ focus(Client *c) + if (selmon->sel && selmon->sel != c) + unfocus(selmon->sel, 0); + if (c) { ++ if (!c->canfocus) ++ return; + if (c->mon != selmon) + selmon = c->mon; + if (c->isurgent) +@@ -837,16 +842,16 @@ focusstack(const Arg *arg) + if (!selmon->sel) + return; + if (arg->i > 0) { +- for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); ++ for (c = selmon->sel->next; c && (!ISVISIBLE(c) || !c->canfocus); c = c->next); + if (!c) +- for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); ++ for (c = selmon->clients; c && (!ISVISIBLE(c) || !c->canfocus); c = c->next); + } else { + for (i = selmon->clients; i != selmon->sel; i = i->next) +- if (ISVISIBLE(i)) ++ if (ISVISIBLE(i) && i->canfocus) + c = i; + if (!c) + for (; i; i = i->next) +- if (ISVISIBLE(i)) ++ if (ISVISIBLE(i) && i->canfocus) + c = i; + } + if (c) { +-- +2.25.0 + diff --git a/patches/dwm-centeredmaster-6.1.diff b/patches/dwm-centeredmaster-6.1.diff new file mode 100644 index 0000000..6926892 --- /dev/null +++ b/patches/dwm-centeredmaster-6.1.diff @@ -0,0 +1,142 @@ +diff --git a/config.def.h b/config.def.h +index 7054c06..527b214 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -39,6 +39,8 @@ static const Layout layouts[] = { + { "[]=", tile }, /* first entry is default */ + { "><>", NULL }, /* no layout function means floating behavior */ + { "[M]", monocle }, ++ { "|M|", centeredmaster }, ++ { ">M>", centeredfloatingmaster }, + }; + + /* key definitions */ +@@ -74,6 +76,8 @@ static Key keys[] = { + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY, XK_u, setlayout, {.v = &layouts[3]} }, ++ { MODKEY, XK_o, setlayout, {.v = &layouts[4]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, +diff --git a/dwm.c b/dwm.c +index 0362114..1e81412 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -233,6 +233,8 @@ static int xerror(Display *dpy, XErrorEvent *ee); + static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(const Arg *arg); ++static void centeredmaster(Monitor *m); ++static void centeredfloatingmaster(Monitor *m); + + /* variables */ + static const char broken[] = "broken"; +@@ -2139,3 +2141,106 @@ main(int argc, char *argv[]) + XCloseDisplay(dpy); + return EXIT_SUCCESS; + } ++ ++void ++centeredmaster(Monitor *m) ++{ ++ unsigned int i, n, h, mw, mx, my, oty, ety, tw; ++ Client *c; ++ ++ /* count number of clients in the selected monitor */ ++ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); ++ if (n == 0) ++ return; ++ ++ /* initialize areas */ ++ mw = m->ww; ++ mx = 0; ++ my = 0; ++ tw = mw; ++ ++ if (n > m->nmaster) { ++ /* go mfact box in the center if more than nmaster clients */ ++ mw = m->nmaster ? m->ww * m->mfact : 0; ++ tw = m->ww - mw; ++ ++ if (n - m->nmaster > 1) { ++ /* only one client */ ++ mx = (m->ww - mw) / 2; ++ tw = (m->ww - mw) / 2; ++ } ++ } ++ ++ oty = 0; ++ ety = 0; ++ for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) ++ if (i < m->nmaster) { ++ /* nmaster clients are stacked vertically, in the center ++ * of the screen */ ++ h = (m->wh - my) / (MIN(n, m->nmaster) - i); ++ resize(c, m->wx + mx, m->wy + my, mw - (2*c->bw), ++ h - (2*c->bw), 0); ++ my += HEIGHT(c); ++ } else { ++ /* stack clients are stacked vertically */ ++ if ((i - m->nmaster) % 2 ) { ++ h = (m->wh - ety) / ( (1 + n - i) / 2); ++ resize(c, m->wx, m->wy + ety, tw - (2*c->bw), ++ h - (2*c->bw), 0); ++ ety += HEIGHT(c); ++ } else { ++ h = (m->wh - oty) / ((1 + n - i) / 2); ++ resize(c, m->wx + mx + mw, m->wy + oty, ++ tw - (2*c->bw), h - (2*c->bw), 0); ++ oty += HEIGHT(c); ++ } ++ } ++} ++ ++void ++centeredfloatingmaster(Monitor *m) ++{ ++ unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx; ++ Client *c; ++ ++ /* count number of clients in the selected monitor */ ++ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); ++ if (n == 0) ++ return; ++ ++ /* initialize nmaster area */ ++ if (n > m->nmaster) { ++ /* go mfact box in the center if more than nmaster clients */ ++ if (m->ww > m->wh) { ++ mw = m->nmaster ? m->ww * m->mfact : 0; ++ mh = m->nmaster ? m->wh * 0.9 : 0; ++ } else { ++ mh = m->nmaster ? m->wh * m->mfact : 0; ++ mw = m->nmaster ? m->ww * 0.9 : 0; ++ } ++ mx = mxo = (m->ww - mw) / 2; ++ my = myo = (m->wh - mh) / 2; ++ } else { ++ /* go fullscreen if all clients are in the master area */ ++ mh = m->wh; ++ mw = m->ww; ++ mx = mxo = 0; ++ my = myo = 0; ++ } ++ ++ for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) ++ if (i < m->nmaster) { ++ /* nmaster clients are stacked horizontally, in the center ++ * of the screen */ ++ w = (mw + mxo - mx) / (MIN(n, m->nmaster) - i); ++ resize(c, m->wx + mx, m->wy + my, w - (2*c->bw), ++ mh - (2*c->bw), 0); ++ mx += WIDTH(c); ++ } else { ++ /* stack clients are stacked horizontally */ ++ w = (m->ww - tx) / (n - i); ++ resize(c, m->wx + tx, m->wy, w - (2*c->bw), ++ m->wh - (2*c->bw), 0); ++ tx += WIDTH(c); ++ } ++} diff --git a/patches/dwm-dwmc-6.2.diff b/patches/dwm-dwmc-6.2.diff new file mode 100644 index 0000000..73b2b01 --- /dev/null +++ b/patches/dwm-dwmc-6.2.diff @@ -0,0 +1,237 @@ +From f2af4bc3699461833d614dbd1610123b1c315853 Mon Sep 17 00:00:00 2001 +From: Daniel Perez Alvarez <danielpza@protonmail.com> +Date: Sat, 28 Sep 2019 15:17:28 +0000 +Subject: [PATCH] dwm-client + +--- + Makefile | 2 +- + config.def.h | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + dwm.c | 52 +++++++++++++++++++++++++++++++++++++- + dwmc | 40 ++++++++++++++++++++++++++++++ + 4 files changed, 162 insertions(+), 2 deletions(-) + create mode 100755 dwmc + +diff --git a/Makefile b/Makefile +index 77bcbc0..f837f5c 100644 +--- a/Makefile ++++ b/Makefile +@@ -38,7 +38,7 @@ dist: clean + + install: all + mkdir -p ${DESTDIR}${PREFIX}/bin +- cp -f dwm ${DESTDIR}${PREFIX}/bin ++ cp -f dwm dwmc ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/dwm + mkdir -p ${DESTDIR}${MANPREFIX}/man1 + sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 +diff --git a/config.def.h b/config.def.h +index 1c0b587..efbae79 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -113,3 +113,73 @@ static Button buttons[] = { + { ClkTagBar, MODKEY, Button3, toggletag, {0} }, + }; + ++void ++setlayoutex(const Arg *arg) ++{ ++ setlayout(&((Arg) { .v = &layouts[arg->i] })); ++} ++ ++void ++viewex(const Arg *arg) ++{ ++ view(&((Arg) { .ui = 1 << arg->ui })); ++} ++ ++void ++viewall(const Arg *arg) ++{ ++ view(&((Arg){.ui = ~0})); ++} ++ ++void ++toggleviewex(const Arg *arg) ++{ ++ toggleview(&((Arg) { .ui = 1 << arg->ui })); ++} ++ ++void ++tagex(const Arg *arg) ++{ ++ tag(&((Arg) { .ui = 1 << arg->ui })); ++} ++ ++void ++toggletagex(const Arg *arg) ++{ ++ toggletag(&((Arg) { .ui = 1 << arg->ui })); ++} ++ ++void ++tagall(const Arg *arg) ++{ ++ tag(&((Arg){.ui = ~0})); ++} ++ ++/* signal definitions */ ++/* signum must be greater than 0 */ ++/* trigger signals using `xsetroot -name "fsignal:<signame> [<type> <value>]"` */ ++static Signal signals[] = { ++ /* signum function */ ++ { "focusstack", focusstack }, ++ { "setmfact", setmfact }, ++ { "togglebar", togglebar }, ++ { "incnmaster", incnmaster }, ++ { "togglefloating", togglefloating }, ++ { "focusmon", focusmon }, ++ { "tagmon", tagmon }, ++ { "zoom", zoom }, ++ { "view", view }, ++ { "viewall", viewall }, ++ { "viewex", viewex }, ++ { "toggleview", view }, ++ { "toggleviewex", toggleviewex }, ++ { "tag", tag }, ++ { "tagall", tagall }, ++ { "tagex", tagex }, ++ { "toggletag", tag }, ++ { "toggletagex", toggletagex }, ++ { "killclient", killclient }, ++ { "quit", quit }, ++ { "setlayout", setlayout }, ++ { "setlayoutex", setlayoutex }, ++}; +diff --git a/dwm.c b/dwm.c +index 4465af1..e0fc838 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -106,6 +106,11 @@ typedef struct { + const Arg arg; + } Key; + ++typedef struct { ++ const char * sig; ++ void (*func)(const Arg *); ++} Signal; ++ + typedef struct { + const char *symbol; + void (*arrange)(Monitor *); +@@ -148,6 +153,7 @@ static void arrange(Monitor *m); + static void arrangemon(Monitor *m); + static void attach(Client *c); + static void attachstack(Client *c); ++static int fake_signal(void); + static void buttonpress(XEvent *e); + static void checkotherwm(void); + static void cleanup(void); +@@ -998,6 +1004,49 @@ keypress(XEvent *e) + keys[i].func(&(keys[i].arg)); + } + ++int ++fake_signal(void) ++{ ++ char fsignal[256]; ++ char indicator[9] = "fsignal:"; ++ char str_sig[50]; ++ char param[16]; ++ int i, len_str_sig, n, paramn; ++ size_t len_fsignal, len_indicator = strlen(indicator); ++ Arg arg; ++ ++ // Get root name property ++ if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) { ++ len_fsignal = strlen(fsignal); ++ ++ // Check if this is indeed a fake signal ++ if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) { ++ paramn = sscanf(fsignal+len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n); ++ ++ if (paramn == 1) arg = (Arg) {0}; ++ else if (paramn > 2) return 1; ++ else if (strncmp(param, "i", n - len_str_sig) == 0) ++ sscanf(fsignal + len_indicator + n, "%i", &(arg.i)); ++ else if (strncmp(param, "ui", n - len_str_sig) == 0) ++ sscanf(fsignal + len_indicator + n, "%u", &(arg.ui)); ++ else if (strncmp(param, "f", n - len_str_sig) == 0) ++ sscanf(fsignal + len_indicator + n, "%f", &(arg.f)); ++ else return 1; ++ ++ // Check if a signal was found, and if so handle it ++ for (i = 0; i < LENGTH(signals); i++) ++ if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func) ++ signals[i].func(&(arg)); ++ ++ // A fake signal was sent ++ return 1; ++ } ++ } ++ ++ // No fake signal was sent, so proceed with update ++ return 0; ++} ++ + void + killclient(const Arg *arg) + { +@@ -1216,7 +1265,8 @@ propertynotify(XEvent *e) + XPropertyEvent *ev = &e->xproperty; + + if ((ev->window == root) && (ev->atom == XA_WM_NAME)) +- updatestatus(); ++ if (!fake_signal()) ++ updatestatus(); + else if (ev->state == PropertyDelete) + return; /* ignore */ + else if ((c = wintoclient(ev->window))) { +diff --git a/dwmc b/dwmc +new file mode 100755 +index 0000000..5ff8dbc +--- /dev/null ++++ b/dwmc +@@ -0,0 +1,40 @@ ++#!/usr/bin/env sh ++ ++signal() { ++ xsetroot -name "fsignal:$*" ++} ++ ++case $# in ++1) ++ case $1 in ++ setlayout | view | viewall | togglebar | togglefloating | zoom | killclient | quit) ++ signal $1 ++ ;; ++ *) ++ echo "Unknown command or missing one argument." ++ exit 1 ++ ;; ++ esac ++ ;; ++2) ++ case $1 in ++ view) ++ signal $1 ui $2 ++ ;; ++ viewex | toggleviewex | tagex | toggletagex | setlayoutex | focusstack | incnmaster | focusmon | tagmon) ++ signal $1 i $2 ++ ;; ++ setmfact) ++ signal $1 f $2 ++ ;; ++ *) ++ echo "Unknown command or one too many arguments." ++ exit 1 ++ ;; ++ esac ++ ;; ++*) ++ echo "Too many arguments." ++ exit 1 ++ ;; ++esac +-- +2.17.1 + diff --git a/patches/dwm-focusmaster.diff b/patches/dwm-focusmaster.diff new file mode 100644 index 0000000..d5dd30f --- /dev/null +++ b/patches/dwm-focusmaster.diff @@ -0,0 +1,13 @@ +Author: Jan Christoph Ebersbach <jceb@e-jc.de> +URL: no URL yet +Straight forward patch to focus the master window with a keybinding. + +Index: dwm/focusmaster.c +=================================================================== +--- /dev/null ++++ dwm/focusmaster.c +@@ -0,0 +1,4 @@ ++static void ++focusmaster(const Arg *arg) { ++ focus(nexttiled(selmon->clients)); ++} diff --git a/patches/dwm-fullscreen.diff b/patches/dwm-fullscreen.diff new file mode 100644 index 0000000..27e437d --- /dev/null +++ b/patches/dwm-fullscreen.diff @@ -0,0 +1,71 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..b859e78 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -34,7 +34,7 @@ static const Rule rules[] = { + /* layout(s) */ + static const 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 const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ ++static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ + + static const Layout layouts[] = { + /* symbol arrange function */ +@@ -76,6 +76,7 @@ static Key keys[] = { + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY|ShiftMask, XK_f, fullscreen, {0} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, +diff --git a/dwm.c b/dwm.c +index 4465af1..ce893d0 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -199,6 +199,7 @@ static void sendmon(Client *c, Monitor *m); + static void setclientstate(Client *c, long state); + static void setfocus(Client *c); + static void setfullscreen(Client *c, int fullscreen); ++static void fullscreen(const Arg *arg); + static void setlayout(const Arg *arg); + static void setmfact(const Arg *arg); + static void setup(void); +@@ -267,6 +268,8 @@ static Display *dpy; + static Drw *drw; + static Monitor *mons, *selmon; + static Window root, wmcheckwin; ++static Layout *last_layout; ++ + + /* configuration, allows nested code to access above variables */ + #include "config.h" +@@ -1497,6 +1500,28 @@ setfullscreen(Client *c, int fullscreen) + } + } + ++void ++fullscreen(const Arg *arg) ++{ ++ XWindowChanges wc; ++ if (selmon->showbar) { ++ for(last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++); ++ setlayout(&((Arg) { .v = &layouts[2] })); ++ selmon->sel->bw = 0; ++ selmon->showbar = 0; ++ } else { ++ setlayout(&((Arg) { .v = last_layout })); ++ selmon->sel->bw = borderpx; ++ selmon->showbar = 1; ++ } ++ updatebarpos(selmon); ++ wc.border_width = selmon->sel->bw; ++ XConfigureWindow(dpy, selmon->sel->win, CWBorderWidth, &wc); ++ XSetWindowBorder(dpy, selmon->sel->win, scheme[SchemeNorm][ColBorder].pixel); ++ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); ++ arrange(selmon); ++} ++ + void + setlayout(const Arg *arg) + { diff --git a/patches/dwm-gaplessgrid-20160731-56a31dc.diff b/patches/dwm-gaplessgrid-20160731-56a31dc.diff new file mode 100644 index 0000000..4f3bb13 --- /dev/null +++ b/patches/dwm-gaplessgrid-20160731-56a31dc.diff @@ -0,0 +1,43 @@ +URL: http://dwm.suckless.org/patches/gapless_grid +Add gapless grid layout. + +Index: dwm/gaplessgrid.c +=================================================================== +--- /dev/null ++++ dwm/gaplessgrid.c +@@ -0,0 +1,35 @@ ++void ++gaplessgrid(Monitor *m) { ++ unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch; ++ Client *c; ++ ++ for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ; ++ if(n == 0) ++ return; ++ ++ /* grid dimensions */ ++ for(cols = 0; cols <= n/2; cols++) ++ if(cols*cols >= n) ++ break; ++ if(n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */ ++ cols = 2; ++ rows = n/cols; ++ ++ /* window geometries */ ++ cw = cols ? m->ww / cols : m->ww; ++ cn = 0; /* current column number */ ++ rn = 0; /* current row number */ ++ for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) { ++ if(i/rows + 1 > cols - n%cols) ++ rows = n/cols + 1; ++ ch = rows ? m->wh / rows : m->wh; ++ cx = m->wx + cn*cw; ++ cy = m->wy + rn*ch; ++ resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False); ++ rn++; ++ if(rn >= rows) { ++ rn = 0; ++ cn++; ++ } ++ } ++} diff --git a/patches/dwm-libxft-bgra.diff b/patches/dwm-libxft-bgra.diff new file mode 100644 index 0000000..8cded6c --- /dev/null +++ b/patches/dwm-libxft-bgra.diff @@ -0,0 +1,41 @@ +diff --git a/drw.c b/drw.c +index 8fd1ca4..66acbbe 100644 +--- a/drw.c ++++ b/drw.c +@@ -11,6 +11,8 @@ + #define UTF_INVALID 0xFFFD + #define UTF_SIZ 4 + ++int has_libxft_bgra = 0; ++ + static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; + static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; + static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; +@@ -139,11 +141,13 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) + * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 + * and lots more all over the internet. + */ +- FcBool iscol; +- if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { +- XftFontClose(drw->dpy, xfont); +- return NULL; +- } ++ if (!has_libxft_bgra){ ++ FcBool iscol; ++ if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { ++ XftFontClose(drw->dpy, xfont); ++ return NULL; ++ } ++ } + + font = ecalloc(1, sizeof(Fnt)); + font->xfont = xfont; +@@ -174,6 +178,8 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) + if (!drw || !fonts) + return NULL; + ++ has_libxft_bgra = !system("pacman -Q libxft | grep bgra > /dev/null 2> /dev/null"); ++ + for (i = 1; i <= fontcount; i++) { + if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { + cur->next = ret; diff --git a/patches/dwm-movestack-6.1.diff b/patches/dwm-movestack-6.1.diff new file mode 100644 index 0000000..a6c83fa --- /dev/null +++ b/patches/dwm-movestack-6.1.diff @@ -0,0 +1,73 @@ +diff -r 050d521d66d8 config.def.h +--- a/config.def.h Tue Aug 24 13:13:20 2010 +0100 ++++ b/config.def.h Sun Sep 05 18:43:07 2010 +0200 +@@ -57,6 +57,7 @@ + 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 }; + ++#include "movestack.c" + static Key keys[] = { + /* modifier key function argument */ + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, +@@ -68,6 +69,8 @@ + { MODKEY, XK_d, incnmaster, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, ++ { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, ++ { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, +diff -r 050d521d66d8 movestack.c +--- /dev/null Thu Jan 01 00:00:00 1970 +0000 ++++ b/movestack.c Sun Sep 05 18:43:07 2010 +0200 +@@ -0,0 +1,49 @@ ++void ++movestack(const Arg *arg) { ++ Client *c = NULL, *p = NULL, *pc = NULL, *i; ++ ++ if(arg->i > 0) { ++ /* find the client after selmon->sel */ ++ for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); ++ if(!c) ++ for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); ++ ++ } ++ else { ++ /* find the client before selmon->sel */ ++ for(i = selmon->clients; i != selmon->sel; i = i->next) ++ if(ISVISIBLE(i) && !i->isfloating) ++ c = i; ++ if(!c) ++ for(; i; i = i->next) ++ if(ISVISIBLE(i) && !i->isfloating) ++ c = i; ++ } ++ /* find the client before selmon->sel and c */ ++ for(i = selmon->clients; i && (!p || !pc); i = i->next) { ++ if(i->next == selmon->sel) ++ p = i; ++ if(i->next == c) ++ pc = i; ++ } ++ ++ /* swap c and selmon->sel selmon->clients in the selmon->clients list */ ++ if(c && c != selmon->sel) { ++ Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; ++ selmon->sel->next = c->next==selmon->sel?c:c->next; ++ c->next = temp; ++ ++ if(p && p != c) ++ p->next = c; ++ if(pc && pc != selmon->sel) ++ pc->next = selmon->sel; ++ ++ if(selmon->sel == selmon->clients) ++ selmon->clients = c; ++ else if(c == selmon->clients) ++ selmon->clients = selmon->sel; ++ ++ arrange(selmon); ++ } ++} ++ diff --git a/patches/dwm-resizecorners-6.2.diff b/patches/dwm-resizecorners-6.2.diff new file mode 100644 index 0000000..72d50f6 --- /dev/null +++ b/patches/dwm-resizecorners-6.2.diff @@ -0,0 +1,65 @@ +--- a/dwm.c 2019-02-02 10:55:28.000000000 -0200 ++++ b/dwm.c 2020-06-11 20:09:16.786504007 -0300 +@@ -1291,9 +1291,14 @@ + resizemouse(const Arg *arg) + { + int ocx, ocy, nw, nh; ++ int ocx2, ocy2, nx, ny; + Client *c; + Monitor *m; + XEvent ev; ++ int horizcorner, vertcorner; ++ int di; ++ unsigned int dui; ++ Window dummy; + Time lasttime = 0; + + if (!(c = selmon->sel)) +@@ -1303,10 +1308,18 @@ + restack(selmon); + ocx = c->x; + ocy = c->y; ++ ocx2 = c->x + c->w; ++ ocy2 = c->y + c->h; + if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) + return; +- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); ++ if (!XQueryPointer (dpy, c->win, &dummy, &dummy, &di, &di, &nx, &ny, &dui)) ++ return; ++ horizcorner = nx < c->w / 2; ++ vertcorner = ny < c->h / 2; ++ XWarpPointer (dpy, None, c->win, 0, 0, 0, 0, ++ horizcorner ? (-c->bw) : (c->w + c->bw -1), ++ vertcorner ? (-c->bw) : (c->h + c->bw -1)); + do { + XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); + switch(ev.type) { +@@ -1322,6 +1335,11 @@ + + nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); + nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); ++ nx = horizcorner ? ev.xmotion.x : c->x; ++ ny = vertcorner ? ev.xmotion.y : c->y; ++ nw = MAX(horizcorner ? (ocx2 - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1); ++ nh = MAX(vertcorner ? (ocy2 - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1); ++ + if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww + && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) + { +@@ -1330,11 +1348,13 @@ + togglefloating(NULL); + } + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) +- resize(c, c->x, c->y, nw, nh, 1); ++ resize(c, nx, ny, nw, nh, 1); + break; + } + } while (ev.type != ButtonRelease); +- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); ++ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, ++ horizcorner ? (-c->bw) : (c->w + c->bw - 1), ++ vertcorner ? (-c->bw) : (c->h + c->bw - 1)); + XUngrabPointer(dpy, CurrentTime); + while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { diff --git a/patches/dwm-rotatestack-20161021-ab9571b.diff b/patches/dwm-rotatestack-20161021-ab9571b.diff new file mode 100644 index 0000000..ed74c6d --- /dev/null +++ b/patches/dwm-rotatestack-20161021-ab9571b.diff @@ -0,0 +1,102 @@ +diff --git a/config.def.h b/config.def.h +index fd77a07..09737d7 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -64,6 +64,8 @@ static Key keys[] = { + { MODKEY, XK_p, spawn, {.v = dmenucmd } }, + { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } }, + { MODKEY, XK_b, togglebar, {0} }, ++ { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, ++ { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, + { MODKEY, XK_i, incnmaster, {.i = +1 } }, +diff --git a/dwm.c b/dwm.c +index 421bf27..1ec8b10 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -165,6 +165,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); +@@ -194,6 +196,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); +@@ -765,6 +768,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; +@@ -1390,6 +1415,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; diff --git a/patches/dwm-statuscmd-signal-6.2.diff b/patches/dwm-statuscmd-signal-6.2.diff new file mode 100644 index 0000000..97fda1b --- /dev/null +++ b/patches/dwm-statuscmd-signal-6.2.diff @@ -0,0 +1,157 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..b67825e 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -103,7 +103,9 @@ static Button buttons[] = { + { ClkLtSymbol, 0, Button1, setlayout, {0} }, + { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, + { ClkWinTitle, 0, Button2, zoom, {0} }, +- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, ++ { ClkStatusText, 0, Button1, sigdwmblocks, {.i = 1} }, ++ { ClkStatusText, 0, Button2, sigdwmblocks, {.i = 2} }, ++ { ClkStatusText, 0, Button3, sigdwmblocks, {.i = 3} }, + { ClkClientWin, MODKEY, Button1, movemouse, {0} }, + { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, + { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, +diff --git a/dwm.c b/dwm.c +index 4465af1..c600131 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -156,6 +156,7 @@ static void clientmessage(XEvent *e); + static void configure(Client *c); + static void configurenotify(XEvent *e); + static void configurerequest(XEvent *e); ++static void copyvalidchars(char *text, char *rawtext); + static Monitor *createmon(void); + static void destroynotify(XEvent *e); + static void detach(Client *c); +@@ -169,6 +170,7 @@ static void focus(Client *c); + static void focusin(XEvent *e); + static void focusmon(const Arg *arg); + static void focusstack(const Arg *arg); ++static int getdwmblockspid(); + static int getrootptr(int *x, int *y); + static long getstate(Window w); + static int gettextprop(Window w, Atom atom, char *text, unsigned int size); +@@ -205,6 +207,7 @@ static void setup(void); + static void seturgent(Client *c, int urg); + static void showhide(Client *c); + static void sigchld(int unused); ++static void sigdwmblocks(const Arg *arg); + static void spawn(const Arg *arg); + static void tag(const Arg *arg); + static void tagmon(const Arg *arg); +@@ -237,6 +240,9 @@ static void zoom(const Arg *arg); + /* variables */ + static const char broken[] = "broken"; + static char stext[256]; ++static char rawstext[256]; ++static int dwmblockssig; ++pid_t dwmblockspid = 0; + static int screen; + static int sw, sh; /* X display screen geometry width, height */ + static int bh, blw = 0; /* bar geometry */ +@@ -439,9 +445,26 @@ buttonpress(XEvent *e) + arg.ui = 1 << i; + } else if (ev->x < x + blw) + click = ClkLtSymbol; +- else if (ev->x > selmon->ww - TEXTW(stext)) ++ else if (ev->x > (x = selmon->ww - TEXTW(stext) + lrpad)) { + click = ClkStatusText; +- else ++ ++ char *text = rawstext; ++ int i = -1; ++ char ch; ++ dwmblockssig = 0; ++ while (text[++i]) { ++ if ((unsigned char)text[i] < ' ') { ++ ch = text[i]; ++ text[i] = '\0'; ++ x += TEXTW(text) - lrpad; ++ text[i] = ch; ++ text += i+1; ++ i = -1; ++ if (x >= ev->x) break; ++ dwmblockssig = ch; ++ } ++ } ++ } else + click = ClkWinTitle; + } else if ((c = wintoclient(ev->window))) { + focus(c); +@@ -627,6 +650,19 @@ configurerequest(XEvent *e) + XSync(dpy, False); + } + ++void ++copyvalidchars(char *text, char *rawtext) ++{ ++ int i = -1, j = 0; ++ ++ while(rawtext[++i]) { ++ if ((unsigned char)rawtext[i] >= ' ') { ++ text[j++] = rawtext[i]; ++ } ++ } ++ text[j] = '\0'; ++} ++ + Monitor * + createmon(void) + { +@@ -871,6 +907,18 @@ getatomprop(Client *c, Atom prop) + return atom; + } + ++int ++getdwmblockspid() ++{ ++ char buf[16]; ++ FILE *fp = popen("pidof -s dwmblocks", "r"); ++ fgets(buf, sizeof(buf), fp); ++ pid_t pid = strtoul(buf, NULL, 10); ++ pclose(fp); ++ dwmblockspid = pid; ++ return pid != 0 ? 0 : -1; ++} ++ + int + getrootptr(int *x, int *y) + { +@@ -1636,6 +1684,23 @@ sigchld(int unused) + while (0 < waitpid(-1, NULL, WNOHANG)); + } + ++void ++sigdwmblocks(const Arg *arg) ++{ ++ union sigval sv; ++ sv.sival_int = (dwmblockssig << 8) | arg->i; ++ if (!dwmblockspid) ++ if (getdwmblockspid() == -1) ++ return; ++ ++ if (sigqueue(dwmblockspid, SIGUSR1, sv) == -1) { ++ if (errno == ESRCH) { ++ if (!getdwmblockspid()) ++ sigqueue(dwmblockspid, SIGUSR1, sv); ++ } ++ } ++} ++ + void + spawn(const Arg *arg) + { +@@ -1987,8 +2052,10 @@ updatesizehints(Client *c) + void + updatestatus(void) + { +- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) ++ if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) + strcpy(stext, "dwm-"VERSION); ++ else ++ copyvalidchars(stext, rawstext); + drawbar(selmon); + } + diff --git a/patches/dwm-tilegap.diff b/patches/dwm-tilegap.diff new file mode 100644 index 0000000..d5832ee --- /dev/null +++ b/patches/dwm-tilegap.diff @@ -0,0 +1,108 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..bc1a869 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -1,7 +1,8 @@ + /* See LICENSE file for copyright and license details. */ + + /* appearance */ +-static const unsigned int borderpx = 1; /* border pixel of windows */ ++static const unsigned int borderpx = 2; /* border pixel of windows */ ++static const unsigned int gappx = 20; /* gap pixel between windows */ + static const unsigned int snap = 32; /* snap pixel */ + static const int showbar = 1; /* 0 means no bar */ + static const int topbar = 1; /* 0 means bottom bar */ +@@ -32,7 +33,7 @@ static const Rule rules[] = { + }; + + /* layout(s) */ +-static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ ++static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */ + static const int nmaster = 1; /* number of clients in master area */ + static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ + +diff --git a/dwm.c b/dwm.c +index 4465af1..dc953c0 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -783,6 +783,7 @@ expose(XEvent *e) + void + focus(Client *c) + { ++ XWindowChanges wc; + if (!c || !ISVISIBLE(c)) + for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); + if (selmon->sel && selmon->sel != c) +@@ -795,6 +796,9 @@ focus(Client *c) + detachstack(c); + attachstack(c); + grabbuttons(c, 1); ++ c->bw = borderpx; ++ wc.border_width = c->bw; ++ XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); + XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); + setfocus(c); + } else { +@@ -1047,7 +1051,7 @@ manage(Window w, XWindowAttributes *wa) + /* only fix client y-offset, if the client center might cover the bar */ + c->y = MAX(c->y, ((c->mon->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx) + && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); +- c->bw = borderpx; ++ c->bw = 0; // borderpx + + wc.border_width = c->bw; + XConfigureWindow(dpy, w, CWBorderWidth, &wc); +@@ -1673,26 +1677,29 @@ tagmon(const Arg *arg) + void + tile(Monitor *m) + { +- unsigned int i, n, h, mw, my, ty; ++ unsigned int i, n, h, mw, my, ty, ns; + Client *c; + + for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if (n == 0) + return; + +- if (n > m->nmaster) ++ if (n > m->nmaster) { + mw = m->nmaster ? m->ww * m->mfact : 0; +- else ++ ns = m->nmaster > 0 ? 2 : 1; ++ } else { + mw = m->ww; +- for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) ++ ns = 1; ++ } ++ for(i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { +- h = (m->wh - my) / (MIN(n, m->nmaster) - i); +- resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); +- my += HEIGHT(c); ++ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gappx; ++ resize(c, m->wx + gappx, m->wy + my, mw - (2*c->bw) - gappx*(5-ns)/2, h - (2*c->bw), False); ++ my += HEIGHT(c) + gappx; + } else { +- h = (m->wh - ty) / (n - i); +- resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); +- ty += HEIGHT(c); ++ h = (m->wh - ty) / (n - i) - gappx; ++ resize(c, m->wx + mw + gappx/ns, m->wy + ty, m->ww - mw - (2*c->bw) - gappx*(5-ns)/2, h - (2*c->bw), False); ++ ty += HEIGHT(c) + gappx; + } + } + +@@ -1749,9 +1756,13 @@ toggleview(const Arg *arg) + void + unfocus(Client *c, int setfocus) + { ++ XWindowChanges wc; + if (!c) + return; + grabbuttons(c, 0); ++ c->bw = 0; // borderpx ++ wc.border_width = c->bw; ++ XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); + XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); + if (setfocus) { + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); diff --git a/patches/dwm-zoomswap-6.2.diff b/patches/dwm-zoomswap-6.2.diff new file mode 100644 index 0000000..3c658e6 --- /dev/null +++ b/patches/dwm-zoomswap-6.2.diff @@ -0,0 +1,95 @@ +From 3867ef5a68e15a4faff377ddbc8371853de4a800 Mon Sep 17 00:00:00 2001 +From: aleks <aleks.stier@icloud.com> +Date: Sat, 19 Oct 2019 00:56:21 +0200 +Subject: [PATCH] Put master to exact position of zoomed client + +The default behaviour when zooming a client is to put the previous +master on top of the client-stack. This patch puts the master to the +exact position of the zoomed client in the stack. +--- + dwm.c | 44 ++++++++++++++++++++++++++++++++++++++++---- + 1 file changed, 40 insertions(+), 4 deletions(-) + +diff --git a/dwm.c b/dwm.c +index 4465af1..1719b36 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -165,6 +165,7 @@ static void drawbar(Monitor *m); + static void drawbars(void); + static void enternotify(XEvent *e); + static void expose(XEvent *e); ++static Client *findbefore(Client *c); + static void focus(Client *c); + static void focusin(XEvent *e); + static void focusmon(const Arg *arg); +@@ -235,6 +236,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(const Arg *arg); + + /* variables */ ++static Client *prevzoom = NULL; + static const char broken[] = "broken"; + static char stext[256]; + static int screen; +@@ -780,6 +782,16 @@ expose(XEvent *e) + drawbar(m); + } + ++Client * ++findbefore(Client *c) ++{ ++ Client *tmp; ++ if (c == selmon->clients) ++ return NULL; ++ for (tmp = selmon->clients; tmp && tmp->next != c; tmp = tmp->next); ++ return tmp; ++} ++ + void + focus(Client *c) + { +@@ -2114,14 +2126,38 @@ void + zoom(const Arg *arg) + { + Client *c = selmon->sel; ++ Client *at = NULL, *cold, *cprevious = NULL; + + if (!selmon->lt[selmon->sellt]->arrange + || (selmon->sel && selmon->sel->isfloating)) + return; +- if (c == nexttiled(selmon->clients)) +- if (!c || !(c = nexttiled(c->next))) +- return; +- pop(c); ++ if (c == nexttiled(selmon->clients)) { ++ at = findbefore(prevzoom); ++ if (at) ++ cprevious = nexttiled(at->next); ++ if (!cprevious || cprevious != prevzoom) { ++ prevzoom = NULL; ++ if (!c || !(c = nexttiled(c->next))) ++ return; ++ } else ++ c = cprevious; ++ } ++ cold = nexttiled(selmon->clients); ++ if (c != cold && !at) ++ at = findbefore(c); ++ detach(c); ++ attach(c); ++ /* swap windows instead of pushing the previous one down */ ++ if (c != cold && at) { ++ prevzoom = cold; ++ if (cold && at != cold) { ++ detach(cold); ++ cold->next = at->next; ++ at->next = cold; ++ } ++ } ++ focus(c); ++ arrange(c->mon); + } + + int +-- +2.23.0 + diff --git a/patches/flaport-center.diff b/patches/flaport-center.diff new file mode 100644 index 0000000..0e33d01 --- /dev/null +++ b/patches/flaport-center.diff @@ -0,0 +1,71 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..ae7af3b 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -26,9 +26,9 @@ static const Rule rules[] = { + * 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 iscentered isfloating monitor */ ++ { "Gimp", NULL, NULL, 0, 0, 1, -1 }, ++ { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1 }, + }; + + /* layout(s) */ +diff --git a/dwm.c b/dwm.c +index 4465af1..33b753f 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -92,7 +92,7 @@ struct Client { + int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int bw, oldbw; + unsigned int tags; +- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; ++ int isfixed, iscentered, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + Client *next; + Client *snext; + Monitor *mon; +@@ -137,6 +137,7 @@ typedef struct { + const char *instance; + const char *title; + unsigned int tags; ++ int iscentered; + int isfloating; + int monitor; + } Rule; +@@ -297,6 +298,7 @@ applyrules(Client *c) + && (!r->class || strstr(class, r->class)) + && (!r->instance || strstr(instance, r->instance))) + { ++ c->iscentered = r->iscentered; + c->isfloating = r->isfloating; + c->tags |= r->tags; + for (m = mons; m && m->num != r->monitor; m = m->next); +@@ -1017,6 +1019,7 @@ killclient(const Arg *arg) + void + manage(Window w, XWindowAttributes *wa) + { ++ Monitor *m; + Client *c, *t = NULL; + Window trans = None; + XWindowChanges wc; +@@ -1060,8 +1063,15 @@ manage(Window w, XWindowAttributes *wa) + grabbuttons(c, 0); + if (!c->isfloating) + c->isfloating = c->oldstate = trans != None || c->isfixed; +- if (c->isfloating) ++ if (c->isfloating){ + XRaiseWindow(dpy, c->win); ++ if(c->iscentered) { ++ c->x = (c->mon->mw - WIDTH(c)) / 2; ++ c->y = (c->mon->mh - HEIGHT(c)) / 2; ++ for (m=mons; m != c->mon; m = m->next) ++ c->x += m->mw; ++ } ++ } + attach(c); + attachstack(c); + XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, diff --git a/patches/flaport-mastermon.diff b/patches/flaport-mastermon.diff new file mode 100644 index 0000000..cdedae5 --- /dev/null +++ b/patches/flaport-mastermon.diff @@ -0,0 +1,527 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..2c9c26c 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -16,10 +16,12 @@ static const char *colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, + [SchemeSel] = { col_gray4, col_cyan, col_cyan }, ++ [SchemeInactive] = { col_gray4, col_gray2, NULL }, + }; + + /* tagging */ + static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; ++static const char *montags[] = { "Z", "X", "C", "V"}; + + static const Rule rules[] = { + /* xprop(1): +@@ -50,6 +52,10 @@ static const Layout layouts[] = { + { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ + { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ + { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, ++#define MONKEYS(KEY,TAG) \ ++ { MODKEY, KEY, focusmon, {.i = TAG+1} }, \ ++ { MODKEY|ShiftMask, KEY, tagmon, {.i = TAG+1} }, \ ++ { MODKEY|ControlMask, KEY, swapmon, {.i = TAG+1} }, + + /* helper for spawning shell commands in the pre dwm-5.0 fashion */ + #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } +@@ -72,18 +78,23 @@ static Key keys[] = { + { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY, XK_Return, zoom, {0} }, + { MODKEY, XK_Tab, view, {0} }, +- { MODKEY|ShiftMask, XK_c, killclient, {0} }, ++ { MODKEY|ControlMask, XK_Tab, swapmon, {.i = 0} }, ++ { MODKEY, XK_q, killclient, {0} }, ++ { MODKEY|ShiftMask, XK_q, quit, {0} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, + { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, ++ { MODKEY|ControlMask, XK_m, setmastermon, {.i = 0} }, + { 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|ControlMask, XK_comma, setmastermon, {.i = -1 } }, ++ { MODKEY, XK_period, focusmon, {.i = +1 } }, + { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, ++ { MODKEY|ControlMask, XK_period, setmastermon, {.i = +1 } }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) +@@ -93,7 +104,10 @@ static Key keys[] = { + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) +- { MODKEY|ShiftMask, XK_q, quit, {0} }, ++ MONKEYS( XK_z, 1) ++ MONKEYS( XK_x, 2) ++ MONKEYS( XK_c, 3) ++ MONKEYS( XK_v, 4) + }; + + /* button definitions */ +diff --git a/dwm.c b/dwm.c +index 4465af1..75e4401 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -59,7 +59,7 @@ + + /* enums */ + enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ +-enum { SchemeNorm, SchemeSel }; /* color schemes */ ++enum { SchemeNorm, SchemeSel, SchemeInactive }; /* color schemes */ + enum { NetSupported, NetWMName, NetWMState, NetWMCheck, + NetWMFullscreen, NetActiveWindow, NetWMWindowType, + NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ +@@ -177,12 +177,14 @@ static void grabkeys(void); + static void incnmaster(const Arg *arg); + static void keypress(XEvent *e); + static void killclient(const Arg *arg); ++static void makemastermon(Monitor *m); + static void manage(Window w, XWindowAttributes *wa); + static void mappingnotify(XEvent *e); + static void maprequest(XEvent *e); + static void monocle(Monitor *m); + static void motionnotify(XEvent *e); + static void movemouse(const Arg *arg); ++static Monitor *numtomon(const unsigned int num); + static Client *nexttiled(Client *c); + static void pop(Client *); + static void propertynotify(XEvent *e); +@@ -200,12 +202,14 @@ static void setclientstate(Client *c, long state); + static void setfocus(Client *c); + static void setfullscreen(Client *c, int fullscreen); + static void setlayout(const Arg *arg); ++static void setmastermon(const Arg *arg); + static void setmfact(const Arg *arg); + static void setup(void); + static void seturgent(Client *c, int urg); + static void showhide(Client *c); + static void sigchld(int unused); + static void spawn(const Arg *arg); ++static void swapmon(const Arg *arg); + static void tag(const Arg *arg); + static void tagmon(const Arg *arg); + static void tile(Monitor *); +@@ -265,7 +269,7 @@ static Cur *cursor[CurLast]; + static Clr **scheme; + static Display *dpy; + static Drw *drw; +-static Monitor *mons, *selmon; ++static Monitor *mons, *selmon, *mastermon; + static Window root, wmcheckwin; + + /* configuration, allows nested code to access above variables */ +@@ -431,13 +435,29 @@ buttonpress(XEvent *e) + } + if (ev->window == selmon->barwin) { + i = x = 0; +- do +- x += TEXTW(tags[i]); +- while (ev->x >= x && ++i < LENGTH(tags)); +- if (i < LENGTH(tags)) { ++ if (mons->next){ ++ x += TEXTW(montags[m->num]); ++ if (ev->x < x){ ++ if (ev->button == 1){ ++ makemastermon(selmon); ++ } ++ return; ++ } ++ x += TEXTW(" "); ++ if (ev->x < x) ++ return; ++ } ++ ++ if (selmon == mastermon){ ++ do ++ x += TEXTW(tags[i]); ++ while (ev->x >= x && ++i < LENGTH(tags)); ++ } ++ ++ if ((i < LENGTH(tags)) && (selmon == mastermon)) { + click = ClkTagBar; + arg.ui = 1 << i; +- } else if (ev->x < x + blw) ++ } else if (ev->x < x + TEXTW(selmon->ltsymbol)) + click = ClkLtSymbol; + else if (ev->x > selmon->ww - TEXTW(stext)) + click = ClkStatusText; +@@ -504,6 +524,13 @@ cleanupmon(Monitor *mon) + for (m = mons; m && m->next != mon; m = m->next); + m->next = mon->next; + } ++ if (mon == mastermon){ ++ mastermon = mon->next; ++ if (!mastermon){ ++ mastermon = mons; // do not use makemastermon here. ++ } ++ drawbars(); ++ } + XUnmapWindow(dpy, mon->barwin); + XDestroyWindow(dpy, mon->barwin); + free(mon); +@@ -713,17 +740,29 @@ drawbar(Monitor *m) + if (c->isurgent) + urg |= c->tags; + } ++ + x = 0; +- for (i = 0; i < LENGTH(tags); i++) { +- w = TEXTW(tags[i]); +- drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); +- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); +- if (occ & 1 << i) +- drw_rect(drw, x + boxs, boxs, boxw, boxw, +- m == selmon && selmon->sel && selmon->sel->tags & 1 << i, +- urg & 1 << i); +- x += w; +- } ++ ++ if (mons->next){ ++ w = blw = TEXTW(montags[m->num]); ++ drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeInactive]); ++ x = drw_text(drw, x, 0, w, bh, lrpad / 2, montags[m->num], 0); ++ drw_setscheme(drw, scheme[SchemeNorm]); ++ x = drw_text(drw, x, 0, w, bh, lrpad / 2, " ", 0); ++ } ++ ++ if (m == mastermon){ ++ for (i = 0; i < LENGTH(tags); i++) { ++ w = TEXTW(tags[i]); ++ drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? ( m == selmon ? SchemeSel : SchemeInactive) : SchemeNorm]); ++ drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); ++ if (occ & 1 << i) ++ drw_rect(drw, x + boxs, boxs, boxw, boxw, ++ m == selmon && selmon->sel && selmon->sel->tags & 1 << i, ++ urg & 1 << i); ++ x += w; ++ } ++ } + w = blw = TEXTW(m->ltsymbol); + drw_setscheme(drw, scheme[SchemeNorm]); + x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); +@@ -819,11 +858,18 @@ void + focusmon(const Arg *arg) + { + Monitor *m; +- +- if (!mons->next) +- return; +- if ((m = dirtomon(arg->i)) == selmon) +- return; ++ if (arg->i > 1){ ++ m = numtomon(arg->i-2); ++ if (!m) ++ return; ++ } else if ((arg->i == -1) || (arg->i == 1)){ ++ if (!mons->next) ++ return; ++ if ((m = dirtomon(arg->i)) == selmon) ++ return; ++ } else { ++ return; ++ } + unfocus(selmon->sel, 0); + selmon = m; + focus(NULL); +@@ -1014,6 +1060,75 @@ killclient(const Arg *arg) + } + } + ++void ++makemastermon(Monitor *m){ ++ Monitor *mon; ++ ++ for (mon=mons; (mon && mon!=mastermon) ; mon=mon->next); ++ ++ if (mon != mastermon){ ++ mastermon = m; ++ drawbars(); ++ return; ++ } ++ ++ if (m == mastermon){ ++ m = m->next ? m->next : mons; ++ } ++ ++ unsigned int mastertagset, N, n, p; ++ Client *clients, *otherclients, *masterclients; ++ ++ masterclients = mastermon->clients; ++ mastertagset = mastermon->tagset[mastermon->seltags]; ++ ++ otherclients = m->clients; ++ unfocus(otherclients, 1); ++ ++ if (otherclients){ ++ for (N=1, clients=otherclients; clients->next; clients=clients->next, N++); ++ for (n=N; n>0; n--){ ++ for (p=1, clients=otherclients; p<n; p++, clients=clients->next); ++ detach(clients); ++ detachstack(clients); ++ clients->mon = mastermon; ++ clients->tags = 1; ++ attach(clients); ++ attachstack(clients); ++ } ++ } ++ ++ if (masterclients){ ++ for (N=1, clients=masterclients; clients->next; clients=clients->next, N++); ++ for (n=N; n>0; n--){ ++ for (p=1, clients=masterclients; p<n; p++, clients=clients->next); ++ detach(clients); ++ detachstack(clients); ++ clients->mon = m; ++ attach(clients); ++ attachstack(clients); ++ } ++ } ++ ++ if (masterclients || otherclients){ ++ focus(NULL); ++ arrange(NULL); ++ } ++ ++ m->tagset[m->seltags] = mastertagset; ++ mastermon->tagset[mastermon->seltags] = 1; ++ arrange(m); ++ arrange(mastermon); ++ if (masterclients){ ++ if (otherclients) ++ unfocus(otherclients, 1); ++ focus(masterclients); ++ arrange(masterclients->mon); ++ } ++ mastermon = m; ++ drawbars(); ++} ++ + void + manage(Window w, XWindowAttributes *wa) + { +@@ -1199,6 +1314,23 @@ nexttiled(Client *c) + return c; + } + ++ ++Monitor ++*numtomon(const unsigned int num){ ++ Monitor *m; ++ if (num == selmon->num) ++ return selmon; ++ for (m = mons; m->next; m = m->next); ++ if (num > m->num){ ++ return NULL; ++ } ++ if (num == m->num){ ++ return m; ++ } ++ for (m=mons; m->next->num <= num; m = m->next); ++ return m; ++} ++ + void + pop(Client *c) + { +@@ -1511,6 +1643,29 @@ setlayout(const Arg *arg) + drawbar(selmon); + } + ++void ++setmastermon(const Arg *arg) { ++ ++ if ((selmon != mastermon)){ ++ makemastermon(selmon); ++ return; ++ } ++ ++ if (arg->i != -1 && arg->i != +1) ++ return; ++ ++ Monitor *m; ++ if (arg->i == -1){ ++ for (m=mons; (m->next && m->next==selmon); m=m->next); ++ } else { ++ m = selmon->next ? selmon->next : mons; ++ } ++ makemastermon(m); ++ unfocus(selmon->sel, 0); ++ selmon = m; ++ focus(NULL); ++} ++ + /* arg > 1.0 will set mfact absolutely */ + void + setmfact(const Arg *arg) +@@ -1652,20 +1807,123 @@ spawn(const Arg *arg) + } + } + ++void ++swapmon(const Arg *arg) ++{ ++ if (!mons->next) ++ return; ++ ++ if (arg->i < -1 || arg->i > 1) ++ return; ++ ++ Monitor *m1, *m2; ++ Client *c, *c1, *c2; ++ unsigned int N, n, p; ++ ++ m1 = selmon; ++ if (arg->i == -1) ++ for (m2=mons; (m2->next && m2->next==m1); m2=m2->next); ++ else if (arg->i == +1) ++ m2 = m1->next ? m1->next : mons; ++ else if (mastermon && (mastermon != selmon)) ++ m2 = mastermon; ++ else if (selmon->next) ++ m2 = selmon->next; ++ else ++ m2 = mons; ++ ++ ++ unfocus(m1->sel, 1); ++ unfocus(m2->sel, 1); ++ ++ c1 = c = m1->clients; ++ c2 = m2->clients; ++ unfocus(c1, 1); ++ ++ if (c1){ ++ for (N=1, c=c1; c->next; c=c->next, N++); ++ for (n=N; n>0; n--){ ++ for (p=1, c=c1; p<n; p++, c=c->next); ++ if ISVISIBLE(c){ ++ detach(c); ++ detachstack(c); ++ c->mon = m2; ++ c->tags = m2->tagset[m2->seltags]; /* assign tags of target monitor */ ++ attach(c); ++ attachstack(c); ++ } ++ } ++ } ++ ++ if (c2){ ++ for (N=1, c=c2; c->next; c=c->next, N++); ++ for (n=N; n>0; n--){ ++ for (p=1, c=c2; p<n; p++, c=c->next); ++ if ISVISIBLE(c){ ++ detach(c); ++ detachstack(c); ++ c->mon = m1; ++ c->tags = m1->tagset[m1->seltags]; /* assign tags of target monitor */ ++ attach(c); ++ attachstack(c); ++ } ++ } ++ } ++ ++ if (c1 || c2){ ++ focus(NULL); ++ arrange(NULL); ++ } ++ ++ if (c2){ ++ if (c1) ++ unfocus(c1, 1); ++ focus(c2); ++ arrange(c2->mon); ++ } ++ ++ arrange(selmon); ++ focus(c); ++} ++ + void + tag(const Arg *arg) + { +- if (selmon->sel && arg->ui & TAGMASK) { +- selmon->sel->tags = arg->ui & TAGMASK; +- focus(NULL); +- arrange(selmon); +- } ++ if (!selmon->sel || !(arg->ui & TAGMASK)) ++ return; ++ ++ if (selmon == mastermon){ ++ selmon->sel->tags = arg->ui & TAGMASK; ++ focus(NULL); ++ arrange(selmon); ++ return; ++ } ++ ++ Client *c = selmon->sel; ++ unfocus(c, 1); ++ detach(c); ++ detachstack(c); ++ c->mon = mastermon; ++ c->tags = arg->ui & TAGMASK; ++ attach(c); ++ attachstack(c); ++ focus(NULL); ++ arrange(NULL); + } + + void + tagmon(const Arg *arg) + { +- if (!selmon->sel || !mons->next) ++ Monitor *m; ++ if (!selmon->sel) ++ return; ++ if (arg->i > 1){ ++ m=numtomon(arg->ui-2); ++ if (m) ++ sendmon(selmon->sel, m); ++ return; ++ } ++ if (!mons->next) + return; + sendmon(selmon->sel, dirtomon(arg->i)); + } +@@ -1887,6 +2145,7 @@ updategeom(void) + m->my = m->wy = unique[i].y_org; + m->mw = m->ww = unique[i].width; + m->mh = m->wh = unique[i].height; ++ mastermon = m; // do not use makemastermon here. + updatebarpos(m); + } + } else { /* less monitors available nn < n */ +@@ -1901,7 +2160,7 @@ updategeom(void) + attachstack(c); + } + if (m == selmon) +- selmon = mons; ++ selmon = mons; + cleanupmon(m); + } + } +@@ -2035,13 +2294,15 @@ updatewmhints(Client *c) + void + view(const Arg *arg) + { +- if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) ++ if ((selmon == mastermon) && ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])) + return; ++ if (selmon != mastermon) ++ selmon = mastermon; + selmon->seltags ^= 1; /* toggle sel tagset */ + if (arg->ui & TAGMASK) + selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; +- focus(NULL); +- arrange(selmon); ++ arrange(selmon); ++ focus(selmon->sel); + } + + Client * diff --git a/patches/flaport-swallow.diff b/patches/flaport-swallow.diff new file mode 100644 index 0000000..3b481ec --- /dev/null +++ b/patches/flaport-swallow.diff @@ -0,0 +1,406 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..4c0b25c 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -3,6 +3,7 @@ + /* 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" }; +@@ -26,9 +27,11 @@ static const Rule rules[] = { + * 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, -1, -1 }, ++ { NULL, NULL, "Event Tester", 0, 1, 0, 1, -1 }, /* xev */ + }; + + /* layout(s) */ +diff --git a/config.mk b/config.mk +index 7084c33..b77641d 100644 +--- a/config.mk ++++ b/config.mk +@@ -22,7 +22,7 @@ FREETYPEINC = /usr/include/freetype2 + + # 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 + + # flags + CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} +diff --git a/dwm.c b/dwm.c +index 9fd0286..1befee4 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -40,6 +40,8 @@ + #include <X11/extensions/Xinerama.h> + #endif /* XINERAMA */ + #include <X11/Xft/Xft.h> ++#include <X11/Xlib-xcb.h> ++#include <xcb/res.h> + + #include "drw.h" + #include "util.h" +@@ -92,9 +94,11 @@ struct Client { + int basew, baseh, incw, inch, maxw, maxh, minw, minh; + 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; + }; +@@ -138,6 +142,8 @@ typedef struct { + const char *title; + unsigned int tags; + int isfloating; ++ int isterminal; ++ int noswallow; + int monitor; + } Rule; + +@@ -235,9 +241,16 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); + static int xerrorstart(Display *dpy, XErrorEvent *ee); + static void zoom(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"; + static char stext[256]; ++static int scanner; + static int screen; + static int sw, sh; /* X display screen geometry width, height */ + static int bh, blw = 0; /* bar geometry */ +@@ -269,6 +282,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" + +@@ -286,6 +301,7 @@ applyrules(Client *c) + XClassHint ch = { NULL, NULL }; + + /* rule matching */ ++ c->noswallow = -1; + c->isfloating = 0; + c->tags = 0; + XGetClassHint(dpy, c->win, &ch); +@@ -298,6 +314,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); +@@ -414,6 +432,61 @@ attachstack(Client *c) + c->mon->stack = c; + } + ++void ++swallow(Client *p, Client *c) ++{ ++ Client *s; ++ ++ if (c->noswallow > 0 || c->isterminal) ++ return; ++ if (c->noswallow < 0 && !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; ++ ++ XChangeProperty(dpy, c->win, netatom[NetClientList], XA_WINDOW, 32, PropModeReplace, ++ (unsigned char *) &(p->win), 1); ++ ++ updatetitle(p); ++ s = scanner ? c : p; ++ XMoveResizeWindow(dpy, p->win, s->x, s->y, s->w, s->h); ++ arrange(p->mon); ++ configure(p); ++ updateclientlist(); ++} ++ ++void ++unswallow(Client *c) ++{ ++ c->win = c->swallowing->win; ++ ++ free(c->swallowing); ++ c->swallowing = NULL; ++ ++ XDeleteProperty(dpy, c->win, netatom[NetClientList]); ++ ++ /* 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) + { +@@ -653,6 +726,9 @@ destroynotify(XEvent *e) + + if ((c = wintoclient(ev->window))) + unmanage(c, 1); ++ ++ else if ((c = swallowingclient(ev->window))) ++ unmanage(c->swallowing, 1); + } + + void +@@ -1018,12 +1094,13 @@ killclient(const Arg *arg) + 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; +@@ -1038,6 +1115,7 @@ manage(Window w, XWindowAttributes *wa) + } else { + c->mon = selmon; + applyrules(c); ++ term = termforwin(c); + } + + if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) +@@ -1074,6 +1152,8 @@ manage(Window w, XWindowAttributes *wa) + c->mon->sel = c; + arrange(c->mon); + XMapWindow(dpy, c->win); ++ if (term) ++ swallow(term, c); + focus(NULL); + } + +@@ -1384,7 +1464,9 @@ run(void) + void + scan(void) + { ++ scanner = 1; + unsigned int i, num; ++ char swin[256]; + Window d1, d2, *wins = NULL; + XWindowAttributes wa; + +@@ -1395,6 +1477,8 @@ scan(void) + continue; + if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState) + manage(wins[i], &wa); ++ else if (gettextprop(wins[i], netatom[NetClientList], swin, sizeof swin)) ++ manage(wins[i], &wa); + } + for (i = 0; i < num; i++) { /* now the transients */ + if (!XGetWindowAttributes(dpy, wins[i], &wa)) +@@ -1406,6 +1490,7 @@ scan(void) + if (wins) + XFree(wins); + } ++ scanner = 0; + } + + void +@@ -1768,6 +1853,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) { +@@ -1782,9 +1881,12 @@ unmanage(Client *c, int destroyed) + XUngrabServer(dpy); + } + free(c); +- focus(NULL); +- updateclientlist(); +- arrange(m); ++ ++ if (!s) { ++ arrange(m); ++ focus(NULL); ++ updateclientlist(); ++ } + } + + void +@@ -2047,6 +2149,110 @@ view(const Arg *arg) + arrange(selmon); + } + ++pid_t ++winpid(Window w) ++{ ++ pid_t result = 0; ++ ++ 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; ++ return result; ++} ++ ++pid_t ++getparentprocess(pid_t p) ++{ ++ unsigned int v = 0; ++ ++#if defined(__linux__) ++ FILE *f; ++ char buf[256]; ++ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); ++ ++ if (!(f = fopen(buf, "r"))) ++ return (pid_t)0; ++ ++ if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1) ++ v = (pid_t)0; ++ fclose(f); ++#elif defined(__FreeBSD__) ++ struct kinfo_proc *proc = kinfo_getproc(p); ++ if (!proc) ++ return (pid_t)0; ++ ++ v = proc->ki_ppid; ++ free(proc); ++#endif ++ 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) + { +@@ -2138,6 +2344,8 @@ 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(); + setup(); + #ifdef __OpenBSD__ |