aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-04-24 22:24:36 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-04-24 22:24:36 +0530
commit97d74845df1544e893bc20f6f17283468be0566b (patch)
tree1ff44621af2360cd2c80ad7033075a56d0266243
parent168cea5d761611e3655cde0c5d366ac3fd02c1bf (diff)
downloaddwm-97d74845df1544e893bc20f6f17283468be0566b.tar.gz
dwm-97d74845df1544e893bc20f6f17283468be0566b.tar.bz2
dwm-97d74845df1544e893bc20f6f17283468be0566b.zip
Patche
-rw-r--r--.gitignore1
-rw-r--r--LICENSE37
-rw-r--r--Makefile14
-rw-r--r--README48
-rw-r--r--README.md41
-rw-r--r--app.pngbin1295442 -> 0 bytes
-rw-r--r--config.h202
-rw-r--r--config.mk13
-rw-r--r--drw.c14
-rw-r--r--drw.h12
-rw-r--r--drw.obin10536 -> 10328 bytes
-rwxr-xr-xdwmbin82520 -> 75136 bytes
-rw-r--r--dwm.16
-rw-r--r--dwm.c382
-rw-r--r--dwm.c.orig2448
-rw-r--r--dwm.obin81024 -> 63696 bytes
-rw-r--r--gzdots.mom213
-rw-r--r--md23
-rw-r--r--patches/dwm-activetagindicatorbar-6.2.diff17
-rw-r--r--patcheslist19
-rw-r--r--rice.pngbin1909060 -> 0 bytes
-rw-r--r--util.c2
-rw-r--r--util.h12
-rw-r--r--vanitygaps.c809
24 files changed, 2892 insertions, 1421 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5761abc
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.o
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d221f09
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,37 @@
+MIT/X Consortium License
+
+© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
+© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
+© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
+© 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
+© 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
+© 2007-2009 Christof Musik <christof at sendfax dot de>
+© 2007-2009 Premysl Hruby <dfenze at gmail dot com>
+© 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
+© 2008 Martin Hurton <martin dot hurton at gmail dot com>
+© 2008 Neale Pickett <neale dot woozle dot org>
+© 2009 Mate Nagy <mnagy at port70 dot net>
+© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
+© 2010-2012 Connor Lane Smith <cls@lubutu.com>
+© 2011 Christoph Lohmann <20h@r-36.net>
+© 2015-2016 Quentin Rameau <quinq@fifth.space>
+© 2015-2016 Eric Pruitt <eric.pruitt@gmail.com>
+© 2016-2017 Markus Teich <markus.teich@stusta.mhn.de>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
index 412fbaf..77bcbc0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,3 @@
-
-
# dwm - dynamic window manager
# See LICENSE file for copyright and license details.
@@ -7,7 +5,6 @@ include config.mk
SRC = drw.c dwm.c util.c
OBJ = ${SRC:.c=.o}
-USR = gabrielzschmitz
all: options dwm
@@ -22,15 +19,18 @@ options:
${OBJ}: config.h config.mk
+config.h:
+ cp config.def.h $@
+
dwm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
- rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz *.orig *.rej
+ rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
dist: clean
mkdir -p dwm-${VERSION}
- cp -R LICENSE Makefile README config.mk\
+ cp -R LICENSE Makefile README config.def.h config.mk\
dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
gzip dwm-${VERSION}.tar
@@ -43,13 +43,9 @@ install: all
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
- mkdir -p /home/${USR}/.local/share/dwm
- cp -f gzdots.mom /home/${USR}/.local/share/dwm
- chmod 644 /home/${USR}/.local/share/dwm/gzdots.mom
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
- ${DESTDIR}${PREFIX}/share/dwm/gzdots.mom\
${DESTDIR}${MANPREFIX}/man1/dwm.1
.PHONY: all options clean dist install uninstall
diff --git a/README b/README
new file mode 100644
index 0000000..95d4fd0
--- /dev/null
+++ b/README
@@ -0,0 +1,48 @@
+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
deleted file mode 100644
index 8bf6432..0000000
--- a/README.md
+++ /dev/null
@@ -1,41 +0,0 @@
-# Biswa's build of dwm
-
-## DWM
-
-<img align="center" src="rice.png">
-<img align="center" src="app.png">
-
-
-## FAQ
-
-> What are the bindings?
-This is suckless, mmmbud, the source code is the documentation! Check out [config.h](config.h).
-
-Okay, okay, actually I keep a readme in `larbs.mom` for my whole system, including the binds here.
-Press `super+F1` to view it in dwm (zathura is required for that binding).
-I haven't kept `man dwm`/`dwm.1` updated though. PRs welcome on that, lol.
-
-## Patches and features
-
-- [Clickable statusbar](https://dwm.suckless.org/patches/statuscmd/) with my build of [dwmblocks](https://github.com/xgenos/dwmblocks).
-- Reads [xresources](https://dwm.suckless.org/patches/xresources/) colors/variables (i.e. works with `pywal`, etc.).
-- scratchpad: Accessible with mod+shift+enter.
-- New layouts: bstack, fibonacci, deck, centered master and more. All bound to keys `super+(shift+)t/y/u/i`.
-- True fullscreen (`super+f`) and prevents focus shifting.
-- Windows can be made sticky (`super+s`).
-- [stacker](https://dwm.suckless.org/patches/stacker/): Move windows up the stack manually (`super-K/J`).
-- [shiftview](https://dwm.suckless.org/patches/nextprev/): Cycle through tags (`super+g/;`).
-- [vanitygaps](https://dwm.suckless.org/patches/vanitygaps/): Gaps allowed across all layouts.
-- [swallow patch](https://dwm.suckless.org/patches/swallow/): if a program run from a terminal would make it inoperable, it temporarily takes its place to save space.
-
-## Installation for newbs
-
-```
-git clone https://github.com/xgenos/dwm
-cd dwm
-sudo make install
-```
-
-## Please install `lixft-bgra`!
-
-This build of dwm does not block color emoji in the status/info bar, so you must install [libxft-bgra](https://aur.archlinux.org/packages/libxft-bgra/) from the AUR, which fixes a libxft color emoji rendering problem, otherwise dwm will crash upon trying to render one. Hopefully this fix will be in all libxft soon enough.b
diff --git a/app.png b/app.png
deleted file mode 100644
index a8e16e8..0000000
--- a/app.png
+++ /dev/null
Binary files differ
diff --git a/config.h b/config.h
index 99466a2..c392834 100644
--- a/config.h
+++ b/config.h
@@ -1,29 +1,20 @@
-
-
-/* Constants */
-#define TERMINAL "st"
-#define TERMCLASS "st"
+/* See LICENSE file for copyright and license details. */
/* appearance */
static const unsigned int borderpx = 3; /* border pixel of windows */
+static const unsigned int gappx = 5; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */
-static const unsigned int gappih = 5; /* horiz inner gap between windows */
-static const unsigned int gappiv = 5; /* vert inner gap between windows */
-static const unsigned int gappoh = 5; /* horiz outer gap between windows and screen edge */
-static const unsigned int gappov = 5; /* vert outer gap between windows and screen edge */
-static int smartgaps = 0; /* 1 means no outer gap when there is only one window */
+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 int user_bh = 27; /* 0 means that dwm will calculate bar height, >= 1 means dwm will user_bh as bar height */
-static const int vertpad = 10; /* vertical padding of bar */
-static const int sidepad = 10; /* horizontal padding of bar */
-static const char *fonts[] = { "JetBrains Mono:size=10", "JoyPixels:pixelsize=10:antialias=true:autohint=true" };
-static char normbgcolor[] = "#080808";
-static char normbordercolor[] = "#1a1a1a";
-static char normfgcolor[] = "#e5e5e5";
-static char selfgcolor[] = "#e5e5e5";
-static char selbordercolor[] = "#fc8617";
-static char selbgcolor[] = "#fc8617";
+static const char *fonts[] = { "JetBrains Mono:size=11", "JoyPixels:pixelsize=11:antialias=true:autohint=true"};
+static const char dmenufont[] = "JetBrains Mono:size=11";
+static char normbgcolor[] = "#222222";
+static char normbordercolor[] = "#444444";
+static char normfgcolor[] = "#bbbbbb";
+static char selfgcolor[] = "#eeeeee";
+static char selbordercolor[] = "#005577";
+static char selbgcolor[] = "#005577";
static char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
@@ -31,57 +22,36 @@ static char *colors[][3] = {
};
/* tagging */
-static const char *tags[] = { "", "", "", "", "", "", "", "", "" };
+static const char *tags[] = { "", "", "", "", "", "", "", "", "" };
static const Rule rules[] = {
/* xprop(1):
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Deadbeef", NULL, NULL, 0, 1, -1 },
- { "Gcolor3", NULL, NULL, 0, 1, -1 },
- { "Pavucontrol", NULL, NULL, 0, 1, -1 },
- { "Sxiv", NULL, NULL, 0, 1, -1 },
- { "Pcmanfm", NULL, NULL, 0, 1, -1 },
- { "Zathura", NULL, NULL, 0, 1, -1 },
- { "blueman-manager", NULL, NULL, 0, 1, -1 },
- { "cpomosai", NULL, NULL, 0, 1, -1 },
- { "packagesupgrade", NULL, NULL, 0, 1, -1 },
- { "weatherreport", NULL, NULL, 0, 0, -1 },
+ /* class instance title tags mask isfloating isterminal noswallow monitor */
+ { "TelegramDesktop", NULL, NULL, 0, 1, 0, 0, -1 },
+ { "obs", NULL, NULL, 0, 1, 0, 0, -1 },
+ { "Lutris", NULL, NULL, 0, 1, 0, 0, -1 },
+ { "firefox", NULL, NULL, 1 << 2, 0, 0, -1, -1 },
+ { "St", NULL, NULL, 0, 0, 1, 0, -1 },
+ { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */
};
/* layout(s) */
-static const float mfact = 0.5; /* factor of master area size [0.05..0.95] */
+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 = 0; /* 1 means respect size hints in tiled resizals */
-static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
-
-#define FORCE_VSPLIT 1 /* nrowgrid layout: force two clients to always split vertically */
-#include "vanitygaps.c"
+static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const Layout layouts[] = {
-/* symbol arrange function */
-{ "[F]", NULL }, /* 0 first entry is default */
-{ "[T]", tile }, /* 1 */
-{ "[M]", monocle }, /* 2 */
-{ "[S]", spiral }, /* 3 */
-{ "[DW]", dwindle }, /* 4 */
-{ "[D]", deck }, /* 5 */
-{ "[BS]", bstack }, /* 6 */
-{ "[BSH]", bstackhoriz }, /* 7 */
-{ "[G]", grid }, /* 8 */
-{ "[RG]", nrowgrid }, /* 9 */
-{ "[HG]", horizgrid }, /* 10 */
-{ "[GG]", gaplessgrid }, /* 11 */
-{ "[C]", centeredmaster }, /* 12 */
-{ "[CF]", centeredfloatingmaster }, /* 13 */
-{ NULL, NULL }, /* 14 */
+ /* symbol arrange function */
+ { "[]=", tile }, /* first entry is default */
+ { "><>", NULL }, /* no layout function means floating behavior */
+ { "[M]", monocle },
};
/* key definitions */
#define MODKEY Mod4Mask
-#define PrintScreenDWM 0x0000ff61
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
@@ -92,74 +62,39 @@ static const Layout layouts[] = {
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
/* commands */
-static const char *dmenucmd[] = { "dmenu_run", NULL };
-static const char *cmdprintscreen[] = { "scrot", "-d3", "/home/genos/Pictures/%Y-%m-%d-%s_$wx$h.jpg", NULL };
+static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
+static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont};
+static const char *termcmd[] = { "st", NULL };
-/*static const char *flavorsel[] = { "flavorsel", NULL };*/
-static const char *emojicmd[] = { "emojidmenu", NULL };
-static const char *chrscmd[] = { "chrs", NULL };
-static const char *termcmd[] = { "st", NULL };
-static const char *webcmd[] = { "firefox", NULL };
-static const char *filescmd[] = { "pcmanfm", NULL };
-static const char *powermenu[] = { "powermenu", NULL };
-static const char *shotmenu[] = { "shotmenu", NULL };
-static const char *sysinfo[] = { "sysinfo", NULL };
-static const char *bgset[] = { "bgset", NULL };
-static const char *disset[] = { "disset", NULL };
-static const char *disfix[] = { "disfix", NULL };
-static const char *audiocontrolcmd[] = { "pavucontrol", NULL };
-
-#include <X11/XF86keysym.h>
static Key keys[] = {
/* modifier key function argument */
- { MODKEY, XK_d, spawn, {.v = dmenucmd } },
- { MODKEY, XK_Return, spawn, {.v = termcmd } },
- { MODKEY, XK_w, spawn, {.v = webcmd } },
- { MODKEY, XK_e, spawn, {.v = emojicmd } },
- { MODKEY|ShiftMask, XK_f, spawn, {.v = filescmd } },
- { MODKEY|ShiftMask, XK_m, spawn, {.v = audiocontrolcmd } },
- { MODKEY, XK_0, spawn, {.v = powermenu } },
- { MODKEY|ShiftMask, XK_w, spawn, {.v = bgset } },
- { MODKEY|Mod1Mask, XK_w, spawn, {.v = chrscmd } },
- { MODKEY|ShiftMask, XK_d, spawn, {.v = disset } },
- { MODKEY|Mod1Mask, XK_d, spawn, {.v = disfix } },
- { MODKEY, XK_F2, spawn, SHCMD("groff -mom $HOME/.local/share/dwm/gzdots.mom -T pdf | zathura -") },
- { MODKEY|ShiftMask, XK_t, spawn, SHCMD(TERMINAL " -c cpomosai -e cpomosai") },
- { MODKEY, XK_b, spawn, {.v = sysinfo } },
- { MODKEY|ShiftMask, XK_b, togglebar, {0} },
- { MODKEY, XK_j, focusstack, {.i = +1 } },
+ { MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
- { MODKEY|ControlMask, XK_i, incnmaster, {.i = +1 } },
- { MODKEY|ControlMask, XK_d, incnmaster, {.i = -1 } },
+ { MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
- { MODKEY, XK_l, setmfact, {.f = +0.05} },
- { MODKEY|ShiftMask, XK_Return, zoom, {0} },
- { MODKEY, XK_z, incrgaps, {.i = +3 } },
- { MODKEY, XK_x, incrgaps, {.i = -3 } },
- { MODKEY, XK_a, togglegaps, {0} },
- { MODKEY|ShiftMask, XK_a, defaultgaps, {0} },
+ { MODKEY, XK_g, togglebar, {0} },
+ { MODKEY, XK_f, zoom, {0} },
+ { MODKEY, XK_d, incnmaster, {.i = -1 } },
+ { MODKEY, XK_s, incnmaster, {.i = +1 } },
+ { MODKEY, XK_q, killclient, {0} },
+ { MODKEY, XK_w, setlayout, {.v = &layouts[0]} },
+ { MODKEY, XK_e, setlayout, {.v = &layouts[1]} },
+ { MODKEY, XK_r, setlayout, {.v = &layouts[2]} },
+ { MODKEY|ShiftMask, XK_r, togglefloating, {0} },
+ { MODKEY, XK_t, setlayout, {0} },
+ { MODKEY, XK_space, spawn, {.v = dmenucmd } },
+ { MODKEY, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_Tab, view, {0} },
- { MODKEY, XK_q, killclient, {0} },
- { MODKEY, XK_t, setlayout, {.v = &layouts[1]} },
- { MODKEY, XK_m, setlayout, {.v = &layouts[5]} },
- { MODKEY|ShiftMask, XK_m, setlayout, {.v = &layouts[2]} },
- { MODKEY, XK_s, setlayout, {.v = &layouts[3]} },
- { MODKEY, XK_c, setlayout, {.v = &layouts[12]} },
- { MODKEY, XK_space, setlayout, {.v = &layouts[13]} },
- { MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } },
- { MODKEY|ControlMask, XK_period, cyclelayout, {.i = +1 } },
- { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
- { MODKEY, XK_f, togglefullscr, {0} },
- { MODKEY|ControlMask, XK_0, view, {.ui = ~0 } },
+ { MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
- { MODKEY, XK_Left, focusmon, {.i = -1 } },
- { MODKEY, XK_Right, focusmon, {.i = +1 } },
- { MODKEY|ShiftMask, XK_Left, tagmon, {.i = -1 } },
- { MODKEY|ShiftMask, XK_Right, tagmon, {.i = +1 } },
- { MODKEY, XK_F1, xrdb, {.v = NULL } },
- { MODKEY|ShiftMask, XK_s, spawn, {.v = cmdprintscreen } },
-
- /*{ MODKEY|Mod2Mask, XK_f, spawn, {.v = flavorsel } },*/
+ { 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 } },
+ { MODKEY, XK_minus, setgaps, {.i = -1 } },
+ { MODKEY, XK_equal, setgaps, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_equal, setgaps, {.i = 0 } },
+ { MODKEY, XK_F5, xrdb, {.v = NULL } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
@@ -169,42 +104,9 @@ static Key keys[] = {
TAGKEYS( XK_7, 6)
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
- { 0, XK_Print, spawn, SHCMD("scrot ~/Pictures/allmon-$(date +%H:%M:%S).png --quality 100 --freeze") },
- { MODKEY, XK_Print, spawn, {.v = shotmenu } },
- { 0, XF86XK_AudioMute, spawn, SHCMD("pamixer -t") },
- { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 5") },
- { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 5") },
- { MODKEY, XK_F10, spawn, SHCMD("mpc volume 0") },
- { MODKEY, XK_F11, spawn, SHCMD("mpc volume -5") },
- { MODKEY, XK_F12, spawn, SHCMD("mpc volume +5") },
- { 0, XF86XK_AudioPrev, spawn, SHCMD("mpc prev && covernotify") },
- { 0, XF86XK_AudioNext, spawn, SHCMD("mpc next && covernotify") },
- { 0, XF86XK_AudioPlay, spawn, SHCMD("mpc toggle && covernotify") },
- { 0, XF86XK_AudioStop, spawn, SHCMD("mpc stop && covernotify") },
- { MODKEY, XK_F5, spawn, SHCMD(TERMINAL " -e ncmpcpp") },
- { 0, XF86XK_Calculator, spawn, SHCMD(TERMINAL " -e bc -l") },
- { 0, XF86XK_MonBrightnessUp, spawn, SHCMD("xbacklight -inc 15") },
- { 0, XF86XK_MonBrightnessDown, spawn, SHCMD("xbacklight -dec 15") },
- { MODKEY|ShiftMask, XK_F4, quit, {0} },
-
- /* { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, */
- /* { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, */
- /* { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, */
- /* { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, */
- /* { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, */
- /* { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, */
- /* { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, */
- /* { MODKEY, XK_y, incrihgaps, {.i = +1 } }, */
- /* { MODKEY, XK_o, incrihgaps, {.i = -1 } }, */
- /* { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, */
- /* { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, */
- /* { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, */
- /* { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, */
- /* { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, */
- /* { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, */
+ { MODKEY|ShiftMask, XK_q, quit, {0} },
};
-
/* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
diff --git a/config.mk b/config.mk
index 18b009f..ff9e508 100644
--- a/config.mk
+++ b/config.mk
@@ -1,13 +1,3 @@
-# . . .
-# | | | .
-# ,-. ,-. |-. ,-. . ,-. | ,_, ,-. ,-. |-. ,-,-. . |- ,_,
-# | | ,-| | | | | |-' | / `-. | | | | | | | | /
-# `-| `-^ ^-' ' ' `-' `' '"' `-' `-' ' ' ' ' ' ' `' '"'
-# ,|
-# `'
-# GITHUB:https://github.com/gabrielzschmitz
-# INSTAGRAM:https://www.instagram.com/gabrielz.schmitz/
-# DOTFILES:https://github.com/gabrielzschmitz/dotfiles/
# dwm version
VERSION = 6.2
@@ -29,10 +19,11 @@ FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
# OpenBSD (uncomment)
#FREETYPEINC = ${X11INC}/freetype2
+#KVMLIB = -lkvm
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
-LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res ${KVMLIB}
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
diff --git a/drw.c b/drw.c
index 845c563..f8bc814 100644
--- a/drw.c
+++ b/drw.c
@@ -1,3 +1,4 @@
+/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -132,19 +133,6 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
die("no font specified.");
}
- /* Do not allow using color fonts. This is a workaround for a BadLength
- * error from Xft with color glyphs. Modelled on the Xterm workaround. See
- * https://bugzilla.redhat.com/show_bug.cgi?id=1498269
- * https://lists.suckless.org/dev/1701/30932.html
- * 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;
- }
-
font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont;
font->pattern = pattern;
diff --git a/drw.h b/drw.h
index 6081ec4..42b04ce 100644
--- a/drw.h
+++ b/drw.h
@@ -1,15 +1,3 @@
-/*
-// . . .
-// | | | .
-// ,-. ,-. |-. ,-. . ,-. | ,_, ,-. ,-. |-. ,-,-. . |- ,_,
-// | | ,-| | | | | |-' | / `-. | | | | | | | | /
-// `-| `-^ ^-' ' ' `-' `' '"' `-' `-' ' ' ' ' ' ' `' '"'
-// ,|
-// `'
-// GITHUB:https://github.com/gabrielzschmitz
-// INSTAGRAM:https://www.instagram.com/gabrielz.schmitz/
-// DOTFILES:https://github.com/gabrielzschmitz/dotfiles/
-*/
/* See LICENSE file for copyright and license details. */
typedef struct {
diff --git a/drw.o b/drw.o
index 769ec78..2b22ad3 100644
--- a/drw.o
+++ b/drw.o
Binary files differ
diff --git a/dwm b/dwm
index 5cd5ec9..d9c5423 100755
--- a/dwm
+++ b/dwm
Binary files differ
diff --git a/dwm.1 b/dwm.1
index 829047b..ddc8321 100644
--- a/dwm.1
+++ b/dwm.1
@@ -92,12 +92,6 @@ Sets monocle layout.
.B Mod1\-space
Toggles between current and previous layout.
.TP
-.B Mod1\-Control\-,
-Cycles backwards in layout list.
-.TP
-.B Mod1\-Control\-.
-Cycles forwards in layout list.
-.TP
.B Mod1\-j
Focus next window.
.TP
diff --git a/dwm.c b/dwm.c
index 07a04e3..71ec76e 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1,5 +1,3 @@
-
-
/* See LICENSE file for copyright and license details.
*
* dynamic window manager is designed like any other X client as well. It is
@@ -43,6 +41,12 @@
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
#include <X11/Xft/Xft.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/res.h>
+#ifdef __OpenBSD__
+#include <sys/sysctl.h>
+#include <kvm.h>
+#endif /* __OpenBSD */
#include "drw.h"
#include "util.h"
@@ -110,10 +114,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 issteam;
+ int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow;
+ pid_t pid;
Client *next;
Client *snext;
+ Client *swallowing;
Monitor *mon;
Window win;
};
@@ -138,10 +143,7 @@ struct Monitor {
int by; /* bar geometry */
int mx, my, mw, mh; /* screen size */
int wx, wy, ww, wh; /* window area */
- int gappih; /* horizontal gap between windows */
- int gappiv; /* vertical gap between windows */
- int gappoh; /* horizontal outer gaps */
- int gappov; /* vertical outer gaps */
+ int gappx; /* gaps between windows */
unsigned int seltags;
unsigned int sellt;
unsigned int tagset[2];
@@ -161,6 +163,8 @@ typedef struct {
const char *title;
unsigned int tags;
int isfloating;
+ int isterminal;
+ int noswallow;
int monitor;
} Rule;
@@ -180,7 +184,6 @@ static void configure(Client *c);
static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e);
static Monitor *createmon(void);
-static void cyclelayout(const Arg *arg);
static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
@@ -225,6 +228,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 setgaps(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -234,9 +238,9 @@ static void sigchld(int unused);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
+static void tile(Monitor *);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
-static void togglefullscr(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -261,6 +265,12 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xrdb(const Arg *arg);
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];
@@ -268,8 +278,6 @@ static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh, blw = 0; /* bar geometry */
static int lrpad; /* sum of left and right padding for text */
-static int vp; /* vertical padding for bar */
-static int sp; /* side padding for bar */
static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0;
static void (*handler[LASTEvent]) (XEvent *) = {
@@ -297,6 +305,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"
@@ -320,15 +330,14 @@ applyrules(Client *c)
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
- if (strstr(class, "Steam") || strstr(class, "steam_app_"))
- c->issteam = 1;
-
for (i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
if ((!r->title || strstr(c->name, r->title))
&& (!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);
@@ -446,6 +455,53 @@ attachstack(Client *c)
}
void
+swallow(Client *p, Client *c)
+{
+
+ if (c->noswallow || c->isterminal)
+ return;
+ if (c->noswallow && !swallowfloating && c->isfloating)
+ return;
+
+ detach(c);
+ detachstack(c);
+
+ setclientstate(c, WithdrawnState);
+ XUnmapWindow(dpy, p->win);
+
+ p->swallowing = c;
+ c->mon = p->mon;
+
+ Window w = p->win;
+ p->win = c->win;
+ c->win = w;
+ updatetitle(p);
+ XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h);
+ arrange(p->mon);
+ configure(p);
+ updateclientlist();
+}
+
+void
+unswallow(Client *c)
+{
+ c->win = c->swallowing->win;
+
+ free(c->swallowing);
+ c->swallowing = NULL;
+
+ /* unfullscreen the client */
+ setfullscreen(c, 0);
+ updatetitle(c);
+ arrange(c->mon);
+ XMapWindow(dpy, c->win);
+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+ setclientstate(c, NormalState);
+ focus(NULL);
+ arrange(c->mon);
+}
+
+void
buttonpress(XEvent *e)
{
unsigned int i, x, click;
@@ -599,7 +655,7 @@ configurenotify(XEvent *e)
for (c = m->clients; c; c = c->next)
if (c->isfullscreen)
resizeclient(c, m->mx, m->my, m->mw, m->mh);
- XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh);
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
}
focus(NULL);
arrange(NULL);
@@ -620,15 +676,13 @@ configurerequest(XEvent *e)
c->bw = ev->border_width;
else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
m = c->mon;
- if (!c->issteam) {
- if (ev->value_mask & CWX) {
- c->oldx = c->x;
- c->x = m->mx + ev->x;
- }
- if (ev->value_mask & CWY) {
- c->oldy = c->y;
- c->y = m->my + ev->y;
- }
+ if (ev->value_mask & CWX) {
+ c->oldx = c->x;
+ c->x = m->mx + ev->x;
+ }
+ if (ev->value_mask & CWY) {
+ c->oldy = c->y;
+ c->y = m->my + ev->y;
}
if (ev->value_mask & CWWidth) {
c->oldw = c->w;
@@ -672,10 +726,7 @@ createmon(void)
m->nmaster = nmaster;
m->showbar = showbar;
m->topbar = topbar;
- m->gappih = gappih;
- m->gappiv = gappiv;
- m->gappoh = gappoh;
- m->gappov = gappov;
+ m->gappx = gappx;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
@@ -683,23 +734,6 @@ createmon(void)
}
void
-cyclelayout(const Arg *arg) {
- Layout *l;
- for(l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++);
- if(arg->i > 0) {
- if(l->symbol && (l + 1)->symbol)
- setlayout(&((Arg) { .v = (l + 1) }));
- else
- setlayout(&((Arg) { .v = layouts }));
- } else {
- if(l != layouts && (l - 1)->symbol)
- setlayout(&((Arg) { .v = (l - 1) }));
- else
- setlayout(&((Arg) { .v = &layouts[LENGTH(layouts) - 2] }));
- }
-}
-
-void
destroynotify(XEvent *e)
{
Client *c;
@@ -707,6 +741,9 @@ destroynotify(XEvent *e)
if ((c = wintoclient(ev->window)))
unmanage(c, 1);
+
+ else if ((c = swallowingclient(ev->window)))
+ unmanage(c->swallowing, 1);
}
void
@@ -760,7 +797,7 @@ drawbar(Monitor *m)
if (m == selmon) { /* status is only drawn on selected monitor */
drw_setscheme(drw, scheme[SchemeNorm]);
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
- drw_text(drw, m->ww - tw - 2 * sp, 0, tw, bh, 0, stext, 0);
+ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
}
for (c = m->clients; c; c = c->next) {
@@ -787,12 +824,12 @@ drawbar(Monitor *m)
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
- drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
if (m->sel->isfloating)
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
} else {
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1);
+ drw_rect(drw, x, 0, w, bh, 1, 1);
}
}
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
@@ -883,8 +920,6 @@ focusmon(const Arg *arg)
unfocus(selmon->sel, 0);
selmon = m;
focus(NULL);
- if (selmon->sel)
- XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2);
}
void
@@ -892,7 +927,7 @@ focusstack(const Arg *arg)
{
Client *c = NULL, *i;
- if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen))
+ if (!selmon->sel || selmon->sel->isfullscreen)
return;
if (arg->i > 0) {
for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
@@ -910,7 +945,6 @@ focusstack(const Arg *arg)
if (c) {
focus(c);
restack(selmon);
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
}
}
@@ -1091,12 +1125,12 @@ loadxrdb()
xrdb = XrmGetStringDatabase(resm);
if (xrdb != NULL) {
- XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor);
- XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor);
- XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor);
- XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor);
- XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor);
- XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor);
+ XRDB_LOAD_COLOR("dwm.color0", normbordercolor);
+ XRDB_LOAD_COLOR("dwm.color8", selbordercolor);
+ XRDB_LOAD_COLOR("dwm.color0", normbgcolor);
+ XRDB_LOAD_COLOR("dwm.color6", normfgcolor);
+ XRDB_LOAD_COLOR("dwm.color0", selfgcolor);
+ XRDB_LOAD_COLOR("dwm.color14", selbgcolor);
}
}
}
@@ -1107,12 +1141,13 @@ loadxrdb()
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;
@@ -1127,6 +1162,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)
@@ -1146,8 +1182,6 @@ manage(Window w, XWindowAttributes *wa)
updatewindowtype(c);
updatesizehints(c);
updatewmhints(c);
- c->x = c->mon->mx + (c->mon->mw - WIDTH(c)) / 2;
- c->y = c->mon->my + (c->mon->mh - HEIGHT(c)) / 2;
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, 0);
if (!c->isfloating)
@@ -1165,6 +1199,8 @@ manage(Window w, XWindowAttributes *wa)
c->mon->sel = c;
arrange(c->mon);
XMapWindow(dpy, c->win);
+ if (term)
+ swallow(term, c);
focus(NULL);
}
@@ -1590,6 +1626,16 @@ setfullscreen(Client *c, int fullscreen)
}
void
+setgaps(const Arg *arg)
+{
+ if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
+ selmon->gappx = 0;
+ else
+ selmon->gappx += arg->i;
+ arrange(selmon);
+}
+
+void
setlayout(const Arg *arg)
{
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
@@ -1637,11 +1683,8 @@ setup(void)
if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
- bh = user_bh ? user_bh : drw->fonts->h + 2;
+ bh = drw->fonts->h + 2;
updategeom();
- sp = sidepad;
- vp = (topbar == 1) ? vertpad : - vertpad;
-
/* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
@@ -1668,7 +1711,6 @@ setup(void)
/* init bars */
updatebars();
updatestatus();
- updatebarpos(selmon);
/* supporting window for NetWMCheck */
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
@@ -1685,7 +1727,7 @@ setup(void)
wa.cursor = cursor[CurNormal]->cursor;
wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
|ButtonPressMask|PointerMotionMask|EnterWindowMask
- |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask|KeyPressMask;
+ |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask;
XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask);
grabkeys();
@@ -1735,6 +1777,8 @@ sigchld(int unused)
void
spawn(const Arg *arg)
{
+ if (arg->v == dmenucmd)
+ dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@@ -1765,11 +1809,37 @@ tagmon(const Arg *arg)
}
void
+tile(Monitor *m)
+{
+ unsigned int i, n, h, mw, my, ty;
+ Client *c;
+
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ if (n == 0)
+ return;
+
+ if (n > m->nmaster)
+ mw = m->nmaster ? m->ww * m->mfact : 0;
+ else
+ mw = m->ww - m->gappx;
+ for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ if (i < m->nmaster) {
+ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
+ resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0);
+ my += HEIGHT(c) + m->gappx;
+ } else {
+ h = (m->wh - ty) / (n - i) - m->gappx;
+ resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
+ ty += HEIGHT(c) + m->gappx;
+ }
+}
+
+void
togglebar(const Arg *arg)
{
selmon->showbar = !selmon->showbar;
updatebarpos(selmon);
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx + sp, selmon->by + vp, selmon->ww - 2 * sp, bh);
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon);
}
@@ -1788,13 +1858,6 @@ togglefloating(const Arg *arg)
}
void
-togglefullscr(const Arg *arg)
-{
- if(selmon->sel)
- setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
-}
-
-void
toggletag(const Arg *arg)
{
unsigned int newtags;
@@ -1840,6 +1903,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) {
@@ -1854,9 +1931,12 @@ unmanage(Client *c, int destroyed)
XUngrabServer(dpy);
}
free(c);
- focus(NULL);
- updateclientlist();
- arrange(m);
+
+ if (!s) {
+ arrange(m);
+ focus(NULL);
+ updateclientlist();
+ }
}
void
@@ -1886,7 +1966,7 @@ updatebars(void)
for (m = mons; m; m = m->next) {
if (m->barwin)
continue;
- m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen),
+ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
@@ -1901,11 +1981,11 @@ updatebarpos(Monitor *m)
m->wy = m->my;
m->wh = m->mh;
if (m->showbar) {
- m->wh = m->wh - vertpad - bh;
- m->by = m->topbar ? m->wy : m->wy + m->wh + vertpad;
- m->wy = m->topbar ? m->wy + bh + vp : m->wy;
+ m->wh -= bh;
+ m->by = m->topbar ? m->wy : m->wy + m->wh;
+ m->wy = m->topbar ? m->wy + bh : m->wy;
} else
- m->by = -bh - vp;
+ m->by = -bh;
}
void
@@ -2119,6 +2199,136 @@ view(const Arg *arg)
arrange(selmon);
}
+pid_t
+winpid(Window w)
+{
+
+ pid_t result = 0;
+
+#ifdef __linux__
+ xcb_res_client_id_spec_t spec = {0};
+ spec.client = w;
+ spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
+
+ xcb_generic_error_t *e = NULL;
+ xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec);
+ xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e);
+
+ if (!r)
+ return (pid_t)0;
+
+ xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r);
+ for (; i.rem; xcb_res_client_id_value_next(&i)) {
+ spec = i.data->spec;
+ if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) {
+ uint32_t *t = xcb_res_client_id_value_value(i.data);
+ result = *t;
+ break;
+ }
+ }
+
+ free(r);
+
+ if (result == (pid_t)-1)
+ result = 0;
+
+#endif /* __linux__ */
+
+#ifdef __OpenBSD__
+ Atom type;
+ int format;
+ unsigned long len, bytes;
+ unsigned char *prop;
+ pid_t ret;
+
+ if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 0), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop)
+ return 0;
+
+ ret = *(pid_t*)prop;
+ XFree(prop);
+ result = ret;
+
+#endif /* __OpenBSD__ */
+ return result;
+}
+
+pid_t
+getparentprocess(pid_t p)
+{
+ unsigned int v = 0;
+
+#ifdef __linux__
+ FILE *f;
+ char buf[256];
+ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
+
+ if (!(f = fopen(buf, "r")))
+ return 0;
+
+ fscanf(f, "%*u %*s %*c %u", &v);
+ fclose(f);
+#endif /* __linux__*/
+
+#ifdef __OpenBSD__
+ int n;
+ kvm_t *kd;
+ struct kinfo_proc *kp;
+
+ kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
+ if (!kd)
+ return 0;
+
+ kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n);
+ v = kp->p_ppid;
+#endif /* __OpenBSD__ */
+
+ return (pid_t)v;
+}
+
+int
+isdescprocess(pid_t p, pid_t c)
+{
+ while (p != c && c != 0)
+ c = getparentprocess(c);
+
+ return (int)c;
+}
+
+Client *
+termforwin(const Client *w)
+{
+ Client *c;
+ Monitor *m;
+
+ if (!w->pid || w->isterminal)
+ return NULL;
+
+ for (m = mons; m; m = m->next) {
+ for (c = m->clients; c; c = c->next) {
+ if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
+ return c;
+ }
+ }
+
+ return NULL;
+}
+
+Client *
+swallowingclient(Window w)
+{
+ Client *c;
+ Monitor *m;
+
+ for (m = mons; m; m = m->next) {
+ for (c = m->clients; c; c = c->next) {
+ if (c->swallowing && c->swallowing->win == w)
+ return c;
+ }
+ }
+
+ return NULL;
+}
+
Client *
wintoclient(Window w)
{
@@ -2221,12 +2431,14 @@ main(int argc, char *argv[])
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
+ if (!(xcon = XGetXCBConnection(dpy)))
+ die("dwm: cannot get xcb connection\n");
checkotherwm();
XrmInitialize();
loadxrdb();
setup();
#ifdef __OpenBSD__
- if (pledge("stdio rpath proc exec", NULL) == -1)
+ if (pledge("stdio rpath proc exec ps", NULL) == -1)
die("pledge");
#endif /* __OpenBSD__ */
scan();
diff --git a/dwm.c.orig b/dwm.c.orig
new file mode 100644
index 0000000..cf84ee3
--- /dev/null
+++ b/dwm.c.orig
@@ -0,0 +1,2448 @@
+/* See LICENSE file for copyright and license details.
+ *
+ * dynamic window manager is designed like any other X client as well. It is
+ * driven through handling X events. In contrast to other X clients, a window
+ * manager selects for SubstructureRedirectMask on the root window, to receive
+ * events about window (dis-)appearance. Only one X connection at a time is
+ * allowed to select for this event mask.
+ *
+ * The event handlers of dwm are organized in an array which is accessed
+ * whenever a new event has been fetched. This allows event dispatching
+ * in O(1) time.
+ *
+ * Each child of the root window is called a client, except windows which have
+ * set the override_redirect flag. Clients are organized in a linked client
+ * list on each monitor, the focus history is remembered through a stack list
+ * on each monitor. Each client contains a bit array to indicate the tags of a
+ * client.
+ *
+ * Keys and tagging rules are organized as arrays and defined in config.h.
+ *
+ * To understand everything else, start reading main().
+ */
+#include <errno.h>
+#include <locale.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <X11/cursorfont.h>
+#include <X11/keysym.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xproto.h>
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
+#ifdef XINERAMA
+#include <X11/extensions/Xinerama.h>
+#endif /* XINERAMA */
+#include <X11/Xft/Xft.h>
+#include <X11/Xlib-xcb.h>
+#include <xcb/res.h>
+#ifdef __OpenBSD__
+#include <sys/sysctl.h>
+#include <kvm.h>
+#endif /* __OpenBSD */
+
+#include "drw.h"
+#include "util.h"
+
+/* macros */
+#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
+#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
+#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
+ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
+#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
+#define LENGTH(X) (sizeof X / sizeof X[0])
+#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
+#define WIDTH(X) ((X)->w + 2 * (X)->bw)
+#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
+#define TAGMASK ((1 << LENGTH(tags)) - 1)
+#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \
+ if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \
+ int i = 1; \
+ for (; i <= 6; i++) { \
+ if (value.addr[i] < 48) break; \
+ if (value.addr[i] > 57 && value.addr[i] < 65) break; \
+ if (value.addr[i] > 70 && value.addr[i] < 97) break; \
+ if (value.addr[i] > 102) break; \
+ } \
+ if (i == 7) { \
+ strncpy(V, value.addr, 7); \
+ V[7] = '\0'; \
+ } \
+ } \
+ }
+
+/* enums */
+enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
+enum { SchemeNorm, SchemeSel }; /* color schemes */
+enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+ NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+ NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
+enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
+ ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+
+typedef union {
+ int i;
+ unsigned int ui;
+ float f;
+ const void *v;
+} Arg;
+
+typedef struct {
+ unsigned int click;
+ unsigned int mask;
+ unsigned int button;
+ void (*func)(const Arg *arg);
+ const Arg arg;
+} Button;
+
+typedef struct Monitor Monitor;
+typedef struct Client Client;
+struct Client {
+ char name[256];
+ float mina, maxa;
+ int x, y, w, h;
+ int oldx, oldy, oldw, oldh;
+ int basew, baseh, incw, inch, maxw, maxh, minw, minh;
+ int bw, oldbw;
+ unsigned int tags;
+ int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow;
+ pid_t pid;
+ Client *next;
+ Client *snext;
+ Client *swallowing;
+ Monitor *mon;
+ Window win;
+};
+
+typedef struct {
+ unsigned int mod;
+ KeySym keysym;
+ void (*func)(const Arg *);
+ const Arg arg;
+} Key;
+
+typedef struct {
+ const char *symbol;
+ void (*arrange)(Monitor *);
+} Layout;
+
+struct Monitor {
+ char ltsymbol[16];
+ float mfact;
+ int nmaster;
+ int num;
+ int by; /* bar geometry */
+ int mx, my, mw, mh; /* screen size */
+ int wx, wy, ww, wh; /* window area */
+ int gappx; /* gaps between windows */
+ unsigned int seltags;
+ unsigned int sellt;
+ unsigned int tagset[2];
+ int showbar;
+ int topbar;
+ Client *clients;
+ Client *sel;
+ Client *stack;
+ Monitor *next;
+ Window barwin;
+ const Layout *lt[2];
+};
+
+typedef struct {
+ const char *class;
+ const char *instance;
+ const char *title;
+ unsigned int tags;
+ int isfloating;
+ int isterminal;
+ int noswallow;
+ int monitor;
+} Rule;
+
+/* function declarations */
+static void applyrules(Client *c);
+static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
+static void arrange(Monitor *m);
+static void arrangemon(Monitor *m);
+static void attach(Client *c);
+static void attachstack(Client *c);
+static void buttonpress(XEvent *e);
+static void checkotherwm(void);
+static void cleanup(void);
+static void cleanupmon(Monitor *mon);
+static void clientmessage(XEvent *e);
+static void configure(Client *c);
+static void configurenotify(XEvent *e);
+static void configurerequest(XEvent *e);
+static Monitor *createmon(void);
+static void destroynotify(XEvent *e);
+static void detach(Client *c);
+static void detachstack(Client *c);
+static Monitor *dirtomon(int dir);
+static void drawbar(Monitor *m);
+static void drawbars(void);
+static void enternotify(XEvent *e);
+static void expose(XEvent *e);
+static void focus(Client *c);
+static void focusin(XEvent *e);
+static void focusmon(const Arg *arg);
+static void focusstack(const Arg *arg);
+static Atom getatomprop(Client *c, Atom prop);
+static int getrootptr(int *x, int *y);
+static long getstate(Window w);
+static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
+static void grabbuttons(Client *c, int focused);
+static void grabkeys(void);
+static void incnmaster(const Arg *arg);
+static void keypress(XEvent *e);
+static void killclient(const Arg *arg);
+static void loadxrdb(void);
+static void manage(Window w, XWindowAttributes *wa);
+static void mappingnotify(XEvent *e);
+static void maprequest(XEvent *e);
+static void monocle(Monitor *m);
+static void motionnotify(XEvent *e);
+static void movemouse(const Arg *arg);
+static Client *nexttiled(Client *c);
+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);
+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 run(void);
+static void scan(void);
+static int sendevent(Client *c, Atom proto);
+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 setgaps(const Arg *arg);
+static void setlayout(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 tag(const Arg *arg);
+static void tagmon(const Arg *arg);
+static void tile(Monitor *);
+static void togglebar(const Arg *arg);
+static void togglefloating(const Arg *arg);
+static void toggletag(const Arg *arg);
+static void toggleview(const Arg *arg);
+static void unfocus(Client *c, int setfocus);
+static void unmanage(Client *c, int destroyed);
+static void unmapnotify(XEvent *e);
+static void updatebarpos(Monitor *m);
+static void updatebars(void);
+static void updateclientlist(void);
+static int updategeom(void);
+static void updatenumlockmask(void);
+static void updatesizehints(Client *c);
+static void updatestatus(void);
+static void updatetitle(Client *c);
+static void updatewindowtype(Client *c);
+static void updatewmhints(Client *c);
+static void view(const Arg *arg);
+static Client *wintoclient(Window w);
+static Monitor *wintomon(Window w);
+static int xerror(Display *dpy, XErrorEvent *ee);
+static int xerrordummy(Display *dpy, XErrorEvent *ee);
+static int xerrorstart(Display *dpy, XErrorEvent *ee);
+static void xrdb(const Arg *arg);
+static void zoom(const Arg *arg);
+
+static 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 screen;
+static int sw, sh; /* X display screen geometry width, height */
+static int bh, blw = 0; /* bar geometry */
+static int lrpad; /* sum of left and right padding for text */
+static int (*xerrorxlib)(Display *, XErrorEvent *);
+static unsigned int numlockmask = 0;
+static void (*handler[LASTEvent]) (XEvent *) = {
+ [ButtonPress] = buttonpress,
+ [ClientMessage] = clientmessage,
+ [ConfigureRequest] = configurerequest,
+ [ConfigureNotify] = configurenotify,
+ [DestroyNotify] = destroynotify,
+ [EnterNotify] = enternotify,
+ [Expose] = expose,
+ [FocusIn] = focusin,
+ [KeyPress] = keypress,
+ [MappingNotify] = mappingnotify,
+ [MapRequest] = maprequest,
+ [MotionNotify] = motionnotify,
+ [PropertyNotify] = propertynotify,
+ [UnmapNotify] = unmapnotify
+};
+static Atom wmatom[WMLast], netatom[NetLast];
+static int running = 1;
+static Cur *cursor[CurLast];
+static Clr **scheme;
+static Display *dpy;
+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"
+
+/* compile-time check if all tags fit into an unsigned int bit array. */
+struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+
+/* function implementations */
+void
+applyrules(Client *c)
+{
+ const char *class, *instance;
+ unsigned int i;
+ const Rule *r;
+ Monitor *m;
+ XClassHint ch = { NULL, NULL };
+
+ /* rule matching */
+ c->isfloating = 0;
+ c->tags = 0;
+ XGetClassHint(dpy, c->win, &ch);
+ class = ch.res_class ? ch.res_class : broken;
+ instance = ch.res_name ? ch.res_name : broken;
+
+ for (i = 0; i < LENGTH(rules); i++) {
+ r = &rules[i];
+ if ((!r->title || strstr(c->name, r->title))
+ && (!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);
+ if (m)
+ c->mon = m;
+ }
+ }
+ if (ch.res_class)
+ XFree(ch.res_class);
+ if (ch.res_name)
+ XFree(ch.res_name);
+ c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
+}
+
+int
+applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
+{
+ int baseismin;
+ Monitor *m = c->mon;
+
+ /* set minimum possible */
+ *w = MAX(1, *w);
+ *h = MAX(1, *h);
+ if (interact) {
+ if (*x > sw)
+ *x = sw - WIDTH(c);
+ if (*y > sh)
+ *y = sh - HEIGHT(c);
+ if (*x + *w + 2 * c->bw < 0)
+ *x = 0;
+ if (*y + *h + 2 * c->bw < 0)
+ *y = 0;
+ } else {
+ if (*x >= m->wx + m->ww)
+ *x = m->wx + m->ww - WIDTH(c);
+ if (*y >= m->wy + m->wh)
+ *y = m->wy + m->wh - HEIGHT(c);
+ if (*x + *w + 2 * c->bw <= m->wx)
+ *x = m->wx;
+ if (*y + *h + 2 * c->bw <= m->wy)
+ *y = m->wy;
+ }
+ if (*h < bh)
+ *h = bh;
+ if (*w < bh)
+ *w = bh;
+ if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
+ /* see last two sentences in ICCCM 4.1.2.3 */
+ baseismin = c->basew == c->minw && c->baseh == c->minh;
+ if (!baseismin) { /* temporarily remove base dimensions */
+ *w -= c->basew;
+ *h -= c->baseh;
+ }
+ /* adjust for aspect limits */
+ if (c->mina > 0 && c->maxa > 0) {
+ if (c->maxa < (float)*w / *h)
+ *w = *h * c->maxa + 0.5;
+ else if (c->mina < (float)*h / *w)
+ *h = *w * c->mina + 0.5;
+ }
+ if (baseismin) { /* increment calculation requires this */
+ *w -= c->basew;
+ *h -= c->baseh;
+ }
+ /* adjust for increment value */
+ if (c->incw)
+ *w -= *w % c->incw;
+ if (c->inch)
+ *h -= *h % c->inch;
+ /* restore base dimensions */
+ *w = MAX(*w + c->basew, c->minw);
+ *h = MAX(*h + c->baseh, c->minh);
+ if (c->maxw)
+ *w = MIN(*w, c->maxw);
+ if (c->maxh)
+ *h = MIN(*h, c->maxh);
+ }
+ return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
+}
+
+void
+arrange(Monitor *m)
+{
+ if (m)
+ showhide(m->stack);
+ else for (m = mons; m; m = m->next)
+ showhide(m->stack);
+ if (m) {
+ arrangemon(m);
+ restack(m);
+ } else for (m = mons; m; m = m->next)
+ arrangemon(m);
+}
+
+void
+arrangemon(Monitor *m)
+{
+ strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
+ if (m->lt[m->sellt]->arrange)
+ m->lt[m->sellt]->arrange(m);
+}
+
+void
+attach(Client *c)
+{
+ c->next = c->mon->clients;
+ c->mon->clients = c;
+}
+
+void
+attachstack(Client *c)
+{
+ c->snext = c->mon->stack;
+ c->mon->stack = c;
+}
+
+void
+swallow(Client *p, Client *c)
+{
+
+ if (c->noswallow || c->isterminal)
+ return;
+ if (c->noswallow && !swallowfloating && c->isfloating)
+ return;
+
+ detach(c);
+ detachstack(c);
+
+ setclientstate(c, WithdrawnState);
+ XUnmapWindow(dpy, p->win);
+
+ p->swallowing = c;
+ c->mon = p->mon;
+
+ Window w = p->win;
+ p->win = c->win;
+ c->win = w;
+ updatetitle(p);
+ XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h);
+ arrange(p->mon);
+ configure(p);
+ updateclientlist();
+}
+
+void
+unswallow(Client *c)
+{
+ c->win = c->swallowing->win;
+
+ free(c->swallowing);
+ c->swallowing = NULL;
+
+ /* unfullscreen the client */
+ setfullscreen(c, 0);
+ updatetitle(c);
+ arrange(c->mon);
+ XMapWindow(dpy, c->win);
+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+ setclientstate(c, NormalState);
+ focus(NULL);
+ arrange(c->mon);
+}
+
+void
+buttonpress(XEvent *e)
+{
+ unsigned int i, x, click;
+ Arg arg = {0};
+ Client *c;
+ Monitor *m;
+ XButtonPressedEvent *ev = &e->xbutton;
+
+ click = ClkRootWin;
+ /* focus monitor if necessary */
+ if ((m = wintomon(ev->window)) && m != selmon) {
+ unfocus(selmon->sel, 1);
+ selmon = m;
+ focus(NULL);
+ }
+ if (ev->window == selmon->barwin) {
+ i = x = 0;
+ do
+ x += TEXTW(tags[i]);
+ while (ev->x >= x && ++i < LENGTH(tags));
+ if (i < LENGTH(tags)) {
+ click = ClkTagBar;
+ arg.ui = 1 << i;
+ } else if (ev->x < x + blw)
+ click = ClkLtSymbol;
+ else if (ev->x > selmon->ww - (int)TEXTW(stext))
+ click = ClkStatusText;
+ else
+ click = ClkWinTitle;
+ } else if ((c = wintoclient(ev->window))) {
+ focus(c);
+ restack(selmon);
+ XAllowEvents(dpy, ReplayPointer, CurrentTime);
+ click = ClkClientWin;
+ }
+ for (i = 0; i < LENGTH(buttons); i++)
+ if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
+ && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
+ buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
+}
+
+void
+checkotherwm(void)
+{
+ xerrorxlib = XSetErrorHandler(xerrorstart);
+ /* this causes an error if some other window manager is running */
+ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XSync(dpy, False);
+}
+
+void
+cleanup(void)
+{
+ Arg a = {.ui = ~0};
+ Layout foo = { "", NULL };
+ Monitor *m;
+ size_t i;
+
+ view(&a);
+ selmon->lt[selmon->sellt] = &foo;
+ for (m = mons; m; m = m->next)
+ while (m->stack)
+ unmanage(m->stack, 0);
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
+ while (mons)
+ cleanupmon(mons);
+ for (i = 0; i < CurLast; i++)
+ drw_cur_free(drw, cursor[i]);
+ for (i = 0; i < LENGTH(colors); i++)
+ free(scheme[i]);
+ XDestroyWindow(dpy, wmcheckwin);
+ drw_free(drw);
+ XSync(dpy, False);
+ XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+ XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+}
+
+void
+cleanupmon(Monitor *mon)
+{
+ Monitor *m;
+
+ if (mon == mons)
+ mons = mons->next;
+ else {
+ for (m = mons; m && m->next != mon; m = m->next);
+ m->next = mon->next;
+ }
+ XUnmapWindow(dpy, mon->barwin);
+ XDestroyWindow(dpy, mon->barwin);
+ free(mon);
+}
+
+void
+clientmessage(XEvent *e)
+{
+ XClientMessageEvent *cme = &e->xclient;
+ Client *c = wintoclient(cme->window);
+
+ if (!c)
+ return;
+ if (cme->message_type == netatom[NetWMState]) {
+ if (cme->data.l[1] == netatom[NetWMFullscreen]
+ || cme->data.l[2] == netatom[NetWMFullscreen])
+ setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */
+ || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
+ } else if (cme->message_type == netatom[NetActiveWindow]) {
+ if (c != selmon->sel && !c->isurgent)
+ seturgent(c, 1);
+ }
+}
+
+void
+configure(Client *c)
+{
+ XConfigureEvent ce;
+
+ ce.type = ConfigureNotify;
+ ce.display = dpy;
+ ce.event = c->win;
+ ce.window = c->win;
+ ce.x = c->x;
+ ce.y = c->y;
+ ce.width = c->w;
+ ce.height = c->h;
+ ce.border_width = c->bw;
+ ce.above = None;
+ ce.override_redirect = False;
+ XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
+}
+
+void
+configurenotify(XEvent *e)
+{
+ Monitor *m;
+ Client *c;
+ XConfigureEvent *ev = &e->xconfigure;
+ int dirty;
+
+ /* TODO: updategeom handling sucks, needs to be simplified */
+ if (ev->window == root) {
+ dirty = (sw != ev->width || sh != ev->height);
+ sw = ev->width;
+ sh = ev->height;
+ if (updategeom() || dirty) {
+ drw_resize(drw, sw, bh);
+ updatebars();
+ for (m = mons; m; m = m->next) {
+ for (c = m->clients; c; c = c->next)
+ if (c->isfullscreen)
+ resizeclient(c, m->mx, m->my, m->mw, m->mh);
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
+ }
+ focus(NULL);
+ arrange(NULL);
+ }
+ }
+}
+
+void
+configurerequest(XEvent *e)
+{
+ Client *c;
+ Monitor *m;
+ XConfigureRequestEvent *ev = &e->xconfigurerequest;
+ XWindowChanges wc;
+
+ if ((c = wintoclient(ev->window))) {
+ if (ev->value_mask & CWBorderWidth)
+ c->bw = ev->border_width;
+ else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
+ m = c->mon;
+ if (ev->value_mask & CWX) {
+ c->oldx = c->x;
+ c->x = m->mx + ev->x;
+ }
+ if (ev->value_mask & CWY) {
+ c->oldy = c->y;
+ c->y = m->my + ev->y;
+ }
+ if (ev->value_mask & CWWidth) {
+ c->oldw = c->w;
+ c->w = ev->width;
+ }
+ if (ev->value_mask & CWHeight) {
+ c->oldh = c->h;
+ c->h = ev->height;
+ }
+ if ((c->x + c->w) > m->mx + m->mw && c->isfloating)
+ c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */
+ if ((c->y + c->h) > m->my + m->mh && c->isfloating)
+ c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */
+ if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
+ configure(c);
+ if (ISVISIBLE(c))
+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
+ } else
+ configure(c);
+ } else {
+ wc.x = ev->x;
+ wc.y = ev->y;
+ wc.width = ev->width;
+ wc.height = ev->height;
+ wc.border_width = ev->border_width;
+ wc.sibling = ev->above;
+ wc.stack_mode = ev->detail;
+ XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
+ }
+ XSync(dpy, False);
+}
+
+Monitor *
+createmon(void)
+{
+ Monitor *m;
+
+ m = ecalloc(1, sizeof(Monitor));
+ m->tagset[0] = m->tagset[1] = 1;
+ m->mfact = mfact;
+ m->nmaster = nmaster;
+ m->showbar = showbar;
+ m->topbar = topbar;
+ m->gappx = gappx;
+ m->lt[0] = &layouts[0];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ return m;
+}
+
+void
+destroynotify(XEvent *e)
+{
+ Client *c;
+ XDestroyWindowEvent *ev = &e->xdestroywindow;
+
+ if ((c = wintoclient(ev->window)))
+ unmanage(c, 1);
+
+ else if ((c = swallowingclient(ev->window)))
+ unmanage(c->swallowing, 1);
+}
+
+void
+detach(Client *c)
+{
+ Client **tc;
+
+ for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
+ *tc = c->next;
+}
+
+void
+detachstack(Client *c)
+{
+ Client **tc, *t;
+
+ for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
+ *tc = c->snext;
+
+ if (c == c->mon->sel) {
+ for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
+ c->mon->sel = t;
+ }
+}
+
+Monitor *
+dirtomon(int dir)
+{
+ Monitor *m = NULL;
+
+ if (dir > 0) {
+ if (!(m = selmon->next))
+ m = mons;
+ } else if (selmon == mons)
+ for (m = mons; m->next; m = m->next);
+ else
+ for (m = mons; m->next != selmon; m = m->next);
+ return m;
+}
+
+void
+drawbar(Monitor *m)
+{
+ int x, w, tw = 0;
+ int boxs = drw->fonts->h / 9;
+ int boxw = drw->fonts->h / 6 + 2;
+ unsigned int i, occ = 0, urg = 0;
+ Client *c;
+
+ /* draw status first so it can be overdrawn by tags later */
+ if (m == selmon) { /* status is only drawn on selected monitor */
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
+ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+ }
+
+ for (c = m->clients; c; c = c->next) {
+ occ |= c->tags;
+ 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;
+ }
+ w = blw = TEXTW(m->ltsymbol);
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+
+ if ((w = m->ww - tw - x) > bh) {
+ if (m->sel) {
+ drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+ if (m->sel->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
+ } else {
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x, 0, w, bh, 1, 1);
+ }
+ }
+ drw_map(drw, m->barwin, 0, 0, m->ww, bh);
+}
+
+void
+drawbars(void)
+{
+ Monitor *m;
+
+ for (m = mons; m; m = m->next)
+ drawbar(m);
+}
+
+void
+enternotify(XEvent *e)
+{
+ Client *c;
+ Monitor *m;
+ XCrossingEvent *ev = &e->xcrossing;
+
+ if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
+ return;
+ c = wintoclient(ev->window);
+ m = c ? c->mon : wintomon(ev->window);
+ if (m != selmon) {
+ unfocus(selmon->sel, 1);
+ selmon = m;
+ } else if (!c || c == selmon->sel)
+ return;
+ focus(c);
+}
+
+void
+expose(XEvent *e)
+{
+ Monitor *m;
+ XExposeEvent *ev = &e->xexpose;
+
+ if (ev->count == 0 && (m = wintomon(ev->window)))
+ drawbar(m);
+}
+
+void
+focus(Client *c)
+{
+ 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->mon != selmon)
+ selmon = c->mon;
+ if (c->isurgent)
+ seturgent(c, 0);
+ detachstack(c);
+ attachstack(c);
+ grabbuttons(c, 1);
+ XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel);
+ setfocus(c);
+ } else {
+ XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+ XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+ }
+ selmon->sel = c;
+ drawbars();
+}
+
+/* there are some broken focus acquiring clients needing extra handling */
+void
+focusin(XEvent *e)
+{
+ XFocusChangeEvent *ev = &e->xfocus;
+
+ if (selmon->sel && ev->window != selmon->sel->win)
+ setfocus(selmon->sel);
+}
+
+void
+focusmon(const Arg *arg)
+{
+ Monitor *m;
+
+ if (!mons->next)
+ return;
+ if ((m = dirtomon(arg->i)) == selmon)
+ return;
+ unfocus(selmon->sel, 0);
+ selmon = m;
+ focus(NULL);
+}
+
+void
+focusstack(const Arg *arg)
+{
+ Client *c = NULL, *i;
+
+ if (!selmon->sel || selmon->sel->isfullscreen)
+ return;
+ if (arg->i > 0) {
+ for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
+ if (!c)
+ for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
+ } else {
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
+ if (ISVISIBLE(i))
+ c = i;
+ if (!c)
+ for (; i; i = i->next)
+ if (ISVISIBLE(i))
+ c = i;
+ }
+ if (c) {
+ focus(c);
+ restack(selmon);
+ }
+}
+
+Atom
+getatomprop(Client *c, Atom prop)
+{
+ int di;
+ unsigned long dl;
+ unsigned char *p = NULL;
+ Atom da, atom = None;
+
+ if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
+ &da, &di, &dl, &dl, &p) == Success && p) {
+ atom = *(Atom *)p;
+ XFree(p);
+ }
+ return atom;
+}
+
+int
+getrootptr(int *x, int *y)
+{
+ int di;
+ unsigned int dui;
+ Window dummy;
+
+ return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
+}
+
+long
+getstate(Window w)
+{
+ int format;
+ long result = -1;
+ unsigned char *p = NULL;
+ unsigned long n, extra;
+ Atom real;
+
+ if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
+ &real, &format, &n, &extra, (unsigned char **)&p) != Success)
+ return -1;
+ if (n != 0)
+ result = *p;
+ XFree(p);
+ return result;
+}
+
+int
+gettextprop(Window w, Atom atom, char *text, unsigned int size)
+{
+ char **list = NULL;
+ int n;
+ XTextProperty name;
+
+ if (!text || size == 0)
+ return 0;
+ text[0] = '\0';
+ if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems)
+ return 0;
+ if (name.encoding == XA_STRING)
+ strncpy(text, (char *)name.value, size - 1);
+ else {
+ if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) {
+ strncpy(text, *list, size - 1);
+ XFreeStringList(list);
+ }
+ }
+ text[size - 1] = '\0';
+ XFree(name.value);
+ return 1;
+}
+
+void
+grabbuttons(Client *c, int focused)
+{
+ updatenumlockmask();
+ {
+ unsigned int i, j;
+ unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
+ XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+ if (!focused)
+ XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
+ BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
+ for (i = 0; i < LENGTH(buttons); i++)
+ if (buttons[i].click == ClkClientWin)
+ for (j = 0; j < LENGTH(modifiers); j++)
+ XGrabButton(dpy, buttons[i].button,
+ buttons[i].mask | modifiers[j],
+ c->win, False, BUTTONMASK,
+ GrabModeAsync, GrabModeSync, None, None);
+ }
+}
+
+void
+grabkeys(void)
+{
+ updatenumlockmask();
+ {
+ unsigned int i, j;
+ unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
+ KeyCode code;
+
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
+ for (i = 0; i < LENGTH(keys); i++)
+ if ((code = XKeysymToKeycode(dpy, keys[i].keysym)))
+ for (j = 0; j < LENGTH(modifiers); j++)
+ XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
+ True, GrabModeAsync, GrabModeAsync);
+ }
+}
+
+void
+incnmaster(const Arg *arg)
+{
+ selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
+ arrange(selmon);
+}
+
+#ifdef XINERAMA
+static int
+isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info)
+{
+ while (n--)
+ if (unique[n].x_org == info->x_org && unique[n].y_org == info->y_org
+ && unique[n].width == info->width && unique[n].height == info->height)
+ return 0;
+ return 1;
+}
+#endif /* XINERAMA */
+
+void
+keypress(XEvent *e)
+{
+ unsigned int i;
+ KeySym keysym;
+ XKeyEvent *ev;
+
+ ev = &e->xkey;
+ keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
+ for (i = 0; i < LENGTH(keys); i++)
+ if (keysym == keys[i].keysym
+ && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
+ && keys[i].func)
+ keys[i].func(&(keys[i].arg));
+}
+
+void
+killclient(const Arg *arg)
+{
+ if (!selmon->sel)
+ return;
+ if (!sendevent(selmon->sel, wmatom[WMDelete])) {
+ XGrabServer(dpy);
+ XSetErrorHandler(xerrordummy);
+ XSetCloseDownMode(dpy, DestroyAll);
+ XKillClient(dpy, selmon->sel->win);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
+}
+
+void
+loadxrdb()
+{
+ Display *display;
+ char * resm;
+ XrmDatabase xrdb;
+ char *type;
+ XrmValue value;
+
+ display = XOpenDisplay(NULL);
+
+ if (display != NULL) {
+ resm = XResourceManagerString(display);
+
+ if (resm != NULL) {
+ xrdb = XrmGetStringDatabase(resm);
+
+ if (xrdb != NULL) {
+ XRDB_LOAD_COLOR("dwm.color0", normbordercolor);
+ XRDB_LOAD_COLOR("dwm.color8", selbordercolor);
+ XRDB_LOAD_COLOR("dwm.color0", normbgcolor);
+ XRDB_LOAD_COLOR("dwm.color6", normfgcolor);
+ XRDB_LOAD_COLOR("dwm.color0", selfgcolor);
+ XRDB_LOAD_COLOR("dwm.color14", selbgcolor);
+ }
+ }
+ }
+
+ XCloseDisplay(display);
+}
+
+void
+manage(Window w, XWindowAttributes *wa)
+{
+ 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;
+ c->w = c->oldw = wa->width;
+ c->h = c->oldh = wa->height;
+ c->oldbw = wa->border_width;
+
+ updatetitle(c);
+ if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
+ c->mon = t->mon;
+ c->tags = t->tags;
+ } else {
+ c->mon = selmon;
+ applyrules(c);
+ term = termforwin(c);
+ }
+
+ if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw)
+ c->x = c->mon->mx + c->mon->mw - WIDTH(c);
+ if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh)
+ c->y = c->mon->my + c->mon->mh - HEIGHT(c);
+ c->x = MAX(c->x, c->mon->mx);
+ /* 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;
+
+ wc.border_width = c->bw;
+ XConfigureWindow(dpy, w, CWBorderWidth, &wc);
+ XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel);
+ configure(c); /* propagates border_width, if size doesn't change */
+ updatewindowtype(c);
+ updatesizehints(c);
+ updatewmhints(c);
+ XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
+ grabbuttons(c, 0);
+ if (!c->isfloating)
+ c->isfloating = c->oldstate = trans != None || c->isfixed;
+ if (c->isfloating)
+ XRaiseWindow(dpy, c->win);
+ attach(c);
+ attachstack(c);
+ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
+ (unsigned char *) &(c->win), 1);
+ XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
+ setclientstate(c, NormalState);
+ if (c->mon == selmon)
+ unfocus(selmon->sel, 0);
+ c->mon->sel = c;
+ arrange(c->mon);
+ XMapWindow(dpy, c->win);
+ if (term)
+ swallow(term, c);
+ focus(NULL);
+}
+
+void
+mappingnotify(XEvent *e)
+{
+ XMappingEvent *ev = &e->xmapping;
+
+ XRefreshKeyboardMapping(ev);
+ if (ev->request == MappingKeyboard)
+ grabkeys();
+}
+
+void
+maprequest(XEvent *e)
+{
+ static XWindowAttributes wa;
+ XMapRequestEvent *ev = &e->xmaprequest;
+
+ if (!XGetWindowAttributes(dpy, ev->window, &wa))
+ return;
+ if (wa.override_redirect)
+ return;
+ if (!wintoclient(ev->window))
+ manage(ev->window, &wa);
+}
+
+void
+monocle(Monitor *m)
+{
+ unsigned int n = 0;
+ Client *c;
+
+ for (c = m->clients; c; c = c->next)
+ if (ISVISIBLE(c))
+ n++;
+ if (n > 0) /* override layout symbol */
+ snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
+ for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
+ resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
+}
+
+void
+motionnotify(XEvent *e)
+{
+ static Monitor *mon = NULL;
+ Monitor *m;
+ XMotionEvent *ev = &e->xmotion;
+
+ if (ev->window != root)
+ return;
+ if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
+ unfocus(selmon->sel, 1);
+ selmon = m;
+ focus(NULL);
+ }
+ mon = m;
+}
+
+void
+movemouse(const Arg *arg)
+{
+ int x, y, ocx, ocy, nx, ny;
+ Client *c;
+ Monitor *m;
+ XEvent ev;
+ Time lasttime = 0;
+
+ if (!(c = selmon->sel))
+ return;
+ if (c->isfullscreen) /* no support moving fullscreen windows by mouse */
+ return;
+ restack(selmon);
+ ocx = c->x;
+ ocy = c->y;
+ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
+ None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
+ return;
+ if (!getrootptr(&x, &y))
+ return;
+ do {
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
+ switch(ev.type) {
+ case ConfigureRequest:
+ case Expose:
+ case MapRequest:
+ handler[ev.type](&ev);
+ break;
+ case MotionNotify:
+ if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+ continue;
+ lasttime = ev.xmotion.time;
+
+ nx = ocx + (ev.xmotion.x - x);
+ ny = ocy + (ev.xmotion.y - y);
+ if (abs(selmon->wx - nx) < snap)
+ nx = selmon->wx;
+ else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap)
+ nx = selmon->wx + selmon->ww - WIDTH(c);
+ if (abs(selmon->wy - ny) < snap)
+ ny = selmon->wy;
+ else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap)
+ ny = selmon->wy + selmon->wh - HEIGHT(c);
+ if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
+ && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
+ togglefloating(NULL);
+ if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+ resize(c, nx, ny, c->w, c->h, 1);
+ break;
+ }
+ } while (ev.type != ButtonRelease);
+ XUngrabPointer(dpy, CurrentTime);
+ if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
+ sendmon(c, m);
+ selmon = m;
+ focus(NULL);
+ }
+}
+
+Client *
+nexttiled(Client *c)
+{
+ for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
+ return c;
+}
+
+void
+pop(Client *c)
+{
+ detach(c);
+ attach(c);
+ focus(c);
+ arrange(c->mon);
+}
+
+void
+propertynotify(XEvent *e)
+{
+ Client *c;
+ Window trans;
+ XPropertyEvent *ev = &e->xproperty;
+
+ if ((ev->window == root) && (ev->atom == XA_WM_NAME))
+ updatestatus();
+ else if (ev->state == PropertyDelete)
+ return; /* ignore */
+ else if ((c = wintoclient(ev->window))) {
+ switch(ev->atom) {
+ default: break;
+ case XA_WM_TRANSIENT_FOR:
+ if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
+ (c->isfloating = (wintoclient(trans)) != NULL))
+ arrange(c->mon);
+ break;
+ case XA_WM_NORMAL_HINTS:
+ updatesizehints(c);
+ break;
+ case XA_WM_HINTS:
+ updatewmhints(c);
+ drawbars();
+ break;
+ }
+ if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
+ updatetitle(c);
+ if (c == c->mon->sel)
+ drawbar(c->mon);
+ }
+ if (ev->atom == netatom[NetWMWindowType])
+ updatewindowtype(c);
+ }
+}
+
+void
+quit(const Arg *arg)
+{
+ running = 0;
+}
+
+Monitor *
+recttomon(int x, int y, int w, int h)
+{
+ Monitor *m, *r = selmon;
+ int a, area = 0;
+
+ for (m = mons; m; m = m->next)
+ if ((a = INTERSECT(x, y, w, h, m)) > area) {
+ area = a;
+ r = m;
+ }
+ return r;
+}
+
+void
+resize(Client *c, int x, int y, int w, int h, int interact)
+{
+ if (applysizehints(c, &x, &y, &w, &h, interact))
+ resizeclient(c, x, y, w, h);
+}
+
+void
+resizeclient(Client *c, int x, int y, int w, int h)
+{
+ XWindowChanges wc;
+
+ c->oldx = c->x; c->x = wc.x = x;
+ c->oldy = c->y; c->y = wc.y = y;
+ c->oldw = c->w; c->w = wc.width = w;
+ c->oldh = c->h; c->h = wc.height = h;
+ wc.border_width = c->bw;
+ XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
+ configure(c);
+ XSync(dpy, False);
+}
+
+void
+resizemouse(const Arg *arg)
+{
+ int ocx, ocy, nw, nh;
+ Client *c;
+ Monitor *m;
+ XEvent ev;
+ Time lasttime = 0;
+
+ if (!(c = selmon->sel))
+ return;
+ if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
+ return;
+ restack(selmon);
+ ocx = c->x;
+ ocy = c->y;
+ 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);
+ do {
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
+ switch(ev.type) {
+ case ConfigureRequest:
+ case Expose:
+ case MapRequest:
+ handler[ev.type](&ev);
+ break;
+ case MotionNotify:
+ if ((ev.xmotion.time - lasttime) <= (1000 / 60))
+ continue;
+ lasttime = ev.xmotion.time;
+
+ nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
+ nh = MAX(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)
+ {
+ if (!c->isfloating && selmon->lt[selmon->sellt]->arrange
+ && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
+ togglefloating(NULL);
+ }
+ if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+ resize(c, c->x, c->y, 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);
+ XUngrabPointer(dpy, CurrentTime);
+ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+ if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
+ sendmon(c, m);
+ selmon = m;
+ focus(NULL);
+ }
+}
+
+void
+restack(Monitor *m)
+{
+ Client *c;
+ XEvent ev;
+ XWindowChanges wc;
+
+ drawbar(m);
+ if (!m->sel)
+ return;
+ if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
+ XRaiseWindow(dpy, m->sel->win);
+ if (m->lt[m->sellt]->arrange) {
+ wc.stack_mode = Below;
+ wc.sibling = m->barwin;
+ for (c = m->stack; c; c = c->snext)
+ if (!c->isfloating && ISVISIBLE(c)) {
+ XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
+ wc.sibling = c->win;
+ }
+ }
+ XSync(dpy, False);
+ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+}
+
+void
+run(void)
+{
+ XEvent ev;
+ /* main event loop */
+ XSync(dpy, False);
+ while (running && !XNextEvent(dpy, &ev))
+ if (handler[ev.type])
+ handler[ev.type](&ev); /* call handler */
+}
+
+void
+scan(void)
+{
+ unsigned int i, num;
+ Window d1, d2, *wins = NULL;
+ XWindowAttributes wa;
+
+ if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
+ for (i = 0; i < num; i++) {
+ if (!XGetWindowAttributes(dpy, wins[i], &wa)
+ || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
+ continue;
+ if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
+ manage(wins[i], &wa);
+ }
+ for (i = 0; i < num; i++) { /* now the transients */
+ if (!XGetWindowAttributes(dpy, wins[i], &wa))
+ continue;
+ if (XGetTransientForHint(dpy, wins[i], &d1)
+ && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
+ manage(wins[i], &wa);
+ }
+ if (wins)
+ XFree(wins);
+ }
+}
+
+void
+sendmon(Client *c, Monitor *m)
+{
+ if (c->mon == m)
+ return;
+ unfocus(c, 1);
+ detach(c);
+ detachstack(c);
+ c->mon = m;
+ c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+ attach(c);
+ attachstack(c);
+ focus(NULL);
+ arrange(NULL);
+}
+
+void
+setclientstate(Client *c, long state)
+{
+ long data[] = { state, None };
+
+ XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
+ PropModeReplace, (unsigned char *)data, 2);
+}
+
+int
+sendevent(Client *c, Atom proto)
+{
+ int n;
+ Atom *protocols;
+ int exists = 0;
+ XEvent ev;
+
+ if (XGetWMProtocols(dpy, c->win, &protocols, &n)) {
+ while (!exists && n--)
+ exists = protocols[n] == proto;
+ XFree(protocols);
+ }
+ if (exists) {
+ ev.type = ClientMessage;
+ ev.xclient.window = c->win;
+ ev.xclient.message_type = wmatom[WMProtocols];
+ ev.xclient.format = 32;
+ ev.xclient.data.l[0] = proto;
+ ev.xclient.data.l[1] = CurrentTime;
+ XSendEvent(dpy, c->win, False, NoEventMask, &ev);
+ }
+ return exists;
+}
+
+void
+setfocus(Client *c)
+{
+ if (!c->neverfocus) {
+ XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+ XChangeProperty(dpy, root, netatom[NetActiveWindow],
+ XA_WINDOW, 32, PropModeReplace,
+ (unsigned char *) &(c->win), 1);
+ }
+ sendevent(c, wmatom[WMTakeFocus]);
+}
+
+void
+setfullscreen(Client *c, int fullscreen)
+{
+ if (fullscreen && !c->isfullscreen) {
+ XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
+ PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
+ c->isfullscreen = 1;
+ c->oldstate = c->isfloating;
+ c->oldbw = c->bw;
+ c->bw = 0;
+ c->isfloating = 1;
+ resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
+ XRaiseWindow(dpy, c->win);
+ } else if (!fullscreen && c->isfullscreen){
+ XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
+ PropModeReplace, (unsigned char*)0, 0);
+ c->isfullscreen = 0;
+ c->isfloating = c->oldstate;
+ c->bw = c->oldbw;
+ c->x = c->oldx;
+ c->y = c->oldy;
+ c->w = c->oldw;
+ c->h = c->oldh;
+ resizeclient(c, c->x, c->y, c->w, c->h);
+ arrange(c->mon);
+ }
+}
+
+void
+setgaps(const Arg *arg)
+{
+ if ((arg->i == 0) || (selmon->gappx + arg->i < 0))
+ selmon->gappx = 0;
+ else
+ selmon->gappx += arg->i;
+ arrange(selmon);
+}
+
+void
+setlayout(const Arg *arg)
+{
+ if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
+ selmon->sellt ^= 1;
+ if (arg && arg->v)
+ selmon->lt[selmon->sellt] = (Layout *)arg->v;
+ strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+ if (selmon->sel)
+ arrange(selmon);
+ else
+ drawbar(selmon);
+}
+
+/* arg > 1.0 will set mfact absolutely */
+void
+setmfact(const Arg *arg)
+{
+ float f;
+
+ if (!arg || !selmon->lt[selmon->sellt]->arrange)
+ return;
+ f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
+ if (f < 0.05 || f > 0.95)
+ return;
+ selmon->mfact = f;
+ arrange(selmon);
+}
+
+void
+setup(void)
+{
+ int i;
+ XSetWindowAttributes wa;
+ Atom utf8string;
+
+ /* clean up any zombies immediately */
+ sigchld(0);
+
+ /* init screen */
+ screen = DefaultScreen(dpy);
+ sw = DisplayWidth(dpy, screen);
+ sh = DisplayHeight(dpy, screen);
+ root = RootWindow(dpy, screen);
+ drw = drw_create(dpy, screen, root, sw, sh);
+ if (!drw_fontset_create(drw, fonts, LENGTH(fonts)))
+ die("no fonts could be loaded.");
+ lrpad = drw->fonts->h;
+ bh = drw->fonts->h + 2;
+ updategeom();
+ /* init atoms */
+ utf8string = XInternAtom(dpy, "UTF8_STRING", False);
+ wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
+ wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
+ wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
+ wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
+ netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
+ netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
+ netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
+ netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
+ netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
+ netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
+ netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
+ netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
+ netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
+ /* init cursors */
+ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
+ cursor[CurResize] = drw_cur_create(drw, XC_sizing);
+ cursor[CurMove] = drw_cur_create(drw, XC_fleur);
+ /* init appearance */
+ scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
+ for (i = 0; i < LENGTH(colors); i++)
+ scheme[i] = drw_scm_create(drw, colors[i], 3);
+ /* init bars */
+ updatebars();
+ updatestatus();
+ /* supporting window for NetWMCheck */
+ wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
+ XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
+ PropModeReplace, (unsigned char *) &wmcheckwin, 1);
+ XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8,
+ PropModeReplace, (unsigned char *) "dwm", 3);
+ XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
+ PropModeReplace, (unsigned char *) &wmcheckwin, 1);
+ /* EWMH support per view */
+ XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
+ PropModeReplace, (unsigned char *) netatom, NetLast);
+ XDeleteProperty(dpy, root, netatom[NetClientList]);
+ /* select events */
+ wa.cursor = cursor[CurNormal]->cursor;
+ wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
+ |ButtonPressMask|PointerMotionMask|EnterWindowMask
+ |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask;
+ XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
+ XSelectInput(dpy, root, wa.event_mask);
+ grabkeys();
+ focus(NULL);
+}
+
+
+void
+seturgent(Client *c, int urg)
+{
+ XWMHints *wmh;
+
+ c->isurgent = urg;
+ if (!(wmh = XGetWMHints(dpy, c->win)))
+ return;
+ wmh->flags = urg ? (wmh->flags | XUrgencyHint) : (wmh->flags & ~XUrgencyHint);
+ XSetWMHints(dpy, c->win, wmh);
+ XFree(wmh);
+}
+
+void
+showhide(Client *c)
+{
+ if (!c)
+ return;
+ if (ISVISIBLE(c)) {
+ /* show clients top down */
+ XMoveWindow(dpy, c->win, c->x, c->y);
+ if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
+ resize(c, c->x, c->y, c->w, c->h, 0);
+ showhide(c->snext);
+ } else {
+ /* hide clients bottom up */
+ showhide(c->snext);
+ XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
+ }
+}
+
+void
+sigchld(int unused)
+{
+ if (signal(SIGCHLD, sigchld) == SIG_ERR)
+ die("can't install SIGCHLD handler:");
+ while (0 < waitpid(-1, NULL, WNOHANG));
+}
+
+void
+spawn(const Arg *arg)
+{
+ if (arg->v == dmenucmd)
+ dmenumon[0] = '0' + selmon->num;
+ if (fork() == 0) {
+ if (dpy)
+ close(ConnectionNumber(dpy));
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
+ perror(" failed");
+ exit(EXIT_SUCCESS);
+ }
+}
+
+void
+tag(const Arg *arg)
+{
+ if (selmon->sel && arg->ui & TAGMASK) {
+ selmon->sel->tags = arg->ui & TAGMASK;
+ focus(NULL);
+ arrange(selmon);
+ }
+}
+
+void
+tagmon(const Arg *arg)
+{
+ if (!selmon->sel || !mons->next)
+ return;
+ sendmon(selmon->sel, dirtomon(arg->i));
+}
+
+void
+tile(Monitor *m)
+{
+ unsigned int i, n, h, mw, my, ty;
+ Client *c;
+
+ for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
+ if (n == 0)
+ return;
+
+ if (n > m->nmaster)
+ mw = m->nmaster ? m->ww * m->mfact : 0;
+ else
+ mw = m->ww - m->gappx;
+ for (i = 0, my = ty = m->gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
+ if (i < m->nmaster) {
+ h = (m->wh - my) / (MIN(n, m->nmaster) - i) - m->gappx;
+ resize(c, m->wx + m->gappx, m->wy + my, mw - (2*c->bw) - m->gappx, h - (2*c->bw), 0);
+ my += HEIGHT(c) + m->gappx;
+ } else {
+ h = (m->wh - ty) / (n - i) - m->gappx;
+ resize(c, m->wx + mw + m->gappx, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappx, h - (2*c->bw), 0);
+ ty += HEIGHT(c) + m->gappx;
+ }
+}
+
+void
+togglebar(const Arg *arg)
+{
+ selmon->showbar = !selmon->showbar;
+ updatebarpos(selmon);
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+ arrange(selmon);
+}
+
+void
+togglefloating(const Arg *arg)
+{
+ if (!selmon->sel)
+ return;
+ if (selmon->sel->isfullscreen) /* no support for fullscreen windows */
+ return;
+ selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
+ if (selmon->sel->isfloating)
+ resize(selmon->sel, selmon->sel->x, selmon->sel->y,
+ selmon->sel->w, selmon->sel->h, 0);
+ arrange(selmon);
+}
+
+void
+toggletag(const Arg *arg)
+{
+ unsigned int newtags;
+
+ if (!selmon->sel)
+ return;
+ newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
+ if (newtags) {
+ selmon->sel->tags = newtags;
+ focus(NULL);
+ arrange(selmon);
+ }
+}
+
+void
+toggleview(const Arg *arg)
+{
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+
+ if (newtagset) {
+ selmon->tagset[selmon->seltags] = newtagset;
+ focus(NULL);
+ arrange(selmon);
+ }
+}
+
+void
+unfocus(Client *c, int setfocus)
+{
+ if (!c)
+ return;
+ grabbuttons(c, 0);
+ XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
+ if (setfocus) {
+ XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+ XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+ }
+}
+
+void
+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) {
+ wc.border_width = c->oldbw;
+ XGrabServer(dpy); /* avoid race conditions */
+ XSetErrorHandler(xerrordummy);
+ XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
+ XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+ setclientstate(c, WithdrawnState);
+ XSync(dpy, False);
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
+ free(c);
+
+ if (!s) {
+ arrange(m);
+ focus(NULL);
+ updateclientlist();
+ }
+}
+
+void
+unmapnotify(XEvent *e)
+{
+ Client *c;
+ XUnmapEvent *ev = &e->xunmap;
+
+ if ((c = wintoclient(ev->window))) {
+ if (ev->send_event)
+ setclientstate(c, WithdrawnState);
+ else
+ unmanage(c, 0);
+ }
+}
+
+void
+updatebars(void)
+{
+ Monitor *m;
+ XSetWindowAttributes wa = {
+ .override_redirect = True,
+ .background_pixmap = ParentRelative,
+ .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);
+ XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
+ XMapRaised(dpy, m->barwin);
+ XSetClassHint(dpy, m->barwin, &ch);
+ }
+}
+
+void
+updatebarpos(Monitor *m)
+{
+ m->wy = m->my;
+ m->wh = m->mh;
+ if (m->showbar) {
+ m->wh -= bh;
+ m->by = m->topbar ? m->wy : m->wy + m->wh;
+ m->wy = m->topbar ? m->wy + bh : m->wy;
+ } else
+ m->by = -bh;
+}
+
+void
+updateclientlist()
+{
+ Client *c;
+ Monitor *m;
+
+ XDeleteProperty(dpy, root, netatom[NetClientList]);
+ for (m = mons; m; m = m->next)
+ for (c = m->clients; c; c = c->next)
+ XChangeProperty(dpy, root, netatom[NetClientList],
+ XA_WINDOW, 32, PropModeAppend,
+ (unsigned char *) &(c->win), 1);
+}
+
+int
+updategeom(void)
+{
+ int dirty = 0;
+
+#ifdef XINERAMA
+ if (XineramaIsActive(dpy)) {
+ int i, j, n, nn;
+ Client *c;
+ Monitor *m;
+ XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn);
+ XineramaScreenInfo *unique = NULL;
+
+ for (n = 0, m = mons; m; m = m->next, n++);
+ /* only consider unique geometries as separate screens */
+ unique = ecalloc(nn, sizeof(XineramaScreenInfo));
+ for (i = 0, j = 0; i < nn; i++)
+ if (isuniquegeom(unique, j, &info[i]))
+ memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo));
+ XFree(info);
+ nn = j;
+ if (n <= nn) { /* new monitors available */
+ for (i = 0; i < (nn - n); i++) {
+ for (m = mons; m && m->next; m = m->next);
+ if (m)
+ m->next = createmon();
+ else
+ mons = createmon();
+ }
+ for (i = 0, m = mons; i < nn && m; m = m->next, i++)
+ if (i >= n
+ || unique[i].x_org != m->mx || unique[i].y_org != m->my
+ || unique[i].width != m->mw || unique[i].height != m->mh)
+ {
+ dirty = 1;
+ m->num = i;
+ m->mx = m->wx = unique[i].x_org;
+ m->my = m->wy = unique[i].y_org;
+ m->mw = m->ww = unique[i].width;
+ m->mh = m->wh = unique[i].height;
+ updatebarpos(m);
+ }
+ } else { /* less monitors available nn < n */
+ for (i = nn; i < n; i++) {
+ for (m = mons; m && m->next; m = m->next);
+ while ((c = m->clients)) {
+ dirty = 1;
+ m->clients = c->next;
+ detachstack(c);
+ c->mon = mons;
+ attach(c);
+ attachstack(c);
+ }
+ if (m == selmon)
+ selmon = mons;
+ cleanupmon(m);
+ }
+ }
+ free(unique);
+ } else
+#endif /* XINERAMA */
+ { /* default monitor setup */
+ if (!mons)
+ mons = createmon();
+ if (mons->mw != sw || mons->mh != sh) {
+ dirty = 1;
+ mons->mw = mons->ww = sw;
+ mons->mh = mons->wh = sh;
+ updatebarpos(mons);
+ }
+ }
+ if (dirty) {
+ selmon = mons;
+ selmon = wintomon(root);
+ }
+ return dirty;
+}
+
+void
+updatenumlockmask(void)
+{
+ unsigned int i, j;
+ XModifierKeymap *modmap;
+
+ numlockmask = 0;
+ modmap = XGetModifierMapping(dpy);
+ for (i = 0; i < 8; i++)
+ for (j = 0; j < modmap->max_keypermod; j++)
+ if (modmap->modifiermap[i * modmap->max_keypermod + j]
+ == XKeysymToKeycode(dpy, XK_Num_Lock))
+ numlockmask = (1 << i);
+ XFreeModifiermap(modmap);
+}
+
+void
+updatesizehints(Client *c)
+{
+ long msize;
+ XSizeHints size;
+
+ if (!XGetWMNormalHints(dpy, c->win, &size, &msize))
+ /* size is uninitialized, ensure that size.flags aren't used */
+ size.flags = PSize;
+ if (size.flags & PBaseSize) {
+ c->basew = size.base_width;
+ c->baseh = size.base_height;
+ } else if (size.flags & PMinSize) {
+ c->basew = size.min_width;
+ c->baseh = size.min_height;
+ } else
+ c->basew = c->baseh = 0;
+ if (size.flags & PResizeInc) {
+ c->incw = size.width_inc;
+ c->inch = size.height_inc;
+ } else
+ c->incw = c->inch = 0;
+ if (size.flags & PMaxSize) {
+ c->maxw = size.max_width;
+ c->maxh = size.max_height;
+ } else
+ c->maxw = c->maxh = 0;
+ if (size.flags & PMinSize) {
+ c->minw = size.min_width;
+ c->minh = size.min_height;
+ } else if (size.flags & PBaseSize) {
+ c->minw = size.base_width;
+ c->minh = size.base_height;
+ } else
+ c->minw = c->minh = 0;
+ if (size.flags & PAspect) {
+ c->mina = (float)size.min_aspect.y / size.min_aspect.x;
+ c->maxa = (float)size.max_aspect.x / size.max_aspect.y;
+ } else
+ c->maxa = c->mina = 0.0;
+ c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh);
+}
+
+void
+updatestatus(void)
+{
+ if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+ strcpy(stext, "dwm-"VERSION);
+ drawbar(selmon);
+}
+
+void
+updatetitle(Client *c)
+{
+ if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
+ gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name);
+ if (c->name[0] == '\0') /* hack to mark broken clients */
+ strcpy(c->name, broken);
+}
+
+void
+updatewindowtype(Client *c)
+{
+ Atom state = getatomprop(c, netatom[NetWMState]);
+ Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
+
+ if (state == netatom[NetWMFullscreen])
+ setfullscreen(c, 1);
+ if (wtype == netatom[NetWMWindowTypeDialog])
+ c->isfloating = 1;
+}
+
+void
+updatewmhints(Client *c)
+{
+ XWMHints *wmh;
+
+ if ((wmh = XGetWMHints(dpy, c->win))) {
+ if (c == selmon->sel && wmh->flags & XUrgencyHint) {
+ wmh->flags &= ~XUrgencyHint;
+ XSetWMHints(dpy, c->win, wmh);
+ } else
+ c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0;
+ if (wmh->flags & InputHint)
+ c->neverfocus = !wmh->input;
+ else
+ c->neverfocus = 0;
+ XFree(wmh);
+ }
+}
+
+void
+view(const Arg *arg)
+{
+ if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+ return;
+ selmon->seltags ^= 1; /* toggle sel tagset */
+ if (arg->ui & TAGMASK)
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ focus(NULL);
+ arrange(selmon);
+}
+
+pid_t
+winpid(Window w)
+{
+
+ pid_t result = 0;
+
+#ifdef __linux__
+ xcb_res_client_id_spec_t spec = {0};
+ spec.client = w;
+ spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
+
+ xcb_generic_error_t *e = NULL;
+ xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec);
+ xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e);
+
+ if (!r)
+ return (pid_t)0;
+
+ xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r);
+ for (; i.rem; xcb_res_client_id_value_next(&i)) {
+ spec = i.data->spec;
+ if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) {
+ uint32_t *t = xcb_res_client_id_value_value(i.data);
+ result = *t;
+ break;
+ }
+ }
+
+ free(r);
+
+ if (result == (pid_t)-1)
+ result = 0;
+
+#endif /* __linux__ */
+
+#ifdef __OpenBSD__
+ Atom type;
+ int format;
+ unsigned long len, bytes;
+ unsigned char *prop;
+ pid_t ret;
+
+ if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 0), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop)
+ return 0;
+
+ ret = *(pid_t*)prop;
+ XFree(prop);
+ result = ret;
+
+#endif /* __OpenBSD__ */
+ return result;
+}
+
+pid_t
+getparentprocess(pid_t p)
+{
+ unsigned int v = 0;
+
+#ifdef __linux__
+ FILE *f;
+ char buf[256];
+ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
+
+ if (!(f = fopen(buf, "r")))
+ return 0;
+
+ fscanf(f, "%*u %*s %*c %u", &v);
+ fclose(f);
+#endif /* __linux__*/
+
+#ifdef __OpenBSD__
+ int n;
+ kvm_t *kd;
+ struct kinfo_proc *kp;
+
+ kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
+ if (!kd)
+ return 0;
+
+ kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n);
+ v = kp->p_ppid;
+#endif /* __OpenBSD__ */
+
+ return (pid_t)v;
+}
+
+int
+isdescprocess(pid_t p, pid_t c)
+{
+ while (p != c && c != 0)
+ c = getparentprocess(c);
+
+ return (int)c;
+}
+
+Client *
+termforwin(const Client *w)
+{
+ Client *c;
+ Monitor *m;
+
+ if (!w->pid || w->isterminal)
+ return NULL;
+
+ for (m = mons; m; m = m->next) {
+ for (c = m->clients; c; c = c->next) {
+ if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid))
+ return c;
+ }
+ }
+
+ return NULL;
+}
+
+Client *
+swallowingclient(Window w)
+{
+ Client *c;
+ Monitor *m;
+
+ for (m = mons; m; m = m->next) {
+ for (c = m->clients; c; c = c->next) {
+ if (c->swallowing && c->swallowing->win == w)
+ return c;
+ }
+ }
+
+ return NULL;
+}
+
+Client *
+wintoclient(Window w)
+{
+ Client *c;
+ Monitor *m;
+
+ for (m = mons; m; m = m->next)
+ for (c = m->clients; c; c = c->next)
+ if (c->win == w)
+ return c;
+ return NULL;
+}
+
+Monitor *
+wintomon(Window w)
+{
+ int x, y;
+ Client *c;
+ Monitor *m;
+
+ if (w == root && getrootptr(&x, &y))
+ return recttomon(x, y, 1, 1);
+ for (m = mons; m; m = m->next)
+ if (w == m->barwin)
+ return m;
+ if ((c = wintoclient(w)))
+ return c->mon;
+ return selmon;
+}
+
+/* There's no way to check accesses to destroyed windows, thus those cases are
+ * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
+ * default error handler, which may call exit. */
+int
+xerror(Display *dpy, XErrorEvent *ee)
+{
+ if (ee->error_code == BadWindow
+ || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
+ || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
+ || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
+ || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
+ || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
+ || (ee->request_code == X_GrabButton && ee->error_code == BadAccess)
+ || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
+ || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
+ return 0;
+ fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
+ ee->request_code, ee->error_code);
+ return xerrorxlib(dpy, ee); /* may call exit */
+}
+
+int
+xerrordummy(Display *dpy, XErrorEvent *ee)
+{
+ return 0;
+}
+
+/* Startup Error handler to check if another window manager
+ * is already running. */
+int
+xerrorstart(Display *dpy, XErrorEvent *ee)
+{
+ die("dwm: another window manager is already running");
+ return -1;
+}
+
+void
+xrdb(const Arg *arg)
+{
+ loadxrdb();
+ int i;
+ for (i = 0; i < LENGTH(colors); i++)
+ scheme[i] = drw_scm_create(drw, colors[i], 3);
+ focus(NULL);
+ arrange(NULL);
+}
+
+void
+zoom(const Arg *arg)
+{
+ Client *c = selmon->sel;
+
+ 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);
+}
+
+int
+main(int argc, char *argv[])
+{
+ if (argc == 2 && !strcmp("-v", argv[1]))
+ die("dwm-"VERSION);
+ else if (argc != 1)
+ die("usage: dwm [-v]");
+ if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fputs("warning: no locale support\n", stderr);
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("dwm: cannot open display");
+ if (!(xcon = XGetXCBConnection(dpy)))
+ die("dwm: cannot get xcb connection\n");
+ checkotherwm();
+ XrmInitialize();
+ loadxrdb();
+ setup();
+#ifdef __OpenBSD__
+ if (pledge("stdio rpath proc exec ps", NULL) == -1)
+ die("pledge");
+#endif /* __OpenBSD__ */
+ scan();
+ run();
+ cleanup();
+ XCloseDisplay(dpy);
+ return EXIT_SUCCESS;
+}
diff --git a/dwm.o b/dwm.o
index 83f831a..e9b88ff 100644
--- a/dwm.o
+++ b/dwm.o
Binary files differ
diff --git a/gzdots.mom b/gzdots.mom
deleted file mode 100644
index ac5db19..0000000
--- a/gzdots.mom
+++ /dev/null
@@ -1,213 +0,0 @@
-.de LI
-.LIST
-.SHIFT_LIST 10p
-..
-.PARA_SPACE 1m
-.TITLE "\s+(10A Manual to my Rice\s0"
-.AUTHOR "\s+5gabrielzschmitz\s0"
-.DOCTYPE DEFAULT
-.COPYSTYLE FINAL
-.PRINTSTYLE TYPESET
-.PT_SIZE 12
-.START
-Use vim keys (\f(CWh/j/k/l\fP) to navigate this document.
-Pressing \f(CWs\fP will fit it to window width (\f(CWa\fP to revert).
-\f(CW+\fP and \f(CW-\fP zoom in and out.
-\f(CWSuper+f\fP to toggle fullscreen.
-\f(CWq\fP to quit.
-(These are general binds set for \fBzathura\fP, the pdf reader.)
-.LI
-.ITEM
-\f(CWMod+F2\fP will show this document at any time.
-.ITEM
-By \f(CWMod\fP, I mean the Super Key, usually known as "the Windows Key."
-.LIST OFF
-
-.HEADING 1 "Introduction"
-
-.HEADING 2 "Keyboard layout"
-.LI
-.ITEM
-Being a Brazil native, my main language is Portuguese, and for so this system has a litle difference from the default english layout.
-It uses a combination of alt keys to do the latin accents and other symbols.
-To do that, I use a mini script that runs at the xorg startup.
-It is located at \f(CW~/.scripts/kblayout.sh\fP.
-.ITEM
-To remove that feature, delete the script with: \f(CWrm ~/.scripts/kblayout.sh\fP
-And comment it out from \f(CW~/.config/X11/xinitrc\fP.
-.LIST OFF
-.PP
-Additionally, while this isn't a part of the desktop environment, the default editing mode in the shell is using vi bindings.
-This setting can be changed if you don't like it by deleting or commenting out the contents of \f(CW~/.config/zsh/.zshrc\fP.
-
-.HEADING 2 "The Status Bar"
-.PP
-To the left, the numbers of your current tag(s): \f(CW I II III IV V VI VII VIII IX\fP.
-On the right, you'll see the date: \f(CW [Sun] 01/01/21 01:00AM\fP.
-.PP
-To make the setup cleaner I've decided to just include the date in the statusbar.
-But to see more system informations you can press \f(CWMod+b\fP.
-A dmenu will popup with some data, like the uptime, ethernet and wifi status, date, ram usage, weather, installed package count, disk usage, CPU usage, battery status and a shortcut to that manual.
-And by selecting one of the options a notification will popup with some useful or fun script (being the most important the wifi status, which spawns the network manager).
-.PP
-The dmenu script can be found in \f(CW~/.local/bin/sysinfo\fP.
-And the modules it uses can be found in \f(CW~/.local/bin/sysinfoscr/\fP.
-You can see what they do and modify them from there.
-.PP
-Additionally, to toggle the power menu press \f(CWMod+0\fP.
-A dmenu will appear with the shutdown, restart, logout, sleep and lock options.
-
-.HEADING 1 "Key Bindings"
-.PP
-The window manager dwm abstractly orders all of your windows into a stack from most important to least based on when you last manipulated it.
-dwm is an easy to use window manager, but you should understand that it makes use of that stack layout.
-.PP
-Notice also the case sensitivity of the shortcuts.
-.FOOTNOTE
-To type capital letters, hold down the \f(CWShift key\fP.
-.FOOTNOTE OFF
-.LI
-.ITEM
-\f(CWMod+Enter\fP \(en Spawn terminal (the default terminal is \f(CWst\fP; run \f(CWman st\fP for more)
-.ITEM
-\f(CWMod+Q\fP \(en Close window
-.ITEM
-\f(CWMod+d\fP \(en dmenu (For running commands or programs without shortcuts)
-.ITEM
-\f(CWMod+j/k\fP \(en Cycle thru windows by their stack order
-.ITEM
-\f(CWMod+Shift+Enter\fP \(en Make selected window the master (or switch master with 2nd)
-.ITEM
-\f(CWMod+h/l\fP \(en Change width of master window
-.ITEM
-\f(CWMod+z/x\fP \(en Increase/decrease gaps
-.ITEM
-\f(CWMod+a\fP \(en Toggle gaps
-.ITEM
-\f(CWMod+A\fP \(en Gaps return to default values
-.ITEM
-\f(CWMod+Shift+Space\fP \(en Make a window float (move and resize with \f(CWMod+\fPleft/right click)
-.ITEM
-\f(CWMod+B\fP \(en Toggle statusbar
-.LIST OFF
-
-.HEADING 2 "Window layouts"
-.LI
-.ITEM
-\f(CWMod+t\fP \(en Tiling mode (active by default)
-.ITEM
-\f(CWMod+f\fP \(en Fullscreen mode
-.ITEM
-\f(CWMod+Space\fP \(en Floating mode
-.ITEM
-\f(CWMod+s\fP \(en Fibbonacci spiral mode
-.ITEM
-\f(CWMod+m\fP \(en Master on left, other windows in monocle mode
-.ITEM
-\f(CWMod+M\fP \(en Monocle mode (all windows fullscreen and cycle through)
-.ITEM
-\f(CWMod+c\fP \(en Center the master window
-.ITEM
-\f(CWMod+Control+i/d\fP \(en Increase/decrease the number of master windows
-.LIST OFF
-
-.HEADING 2 "Basic Programs"
-.LI
-.ITEM
-\f(CWMod+F\fP \(en pcmanfm (file browser/manager)
-.ITEM
-\f(CWMod+w\fP \(en Web browser (Brave by default)
-.ITEM
-\f(CWMod+M\fP \(en pavucontrol (audio system manager)
-.LIST OFF
-
-.HEADING 2 "Tags/Workspaces"
-.PP
-There are nine tags, active tags are highlighted in the top left.
-.LI
-.ITEM
-\f(CWMod+(Number)\fP \(en Go to that number tag
-.ITEM
-\f(CWMod+Shift+(Number)\fP \(en Send window to that tag
-.ITEM
-\f(CWMod+Tab\fP \(en Go to previous tag
-.ITEM
-\f(CWMod+Left/Right\fP \(en Go to another display
-.ITEM
-\f(CWMod+Shift+Left/+Right\fP \(en Move window to another display
-.LIST OFF
-
-.HEADING 2 "System"
-.LI
-.ITEM
-\f(CWMod+0\fP \(en Choose to shutdown, restart, logout, sleep and lock screen
-.ITEM
-\f(CWMod+F2\fP \(en Show this document
-.ITEM
-\f(CWMod+W\fP \(en Select wallpaper to use
-.ITEM
-\f(CWMod+D\fP \(en Select screen/display to use
-.Item
-\f(CWMod+D\fP \(en Select screen/display to use
-
-.ITEM
-\f(CWMod+M\fP \(en pavucontrol (audio control)
-.ITEM
-\f(CWFN+Brightnessdown\fP \(en Decrease display brightness
-.ITEM
-\f(CWFN+Brightnessup\fP \(en Increase display brightness
-.LIST OFF
-
-.HEADING 2 "Audio"
-.PP
-I use ncmpcpp as a music player, which is a front end for mpd.
-.LI
-.ITEM
-\f(CWMod+F5\fP \(en ncmpcpp, the music player
-.ITEM
-\f(CWFN+Next\fP \(en Next track
-.ITEM
-\f(CWFN+Prev\fP \(en Previous track
-.ITEM
-\f(CWFN+Pause\fP \(en Toggle pause
-.ITEM
-\f(CWFN+Stop\fP \(en Toggle stop
-.ITEM
-\f(CWFN+Mute\fP \(en Mute all audio
-.ITEM
-\f(CWFN+LowerVolume\fP \(en Decrease system volume
-.ITEM
-\f(CWFN+RaiseVolume\fP \(en Increase system volume
-.ITEM
-\f(CWMod+F10\fP \(en Music volume to 0 (use Mod+F12 to increase it again)
-.ITEM
-\f(CWMod+F11\fP \(en Decrease music volume
-.ITEM
-\f(CWMod+F12\fP \(en Increase music volume
-.ITEM
-\f(CWMod+M\fP \(en pavucontrol (general audio/volume sink/source manager)
-.LIST OFF
-
-.HEADING 1 "Configuration"
-.PP
-Dotfiles/settings files are located in \f(CW~/.config/\fP.
-.PP
-Suckless programs, dwm (the window manager), st (the terminal) and dmenu among others do not have traditional config files, but have their source code location is \f(CW~/.local/src/\fP.
-There you can modify their \f(CWconfig.h\fP files or other source code, then \f(CWsudo make install\fP to reinstall.
-You'll have to restart the program to see its effects, obviously.
-
-.HEADING 1 "My keyboard isn't working as expected!"
-.PP
-As mentioned above, I've made some keyboard changes with the \f(CWkblayout\fP script.
-These settings may override your preferred settings, so you should open this file and comment out troublesome lines if you have issues.
-.PP
-Additionally, I've set vim to use the clipboard as the default buffer, which means when you yank or delete something in vim, it will be in your system clipboard as well, so you can \f(CWctrl-v\fP it into your browser instance, etc. You can also paste material copied from other programs into vim with the typical vim bindings.
-
-.HEADING 1 "Important Links"
-.PP
-You can follow links via the keyboard in this pdf reader by pressing \f(CWf\fP followed by the number that appears on the desired link.
-.LI
-.ITEM
-.PDF_WWW_LINK "https://github.com/gabrielzschmitz/dotfiles" "My dotfiles"
-\(en For the code behind it!
-.LIST OFF
diff --git a/md b/md
deleted file mode 100644
index a4c6acf..0000000
--- a/md
+++ /dev/null
@@ -1,23 +0,0 @@
-[?1049h[?1h=]11;?[?2004h[?25h[?25l
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-~
-(BREADME 0,0-1 All[2 q[2 q[?25h[?25l[?1004h[?25h \ No newline at end of file
diff --git a/patches/dwm-activetagindicatorbar-6.2.diff b/patches/dwm-activetagindicatorbar-6.2.diff
deleted file mode 100644
index 4450099..0000000
--- a/patches/dwm-activetagindicatorbar-6.2.diff
+++ /dev/null
@@ -1,17 +0,0 @@
-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/patcheslist b/patcheslist
deleted file mode 100644
index 0881485..0000000
--- a/patcheslist
+++ /dev/null
@@ -1,19 +0,0 @@
-# . . .
-# | | | .
-# ,-. ,-. |-. ,-. . ,-. | ,_, ,-. ,-. |-. ,-,-. . |- ,_,
-# | | ,-| | | | | |-' | / `-. | | | | | | | | /
-# `-| `-^ ^-' ' ' `-' `' '"' `-' `-' ' ' ' ' ' ' `' '"'
-# ,|
-# `'
-# GITHUB:https://github.com/gabrielzschmitz
-# INSTAGRAM:https://www.instagram.com/gabrielz.schmitz/
-# DOTFILES:https://github.com/gabrielzschmitz/dotfiles/
-dwm-actualfullscreen.diff
-dwm-alwayscenter.diff
-dwm-bar-height.diff
-dwm-barpadding.diff
-dwm-cursorwarp.diff
-dwm-cyclelayouts.diff
-dwm-vanitygaps.diff
-dwm-xrdb.diff
-
diff --git a/rice.png b/rice.png
deleted file mode 100644
index 80ca9e1..0000000
--- a/rice.png
+++ /dev/null
Binary files differ
diff --git a/util.c b/util.c
index 76aa7b0..fe044fc 100644
--- a/util.c
+++ b/util.c
@@ -1,4 +1,4 @@
-
+/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/util.h b/util.h
index a842e44..f633b51 100644
--- a/util.h
+++ b/util.h
@@ -1,15 +1,3 @@
-/*
-// . . .
-// | | | .
-// ,-. ,-. |-. ,-. . ,-. | ,_, ,-. ,-. |-. ,-,-. . |- ,_,
-// | | ,-| | | | | |-' | / `-. | | | | | | | | /
-// `-| `-^ ^-' ' ' `-' `' '"' `-' `-' ' ' ' ' ' ' `' '"'
-// ,|
-// `'
-// GITHUB:https://github.com/gabrielzschmitz
-// INSTAGRAM:https://www.instagram.com/gabrielz.schmitz/
-// DOTFILES:https://github.com/gabrielzschmitz/dotfiles/
-*/
/* See LICENSE file for copyright and license details. */
#define MAX(A, B) ((A) > (B) ? (A) : (B))
diff --git a/vanitygaps.c b/vanitygaps.c
deleted file mode 100644
index f5c5e3f..0000000
--- a/vanitygaps.c
+++ /dev/null
@@ -1,809 +0,0 @@
-/* Key binding functions */
-static void defaultgaps(const Arg *arg);
-static void incrgaps(const Arg *arg);
-/*static void incrigaps(const Arg *arg);*/
-/*static void incrogaps(const Arg *arg);*/
-/*static void incrohgaps(const Arg *arg);*/
-/*static void incrovgaps(const Arg *arg);*/
-/*static void incrihgaps(const Arg *arg);*/
-/*static void incrivgaps(const Arg *arg);*/
-static void togglegaps(const Arg *arg);
-/* Layouts (delete the ones you do not need) */
-static void bstack(Monitor *m);
-static void bstackhoriz(Monitor *m);
-static void centeredmaster(Monitor *m);
-static void centeredfloatingmaster(Monitor *m);
-static void deck(Monitor *m);
-static void dwindle(Monitor *m);
-static void fibonacci(Monitor *m, int s);
-static void grid(Monitor *m);
-static void nrowgrid(Monitor *m);
-static void spiral(Monitor *m);
-static void tile(Monitor *m);
-/* Internals */
-static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
-static void getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr);
-static void setgaps(int oh, int ov, int ih, int iv);
-
-/* Settings */
-#if !PERTAG_PATCH
-static int enablegaps = 1;
-#endif // PERTAG_PATCH
-
-void
-setgaps(int oh, int ov, int ih, int iv)
-{
- if (oh < 0) oh = 0;
- if (ov < 0) ov = 0;
- if (ih < 0) ih = 0;
- if (iv < 0) iv = 0;
-
- selmon->gappoh = oh;
- selmon->gappov = ov;
- selmon->gappih = ih;
- selmon->gappiv = iv;
- arrange(selmon);
-}
-
-void
-togglegaps(const Arg *arg)
-{
- #if PERTAG_PATCH
- selmon->pertag->enablegaps[selmon->pertag->curtag] = !selmon->pertag->enablegaps[selmon->pertag->curtag];
- #else
- enablegaps = !enablegaps;
- #endif // PERTAG_PATCH
- arrange(NULL);
-}
-
-void
-defaultgaps(const Arg *arg)
-{
- setgaps(gappoh, gappov, gappih, gappiv);
-}
-
-void
-incrgaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh + arg->i,
- selmon->gappov + arg->i,
- selmon->gappih + arg->i,
- selmon->gappiv + arg->i
- );
-}
-
-void
-incrigaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh,
- selmon->gappov,
- selmon->gappih + arg->i,
- selmon->gappiv + arg->i
- );
-}
-
-void
-incrogaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh + arg->i,
- selmon->gappov + arg->i,
- selmon->gappih,
- selmon->gappiv
- );
-}
-
-void
-incrohgaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh + arg->i,
- selmon->gappov,
- selmon->gappih,
- selmon->gappiv
- );
-}
-
-void
-incrovgaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh,
- selmon->gappov + arg->i,
- selmon->gappih,
- selmon->gappiv
- );
-}
-
-void
-incrihgaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh,
- selmon->gappov,
- selmon->gappih + arg->i,
- selmon->gappiv
- );
-}
-
-void
-incrivgaps(const Arg *arg)
-{
- setgaps(
- selmon->gappoh,
- selmon->gappov,
- selmon->gappih,
- selmon->gappiv + arg->i
- );
-}
-
-void
-getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
-{
- unsigned int n, oe, ie;
- #if PERTAG_PATCH
- oe = ie = selmon->pertag->enablegaps[selmon->pertag->curtag];
- #else
- oe = ie = enablegaps;
- #endif // PERTAG_PATCH
- Client *c;
-
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
- if (smartgaps && n == 1) {
- oe = 0; // outer gaps disabled when only one client
- }
-
- *oh = m->gappoh*oe; // outer horizontal gap
- *ov = m->gappov*oe; // outer vertical gap
- *ih = m->gappih*ie; // inner horizontal gap
- *iv = m->gappiv*ie; // inner vertical gap
- *nc = n; // number of clients
-}
-
-void
-getfacts(Monitor *m, int msize, int ssize, float *mf, float *sf, int *mr, int *sr)
-{
- unsigned int n;
- float mfacts, sfacts;
- int mtotal = 0, stotal = 0;
- Client *c;
-
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
- mfacts = MIN(n, m->nmaster);
- sfacts = n - m->nmaster;
-
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
- if (n < m->nmaster)
- mtotal += msize / mfacts;
- else
- stotal += ssize / sfacts;
-
- *mf = mfacts; // total factor of master area
- *sf = sfacts; // total factor of stack area
- *mr = msize - mtotal; // the remainder (rest) of pixels after an even master split
- *sr = ssize - stotal; // the remainder (rest) of pixels after an even stack split
-}
-
-/***
- * Layouts
- */
-
-/*
- * Bottomstack layout + gaps
- * https://dwm.suckless.org/patches/bottomstack/
- */
-static void
-bstack(Monitor *m)
-{
- unsigned int i, n;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- float mfacts, sfacts;
- int mrest, srest;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- sh = mh = m->wh - 2*oh;
- mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
- sw = m->ww - 2*ov - iv * (n - m->nmaster - 1);
-
- if (m->nmaster && n > m->nmaster) {
- sh = (mh - ih) * (1 - m->mfact);
- mh = mh - ih - sh;
- sx = mx;
- sy = my + mh + ih;
- }
-
- getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
- if (i < m->nmaster) {
- resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
- mx += WIDTH(c) + iv;
- } else {
- resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
- sx += WIDTH(c) + iv;
- }
- }
-}
-
-static void
-bstackhoriz(Monitor *m)
-{
- unsigned int i, n;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- float mfacts, sfacts;
- int mrest, srest;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- mh = m->wh - 2*oh;
- sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
- mw = m->ww - 2*ov - iv * (MIN(n, m->nmaster) - 1);
- sw = m->ww - 2*ov;
-
- if (m->nmaster && n > m->nmaster) {
- sh = (mh - ih) * (1 - m->mfact);
- mh = mh - ih - sh;
- sy = my + mh + ih;
- sh = m->wh - mh - 2*oh - ih * (n - m->nmaster);
- }
-
- getfacts(m, mw, sh, &mfacts, &sfacts, &mrest, &srest);
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
- if (i < m->nmaster) {
- resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
- mx += WIDTH(c) + iv;
- } else {
- resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
- sy += HEIGHT(c) + ih;
- }
- }
-}
-
-/*
- * Centred master layout + gaps
- * https://dwm.suckless.org/patches/centeredmaster/
- */
-void
-centeredmaster(Monitor *m)
-{
- unsigned int i, n;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int lx = 0, ly = 0, lw = 0, lh = 0;
- int rx = 0, ry = 0, rw = 0, rh = 0;
- float mfacts = 0, lfacts = 0, rfacts = 0;
- int mtotal = 0, ltotal = 0, rtotal = 0;
- int mrest = 0, lrest = 0, rrest = 0;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- /* initialize areas */
- mx = m->wx + ov;
- my = m->wy + oh;
- mh = m->wh - 2*oh - ih * ((!m->nmaster ? n : MIN(n, m->nmaster)) - 1);
- mw = m->ww - 2*ov;
- lh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - 1);
- rh = m->wh - 2*oh - ih * (((n - m->nmaster) / 2) - ((n - m->nmaster) % 2 ? 0 : 1));
-
- if (m->nmaster && n > m->nmaster) {
- /* go mfact box in the center if more than nmaster clients */
- if (n - m->nmaster > 1) {
- /* ||<-S->|<---M--->|<-S->|| */
- mw = (m->ww - 2*ov - 2*iv) * m->mfact;
- lw = (m->ww - mw - 2*ov - 2*iv) / 2;
- rw = (m->ww - mw - 2*ov - 2*iv) - lw;
- mx += lw + iv;
- } else {
- /* ||<---M--->|<-S->|| */
- mw = (mw - iv) * m->mfact;
- lw = 0;
- rw = m->ww - mw - iv - 2*ov;
- }
- lx = m->wx + ov;
- ly = m->wy + oh;
- rx = mx + mw + iv;
- ry = m->wy + oh;
- }
-
- /* calculate facts */
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
- if (!m->nmaster || n < m->nmaster)
- mfacts += 1;
- else if ((n - m->nmaster) % 2)
- lfacts += 1; // total factor of left hand stack area
- else
- rfacts += 1; // total factor of right hand stack area
- }
-
- for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++)
- if (!m->nmaster || n < m->nmaster)
- mtotal += mh / mfacts;
- else if ((n - m->nmaster) % 2)
- ltotal += lh / lfacts;
- else
- rtotal += rh / rfacts;
-
- mrest = mh - mtotal;
- lrest = lh - ltotal;
- rrest = rh - rtotal;
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
- if (!m->nmaster || i < m->nmaster) {
- /* nmaster clients are stacked vertically, in the center of the screen */
- resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
- my += HEIGHT(c) + ih;
- } else {
- /* stack clients are stacked vertically */
- if ((i - m->nmaster) % 2 ) {
- resize(c, lx, ly, lw - (2*c->bw), (lh / lfacts) + ((i - 2*m->nmaster) < 2*lrest ? 1 : 0) - (2*c->bw), 0);
- ly += HEIGHT(c) + ih;
- } else {
- resize(c, rx, ry, rw - (2*c->bw), (rh / rfacts) + ((i - 2*m->nmaster) < 2*rrest ? 1 : 0) - (2*c->bw), 0);
- ry += HEIGHT(c) + ih;
- }
- }
- }
-}
-
-void
-centeredfloatingmaster(Monitor *m)
-{
- unsigned int i, n;
- float mfacts, sfacts;
- float mivf = 1.0; // master inner vertical gap factor
- int oh, ov, ih, iv, mrest, srest;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- sh = mh = m->wh - 2*oh;
- mw = m->ww - 2*ov - iv*(n - 1);
- sw = m->ww - 2*ov - iv*(n - m->nmaster - 1);
-
- if (m->nmaster && n > m->nmaster) {
- mivf = 0.8;
- /* go mfact box in the center if more than nmaster clients */
- if (m->ww > m->wh) {
- mw = m->ww * m->mfact - iv*mivf*(MIN(n, m->nmaster) - 1);
- mh = m->wh * 0.9;
- } else {
- mw = m->ww * 0.9 - iv*mivf*(MIN(n, m->nmaster) - 1);
- mh = m->wh * m->mfact;
- }
- mx = m->wx + (m->ww - mw) / 2;
- my = m->wy + (m->wh - mh - 2*oh) / 2;
-
- sx = m->wx + ov;
- sy = m->wy + oh;
- sh = m->wh - 2*oh;
- }
-
- getfacts(m, mw, sw, &mfacts, &sfacts, &mrest, &srest);
-
- for (i = 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 */
- resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
- mx += WIDTH(c) + iv*mivf;
- } else {
- /* stack clients are stacked horizontally */
- resize(c, sx, sy, (sw / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
- sx += WIDTH(c) + iv;
- }
-}
-
-/*
- * Deck layout + gaps
- * https://dwm.suckless.org/patches/deck/
- */
-void
-deck(Monitor *m)
-{
- unsigned int i, n;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- float mfacts, sfacts;
- int mrest, srest;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- sh = mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
- sw = mw = m->ww - 2*ov;
-
- if (m->nmaster && n > m->nmaster) {
- sw = (mw - iv) * (1 - m->mfact);
- mw = mw - iv - sw;
- sx = mx + mw + iv;
- sh = m->wh - 2*oh;
- }
-
- getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
-
- if (n - m->nmaster > 0) /* override layout symbol */
- snprintf(m->ltsymbol, sizeof m->ltsymbol, "D %d", n - m->nmaster);
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
- if (i < m->nmaster) {
- resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
- my += HEIGHT(c) + ih;
- } else {
- resize(c, sx, sy, sw - (2*c->bw), sh - (2*c->bw), 0);
- }
-}
-
-/*
- * Fibonacci layout + gaps
- * https://dwm.suckless.org/patches/fibonacci/
- */
-void
-fibonacci(Monitor *m, int s)
-{
- unsigned int i, n;
- int nx, ny, nw, nh;
- int oh, ov, ih, iv;
- int nv, hrest = 0, wrest = 0, r = 1;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- nx = m->wx + ov;
- ny = m->wy + oh;
- nw = m->ww - 2*ov;
- nh = m->wh - 2*oh;
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
- if (r) {
- if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
- || (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
- r = 0;
- }
- if (r && i < n - 1) {
- if (i % 2) {
- nv = (nh - ih) / 2;
- hrest = nh - 2*nv - ih;
- nh = nv;
- } else {
- nv = (nw - iv) / 2;
- wrest = nw - 2*nv - iv;
- nw = nv;
- }
-
- if ((i % 4) == 2 && !s)
- nx += nw + iv;
- else if ((i % 4) == 3 && !s)
- ny += nh + ih;
- }
-
- if ((i % 4) == 0) {
- if (s) {
- ny += nh + ih;
- nh += hrest;
- }
- else {
- nh -= hrest;
- ny -= nh + ih;
- }
- }
- else if ((i % 4) == 1) {
- nx += nw + iv;
- nw += wrest;
- }
- else if ((i % 4) == 2) {
- ny += nh + ih;
- nh += hrest;
- if (i < n - 1)
- nw += wrest;
- }
- else if ((i % 4) == 3) {
- if (s) {
- nx += nw + iv;
- nw -= wrest;
- } else {
- nw -= wrest;
- nx -= nw + iv;
- nh += hrest;
- }
- }
- if (i == 0) {
- if (n != 1) {
- nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
- wrest = 0;
- }
- ny = m->wy + oh;
- }
- else if (i == 1)
- nw = m->ww - nw - iv - 2*ov;
- i++;
- }
-
- resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
- }
-}
-
-void
-dwindle(Monitor *m)
-{
- fibonacci(m, 1);
-}
-
-void
-spiral(Monitor *m)
-{
- fibonacci(m, 0);
-}
-
-/*
- * Gappless grid layout + gaps (ironically)
- * https://dwm.suckless.org/patches/gaplessgrid/
- */
-void
-gaplessgrid(Monitor *m)
-{
- unsigned int i, n;
- int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
- int oh, ov, ih, iv;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &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;
- cn = rn = 0; // reset column no, row no, client count
-
- ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
- cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
- rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
- crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
- x = m->wx + ov;
- y = m->wy + oh;
-
- 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 = (m->wh - 2*oh - ih * (rows - 1)) / rows;
- rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
- }
- resize(c,
- x,
- y + rn*(ch + ih) + MIN(rn, rrest),
- cw + (cn < crest ? 1 : 0) - 2*c->bw,
- ch + (rn < rrest ? 1 : 0) - 2*c->bw,
- 0);
- rn++;
- if (rn >= rows) {
- rn = 0;
- x += cw + ih + (cn < crest ? 1 : 0);
- cn++;
- }
- }
-}
-
-/*
- * Gridmode layout + gaps
- * https://dwm.suckless.org/patches/gridmode/
- */
-void
-grid(Monitor *m)
-{
- unsigned int i, n;
- int cx, cy, cw, ch, cc, cr, chrest, cwrest, cols, rows;
- int oh, ov, ih, iv;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
-
- /* grid dimensions */
- for (rows = 0; rows <= n/2; rows++)
- if (rows*rows >= n)
- break;
- cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;
-
- /* window geoms (cell height/width) */
- ch = (m->wh - 2*oh - ih * (rows - 1)) / (rows ? rows : 1);
- cw = (m->ww - 2*ov - iv * (cols - 1)) / (cols ? cols : 1);
- chrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
- cwrest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
- cc = i / rows;
- cr = i % rows;
- cx = m->wx + ov + cc * (cw + iv) + MIN(cc, cwrest);
- cy = m->wy + oh + cr * (ch + ih) + MIN(cr, chrest);
- resize(c, cx, cy, cw + (cc < cwrest ? 1 : 0) - 2*c->bw, ch + (cr < chrest ? 1 : 0) - 2*c->bw, False);
- }
-}
-
-/*
- * Horizontal grid layout + gaps
- * https://dwm.suckless.org/patches/horizgrid/
- */
-void
-horizgrid(Monitor *m) {
- Client *c;
- unsigned int n, i;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- int ntop, nbottom = 1;
- float mfacts, sfacts;
- int mrest, srest;
-
- /* Count windows */
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- if (n <= 2)
- ntop = n;
- else {
- ntop = n / 2;
- nbottom = n - ntop;
- }
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- sh = mh = m->wh - 2*oh;
- sw = mw = m->ww - 2*ov;
-
- if (n > ntop) {
- sh = (mh - ih) / 2;
- mh = mh - ih - sh;
- sy = my + mh + ih;
- mw = m->ww - 2*ov - iv * (ntop - 1);
- sw = m->ww - 2*ov - iv * (nbottom - 1);
- }
-
- mfacts = ntop;
- sfacts = nbottom;
- mrest = mw - (mw / ntop) * ntop;
- srest = sw - (sw / nbottom) * nbottom;
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
- if (i < ntop) {
- resize(c, mx, my, (mw / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), mh - (2*c->bw), 0);
- mx += WIDTH(c) + iv;
- } else {
- resize(c, sx, sy, (sw / sfacts) + ((i - ntop) < srest ? 1 : 0) - (2*c->bw), sh - (2*c->bw), 0);
- sx += WIDTH(c) + iv;
- }
-}
-
-/*
- * nrowgrid layout + gaps
- * https://dwm.suckless.org/patches/nrowgrid/
- */
-void
-nrowgrid(Monitor *m)
-{
- unsigned int n;
- int ri = 0, ci = 0; /* counters */
- int oh, ov, ih, iv; /* vanitygap settings */
- unsigned int cx, cy, cw, ch; /* client geometry */
- unsigned int uw = 0, uh = 0, uc = 0; /* utilization trackers */
- unsigned int cols, rows = m->nmaster + 1;
- Client *c;
-
- /* count clients */
- getgaps(m, &oh, &ov, &ih, &iv, &n);
-
- /* nothing to do here */
- if (n == 0)
- return;
-
- /* force 2 clients to always split vertically */
- if (FORCE_VSPLIT && n == 2)
- rows = 1;
-
- /* never allow empty rows */
- if (n < rows)
- rows = n;
-
- /* define first row */
- cols = n / rows;
- uc = cols;
- cy = m->wy + oh;
- ch = (m->wh - 2*oh - ih*(rows - 1)) / rows;
- uh = ch;
-
- for (c = nexttiled(m->clients); c; c = nexttiled(c->next), ci++) {
- if (ci == cols) {
- uw = 0;
- ci = 0;
- ri++;
-
- /* next row */
- cols = (n - uc) / (rows - ri);
- uc += cols;
- cy = m->wy + oh + uh + ih;
- uh += ch + ih;
- }
-
- cx = m->wx + ov + uw;
- cw = (m->ww - 2*ov - uw) / (cols - ci);
- uw += cw + iv;
-
- resize(c, cx, cy, cw - (2*c->bw), ch - (2*c->bw), 0);
- }
-}
-
-/*
- * Default tile layout + gaps
- */
-static void
-tile(Monitor *m)
-{
- unsigned int i, n;
- int oh, ov, ih, iv;
- int mx = 0, my = 0, mh = 0, mw = 0;
- int sx = 0, sy = 0, sh = 0, sw = 0;
- float mfacts, sfacts;
- int mrest, srest;
- Client *c;
-
- getgaps(m, &oh, &ov, &ih, &iv, &n);
- if (n == 0)
- return;
-
- sx = mx = m->wx + ov;
- sy = my = m->wy + oh;
- mh = m->wh - 2*oh - ih * (MIN(n, m->nmaster) - 1);
- sh = m->wh - 2*oh - ih * (n - m->nmaster - 1);
- sw = mw = m->ww - 2*ov;
-
- if (m->nmaster && n > m->nmaster) {
- sw = (mw - iv) * (1 - m->mfact);
- mw = mw - iv - sw;
- sx = mx + mw + iv;
- }
-
- getfacts(m, mh, sh, &mfacts, &sfacts, &mrest, &srest);
-
- for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
- if (i < m->nmaster) {
- resize(c, mx, my, mw - (2*c->bw), (mh / mfacts) + (i < mrest ? 1 : 0) - (2*c->bw), 0);
- my += HEIGHT(c) + ih;
- } else {
- resize(c, sx, sy, sw - (2*c->bw), (sh / sfacts) + ((i - m->nmaster) < srest ? 1 : 0) - (2*c->bw), 0);
- sy += HEIGHT(c) + ih;
- }
-}