├── LICENSE ├── Makefile ├── README.md ├── assets ├── dwm-preview1.png ├── dwm-preview2.png ├── dwm-preview3.png └── dwm-preview4.png ├── autostart ├── autostart ├── autostart_blocking └── bar ├── colors └── rose-pine.h ├── config.def.h ├── config.h ├── config.mk ├── drw.c ├── drw.h ├── drw.o ├── dwm ├── dwm.1 ├── dwm.c ├── dwm.o ├── dwm.png ├── dwmclean ├── movestack.c ├── transient.c ├── util.c ├── util.h └── util.o /LICENSE: -------------------------------------------------------------------------------- 1 | MIT/X Consortium License 2 | 3 | © 2006-2019 Anselm R Garbe 4 | © 2006-2009 Jukka Salmi 5 | © 2006-2007 Sander van Dijk 6 | © 2007-2011 Peter Hartlich 7 | © 2007-2009 Szabolcs Nagy 8 | © 2007-2009 Christof Musik 9 | © 2007-2009 Premysl Hruby 10 | © 2007-2008 Enno Gottox Boland 11 | © 2008 Martin Hurton 12 | © 2008 Neale Pickett 13 | © 2009 Mate Nagy 14 | © 2010-2016 Hiltjo Posthuma 15 | © 2010-2012 Connor Lane Smith 16 | © 2011 Christoph Lohmann <20h@r-36.net> 17 | © 2015-2016 Quentin Rameau 18 | © 2015-2016 Eric Pruitt 19 | © 2016-2017 Markus Teich 20 | © 2020-2022 Chris Down 21 | 22 | Permission is hereby granted, free of charge, to any person obtaining a 23 | copy of this software and associated documentation files (the "Software"), 24 | to deal in the Software without restriction, including without limitation 25 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 26 | and/or sell copies of the Software, and to permit persons to whom the 27 | Software is furnished to do so, subject to the following conditions: 28 | 29 | The above copyright notice and this permission notice shall be included in 30 | all copies or substantial portions of the Software. 31 | 32 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 33 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 34 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 35 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 36 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 37 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 38 | DEALINGS IN THE SOFTWARE. 39 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # dwm - dynamic window manager 2 | # See LICENSE file for copyright and license details. 3 | 4 | include config.mk 5 | 6 | SRC = drw.c dwm.c util.c 7 | OBJ = ${SRC:.c=.o} 8 | 9 | all: options dwm 10 | 11 | options: 12 | @echo dwm build options: 13 | @echo "CFLAGS = ${CFLAGS}" 14 | @echo "LDFLAGS = ${LDFLAGS}" 15 | @echo "CC = ${CC}" 16 | 17 | .c.o: 18 | ${CC} -c ${CFLAGS} $< 19 | 20 | ${OBJ}: config.h config.mk 21 | 22 | config.h: 23 | cp config.def.h $@ 24 | 25 | dwm: ${OBJ} 26 | ${CC} -o $@ ${OBJ} ${LDFLAGS} 27 | 28 | clean: 29 | rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz 30 | 31 | dist: clean 32 | mkdir -p dwm-${VERSION} 33 | cp -R LICENSE Makefile README config.def.h config.mk\ 34 | dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION} 35 | tar -cf dwm-${VERSION}.tar dwm-${VERSION} 36 | gzip dwm-${VERSION}.tar 37 | rm -rf dwm-${VERSION} 38 | 39 | install: all 40 | mkdir -p ${DESTDIR}${PREFIX}/bin 41 | cp -f dwm ${DESTDIR}${PREFIX}/bin 42 | chmod 755 ${DESTDIR}${PREFIX}/bin/dwm 43 | mkdir -p ${DESTDIR}${MANPREFIX}/man1 44 | sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1 45 | chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1 46 | 47 | uninstall: 48 | rm -f ${DESTDIR}${PREFIX}/bin/dwm\ 49 | ${DESTDIR}${MANPREFIX}/man1/dwm.1 50 | 51 | .PHONY: all options clean dist install uninstall 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # DWM 3 | dwm is a dynamic window manager for X. It manages windows in tiled, monocle and floating layouts. All of the layouts can be applied dynamically, optimising the environment for the application in use and the task performed. 4 | 5 | # Preview 6 | 7 | 8 | 9 |
10 | 11 | # Keybind 12 | ``` 13 | # Spawn Terminal (st) 14 | Alt + Enter 15 | 16 | # Close and Kill 17 | Alt + q 18 | 19 | # Quit DWM 20 | Alt + Shift + q 21 | ``` 22 | 23 | # Requirements 24 | + Void 25 | ``` 26 | xbps-install libXft-devel libX11-devel libXinerama-devel 27 | ``` 28 | # Font 29 | 30 | + [Iosevka-Mayukai-Sonata](https://github.com/Iosevka-Mayukai/Iosevka-Mayukai) 31 | 32 | + Symbols Nerd Font 33 | 34 | # Installation 35 | + Clone Repo 36 | use this command if you want the autostart working 37 | ``` 38 | git clone https://github.com/motolla/dwm-rose.git $HOME/dot/dwm 39 | ``` 40 | or u can edit this [line](https://github.com/motolla/dwm-rose/blob/35f761be2e0588093242eaeb406780a52a590b5e/dwm.c#L1525) to directory you cloned the repo 41 | + Build & Install 42 | ``` 43 | ./dwmclean 44 | ``` 45 | 46 | # Patch Applied 47 | + autostart 48 | + actualfullscreen 49 | + alwayscenter 50 | + barpadding 51 | + colorfull tag 52 | + movestack 53 | + notitle 54 | + statuspadding 55 | + vanity gaps 56 | -------------------------------------------------------------------------------- /assets/dwm-preview1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/assets/dwm-preview1.png -------------------------------------------------------------------------------- /assets/dwm-preview2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/assets/dwm-preview2.png -------------------------------------------------------------------------------- /assets/dwm-preview3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/assets/dwm-preview3.png -------------------------------------------------------------------------------- /assets/dwm-preview4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/assets/dwm-preview4.png -------------------------------------------------------------------------------- /autostart/autostart: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Audio 4 | pipewire & 5 | pipewire-pulse & 6 | 7 | # Compositor 8 | picom --experimental-backends & 9 | 10 | # Spawn Statusbar 11 | ~/dot/dwm-6.4/autostart/bar & 12 | 13 | # Background 14 | feh --bg-fill /media/void/dot/wall/wallhaven-vmxmxl_1920x1080.png & 15 | 16 | # Update Info 17 | ~/bin/update_info 18 | 19 | -------------------------------------------------------------------------------- /autostart/autostart_blocking: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | -------------------------------------------------------------------------------- /autostart/bar: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # rose pine colors 4 | love=#eb6f92 5 | gold=#f6c177 6 | rose=#ebbcba 7 | pine=#31748f 8 | foam=#9ccfd8 9 | iris=#c4a7e7 10 | overlay=#26233a 11 | bg=#25233a 12 | subtle=#908caa 13 | fg=#e0def4 14 | 15 | interval=0 16 | 17 | wlan() { 18 | interface='wlp0s20u2' 19 | ssid=$(iw $interface link | grep 'SSID' | awk 'NR%1==0 {print $2}') 20 | 21 | case "$(cat /sys/class/net/wl*/operstate 2>/dev/null)" in 22 | up) printf "^c$rose^󰤨 $ssid^d^" ;; 23 | down) printf "^c$subtle^󰤮 offline^d^" ;; 24 | esac 25 | } 26 | 27 | audio() { 28 | vol=$(pamixer --get-volume-human) 29 | check_o=$(pactl list sinks | grep Active | awk '{print $3}') 30 | 31 | case $check_o in 32 | analog-output-speaker) echo "^c$foam^󰓃 $vol^d^" ;; 33 | analog-output-headphones) echo "^c$foam^󰋋 $vol^d^" ;; 34 | esac 35 | } 36 | 37 | ram() { 38 | mem_total=$(free -m | awk 'NR%2==0 {print $2}') 39 | mem_avail=$(free -m | awk 'NR%2==0 {print $7}') 40 | mem_used=$(( $mem_total - $mem_avail )) 41 | mem_usage=$(( $mem_used * 100 / $mem_total )) 42 | if [ $mem_usage -ge 80 ]; then 43 | printf "^c$love^󰘚 ${mem_usage}%%!" 44 | else 45 | printf "^c$pine^󰘚 ${mem_usage}%%" 46 | fi 47 | } 48 | 49 | while true; do 50 | interval=$((interval + 1)) 51 | xsetroot -name " $(audio) $(ram) $(wlan) $(date +"^c$iris^󰃮 %a %d %B 󱑇 %I:%M %p") " 52 | sleep 1 53 | done 54 | 55 | -------------------------------------------------------------------------------- /colors/rose-pine.h: -------------------------------------------------------------------------------- 1 | static const char bg0[] = "#191724"; 2 | static const char bg1[] = "#1f1d2e"; 3 | static const char bg2[] = "#26233a"; 4 | static const char fg0[] = "#e0def4"; 5 | static const char fg1[] = "#6e6a86"; 6 | static const char fg2[] = "#908caa"; 7 | static const char red[] = "#eb6f92"; 8 | static const char yellow[] = "#f6c177"; 9 | static const char rose[] = "#ebbcba"; 10 | static const char bluu[] = "#31748f"; 11 | static const char cyan[] = "#9ccfd8"; 12 | static const char purple[] = "#c4a7e7"; 13 | -------------------------------------------------------------------------------- /config.def.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* appearance */ 4 | static const unsigned int borderpx = 0; /* border pixel of windows */ 5 | static const unsigned int snap = 32; /* snap pixel */ 6 | static const unsigned int gappih = 10; /* horiz inner gap between windows */ 7 | static const unsigned int gappiv = 10; /* vert inner gap between windows */ 8 | static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ 9 | static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ 10 | static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */ 11 | static const unsigned int colorfultag = 1; /* 0 means use SchemeSel for selected tag */ 12 | static const int showbar = 1; /* 0 means no bar */ 13 | static const int topbar = 1; /* 0 means bottom bar */ 14 | static const int vertpad = 8; /* vertical padding of bar */ 15 | static const int sidepad = 8; /* horizontal padding of bar */ 16 | static const int horizpadbar = 6; /* horizontal padding for statusbar */ 17 | static const int vertpadbar = 12; /* vertical padding for statusbar */ 18 | static const char *fonts[] = { "Iosevka Mayukai Sonata:Bold:size=12", "Symbols Nerd Font:Semibold:size=16" }; 19 | 20 | #include "colors/rose-pine.h" 21 | static const char *colors[][3] = { 22 | /* fg bg border */ 23 | [SchemeNorm] = { fg1, bg0, fg2 }, 24 | [SchemeSel] = { bg1, rose, rose }, 25 | [SchemeTag] = { bg0, bg1, bg0 }, 26 | [SchemeTag1] = { rose, bg0, bg1 }, 27 | [SchemeTag2] = { red, bg0, bg1 }, 28 | [SchemeTag3] = { yellow, bg0, bg1 }, 29 | [SchemeTag4] = { bluu, bg0, bg1 }, 30 | [SchemeTag5] = { purple, bg0, bg1 }, 31 | [SchemeTag6] = { cyan, bg0, bg1 }, 32 | [SchemeLayout] = { rose, bg0, bg1 }, 33 | [SchemeTitle] = { fg0, bg0, bg1 }, 34 | [SchemeTitle1] = { rose, bg0, bg1 }, 35 | [SchemeTitle2] = { red, bg0, bg1 }, 36 | [SchemeTitle3] = { yellow, bg0, bg1 }, 37 | [SchemeTitle4] = { bluu, bg0, bg1 }, 38 | [SchemeTitle5] = { purple, bg0, bg1 }, 39 | [SchemeTitle6] = { cyan, bg0, bg1 }, 40 | }; 41 | 42 | static const int tagschemes[] = { SchemeTag1, SchemeTag2, SchemeTag3, 43 | SchemeTag4, SchemeTag5, SchemeTag6 }; 44 | 45 | static const int titleschemes[] = { SchemeTitle1, SchemeTitle2, SchemeTitle3, 46 | SchemeTitle4, SchemeTitle5, SchemeTitle6 }; 47 | 48 | /* tagging */ 49 | static const char *tags[] = { "󰅩", "󰈹", "󰘬", "󰓇", "󰠖", "󱍢"}; 50 | 51 | static const Rule rules[] = { 52 | /* xprop(1): 53 | * WM_CLASS(STRING) = instance, class 54 | * WM_NAME(STRING) = title 55 | */ 56 | /* class instance title tags mask isfloating monitor */ 57 | { "Gimp", NULL, NULL, 0, 1, -1 }, 58 | { "Firefox", NULL, NULL, 2, 0, -1 }, 59 | }; 60 | 61 | /* layout(s) */ 62 | static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ 63 | static const int nmaster = 1; /* number of clients in master area */ 64 | static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ 65 | static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ 66 | 67 | static const Layout layouts[] = { 68 | /* symbol arrange function */ 69 | { " ", tile }, /* first entry is default */ 70 | { "󱂬 ", NULL }, /* no layout function means floating behavior */ 71 | { " ", monocle }, 72 | }; 73 | 74 | /* key definitions */ 75 | #define MODKEY Mod1Mask 76 | #define TAGKEYS(KEY,TAG) \ 77 | { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ 78 | { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ 79 | { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ 80 | { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, 81 | 82 | /* helper for spawning shell commands in the pre dwm-5.0 fashion */ 83 | #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } 84 | #include "movestack.c" 85 | 86 | /* commands */ 87 | static const char *dmenucmd[] = { "dmenu_run", "-c", "-l", "12", NULL }; 88 | static const char *termcmd[] = { "st", NULL }; 89 | 90 | /* volume commands */ 91 | static const char *uvol[] = { "pactl", "set-sink-volume", "0", "+5%", NULL }; 92 | static const char *dvol[] = { "pactl", "set-sink-volume", "0", "-5%", NULL }; 93 | static const char *mvol[] = { "pactl", "set-sink-mute", "0", "toggle", NULL }; 94 | 95 | /* brightness commands */ 96 | static const char *ubright[] = { "xbacklight", "-inc", "10", NULL }; 97 | static const char *dbright[] = { "xbacklight", "-dec", "10", NULL }; 98 | 99 | static const Key keys[] = { 100 | /* modifier key function argument */ 101 | 102 | // Programs // 103 | { MODKEY, XK_p, spawn, {.v = dmenucmd } }, 104 | { MODKEY, XK_Return, spawn, {.v = termcmd } }, 105 | { MODKEY, XK_bracketleft, spawn, SHCMD("~/bin/volcon") }, 106 | { MODKEY, XK_Print, spawn, SHCMD("~/bin/scrot") }, 107 | // Programs: brightness // 108 | { 0, 0x1008FF02, spawn, {.v = ubright } }, 109 | { 0, 0x1008FF03, spawn, {.v = dbright } }, 110 | // Programs: audio // 111 | { 0, 0x1008FF13, spawn, {.v = uvol } }, 112 | { 0, 0x1008FF11, spawn, {.v = dvol } }, 113 | { 0, 0x1008FF12, spawn, {.v = mvol } }, 114 | 115 | // Visual // 116 | { MODKEY, XK_b, togglebar, {0} }, 117 | { MODKEY, XK_j, focusstack, {.i = +1 } }, 118 | { MODKEY, XK_k, focusstack, {.i = -1 } }, 119 | { MODKEY, XK_i, incnmaster, {.i = +1 } }, 120 | { MODKEY, XK_d, incnmaster, {.i = -1 } }, 121 | { MODKEY, XK_h, setmfact, {.f = -0.05} }, 122 | { MODKEY, XK_l, setmfact, {.f = +0.05} }, 123 | { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, 124 | { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, 125 | { MODKEY|ShiftMask, XK_n, togglecolorfultag, {0} }, 126 | { MODKEY|ShiftMask, XK_Return, zoom, {0} }, 127 | { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, 128 | { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, 129 | { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, 130 | { MODKEY, XK_space, setlayout, {0} }, 131 | { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, 132 | { MODKEY|ShiftMask, XK_f, togglefullscr, {0} }, 133 | 134 | 135 | // Visual: gaps // 136 | { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, 137 | { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, 138 | { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, 139 | { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, 140 | { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, 141 | { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, 142 | { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, 143 | { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, 144 | { MODKEY, XK_y, incrihgaps, {.i = +1 } }, 145 | { MODKEY, XK_o, incrihgaps, {.i = -1 } }, 146 | { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, 147 | { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, 148 | { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, 149 | { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, 150 | { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, 151 | { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, 152 | 153 | // Misc // 154 | { MODKEY, XK_Tab, view, {0} }, 155 | { MODKEY, XK_q, killclient, {0} }, 156 | { MODKEY, XK_0, view, {.ui = ~0 } }, 157 | { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, 158 | { MODKEY, XK_comma, focusmon, {.i = -1 } }, 159 | { MODKEY, XK_period, focusmon, {.i = +1 } }, 160 | { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 161 | { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 162 | // Quit dwm // 163 | { MODKEY|ShiftMask, XK_q, quit, {0} }, 164 | 165 | 166 | // Workspaces // 167 | TAGKEYS( XK_1, 0) 168 | TAGKEYS( XK_2, 1) 169 | TAGKEYS( XK_3, 2) 170 | TAGKEYS( XK_4, 3) 171 | TAGKEYS( XK_5, 4) 172 | TAGKEYS( XK_6, 5) 173 | TAGKEYS( XK_7, 6) 174 | TAGKEYS( XK_8, 7) 175 | TAGKEYS( XK_9, 8) 176 | }; 177 | 178 | /* button definitions */ 179 | /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ 180 | static const Button buttons[] = { 181 | /* click event mask button function argument */ 182 | { ClkLtSymbol, 0, Button1, setlayout, {0} }, 183 | { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, 184 | { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, 185 | { ClkClientWin, MODKEY, Button1, movemouse, {0} }, 186 | { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, 187 | { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, 188 | { ClkTagBar, 0, Button1, view, {0} }, 189 | { ClkTagBar, 0, Button3, toggleview, {0} }, 190 | { ClkTagBar, MODKEY, Button1, tag, {0} }, 191 | { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 192 | }; 193 | 194 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | /* appearance */ 4 | static const unsigned int borderpx = 0; /* border pixel of windows */ 5 | static const unsigned int snap = 32; /* snap pixel */ 6 | static const unsigned int gappih = 10; /* horiz inner gap between windows */ 7 | static const unsigned int gappiv = 10; /* vert inner gap between windows */ 8 | static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ 9 | static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ 10 | static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */ 11 | static const unsigned int colorfultag = 1; /* 0 means use SchemeSel for selected tag */ 12 | static const int showbar = 1; /* 0 means no bar */ 13 | static const int topbar = 1; /* 0 means bottom bar */ 14 | static const int vertpad = 8; /* vertical padding of bar */ 15 | static const int sidepad = 8; /* horizontal padding of bar */ 16 | static const int horizpadbar = 6; /* horizontal padding for statusbar */ 17 | static const int vertpadbar = 12; /* vertical padding for statusbar */ 18 | static const char *fonts[] = { "Iosevka Mayukai Sonata:Bold:size=12", "Symbols Nerd Font:Semibold:size=16" }; 19 | 20 | #include "colors/rose-pine.h" 21 | static const char *colors[][3] = { 22 | /* fg bg border */ 23 | [SchemeNorm] = { fg1, bg0, fg2 }, 24 | [SchemeSel] = { bg1, rose, rose }, 25 | [SchemeTag] = { bg0, bg1, bg0 }, 26 | [SchemeTag1] = { rose, bg0, bg1 }, 27 | [SchemeTag2] = { red, bg0, bg1 }, 28 | [SchemeTag3] = { yellow, bg0, bg1 }, 29 | [SchemeTag4] = { bluu, bg0, bg1 }, 30 | [SchemeTag5] = { purple, bg0, bg1 }, 31 | [SchemeTag6] = { cyan, bg0, bg1 }, 32 | [SchemeLayout] = { rose, bg0, bg1 }, 33 | [SchemeTitle] = { fg0, bg0, bg1 }, 34 | [SchemeTitle1] = { rose, bg0, bg1 }, 35 | [SchemeTitle2] = { red, bg0, bg1 }, 36 | [SchemeTitle3] = { yellow, bg0, bg1 }, 37 | [SchemeTitle4] = { bluu, bg0, bg1 }, 38 | [SchemeTitle5] = { purple, bg0, bg1 }, 39 | [SchemeTitle6] = { cyan, bg0, bg1 }, 40 | }; 41 | 42 | static const int tagschemes[] = { SchemeTag1, SchemeTag2, SchemeTag3, 43 | SchemeTag4, SchemeTag5, SchemeTag6 }; 44 | 45 | static const int titleschemes[] = { SchemeTitle1, SchemeTitle2, SchemeTitle3, 46 | SchemeTitle4, SchemeTitle5, SchemeTitle6 }; 47 | 48 | /* tagging */ 49 | static const char *tags[] = { "󰅩", "󰈹", "󰘬", "󰓇", "󰠖", "󱍢"}; 50 | 51 | static const Rule rules[] = { 52 | /* xprop(1): 53 | * WM_CLASS(STRING) = instance, class 54 | * WM_NAME(STRING) = title 55 | */ 56 | /* class instance title tags mask isfloating monitor */ 57 | { "Gimp", NULL, NULL, 0, 1, -1 }, 58 | { "Firefox", NULL, NULL, 2, 0, -1 }, 59 | }; 60 | 61 | /* layout(s) */ 62 | static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ 63 | static const int nmaster = 1; /* number of clients in master area */ 64 | static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ 65 | static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ 66 | 67 | static const Layout layouts[] = { 68 | /* symbol arrange function */ 69 | { " ", tile }, /* first entry is default */ 70 | { "󱂬 ", NULL }, /* no layout function means floating behavior */ 71 | { " ", monocle }, 72 | }; 73 | 74 | /* key definitions */ 75 | #define MODKEY Mod1Mask 76 | #define TAGKEYS(KEY,TAG) \ 77 | { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ 78 | { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ 79 | { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ 80 | { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, 81 | 82 | /* helper for spawning shell commands in the pre dwm-5.0 fashion */ 83 | #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } 84 | #include "movestack.c" 85 | 86 | /* commands */ 87 | static const char *dmenucmd[] = { "dmenu_run", "-c", "-l", "12", NULL }; 88 | static const char *termcmd[] = { "st", NULL }; 89 | 90 | /* volume commands */ 91 | static const char *uvol[] = { "pactl", "set-sink-volume", "0", "+5%", NULL }; 92 | static const char *dvol[] = { "pactl", "set-sink-volume", "0", "-5%", NULL }; 93 | static const char *mvol[] = { "pactl", "set-sink-mute", "0", "toggle", NULL }; 94 | 95 | /* brightness commands */ 96 | static const char *ubright[] = { "xbacklight", "-inc", "10", NULL }; 97 | static const char *dbright[] = { "xbacklight", "-dec", "10", NULL }; 98 | 99 | static const Key keys[] = { 100 | /* modifier key function argument */ 101 | 102 | // Programs // 103 | { MODKEY, XK_p, spawn, {.v = dmenucmd } }, 104 | { MODKEY, XK_Return, spawn, {.v = termcmd } }, 105 | { MODKEY, XK_bracketleft, spawn, SHCMD("~/bin/volcon") }, 106 | { MODKEY, XK_Print, spawn, SHCMD("~/bin/scrot") }, 107 | // Programs: brightness // 108 | { 0, 0x1008FF02, spawn, {.v = ubright } }, 109 | { 0, 0x1008FF03, spawn, {.v = dbright } }, 110 | // Programs: audio // 111 | { 0, 0x1008FF13, spawn, {.v = uvol } }, 112 | { 0, 0x1008FF11, spawn, {.v = dvol } }, 113 | { 0, 0x1008FF12, spawn, {.v = mvol } }, 114 | 115 | // Visual // 116 | { MODKEY, XK_b, togglebar, {0} }, 117 | { MODKEY, XK_j, focusstack, {.i = +1 } }, 118 | { MODKEY, XK_k, focusstack, {.i = -1 } }, 119 | { MODKEY, XK_i, incnmaster, {.i = +1 } }, 120 | { MODKEY, XK_d, incnmaster, {.i = -1 } }, 121 | { MODKEY, XK_h, setmfact, {.f = -0.05} }, 122 | { MODKEY, XK_l, setmfact, {.f = +0.05} }, 123 | { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, 124 | { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, 125 | { MODKEY|ShiftMask, XK_n, togglecolorfultag, {0} }, 126 | { MODKEY|ShiftMask, XK_Return, zoom, {0} }, 127 | { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, 128 | { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, 129 | { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, 130 | { MODKEY, XK_space, setlayout, {0} }, 131 | { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, 132 | { MODKEY|ShiftMask, XK_f, togglefullscr, {0} }, 133 | 134 | 135 | // Visual: gaps // 136 | { MODKEY|Mod4Mask, XK_h, incrgaps, {.i = +1 } }, 137 | { MODKEY|Mod4Mask, XK_l, incrgaps, {.i = -1 } }, 138 | { MODKEY|Mod4Mask|ShiftMask, XK_h, incrogaps, {.i = +1 } }, 139 | { MODKEY|Mod4Mask|ShiftMask, XK_l, incrogaps, {.i = -1 } }, 140 | { MODKEY|Mod4Mask|ControlMask, XK_h, incrigaps, {.i = +1 } }, 141 | { MODKEY|Mod4Mask|ControlMask, XK_l, incrigaps, {.i = -1 } }, 142 | { MODKEY|Mod4Mask, XK_0, togglegaps, {0} }, 143 | { MODKEY|Mod4Mask|ShiftMask, XK_0, defaultgaps, {0} }, 144 | { MODKEY, XK_y, incrihgaps, {.i = +1 } }, 145 | { MODKEY, XK_o, incrihgaps, {.i = -1 } }, 146 | { MODKEY|ControlMask, XK_y, incrivgaps, {.i = +1 } }, 147 | { MODKEY|ControlMask, XK_o, incrivgaps, {.i = -1 } }, 148 | { MODKEY|Mod4Mask, XK_y, incrohgaps, {.i = +1 } }, 149 | { MODKEY|Mod4Mask, XK_o, incrohgaps, {.i = -1 } }, 150 | { MODKEY|ShiftMask, XK_y, incrovgaps, {.i = +1 } }, 151 | { MODKEY|ShiftMask, XK_o, incrovgaps, {.i = -1 } }, 152 | 153 | // Misc // 154 | { MODKEY, XK_Tab, view, {0} }, 155 | { MODKEY, XK_q, killclient, {0} }, 156 | { MODKEY, XK_0, view, {.ui = ~0 } }, 157 | { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, 158 | { MODKEY, XK_comma, focusmon, {.i = -1 } }, 159 | { MODKEY, XK_period, focusmon, {.i = +1 } }, 160 | { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 161 | { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 162 | // Quit dwm // 163 | { MODKEY|ShiftMask, XK_q, quit, {0} }, 164 | 165 | 166 | // Workspaces // 167 | TAGKEYS( XK_1, 0) 168 | TAGKEYS( XK_2, 1) 169 | TAGKEYS( XK_3, 2) 170 | TAGKEYS( XK_4, 3) 171 | TAGKEYS( XK_5, 4) 172 | TAGKEYS( XK_6, 5) 173 | TAGKEYS( XK_7, 6) 174 | TAGKEYS( XK_8, 7) 175 | TAGKEYS( XK_9, 8) 176 | }; 177 | 178 | /* button definitions */ 179 | /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ 180 | static const Button buttons[] = { 181 | /* click event mask button function argument */ 182 | { ClkLtSymbol, 0, Button1, setlayout, {0} }, 183 | { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, 184 | { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, 185 | { ClkClientWin, MODKEY, Button1, movemouse, {0} }, 186 | { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, 187 | { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, 188 | { ClkTagBar, 0, Button1, view, {0} }, 189 | { ClkTagBar, 0, Button3, toggleview, {0} }, 190 | { ClkTagBar, MODKEY, Button1, tag, {0} }, 191 | { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 192 | }; 193 | 194 | -------------------------------------------------------------------------------- /config.mk: -------------------------------------------------------------------------------- 1 | # dwm version 2 | VERSION = 6.4 3 | 4 | # Customize below to fit your system 5 | 6 | # paths 7 | PREFIX = /usr/local 8 | MANPREFIX = ${PREFIX}/share/man 9 | 10 | X11INC = /usr/include/X11 11 | X11LIB = /usr/lib/X11 12 | 13 | # Xinerama, comment if you don't want it 14 | XINERAMALIBS = -lXinerama 15 | XINERAMAFLAGS = -DXINERAMA 16 | 17 | # freetype 18 | FREETYPELIBS = -lfontconfig -lXft 19 | FREETYPEINC = /usr/include/freetype2 20 | # OpenBSD (uncomment) 21 | #FREETYPEINC = ${X11INC}/freetype2 22 | #MANPREFIX = ${PREFIX}/man 23 | 24 | # includes and libs 25 | INCS = -I${X11INC} -I${FREETYPEINC} 26 | LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} 27 | 28 | # flags 29 | CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} 30 | #CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} 31 | CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS} 32 | LDFLAGS = ${LIBS} 33 | 34 | # Solaris 35 | #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 36 | #LDFLAGS = ${LIBS} 37 | 38 | # compiler and linker 39 | CC = gcc 40 | -------------------------------------------------------------------------------- /drw.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "drw.h" 9 | #include "util.h" 10 | 11 | #define UTF_INVALID 0xFFFD 12 | #define UTF_SIZ 4 13 | 14 | static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 15 | static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; 16 | static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; 17 | static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; 18 | 19 | static long 20 | utf8decodebyte(const char c, size_t *i) 21 | { 22 | for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) 23 | if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) 24 | return (unsigned char)c & ~utfmask[*i]; 25 | return 0; 26 | } 27 | 28 | static size_t 29 | utf8validate(long *u, size_t i) 30 | { 31 | if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) 32 | *u = UTF_INVALID; 33 | for (i = 1; *u > utfmax[i]; ++i) 34 | ; 35 | return i; 36 | } 37 | 38 | static size_t 39 | utf8decode(const char *c, long *u, size_t clen) 40 | { 41 | size_t i, j, len, type; 42 | long udecoded; 43 | 44 | *u = UTF_INVALID; 45 | if (!clen) 46 | return 0; 47 | udecoded = utf8decodebyte(c[0], &len); 48 | if (!BETWEEN(len, 1, UTF_SIZ)) 49 | return 1; 50 | for (i = 1, j = 1; i < clen && j < len; ++i, ++j) { 51 | udecoded = (udecoded << 6) | utf8decodebyte(c[i], &type); 52 | if (type) 53 | return j; 54 | } 55 | if (j < len) 56 | return 0; 57 | *u = udecoded; 58 | utf8validate(u, len); 59 | 60 | return len; 61 | } 62 | 63 | Drw * 64 | drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) 65 | { 66 | Drw *drw = ecalloc(1, sizeof(Drw)); 67 | 68 | drw->dpy = dpy; 69 | drw->screen = screen; 70 | drw->root = root; 71 | drw->w = w; 72 | drw->h = h; 73 | drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); 74 | drw->gc = XCreateGC(dpy, root, 0, NULL); 75 | XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); 76 | 77 | return drw; 78 | } 79 | 80 | void 81 | drw_resize(Drw *drw, unsigned int w, unsigned int h) 82 | { 83 | if (!drw) 84 | return; 85 | 86 | drw->w = w; 87 | drw->h = h; 88 | if (drw->drawable) 89 | XFreePixmap(drw->dpy, drw->drawable); 90 | drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); 91 | } 92 | 93 | void 94 | drw_free(Drw *drw) 95 | { 96 | XFreePixmap(drw->dpy, drw->drawable); 97 | XFreeGC(drw->dpy, drw->gc); 98 | drw_fontset_free(drw->fonts); 99 | free(drw); 100 | } 101 | 102 | /* This function is an implementation detail. Library users should use 103 | * drw_fontset_create instead. 104 | */ 105 | static Fnt * 106 | xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) 107 | { 108 | Fnt *font; 109 | XftFont *xfont = NULL; 110 | FcPattern *pattern = NULL; 111 | 112 | if (fontname) { 113 | /* Using the pattern found at font->xfont->pattern does not yield the 114 | * same substitution results as using the pattern returned by 115 | * FcNameParse; using the latter results in the desired fallback 116 | * behaviour whereas the former just results in missing-character 117 | * rectangles being drawn, at least with some fonts. */ 118 | if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { 119 | fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); 120 | return NULL; 121 | } 122 | if (!(pattern = FcNameParse((FcChar8 *) fontname))) { 123 | fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); 124 | XftFontClose(drw->dpy, xfont); 125 | return NULL; 126 | } 127 | } else if (fontpattern) { 128 | if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { 129 | fprintf(stderr, "error, cannot load font from pattern.\n"); 130 | return NULL; 131 | } 132 | } else { 133 | die("no font specified."); 134 | } 135 | 136 | font = ecalloc(1, sizeof(Fnt)); 137 | font->xfont = xfont; 138 | font->pattern = pattern; 139 | font->h = xfont->ascent + xfont->descent; 140 | font->dpy = drw->dpy; 141 | 142 | return font; 143 | } 144 | 145 | static void 146 | xfont_free(Fnt *font) 147 | { 148 | if (!font) 149 | return; 150 | if (font->pattern) 151 | FcPatternDestroy(font->pattern); 152 | XftFontClose(font->dpy, font->xfont); 153 | free(font); 154 | } 155 | 156 | Fnt* 157 | drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) 158 | { 159 | Fnt *cur, *ret = NULL; 160 | size_t i; 161 | 162 | if (!drw || !fonts) 163 | return NULL; 164 | 165 | for (i = 1; i <= fontcount; i++) { 166 | if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { 167 | cur->next = ret; 168 | ret = cur; 169 | } 170 | } 171 | return (drw->fonts = ret); 172 | } 173 | 174 | void 175 | drw_fontset_free(Fnt *font) 176 | { 177 | if (font) { 178 | drw_fontset_free(font->next); 179 | xfont_free(font); 180 | } 181 | } 182 | 183 | void 184 | drw_clr_create(Drw *drw, Clr *dest, const char *clrname) 185 | { 186 | if (!drw || !dest || !clrname) 187 | return; 188 | 189 | if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), 190 | DefaultColormap(drw->dpy, drw->screen), 191 | clrname, dest)) 192 | die("error, cannot allocate color '%s'", clrname); 193 | } 194 | 195 | /* Wrapper to create color schemes. The caller has to call free(3) on the 196 | * returned color scheme when done using it. */ 197 | Clr * 198 | drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) 199 | { 200 | size_t i; 201 | Clr *ret; 202 | 203 | /* need at least two colors for a scheme */ 204 | if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) 205 | return NULL; 206 | 207 | for (i = 0; i < clrcount; i++) 208 | drw_clr_create(drw, &ret[i], clrnames[i]); 209 | return ret; 210 | } 211 | 212 | void 213 | drw_setfontset(Drw *drw, Fnt *set) 214 | { 215 | if (drw) 216 | drw->fonts = set; 217 | } 218 | 219 | void 220 | drw_setscheme(Drw *drw, Clr *scm) 221 | { 222 | if (drw) 223 | drw->scheme = scm; 224 | } 225 | 226 | void 227 | drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) 228 | { 229 | if (!drw || !drw->scheme) 230 | return; 231 | XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); 232 | if (filled) 233 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); 234 | else 235 | XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); 236 | } 237 | 238 | int 239 | drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) 240 | { 241 | int i, ty, ellipsis_x = 0; 242 | unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; 243 | XftDraw *d = NULL; 244 | Fnt *usedfont, *curfont, *nextfont; 245 | int utf8strlen, utf8charlen, render = x || y || w || h; 246 | long utf8codepoint = 0; 247 | const char *utf8str; 248 | FcCharSet *fccharset; 249 | FcPattern *fcpattern; 250 | FcPattern *match; 251 | XftResult result; 252 | int charexists = 0, overflow = 0; 253 | /* keep track of a couple codepoints for which we have no match. */ 254 | enum { nomatches_len = 64 }; 255 | static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches; 256 | static unsigned int ellipsis_width = 0; 257 | 258 | if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) 259 | return 0; 260 | 261 | if (!render) { 262 | w = invert ? invert : ~invert; 263 | } else { 264 | XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); 265 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); 266 | d = XftDrawCreate(drw->dpy, drw->drawable, 267 | DefaultVisual(drw->dpy, drw->screen), 268 | DefaultColormap(drw->dpy, drw->screen)); 269 | x += lpad; 270 | w -= lpad; 271 | } 272 | 273 | usedfont = drw->fonts; 274 | if (!ellipsis_width && render) 275 | ellipsis_width = drw_fontset_getwidth(drw, "..."); 276 | while (1) { 277 | ew = ellipsis_len = utf8strlen = 0; 278 | utf8str = text; 279 | nextfont = NULL; 280 | while (*text) { 281 | utf8charlen = utf8decode(text, &utf8codepoint, UTF_SIZ); 282 | for (curfont = drw->fonts; curfont; curfont = curfont->next) { 283 | charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); 284 | if (charexists) { 285 | drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL); 286 | if (ew + ellipsis_width <= w) { 287 | /* keep track where the ellipsis still fits */ 288 | ellipsis_x = x + ew; 289 | ellipsis_w = w - ew; 290 | ellipsis_len = utf8strlen; 291 | } 292 | 293 | if (ew + tmpw > w) { 294 | overflow = 1; 295 | /* called from drw_fontset_getwidth_clamp(): 296 | * it wants the width AFTER the overflow 297 | */ 298 | if (!render) 299 | x += tmpw; 300 | else 301 | utf8strlen = ellipsis_len; 302 | } else if (curfont == usedfont) { 303 | utf8strlen += utf8charlen; 304 | text += utf8charlen; 305 | ew += tmpw; 306 | } else { 307 | nextfont = curfont; 308 | } 309 | break; 310 | } 311 | } 312 | 313 | if (overflow || !charexists || nextfont) 314 | break; 315 | else 316 | charexists = 0; 317 | } 318 | 319 | if (utf8strlen) { 320 | if (render) { 321 | ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; 322 | XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], 323 | usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen); 324 | } 325 | x += ew; 326 | w -= ew; 327 | } 328 | if (render && overflow) 329 | drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert); 330 | 331 | if (!*text || overflow) { 332 | break; 333 | } else if (nextfont) { 334 | charexists = 0; 335 | usedfont = nextfont; 336 | } else { 337 | /* Regardless of whether or not a fallback font is found, the 338 | * character must be drawn. */ 339 | charexists = 1; 340 | 341 | for (i = 0; i < nomatches_len; ++i) { 342 | /* avoid calling XftFontMatch if we know we won't find a match */ 343 | if (utf8codepoint == nomatches.codepoint[i]) 344 | goto no_match; 345 | } 346 | 347 | fccharset = FcCharSetCreate(); 348 | FcCharSetAddChar(fccharset, utf8codepoint); 349 | 350 | if (!drw->fonts->pattern) { 351 | /* Refer to the comment in xfont_create for more information. */ 352 | die("the first font in the cache must be loaded from a font string."); 353 | } 354 | 355 | fcpattern = FcPatternDuplicate(drw->fonts->pattern); 356 | FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); 357 | FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); 358 | 359 | FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); 360 | FcDefaultSubstitute(fcpattern); 361 | match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); 362 | 363 | FcCharSetDestroy(fccharset); 364 | FcPatternDestroy(fcpattern); 365 | 366 | if (match) { 367 | usedfont = xfont_create(drw, NULL, match); 368 | if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { 369 | for (curfont = drw->fonts; curfont->next; curfont = curfont->next) 370 | ; /* NOP */ 371 | curfont->next = usedfont; 372 | } else { 373 | xfont_free(usedfont); 374 | nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint; 375 | no_match: 376 | usedfont = drw->fonts; 377 | } 378 | } 379 | } 380 | } 381 | if (d) 382 | XftDrawDestroy(d); 383 | 384 | return x + (render ? w : 0); 385 | } 386 | 387 | void 388 | drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) 389 | { 390 | if (!drw) 391 | return; 392 | 393 | XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); 394 | XSync(drw->dpy, False); 395 | } 396 | 397 | unsigned int 398 | drw_fontset_getwidth(Drw *drw, const char *text) 399 | { 400 | if (!drw || !drw->fonts || !text) 401 | return 0; 402 | return drw_text(drw, 0, 0, 0, 0, 0, text, 0); 403 | } 404 | 405 | unsigned int 406 | drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) 407 | { 408 | unsigned int tmp = 0; 409 | if (drw && drw->fonts && text && n) 410 | tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n); 411 | return MIN(n, tmp); 412 | } 413 | 414 | void 415 | drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) 416 | { 417 | XGlyphInfo ext; 418 | 419 | if (!font || !text) 420 | return; 421 | 422 | XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); 423 | if (w) 424 | *w = ext.xOff; 425 | if (h) 426 | *h = font->h; 427 | } 428 | 429 | Cur * 430 | drw_cur_create(Drw *drw, int shape) 431 | { 432 | Cur *cur; 433 | 434 | if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) 435 | return NULL; 436 | 437 | cur->cursor = XCreateFontCursor(drw->dpy, shape); 438 | 439 | return cur; 440 | } 441 | 442 | void 443 | drw_cur_free(Drw *drw, Cur *cursor) 444 | { 445 | if (!cursor) 446 | return; 447 | 448 | XFreeCursor(drw->dpy, cursor->cursor); 449 | free(cursor); 450 | } 451 | -------------------------------------------------------------------------------- /drw.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | typedef struct { 4 | Cursor cursor; 5 | } Cur; 6 | 7 | typedef struct Fnt { 8 | Display *dpy; 9 | unsigned int h; 10 | XftFont *xfont; 11 | FcPattern *pattern; 12 | struct Fnt *next; 13 | } Fnt; 14 | 15 | enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ 16 | typedef XftColor Clr; 17 | 18 | typedef struct { 19 | unsigned int w, h; 20 | Display *dpy; 21 | int screen; 22 | Window root; 23 | Drawable drawable; 24 | GC gc; 25 | Clr *scheme; 26 | Fnt *fonts; 27 | } Drw; 28 | 29 | /* Drawable abstraction */ 30 | Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); 31 | void drw_resize(Drw *drw, unsigned int w, unsigned int h); 32 | void drw_free(Drw *drw); 33 | 34 | /* Fnt abstraction */ 35 | Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); 36 | void drw_fontset_free(Fnt* set); 37 | unsigned int drw_fontset_getwidth(Drw *drw, const char *text); 38 | unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n); 39 | void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); 40 | 41 | /* Colorscheme abstraction */ 42 | void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); 43 | Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); 44 | 45 | /* Cursor abstraction */ 46 | Cur *drw_cur_create(Drw *drw, int shape); 47 | void drw_cur_free(Drw *drw, Cur *cursor); 48 | 49 | /* Drawing context manipulation */ 50 | void drw_setfontset(Drw *drw, Fnt *set); 51 | void drw_setscheme(Drw *drw, Clr *scm); 52 | 53 | /* Drawing functions */ 54 | void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); 55 | int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert); 56 | 57 | /* Map functions */ 58 | void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); 59 | -------------------------------------------------------------------------------- /drw.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/drw.o -------------------------------------------------------------------------------- /dwm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/dwm -------------------------------------------------------------------------------- /dwm.1: -------------------------------------------------------------------------------- 1 | .TH DWM 1 dwm\-VERSION 2 | .SH NAME 3 | dwm \- dynamic window manager 4 | .SH SYNOPSIS 5 | .B dwm 6 | .RB [ \-v ] 7 | .SH DESCRIPTION 8 | dwm is a dynamic window manager for X. It manages windows in tiled, monocle 9 | and floating layouts. Either layout can be applied dynamically, optimising the 10 | environment for the application in use and the task performed. 11 | .P 12 | In tiled layouts windows are managed in a master and stacking area. The master 13 | area on the left contains one window by default, and the stacking area on the 14 | right contains all other windows. The number of master area windows can be 15 | adjusted from zero to an arbitrary number. In monocle layout all windows are 16 | maximised to the screen size. In floating layout windows can be resized and 17 | moved freely. Dialog windows are always managed floating, regardless of the 18 | layout applied. 19 | .P 20 | Windows are grouped by tags. Each window can be tagged with one or multiple 21 | tags. Selecting certain tags displays all windows with these tags. 22 | .P 23 | Each screen contains a small status bar which displays all available tags, the 24 | layout, the title of the focused window, and the text read from the root window 25 | name property, if the screen is focused. A floating window is indicated with an 26 | empty square and a maximised floating window is indicated with a filled square 27 | before the windows title. The selected tags are indicated with a different 28 | color. The tags of the focused window are indicated with a filled square in the 29 | top left corner. The tags which are applied to one or more windows are 30 | indicated with an empty square in the top left corner. 31 | .P 32 | dwm draws a small border around windows to indicate the focus state. 33 | .SH OPTIONS 34 | .TP 35 | .B \-v 36 | prints version information to stderr, then exits. 37 | .SH USAGE 38 | .SS Status bar 39 | .TP 40 | .B X root window name 41 | is read and displayed in the status text area. It can be set with the 42 | .BR xsetroot (1) 43 | command. 44 | .TP 45 | .B Button1 46 | click on a tag label to display all windows with that tag, click on the layout 47 | label toggles between tiled and floating layout. 48 | .TP 49 | .B Button3 50 | click on a tag label adds/removes all windows with that tag to/from the view. 51 | .TP 52 | .B Mod1\-Button1 53 | click on a tag label applies that tag to the focused window. 54 | .TP 55 | .B Mod1\-Button3 56 | click on a tag label adds/removes that tag to/from the focused window. 57 | .SS Keyboard commands 58 | .TP 59 | .B Mod1\-Shift\-Return 60 | Start 61 | .BR st(1). 62 | .TP 63 | .B Mod1\-p 64 | Spawn 65 | .BR dmenu(1) 66 | for launching other programs. 67 | .TP 68 | .B Mod1\-, 69 | Focus previous screen, if any. 70 | .TP 71 | .B Mod1\-. 72 | Focus next screen, if any. 73 | .TP 74 | .B Mod1\-Shift\-, 75 | Send focused window to previous screen, if any. 76 | .TP 77 | .B Mod1\-Shift\-. 78 | Send focused window to next screen, if any. 79 | .TP 80 | .B Mod1\-b 81 | Toggles bar on and off. 82 | .TP 83 | .B Mod1\-t 84 | Sets tiled layout. 85 | .TP 86 | .B Mod1\-f 87 | Sets floating layout. 88 | .TP 89 | .B Mod1\-m 90 | Sets monocle layout. 91 | .TP 92 | .B Mod1\-space 93 | Toggles between current and previous layout. 94 | .TP 95 | .B Mod1\-j 96 | Focus next window. 97 | .TP 98 | .B Mod1\-k 99 | Focus previous window. 100 | .TP 101 | .B Mod1\-i 102 | Increase number of windows in master area. 103 | .TP 104 | .B Mod1\-d 105 | Decrease number of windows in master area. 106 | .TP 107 | .B Mod1\-l 108 | Increase master area size. 109 | .TP 110 | .B Mod1\-h 111 | Decrease master area size. 112 | .TP 113 | .B Mod1\-Return 114 | Zooms/cycles focused window to/from master area (tiled layouts only). 115 | .TP 116 | .B Mod1\-Shift\-c 117 | Close focused window. 118 | .TP 119 | .B Mod1\-Shift\-f 120 | Toggle fullscreen for focused window. 121 | .TP 122 | .B Mod1\-Shift\-space 123 | Toggle focused window between tiled and floating state. 124 | .TP 125 | .B Mod1\-Tab 126 | Toggles to the previously selected tags. 127 | .TP 128 | .B Mod1\-Shift\-[1..n] 129 | Apply nth tag to focused window. 130 | .TP 131 | .B Mod1\-Shift\-0 132 | Apply all tags to focused window. 133 | .TP 134 | .B Mod1\-Control\-Shift\-[1..n] 135 | Add/remove nth tag to/from focused window. 136 | .TP 137 | .B Mod1\-[1..n] 138 | View all windows with nth tag. 139 | .TP 140 | .B Mod1\-0 141 | View all windows with any tag. 142 | .TP 143 | .B Mod1\-Control\-[1..n] 144 | Add/remove all windows with nth tag to/from the view. 145 | .TP 146 | .B Mod1\-Shift\-q 147 | Quit dwm. 148 | .SS Mouse commands 149 | .TP 150 | .B Mod1\-Button1 151 | Move focused window while dragging. Tiled windows will be toggled to the floating state. 152 | .TP 153 | .B Mod1\-Button2 154 | Toggles focused window between floating and tiled state. 155 | .TP 156 | .B Mod1\-Button3 157 | Resize focused window while dragging. Tiled windows will be toggled to the floating state. 158 | .SH CUSTOMIZATION 159 | dwm is customized by creating a custom config.h and (re)compiling the source 160 | code. This keeps it fast, secure and simple. 161 | .SH SEE ALSO 162 | .BR dmenu (1), 163 | .BR st (1) 164 | .SH ISSUES 165 | Java applications which use the XToolkit/XAWT backend may draw grey windows 166 | only. The XToolkit/XAWT backend breaks ICCCM-compliance in recent JDK 1.5 and early 167 | JDK 1.6 versions, because it assumes a reparenting window manager. Possible workarounds 168 | are using JDK 1.4 (which doesn't contain the XToolkit/XAWT backend) or setting the 169 | environment variable 170 | .BR AWT_TOOLKIT=MToolkit 171 | (to use the older Motif backend instead) or running 172 | .B xprop -root -f _NET_WM_NAME 32a -set _NET_WM_NAME LG3D 173 | or 174 | .B wmname LG3D 175 | (to pretend that a non-reparenting window manager is running that the 176 | XToolkit/XAWT backend can recognize) or when using OpenJDK setting the environment variable 177 | .BR _JAVA_AWT_WM_NONREPARENTING=1 . 178 | .SH BUGS 179 | Send all bug reports with a patch to hackers@suckless.org. 180 | -------------------------------------------------------------------------------- /dwm.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. 2 | * 3 | * dynamic window manager is designed like any other X client as well. It is 4 | * driven through handling X events. In contrast to other X clients, a window 5 | * manager selects for SubstructureRedirectMask on the root window, to receive 6 | * events about window (dis-)appearance. Only one X connection at a time is 7 | * allowed to select for this event mask. 8 | * 9 | * The event handlers of dwm are organized in an array which is accessed 10 | * whenever a new event has been fetched. This allows event dispatching 11 | * in O(1) time. 12 | * 13 | * Each child of the root window is called a client, except windows which have 14 | * set the override_redirect flag. Clients are organized in a linked client 15 | * list on each monitor, the focus history is remembered through a stack list 16 | * on each monitor. Each client contains a bit array to indicate the tags of a 17 | * client. 18 | * 19 | * Keys and tagging rules are organized as arrays and defined in config.h. 20 | * 21 | * To understand everything else, start reading main(). 22 | */ 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #ifdef XINERAMA 40 | #include 41 | #endif /* XINERAMA */ 42 | #include 43 | 44 | #include "drw.h" 45 | #include "util.h" 46 | 47 | /* macros */ 48 | #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) 49 | #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) 50 | #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ 51 | * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) 52 | #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) 53 | #define LENGTH(X) (sizeof X / sizeof X[0]) 54 | #define MOUSEMASK (BUTTONMASK|PointerMotionMask) 55 | #define WIDTH(X) ((X)->w + 2 * (X)->bw) 56 | #define HEIGHT(X) ((X)->h + 2 * (X)->bw) 57 | #define TAGMASK ((1 << LENGTH(tags)) - 1) 58 | #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 59 | 60 | /* enums */ 61 | enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 62 | enum { SchemeNorm, SchemeSel, 63 | SchemeTag, SchemeTag1, SchemeTag2, SchemeTag3, 64 | SchemeTag4, SchemeTag5, SchemeTag6, SchemeLayout, 65 | SchemeTitle, SchemeTitleFloat, 66 | SchemeTitle1, SchemeTitle2, SchemeTitle3, 67 | SchemeTitle4, SchemeTitle5, SchemeTitle6 }; /* color schemes */ 68 | enum { NetSupported, NetWMName, NetWMState, NetWMCheck, 69 | NetWMFullscreen, NetActiveWindow, NetWMWindowType, 70 | NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ 71 | enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ 72 | enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 73 | ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 74 | 75 | typedef union { 76 | int i; 77 | unsigned int ui; 78 | float f; 79 | const void *v; 80 | } Arg; 81 | 82 | typedef struct { 83 | unsigned int click; 84 | unsigned int mask; 85 | unsigned int button; 86 | void (*func)(const Arg *arg); 87 | const Arg arg; 88 | } Button; 89 | 90 | typedef struct Monitor Monitor; 91 | typedef struct Client Client; 92 | struct Client { 93 | char name[256]; 94 | float mina, maxa; 95 | int x, y, w, h; 96 | int oldx, oldy, oldw, oldh; 97 | int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid; 98 | int bw, oldbw; 99 | unsigned int tags; 100 | int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; 101 | Client *next; 102 | Client *snext; 103 | Monitor *mon; 104 | Window win; 105 | }; 106 | 107 | typedef struct { 108 | unsigned int mod; 109 | KeySym keysym; 110 | void (*func)(const Arg *); 111 | const Arg arg; 112 | } Key; 113 | 114 | typedef struct { 115 | const char *symbol; 116 | void (*arrange)(Monitor *); 117 | } Layout; 118 | 119 | struct Monitor { 120 | char ltsymbol[16]; 121 | float mfact; 122 | int nmaster; 123 | int num; 124 | int by; /* bar geometry */ 125 | int mx, my, mw, mh; /* screen size */ 126 | int wx, wy, ww, wh; /* window area */ 127 | int gappih; /* horizontal gap between windows */ 128 | int gappiv; /* vertical gap between windows */ 129 | int gappoh; /* horizontal outer gaps */ 130 | int gappov; /* vertical outer gaps */ 131 | unsigned int seltags; 132 | unsigned int sellt; 133 | unsigned int tagset[2]; 134 | unsigned int colorfultag; 135 | int showbar; 136 | int topbar; 137 | Client *clients; 138 | Client *sel; 139 | Client *stack; 140 | Monitor *next; 141 | Window barwin; 142 | const Layout *lt[2]; 143 | }; 144 | 145 | typedef struct { 146 | const char *class; 147 | const char *instance; 148 | const char *title; 149 | unsigned int tags; 150 | int isfloating; 151 | int monitor; 152 | } Rule; 153 | 154 | /* function declarations */ 155 | static void applyrules(Client *c); 156 | static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); 157 | static void arrange(Monitor *m); 158 | static void arrangemon(Monitor *m); 159 | static void attach(Client *c); 160 | static void attachstack(Client *c); 161 | static void buttonpress(XEvent *e); 162 | static void checkotherwm(void); 163 | static void cleanup(void); 164 | static void cleanupmon(Monitor *mon); 165 | static void clientmessage(XEvent *e); 166 | static void configure(Client *c); 167 | static void configurenotify(XEvent *e); 168 | static void configurerequest(XEvent *e); 169 | static Monitor *createmon(void); 170 | static void destroynotify(XEvent *e); 171 | static void detach(Client *c); 172 | static void detachstack(Client *c); 173 | static Monitor *dirtomon(int dir); 174 | static void drawbar(Monitor *m); 175 | static void drawbars(void); 176 | static int drawstatusbar(Monitor *m, int bh, char* text); 177 | static void enternotify(XEvent *e); 178 | static void expose(XEvent *e); 179 | static void focus(Client *c); 180 | static void focusin(XEvent *e); 181 | static void focusmon(const Arg *arg); 182 | static void focusstack(const Arg *arg); 183 | static Atom getatomprop(Client *c, Atom prop); 184 | static int getrootptr(int *x, int *y); 185 | static long getstate(Window w); 186 | static int gettextprop(Window w, Atom atom, char *text, unsigned int size); 187 | static void grabbuttons(Client *c, int focused); 188 | static void grabkeys(void); 189 | static void incnmaster(const Arg *arg); 190 | static void keypress(XEvent *e); 191 | static void killclient(const Arg *arg); 192 | static void manage(Window w, XWindowAttributes *wa); 193 | static void mappingnotify(XEvent *e); 194 | static void maprequest(XEvent *e); 195 | static void monocle(Monitor *m); 196 | static void motionnotify(XEvent *e); 197 | static void movemouse(const Arg *arg); 198 | static Client *nexttiled(Client *c); 199 | static void pop(Client *c); 200 | static void propertynotify(XEvent *e); 201 | static void quit(const Arg *arg); 202 | static Monitor *recttomon(int x, int y, int w, int h); 203 | static void resize(Client *c, int x, int y, int w, int h, int interact); 204 | static void resizeclient(Client *c, int x, int y, int w, int h); 205 | static void resizemouse(const Arg *arg); 206 | static void restack(Monitor *m); 207 | static void run(void); 208 | static void runAutostart(void); 209 | static void scan(void); 210 | static int sendevent(Client *c, Atom proto); 211 | static void sendmon(Client *c, Monitor *m); 212 | static void setclientstate(Client *c, long state); 213 | static void setfocus(Client *c); 214 | static void setfullscreen(Client *c, int fullscreen); 215 | static void setgaps(int oh, int ov, int ih, int iv); 216 | static void incrgaps(const Arg *arg); 217 | static void incrigaps(const Arg *arg); 218 | static void incrogaps(const Arg *arg); 219 | static void incrohgaps(const Arg *arg); 220 | static void incrovgaps(const Arg *arg); 221 | static void incrihgaps(const Arg *arg); 222 | static void incrivgaps(const Arg *arg); 223 | static void togglegaps(const Arg *arg); 224 | static void defaultgaps(const Arg *arg); 225 | static void setlayout(const Arg *arg); 226 | static void setmfact(const Arg *arg); 227 | static void setup(void); 228 | static void seturgent(Client *c, int urg); 229 | static void showhide(Client *c); 230 | static void sigchld(int unused); 231 | static void spawn(const Arg *arg); 232 | static void tag(const Arg *arg); 233 | static void tagmon(const Arg *arg); 234 | static void tile(Monitor *m); 235 | static void togglebar(const Arg *arg); 236 | static void togglefloating(const Arg *arg); 237 | static void togglefullscr(const Arg *arg); 238 | static void toggletag(const Arg *arg); 239 | static void toggleview(const Arg *arg); 240 | static void togglecolorfultag(); 241 | static void unfocus(Client *c, int setfocus); 242 | static void unmanage(Client *c, int destroyed); 243 | static void unmapnotify(XEvent *e); 244 | static void updatebarpos(Monitor *m); 245 | static void updatebars(void); 246 | static void updateclientlist(void); 247 | static int updategeom(void); 248 | static void updatenumlockmask(void); 249 | static void updatesizehints(Client *c); 250 | static void updatestatus(void); 251 | static void updatetitle(Client *c); 252 | static void updatewindowtype(Client *c); 253 | static void updatewmhints(Client *c); 254 | static void view(const Arg *arg); 255 | static Client *wintoclient(Window w); 256 | static Monitor *wintomon(Window w); 257 | static int xerror(Display *dpy, XErrorEvent *ee); 258 | static int xerrordummy(Display *dpy, XErrorEvent *ee); 259 | static int xerrorstart(Display *dpy, XErrorEvent *ee); 260 | static void zoom(const Arg *arg); 261 | 262 | /* variables */ 263 | static const char broken[] = "broken"; 264 | static char stext[1024]; 265 | static int screen; 266 | static int sw, sh; /* X display screen geometry width, height */ 267 | static int bh; /* bar height */ 268 | static int lrpad; /* sum of left and right padding for text */ 269 | static int vp; /* vertical padding for bar */ 270 | static int sp; /* side padding for bar */ 271 | static int enablegaps = 1; /* enables gaps, used by togglegaps */ 272 | static int (*xerrorxlib)(Display *, XErrorEvent *); 273 | static unsigned int numlockmask = 0; 274 | static void (*handler[LASTEvent]) (XEvent *) = { 275 | [ButtonPress] = buttonpress, 276 | [ClientMessage] = clientmessage, 277 | [ConfigureRequest] = configurerequest, 278 | [ConfigureNotify] = configurenotify, 279 | [DestroyNotify] = destroynotify, 280 | [EnterNotify] = enternotify, 281 | [Expose] = expose, 282 | [FocusIn] = focusin, 283 | [KeyPress] = keypress, 284 | [MappingNotify] = mappingnotify, 285 | [MapRequest] = maprequest, 286 | [MotionNotify] = motionnotify, 287 | [PropertyNotify] = propertynotify, 288 | [UnmapNotify] = unmapnotify 289 | }; 290 | static Atom wmatom[WMLast], netatom[NetLast]; 291 | static int running = 1; 292 | static Cur *cursor[CurLast]; 293 | static Clr **scheme; 294 | static Display *dpy; 295 | static Drw *drw; 296 | static Monitor *mons, *selmon; 297 | static Window root, wmcheckwin; 298 | 299 | /* configuration, allows nested code to access above variables */ 300 | #include "config.h" 301 | 302 | /* compile-time check if all tags fit into an unsigned int bit array. */ 303 | struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 304 | 305 | /* function implementations */ 306 | void 307 | applyrules(Client *c) 308 | { 309 | const char *class, *instance; 310 | unsigned int i; 311 | const Rule *r; 312 | Monitor *m; 313 | XClassHint ch = { NULL, NULL }; 314 | 315 | /* rule matching */ 316 | c->isfloating = 0; 317 | c->tags = 0; 318 | XGetClassHint(dpy, c->win, &ch); 319 | class = ch.res_class ? ch.res_class : broken; 320 | instance = ch.res_name ? ch.res_name : broken; 321 | 322 | for (i = 0; i < LENGTH(rules); i++) { 323 | r = &rules[i]; 324 | if ((!r->title || strstr(c->name, r->title)) 325 | && (!r->class || strstr(class, r->class)) 326 | && (!r->instance || strstr(instance, r->instance))) 327 | { 328 | c->isfloating = r->isfloating; 329 | c->tags |= r->tags; 330 | for (m = mons; m && m->num != r->monitor; m = m->next); 331 | if (m) 332 | c->mon = m; 333 | } 334 | } 335 | if (ch.res_class) 336 | XFree(ch.res_class); 337 | if (ch.res_name) 338 | XFree(ch.res_name); 339 | c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; 340 | } 341 | 342 | int 343 | applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) 344 | { 345 | int baseismin; 346 | Monitor *m = c->mon; 347 | 348 | /* set minimum possible */ 349 | *w = MAX(1, *w); 350 | *h = MAX(1, *h); 351 | if (interact) { 352 | if (*x > sw) 353 | *x = sw - WIDTH(c); 354 | if (*y > sh) 355 | *y = sh - HEIGHT(c); 356 | if (*x + *w + 2 * c->bw < 0) 357 | *x = 0; 358 | if (*y + *h + 2 * c->bw < 0) 359 | *y = 0; 360 | } else { 361 | if (*x >= m->wx + m->ww) 362 | *x = m->wx + m->ww - WIDTH(c); 363 | if (*y >= m->wy + m->wh) 364 | *y = m->wy + m->wh - HEIGHT(c); 365 | if (*x + *w + 2 * c->bw <= m->wx) 366 | *x = m->wx; 367 | if (*y + *h + 2 * c->bw <= m->wy) 368 | *y = m->wy; 369 | } 370 | if (*h < bh) 371 | *h = bh; 372 | if (*w < bh) 373 | *w = bh; 374 | if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { 375 | if (!c->hintsvalid) 376 | updatesizehints(c); 377 | /* see last two sentences in ICCCM 4.1.2.3 */ 378 | baseismin = c->basew == c->minw && c->baseh == c->minh; 379 | if (!baseismin) { /* temporarily remove base dimensions */ 380 | *w -= c->basew; 381 | *h -= c->baseh; 382 | } 383 | /* adjust for aspect limits */ 384 | if (c->mina > 0 && c->maxa > 0) { 385 | if (c->maxa < (float)*w / *h) 386 | *w = *h * c->maxa + 0.5; 387 | else if (c->mina < (float)*h / *w) 388 | *h = *w * c->mina + 0.5; 389 | } 390 | if (baseismin) { /* increment calculation requires this */ 391 | *w -= c->basew; 392 | *h -= c->baseh; 393 | } 394 | /* adjust for increment value */ 395 | if (c->incw) 396 | *w -= *w % c->incw; 397 | if (c->inch) 398 | *h -= *h % c->inch; 399 | /* restore base dimensions */ 400 | *w = MAX(*w + c->basew, c->minw); 401 | *h = MAX(*h + c->baseh, c->minh); 402 | if (c->maxw) 403 | *w = MIN(*w, c->maxw); 404 | if (c->maxh) 405 | *h = MIN(*h, c->maxh); 406 | } 407 | return *x != c->x || *y != c->y || *w != c->w || *h != c->h; 408 | } 409 | 410 | void 411 | arrange(Monitor *m) 412 | { 413 | if (m) 414 | showhide(m->stack); 415 | else for (m = mons; m; m = m->next) 416 | showhide(m->stack); 417 | if (m) { 418 | arrangemon(m); 419 | restack(m); 420 | } else for (m = mons; m; m = m->next) 421 | arrangemon(m); 422 | } 423 | 424 | void 425 | arrangemon(Monitor *m) 426 | { 427 | strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); 428 | if (m->lt[m->sellt]->arrange) 429 | m->lt[m->sellt]->arrange(m); 430 | } 431 | 432 | void 433 | attach(Client *c) 434 | { 435 | c->next = c->mon->clients; 436 | c->mon->clients = c; 437 | } 438 | 439 | void 440 | attachstack(Client *c) 441 | { 442 | c->snext = c->mon->stack; 443 | c->mon->stack = c; 444 | } 445 | 446 | void 447 | buttonpress(XEvent *e) 448 | { 449 | unsigned int i, x, click; 450 | Arg arg = {0}; 451 | Client *c; 452 | Monitor *m; 453 | XButtonPressedEvent *ev = &e->xbutton; 454 | 455 | click = ClkRootWin; 456 | /* focus monitor if necessary */ 457 | if ((m = wintomon(ev->window)) && m != selmon) { 458 | unfocus(selmon->sel, 1); 459 | selmon = m; 460 | focus(NULL); 461 | } 462 | if (ev->window == selmon->barwin) { 463 | i = x = 0; 464 | do 465 | x += TEXTW(tags[i]); 466 | while (ev->x >= x && ++i < LENGTH(tags)); 467 | if (i < LENGTH(tags)) { 468 | click = ClkTagBar; 469 | arg.ui = 1 << i; 470 | } else if (ev->x < x + TEXTW(selmon->ltsymbol)) 471 | click = ClkLtSymbol; 472 | else 473 | click = ClkStatusText; 474 | } else if ((c = wintoclient(ev->window))) { 475 | focus(c); 476 | restack(selmon); 477 | XAllowEvents(dpy, ReplayPointer, CurrentTime); 478 | click = ClkClientWin; 479 | } 480 | for (i = 0; i < LENGTH(buttons); i++) 481 | if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button 482 | && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) 483 | buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); 484 | } 485 | 486 | void 487 | checkotherwm(void) 488 | { 489 | xerrorxlib = XSetErrorHandler(xerrorstart); 490 | /* this causes an error if some other window manager is running */ 491 | XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); 492 | XSync(dpy, False); 493 | XSetErrorHandler(xerror); 494 | XSync(dpy, False); 495 | } 496 | 497 | void 498 | cleanup(void) 499 | { 500 | Arg a = {.ui = ~0}; 501 | Layout foo = { "", NULL }; 502 | Monitor *m; 503 | size_t i; 504 | 505 | view(&a); 506 | selmon->lt[selmon->sellt] = &foo; 507 | for (m = mons; m; m = m->next) 508 | while (m->stack) 509 | unmanage(m->stack, 0); 510 | XUngrabKey(dpy, AnyKey, AnyModifier, root); 511 | while (mons) 512 | cleanupmon(mons); 513 | for (i = 0; i < CurLast; i++) 514 | drw_cur_free(drw, cursor[i]); 515 | for (i = 0; i < LENGTH(colors) + 1; i++) 516 | free(scheme[i]); 517 | free(scheme); 518 | XDestroyWindow(dpy, wmcheckwin); 519 | drw_free(drw); 520 | XSync(dpy, False); 521 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 522 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); 523 | } 524 | 525 | void 526 | cleanupmon(Monitor *mon) 527 | { 528 | Monitor *m; 529 | 530 | if (mon == mons) 531 | mons = mons->next; 532 | else { 533 | for (m = mons; m && m->next != mon; m = m->next); 534 | m->next = mon->next; 535 | } 536 | XUnmapWindow(dpy, mon->barwin); 537 | XDestroyWindow(dpy, mon->barwin); 538 | free(mon); 539 | } 540 | 541 | void 542 | clientmessage(XEvent *e) 543 | { 544 | XClientMessageEvent *cme = &e->xclient; 545 | Client *c = wintoclient(cme->window); 546 | 547 | if (!c) 548 | return; 549 | if (cme->message_type == netatom[NetWMState]) { 550 | if (cme->data.l[1] == netatom[NetWMFullscreen] 551 | || cme->data.l[2] == netatom[NetWMFullscreen]) 552 | setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ 553 | || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); 554 | } else if (cme->message_type == netatom[NetActiveWindow]) { 555 | if (c != selmon->sel && !c->isurgent) 556 | seturgent(c, 1); 557 | } 558 | } 559 | 560 | void 561 | configure(Client *c) 562 | { 563 | XConfigureEvent ce; 564 | 565 | ce.type = ConfigureNotify; 566 | ce.display = dpy; 567 | ce.event = c->win; 568 | ce.window = c->win; 569 | ce.x = c->x; 570 | ce.y = c->y; 571 | ce.width = c->w; 572 | ce.height = c->h; 573 | ce.border_width = c->bw; 574 | ce.above = None; 575 | ce.override_redirect = False; 576 | XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce); 577 | } 578 | 579 | void 580 | configurenotify(XEvent *e) 581 | { 582 | Monitor *m; 583 | Client *c; 584 | XConfigureEvent *ev = &e->xconfigure; 585 | int dirty; 586 | 587 | /* TODO: updategeom handling sucks, needs to be simplified */ 588 | if (ev->window == root) { 589 | dirty = (sw != ev->width || sh != ev->height); 590 | sw = ev->width; 591 | sh = ev->height; 592 | if (updategeom() || dirty) { 593 | drw_resize(drw, sw, bh); 594 | updatebars(); 595 | for (m = mons; m; m = m->next) { 596 | for (c = m->clients; c; c = c->next) 597 | if (c->isfullscreen) 598 | resizeclient(c, m->mx, m->my, m->mw, m->mh); 599 | XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh); 600 | } 601 | focus(NULL); 602 | arrange(NULL); 603 | } 604 | } 605 | } 606 | 607 | void 608 | configurerequest(XEvent *e) 609 | { 610 | Client *c; 611 | Monitor *m; 612 | XConfigureRequestEvent *ev = &e->xconfigurerequest; 613 | XWindowChanges wc; 614 | 615 | if ((c = wintoclient(ev->window))) { 616 | if (ev->value_mask & CWBorderWidth) 617 | c->bw = ev->border_width; 618 | else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) { 619 | m = c->mon; 620 | if (ev->value_mask & CWX) { 621 | c->oldx = c->x; 622 | c->x = m->mx + ev->x; 623 | } 624 | if (ev->value_mask & CWY) { 625 | c->oldy = c->y; 626 | c->y = m->my + ev->y; 627 | } 628 | if (ev->value_mask & CWWidth) { 629 | c->oldw = c->w; 630 | c->w = ev->width; 631 | } 632 | if (ev->value_mask & CWHeight) { 633 | c->oldh = c->h; 634 | c->h = ev->height; 635 | } 636 | if ((c->x + c->w) > m->mx + m->mw && c->isfloating) 637 | c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */ 638 | if ((c->y + c->h) > m->my + m->mh && c->isfloating) 639 | c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */ 640 | if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) 641 | configure(c); 642 | if (ISVISIBLE(c)) 643 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 644 | } else 645 | configure(c); 646 | } else { 647 | wc.x = ev->x; 648 | wc.y = ev->y; 649 | wc.width = ev->width; 650 | wc.height = ev->height; 651 | wc.border_width = ev->border_width; 652 | wc.sibling = ev->above; 653 | wc.stack_mode = ev->detail; 654 | XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); 655 | } 656 | XSync(dpy, False); 657 | } 658 | 659 | Monitor * 660 | createmon(void) 661 | { 662 | Monitor *m; 663 | 664 | m = ecalloc(1, sizeof(Monitor)); 665 | m->tagset[0] = m->tagset[1] = 1; 666 | m->mfact = mfact; 667 | m->nmaster = nmaster; 668 | m->showbar = showbar; 669 | m->topbar = topbar; 670 | m->gappih = gappih; 671 | m->gappiv = gappiv; 672 | m->gappoh = gappoh; 673 | m->gappov = gappov; 674 | m->colorfultag = colorfultag ? colorfultag : 0; 675 | m->lt[0] = &layouts[0]; 676 | m->lt[1] = &layouts[1 % LENGTH(layouts)]; 677 | strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 678 | return m; 679 | } 680 | 681 | void 682 | destroynotify(XEvent *e) 683 | { 684 | Client *c; 685 | XDestroyWindowEvent *ev = &e->xdestroywindow; 686 | 687 | if ((c = wintoclient(ev->window))) 688 | unmanage(c, 1); 689 | } 690 | 691 | void 692 | detach(Client *c) 693 | { 694 | Client **tc; 695 | 696 | for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); 697 | *tc = c->next; 698 | } 699 | 700 | void 701 | detachstack(Client *c) 702 | { 703 | Client **tc, *t; 704 | 705 | for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); 706 | *tc = c->snext; 707 | 708 | if (c == c->mon->sel) { 709 | for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); 710 | c->mon->sel = t; 711 | } 712 | } 713 | 714 | Monitor * 715 | dirtomon(int dir) 716 | { 717 | Monitor *m = NULL; 718 | 719 | if (dir > 0) { 720 | if (!(m = selmon->next)) 721 | m = mons; 722 | } else if (selmon == mons) 723 | for (m = mons; m->next; m = m->next); 724 | else 725 | for (m = mons; m->next != selmon; m = m->next); 726 | return m; 727 | } 728 | 729 | int 730 | drawstatusbar(Monitor *m, int bh, char* stext) { 731 | int ret, i, w, x, len; 732 | short isCode = 0; 733 | char *text; 734 | char *p; 735 | 736 | len = strlen(stext) + 1 ; 737 | if (!(text = (char*) malloc(sizeof(char)*len))) 738 | die("malloc"); 739 | p = text; 740 | memcpy(text, stext, len); 741 | 742 | /* compute width of the status text */ 743 | w = 0; 744 | i = -1; 745 | while (text[++i]) { 746 | if (text[i] == '^') { 747 | if (!isCode) { 748 | isCode = 1; 749 | text[i] = '\0'; 750 | w += TEXTW(text) - lrpad; 751 | text[i] = '^'; 752 | if (text[++i] == 'f') 753 | w += atoi(text + ++i); 754 | } else { 755 | isCode = 0; 756 | text = text + i + 1; 757 | i = -1; 758 | } 759 | } 760 | } 761 | if (!isCode) 762 | w += TEXTW(text) - lrpad; 763 | else 764 | isCode = 0; 765 | text = p; 766 | 767 | w += 2; /* 1px padding on both sides */ 768 | ret = x = m->ww - w; 769 | 770 | drw_setscheme(drw, scheme[LENGTH(colors)]); 771 | drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; 772 | drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; 773 | drw_rect(drw, x, 0, w, bh, 1, 1); 774 | x++; 775 | 776 | /* process status text */ 777 | i = -1; 778 | while (text[++i]) { 779 | if (text[i] == '^' && !isCode) { 780 | isCode = 1; 781 | 782 | text[i] = '\0'; 783 | w = TEXTW(text) - lrpad; 784 | drw_text(drw, x, 0, w, bh, 0, text, 0); 785 | 786 | x += w; 787 | 788 | /* process code */ 789 | while (text[++i] != '^') { 790 | if (text[i] == 'c') { 791 | char buf[8]; 792 | memcpy(buf, (char*)text+i+1, 7); 793 | buf[7] = '\0'; 794 | drw_clr_create(drw, &drw->scheme[ColFg], buf); 795 | i += 7; 796 | } else if (text[i] == 'b') { 797 | char buf[8]; 798 | memcpy(buf, (char*)text+i+1, 7); 799 | buf[7] = '\0'; 800 | drw_clr_create(drw, &drw->scheme[ColBg], buf); 801 | i += 7; 802 | } else if (text[i] == 'd') { 803 | drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; 804 | drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; 805 | } else if (text[i] == 'r') { 806 | int rx = atoi(text + ++i); 807 | while (text[++i] != ','); 808 | int ry = atoi(text + ++i); 809 | while (text[++i] != ','); 810 | int rw = atoi(text + ++i); 811 | while (text[++i] != ','); 812 | int rh = atoi(text + ++i); 813 | drw_rect(drw, rx + x, ry + borderpx + vertpadbar / 2, rw, rh, 1, 0); 814 | //drw_rect(drw, rx + x, ry, rw, rh, 1, 0); 815 | } else if (text[i] == 'f') { 816 | x += atoi(text + ++i); 817 | } 818 | } 819 | 820 | text = text + i + 1; 821 | i=-1; 822 | isCode = 0; 823 | } 824 | } 825 | 826 | if (!isCode) { 827 | w = TEXTW(text) - lrpad; 828 | drw_text(drw, x, 0, w, bh, 0, text, 0); 829 | } 830 | 831 | drw_setscheme(drw, scheme[SchemeNorm]); 832 | free(p); 833 | 834 | return ret; 835 | } 836 | 837 | void 838 | drawbar(Monitor *m) 839 | { 840 | int x, w, tw = 0; 841 | int boxs = drw->fonts->h / 9; 842 | int boxw = drw->fonts->h / 6 + 2; 843 | unsigned int i, occ = 0, urg = 0; 844 | Client *c; 845 | 846 | XFillRectangle(drw->dpy, drw->drawable, drw->gc, 0, 0, m->ww, bh); 847 | 848 | if (!m->showbar) 849 | return; 850 | 851 | /* draw status first so it can be overdrawn by tags later */ 852 | if (m == selmon) { /* status is only drawn on selected monitor */ 853 | drw_setscheme(drw, scheme[SchemeNorm]); 854 | tw = TEXTW(stext); 855 | tw = m->ww - drawstatusbar(m, bh, stext); 856 | tw = tw - 2 * sp; 857 | } 858 | 859 | for (c = m->clients; c; c = c->next) { 860 | occ |= c->tags; 861 | if (c->isurgent) 862 | urg |= c->tags; 863 | } 864 | x = 0; 865 | for (i = 0; i < LENGTH(tags); i++) { 866 | w = TEXTW(tags[i]); 867 | drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i || occ & 1 << i ? tagschemes[i] : SchemeNorm]); 868 | drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 869 | if (occ & 1 << i) 870 | drw_rect(drw, x + boxs, boxs, boxw, boxw, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, urg & 1 << i); 871 | x += w; 872 | } 873 | w = TEXTW(m->ltsymbol); 874 | drw_setscheme(drw, scheme[SchemeLayout]); 875 | x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 876 | 877 | if ((w = m->ww - tw - x) > bh) { 878 | if (m->sel) { 879 | drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0); 880 | drw_setscheme(drw, scheme[SchemeNorm]); 881 | drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1); 882 | } 883 | } 884 | drw_map(drw, m->barwin, 0, 0, m->ww, bh); 885 | } 886 | 887 | void 888 | drawbars(void) 889 | { 890 | Monitor *m; 891 | 892 | for (m = mons; m; m = m->next) 893 | drawbar(m); 894 | } 895 | 896 | void 897 | enternotify(XEvent *e) 898 | { 899 | Client *c; 900 | Monitor *m; 901 | XCrossingEvent *ev = &e->xcrossing; 902 | 903 | if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) 904 | return; 905 | c = wintoclient(ev->window); 906 | m = c ? c->mon : wintomon(ev->window); 907 | if (m != selmon) { 908 | unfocus(selmon->sel, 1); 909 | selmon = m; 910 | } else if (!c || c == selmon->sel) 911 | return; 912 | focus(c); 913 | } 914 | 915 | void 916 | expose(XEvent *e) 917 | { 918 | Monitor *m; 919 | XExposeEvent *ev = &e->xexpose; 920 | 921 | if (ev->count == 0 && (m = wintomon(ev->window))) 922 | drawbar(m); 923 | } 924 | 925 | void 926 | focus(Client *c) 927 | { 928 | if (!c || !ISVISIBLE(c)) 929 | for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); 930 | if (selmon->sel && selmon->sel != c) 931 | unfocus(selmon->sel, 0); 932 | if (c) { 933 | if (c->mon != selmon) 934 | selmon = c->mon; 935 | if (c->isurgent) 936 | seturgent(c, 0); 937 | detachstack(c); 938 | attachstack(c); 939 | grabbuttons(c, 1); 940 | XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); 941 | setfocus(c); 942 | } else { 943 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 944 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); 945 | } 946 | selmon->sel = c; 947 | drawbars(); 948 | } 949 | 950 | /* there are some broken focus acquiring clients needing extra handling */ 951 | void 952 | focusin(XEvent *e) 953 | { 954 | XFocusChangeEvent *ev = &e->xfocus; 955 | 956 | if (selmon->sel && ev->window != selmon->sel->win) 957 | setfocus(selmon->sel); 958 | } 959 | 960 | void 961 | focusmon(const Arg *arg) 962 | { 963 | Monitor *m; 964 | 965 | if (!mons->next) 966 | return; 967 | if ((m = dirtomon(arg->i)) == selmon) 968 | return; 969 | unfocus(selmon->sel, 0); 970 | selmon = m; 971 | focus(NULL); 972 | } 973 | 974 | void 975 | focusstack(const Arg *arg) 976 | { 977 | Client *c = NULL, *i; 978 | 979 | if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) 980 | return; 981 | if (arg->i > 0) { 982 | for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); 983 | if (!c) 984 | for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); 985 | } else { 986 | for (i = selmon->clients; i != selmon->sel; i = i->next) 987 | if (ISVISIBLE(i)) 988 | c = i; 989 | if (!c) 990 | for (; i; i = i->next) 991 | if (ISVISIBLE(i)) 992 | c = i; 993 | } 994 | if (c) { 995 | focus(c); 996 | restack(selmon); 997 | } 998 | } 999 | 1000 | Atom 1001 | getatomprop(Client *c, Atom prop) 1002 | { 1003 | int di; 1004 | unsigned long dl; 1005 | unsigned char *p = NULL; 1006 | Atom da, atom = None; 1007 | 1008 | if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, 1009 | &da, &di, &dl, &dl, &p) == Success && p) { 1010 | atom = *(Atom *)p; 1011 | XFree(p); 1012 | } 1013 | return atom; 1014 | } 1015 | 1016 | int 1017 | getrootptr(int *x, int *y) 1018 | { 1019 | int di; 1020 | unsigned int dui; 1021 | Window dummy; 1022 | 1023 | return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui); 1024 | } 1025 | 1026 | long 1027 | getstate(Window w) 1028 | { 1029 | int format; 1030 | long result = -1; 1031 | unsigned char *p = NULL; 1032 | unsigned long n, extra; 1033 | Atom real; 1034 | 1035 | if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], 1036 | &real, &format, &n, &extra, (unsigned char **)&p) != Success) 1037 | return -1; 1038 | if (n != 0) 1039 | result = *p; 1040 | XFree(p); 1041 | return result; 1042 | } 1043 | 1044 | int 1045 | gettextprop(Window w, Atom atom, char *text, unsigned int size) 1046 | { 1047 | char **list = NULL; 1048 | int n; 1049 | XTextProperty name; 1050 | 1051 | if (!text || size == 0) 1052 | return 0; 1053 | text[0] = '\0'; 1054 | if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) 1055 | return 0; 1056 | if (name.encoding == XA_STRING) { 1057 | strncpy(text, (char *)name.value, size - 1); 1058 | } else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { 1059 | strncpy(text, *list, size - 1); 1060 | XFreeStringList(list); 1061 | } 1062 | text[size - 1] = '\0'; 1063 | XFree(name.value); 1064 | return 1; 1065 | } 1066 | 1067 | void 1068 | grabbuttons(Client *c, int focused) 1069 | { 1070 | updatenumlockmask(); 1071 | { 1072 | unsigned int i, j; 1073 | unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; 1074 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 1075 | if (!focused) 1076 | XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, 1077 | BUTTONMASK, GrabModeSync, GrabModeSync, None, None); 1078 | for (i = 0; i < LENGTH(buttons); i++) 1079 | if (buttons[i].click == ClkClientWin) 1080 | for (j = 0; j < LENGTH(modifiers); j++) 1081 | XGrabButton(dpy, buttons[i].button, 1082 | buttons[i].mask | modifiers[j], 1083 | c->win, False, BUTTONMASK, 1084 | GrabModeAsync, GrabModeSync, None, None); 1085 | } 1086 | } 1087 | 1088 | void 1089 | grabkeys(void) 1090 | { 1091 | updatenumlockmask(); 1092 | { 1093 | unsigned int i, j; 1094 | unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; 1095 | KeyCode code; 1096 | 1097 | XUngrabKey(dpy, AnyKey, AnyModifier, root); 1098 | for (i = 0; i < LENGTH(keys); i++) 1099 | if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) 1100 | for (j = 0; j < LENGTH(modifiers); j++) 1101 | XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, 1102 | True, GrabModeAsync, GrabModeAsync); 1103 | } 1104 | } 1105 | 1106 | void 1107 | incnmaster(const Arg *arg) 1108 | { 1109 | selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); 1110 | arrange(selmon); 1111 | } 1112 | 1113 | #ifdef XINERAMA 1114 | static int 1115 | isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) 1116 | { 1117 | while (n--) 1118 | if (unique[n].x_org == info->x_org && unique[n].y_org == info->y_org 1119 | && unique[n].width == info->width && unique[n].height == info->height) 1120 | return 0; 1121 | return 1; 1122 | } 1123 | #endif /* XINERAMA */ 1124 | 1125 | void 1126 | keypress(XEvent *e) 1127 | { 1128 | unsigned int i; 1129 | KeySym keysym; 1130 | XKeyEvent *ev; 1131 | 1132 | ev = &e->xkey; 1133 | keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 1134 | for (i = 0; i < LENGTH(keys); i++) 1135 | if (keysym == keys[i].keysym 1136 | && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) 1137 | && keys[i].func) 1138 | keys[i].func(&(keys[i].arg)); 1139 | } 1140 | 1141 | void 1142 | killclient(const Arg *arg) 1143 | { 1144 | if (!selmon->sel) 1145 | return; 1146 | if (!sendevent(selmon->sel, wmatom[WMDelete])) { 1147 | XGrabServer(dpy); 1148 | XSetErrorHandler(xerrordummy); 1149 | XSetCloseDownMode(dpy, DestroyAll); 1150 | XKillClient(dpy, selmon->sel->win); 1151 | XSync(dpy, False); 1152 | XSetErrorHandler(xerror); 1153 | XUngrabServer(dpy); 1154 | } 1155 | } 1156 | 1157 | void 1158 | manage(Window w, XWindowAttributes *wa) 1159 | { 1160 | Client *c, *t = NULL; 1161 | Window trans = None; 1162 | XWindowChanges wc; 1163 | 1164 | c = ecalloc(1, sizeof(Client)); 1165 | c->win = w; 1166 | /* geometry */ 1167 | c->x = c->oldx = wa->x; 1168 | c->y = c->oldy = wa->y; 1169 | c->w = c->oldw = wa->width; 1170 | c->h = c->oldh = wa->height; 1171 | c->oldbw = wa->border_width; 1172 | 1173 | updatetitle(c); 1174 | if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { 1175 | c->mon = t->mon; 1176 | c->tags = t->tags; 1177 | } else { 1178 | c->mon = selmon; 1179 | applyrules(c); 1180 | } 1181 | 1182 | if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww) 1183 | c->x = c->mon->wx + c->mon->ww - WIDTH(c); 1184 | if (c->y + HEIGHT(c) > c->mon->wy + c->mon->wh) 1185 | c->y = c->mon->wy + c->mon->wh - HEIGHT(c); 1186 | c->x = MAX(c->x, c->mon->wx); 1187 | c->y = MAX(c->y, c->mon->wy); 1188 | c->bw = borderpx; 1189 | 1190 | wc.border_width = c->bw; 1191 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); 1192 | XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); 1193 | configure(c); /* propagates border_width, if size doesn't change */ 1194 | updatewindowtype(c); 1195 | updatesizehints(c); 1196 | updatewmhints(c); 1197 | c->x = c->mon->mx + (c->mon->mw - WIDTH(c)) / 2; 1198 | c->y = c->mon->my + (c->mon->mh - HEIGHT(c)) / 2; 1199 | XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); 1200 | grabbuttons(c, 0); 1201 | if (!c->isfloating) 1202 | c->isfloating = c->oldstate = trans != None || c->isfixed; 1203 | if (c->isfloating) 1204 | XRaiseWindow(dpy, c->win); 1205 | attach(c); 1206 | attachstack(c); 1207 | XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, 1208 | (unsigned char *) &(c->win), 1); 1209 | XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ 1210 | setclientstate(c, NormalState); 1211 | if (c->mon == selmon) 1212 | unfocus(selmon->sel, 0); 1213 | c->mon->sel = c; 1214 | arrange(c->mon); 1215 | XMapWindow(dpy, c->win); 1216 | focus(NULL); 1217 | } 1218 | 1219 | void 1220 | mappingnotify(XEvent *e) 1221 | { 1222 | XMappingEvent *ev = &e->xmapping; 1223 | 1224 | XRefreshKeyboardMapping(ev); 1225 | if (ev->request == MappingKeyboard) 1226 | grabkeys(); 1227 | } 1228 | 1229 | void 1230 | maprequest(XEvent *e) 1231 | { 1232 | static XWindowAttributes wa; 1233 | XMapRequestEvent *ev = &e->xmaprequest; 1234 | 1235 | if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect) 1236 | return; 1237 | if (!wintoclient(ev->window)) 1238 | manage(ev->window, &wa); 1239 | } 1240 | 1241 | void 1242 | monocle(Monitor *m) 1243 | { 1244 | unsigned int n = 0; 1245 | Client *c; 1246 | 1247 | for (c = m->clients; c; c = c->next) 1248 | if (ISVISIBLE(c)) 1249 | n++; 1250 | if (n > 0) /* override layout symbol */ 1251 | snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); 1252 | for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) 1253 | resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); 1254 | } 1255 | 1256 | void 1257 | motionnotify(XEvent *e) 1258 | { 1259 | static Monitor *mon = NULL; 1260 | Monitor *m; 1261 | XMotionEvent *ev = &e->xmotion; 1262 | 1263 | if (ev->window != root) 1264 | return; 1265 | if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { 1266 | unfocus(selmon->sel, 1); 1267 | selmon = m; 1268 | focus(NULL); 1269 | } 1270 | mon = m; 1271 | } 1272 | 1273 | void 1274 | movemouse(const Arg *arg) 1275 | { 1276 | int x, y, ocx, ocy, nx, ny; 1277 | Client *c; 1278 | Monitor *m; 1279 | XEvent ev; 1280 | Time lasttime = 0; 1281 | 1282 | if (!(c = selmon->sel)) 1283 | return; 1284 | if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ 1285 | return; 1286 | restack(selmon); 1287 | ocx = c->x; 1288 | ocy = c->y; 1289 | if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 1290 | None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) 1291 | return; 1292 | if (!getrootptr(&x, &y)) 1293 | return; 1294 | do { 1295 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); 1296 | switch(ev.type) { 1297 | case ConfigureRequest: 1298 | case Expose: 1299 | case MapRequest: 1300 | handler[ev.type](&ev); 1301 | break; 1302 | case MotionNotify: 1303 | if ((ev.xmotion.time - lasttime) <= (1000 / 60)) 1304 | continue; 1305 | lasttime = ev.xmotion.time; 1306 | 1307 | nx = ocx + (ev.xmotion.x - x); 1308 | ny = ocy + (ev.xmotion.y - y); 1309 | if (abs(selmon->wx - nx) < snap) 1310 | nx = selmon->wx; 1311 | else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) 1312 | nx = selmon->wx + selmon->ww - WIDTH(c); 1313 | if (abs(selmon->wy - ny) < snap) 1314 | ny = selmon->wy; 1315 | else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) 1316 | ny = selmon->wy + selmon->wh - HEIGHT(c); 1317 | if (!c->isfloating && selmon->lt[selmon->sellt]->arrange 1318 | && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) 1319 | togglefloating(NULL); 1320 | if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) 1321 | resize(c, nx, ny, c->w, c->h, 1); 1322 | break; 1323 | } 1324 | } while (ev.type != ButtonRelease); 1325 | XUngrabPointer(dpy, CurrentTime); 1326 | if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { 1327 | sendmon(c, m); 1328 | selmon = m; 1329 | focus(NULL); 1330 | } 1331 | } 1332 | 1333 | Client * 1334 | nexttiled(Client *c) 1335 | { 1336 | for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); 1337 | return c; 1338 | } 1339 | 1340 | void 1341 | pop(Client *c) 1342 | { 1343 | detach(c); 1344 | attach(c); 1345 | focus(c); 1346 | arrange(c->mon); 1347 | } 1348 | 1349 | void 1350 | propertynotify(XEvent *e) 1351 | { 1352 | Client *c; 1353 | Window trans; 1354 | XPropertyEvent *ev = &e->xproperty; 1355 | 1356 | if ((ev->window == root) && (ev->atom == XA_WM_NAME)) 1357 | updatestatus(); 1358 | else if (ev->state == PropertyDelete) 1359 | return; /* ignore */ 1360 | else if ((c = wintoclient(ev->window))) { 1361 | switch(ev->atom) { 1362 | default: break; 1363 | case XA_WM_TRANSIENT_FOR: 1364 | if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && 1365 | (c->isfloating = (wintoclient(trans)) != NULL)) 1366 | arrange(c->mon); 1367 | break; 1368 | case XA_WM_NORMAL_HINTS: 1369 | c->hintsvalid = 0; 1370 | break; 1371 | case XA_WM_HINTS: 1372 | updatewmhints(c); 1373 | drawbars(); 1374 | break; 1375 | } 1376 | /* if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {*/ 1377 | if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) 1378 | updatetitle(c); 1379 | /* if (c == c->mon->sel) 1380 | drawbar(c->mon); 1381 | }*/ 1382 | if (ev->atom == netatom[NetWMWindowType]) 1383 | updatewindowtype(c); 1384 | } 1385 | } 1386 | 1387 | void 1388 | quit(const Arg *arg) 1389 | { 1390 | running = 0; 1391 | } 1392 | 1393 | Monitor * 1394 | recttomon(int x, int y, int w, int h) 1395 | { 1396 | Monitor *m, *r = selmon; 1397 | int a, area = 0; 1398 | 1399 | for (m = mons; m; m = m->next) 1400 | if ((a = INTERSECT(x, y, w, h, m)) > area) { 1401 | area = a; 1402 | r = m; 1403 | } 1404 | return r; 1405 | } 1406 | 1407 | void 1408 | resize(Client *c, int x, int y, int w, int h, int interact) 1409 | { 1410 | if (applysizehints(c, &x, &y, &w, &h, interact)) 1411 | resizeclient(c, x, y, w, h); 1412 | } 1413 | 1414 | void 1415 | resizeclient(Client *c, int x, int y, int w, int h) 1416 | { 1417 | XWindowChanges wc; 1418 | 1419 | c->oldx = c->x; c->x = wc.x = x; 1420 | c->oldy = c->y; c->y = wc.y = y; 1421 | c->oldw = c->w; c->w = wc.width = w; 1422 | c->oldh = c->h; c->h = wc.height = h; 1423 | wc.border_width = c->bw; 1424 | XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); 1425 | configure(c); 1426 | XSync(dpy, False); 1427 | } 1428 | 1429 | void 1430 | resizemouse(const Arg *arg) 1431 | { 1432 | int ocx, ocy, nw, nh; 1433 | Client *c; 1434 | Monitor *m; 1435 | XEvent ev; 1436 | Time lasttime = 0; 1437 | 1438 | if (!(c = selmon->sel)) 1439 | return; 1440 | if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ 1441 | return; 1442 | restack(selmon); 1443 | ocx = c->x; 1444 | ocy = c->y; 1445 | if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 1446 | None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) 1447 | return; 1448 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); 1449 | do { 1450 | XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); 1451 | switch(ev.type) { 1452 | case ConfigureRequest: 1453 | case Expose: 1454 | case MapRequest: 1455 | handler[ev.type](&ev); 1456 | break; 1457 | case MotionNotify: 1458 | if ((ev.xmotion.time - lasttime) <= (1000 / 60)) 1459 | continue; 1460 | lasttime = ev.xmotion.time; 1461 | 1462 | nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); 1463 | nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); 1464 | if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww 1465 | && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) 1466 | { 1467 | if (!c->isfloating && selmon->lt[selmon->sellt]->arrange 1468 | && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) 1469 | togglefloating(NULL); 1470 | } 1471 | if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) 1472 | resize(c, c->x, c->y, nw, nh, 1); 1473 | break; 1474 | } 1475 | } while (ev.type != ButtonRelease); 1476 | XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); 1477 | XUngrabPointer(dpy, CurrentTime); 1478 | while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 1479 | if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { 1480 | sendmon(c, m); 1481 | selmon = m; 1482 | focus(NULL); 1483 | } 1484 | } 1485 | 1486 | void 1487 | restack(Monitor *m) 1488 | { 1489 | Client *c; 1490 | XEvent ev; 1491 | XWindowChanges wc; 1492 | 1493 | drawbar(m); 1494 | if (!m->sel) 1495 | return; 1496 | if (m->sel->isfloating || !m->lt[m->sellt]->arrange) 1497 | XRaiseWindow(dpy, m->sel->win); 1498 | if (m->lt[m->sellt]->arrange) { 1499 | wc.stack_mode = Below; 1500 | wc.sibling = m->barwin; 1501 | for (c = m->stack; c; c = c->snext) 1502 | if (!c->isfloating && ISVISIBLE(c)) { 1503 | XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); 1504 | wc.sibling = c->win; 1505 | } 1506 | } 1507 | XSync(dpy, False); 1508 | while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 1509 | } 1510 | 1511 | void 1512 | run(void) 1513 | { 1514 | XEvent ev; 1515 | /* main event loop */ 1516 | XSync(dpy, False); 1517 | while (running && !XNextEvent(dpy, &ev)) 1518 | if (handler[ev.type]) 1519 | handler[ev.type](&ev); /* call handler */ 1520 | } 1521 | 1522 | void 1523 | runAutostart(void) { 1524 | system("cd ~/dot/dwm/autostart; ./autostart_blocking"); 1525 | system("cd ~/dot/dwm/autostart; ./autostart &"); 1526 | } 1527 | 1528 | void 1529 | scan(void) 1530 | { 1531 | unsigned int i, num; 1532 | Window d1, d2, *wins = NULL; 1533 | XWindowAttributes wa; 1534 | 1535 | if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { 1536 | for (i = 0; i < num; i++) { 1537 | if (!XGetWindowAttributes(dpy, wins[i], &wa) 1538 | || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) 1539 | continue; 1540 | if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState) 1541 | manage(wins[i], &wa); 1542 | } 1543 | for (i = 0; i < num; i++) { /* now the transients */ 1544 | if (!XGetWindowAttributes(dpy, wins[i], &wa)) 1545 | continue; 1546 | if (XGetTransientForHint(dpy, wins[i], &d1) 1547 | && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)) 1548 | manage(wins[i], &wa); 1549 | } 1550 | if (wins) 1551 | XFree(wins); 1552 | } 1553 | } 1554 | 1555 | void 1556 | sendmon(Client *c, Monitor *m) 1557 | { 1558 | if (c->mon == m) 1559 | return; 1560 | unfocus(c, 1); 1561 | detach(c); 1562 | detachstack(c); 1563 | c->mon = m; 1564 | c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ 1565 | attach(c); 1566 | attachstack(c); 1567 | focus(NULL); 1568 | arrange(NULL); 1569 | } 1570 | 1571 | void 1572 | setclientstate(Client *c, long state) 1573 | { 1574 | long data[] = { state, None }; 1575 | 1576 | XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, 1577 | PropModeReplace, (unsigned char *)data, 2); 1578 | } 1579 | 1580 | int 1581 | sendevent(Client *c, Atom proto) 1582 | { 1583 | int n; 1584 | Atom *protocols; 1585 | int exists = 0; 1586 | XEvent ev; 1587 | 1588 | if (XGetWMProtocols(dpy, c->win, &protocols, &n)) { 1589 | while (!exists && n--) 1590 | exists = protocols[n] == proto; 1591 | XFree(protocols); 1592 | } 1593 | if (exists) { 1594 | ev.type = ClientMessage; 1595 | ev.xclient.window = c->win; 1596 | ev.xclient.message_type = wmatom[WMProtocols]; 1597 | ev.xclient.format = 32; 1598 | ev.xclient.data.l[0] = proto; 1599 | ev.xclient.data.l[1] = CurrentTime; 1600 | XSendEvent(dpy, c->win, False, NoEventMask, &ev); 1601 | } 1602 | return exists; 1603 | } 1604 | 1605 | void 1606 | setfocus(Client *c) 1607 | { 1608 | if (!c->neverfocus) { 1609 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 1610 | XChangeProperty(dpy, root, netatom[NetActiveWindow], 1611 | XA_WINDOW, 32, PropModeReplace, 1612 | (unsigned char *) &(c->win), 1); 1613 | } 1614 | sendevent(c, wmatom[WMTakeFocus]); 1615 | } 1616 | 1617 | void 1618 | setfullscreen(Client *c, int fullscreen) 1619 | { 1620 | if (fullscreen && !c->isfullscreen) { 1621 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, 1622 | PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); 1623 | c->isfullscreen = 1; 1624 | c->oldstate = c->isfloating; 1625 | c->oldbw = c->bw; 1626 | c->bw = 0; 1627 | c->isfloating = 1; 1628 | resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); 1629 | XRaiseWindow(dpy, c->win); 1630 | } else if (!fullscreen && c->isfullscreen){ 1631 | XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, 1632 | PropModeReplace, (unsigned char*)0, 0); 1633 | c->isfullscreen = 0; 1634 | c->isfloating = c->oldstate; 1635 | c->bw = c->oldbw; 1636 | c->x = c->oldx; 1637 | c->y = c->oldy; 1638 | c->w = c->oldw; 1639 | c->h = c->oldh; 1640 | resizeclient(c, c->x, c->y, c->w, c->h); 1641 | arrange(c->mon); 1642 | } 1643 | } 1644 | 1645 | void 1646 | setgaps(int oh, int ov, int ih, int iv) 1647 | { 1648 | if (oh < 0) oh = 0; 1649 | if (ov < 0) ov = 0; 1650 | if (ih < 0) ih = 0; 1651 | if (iv < 0) iv = 0; 1652 | 1653 | selmon->gappoh = oh; 1654 | selmon->gappov = ov; 1655 | selmon->gappih = ih; 1656 | selmon->gappiv = iv; 1657 | arrange(selmon); 1658 | } 1659 | 1660 | void 1661 | togglegaps(const Arg *arg) 1662 | { 1663 | enablegaps = !enablegaps; 1664 | arrange(selmon); 1665 | } 1666 | 1667 | void 1668 | defaultgaps(const Arg *arg) 1669 | { 1670 | setgaps(gappoh, gappov, gappih, gappiv); 1671 | } 1672 | 1673 | void 1674 | incrgaps(const Arg *arg) 1675 | { 1676 | setgaps( 1677 | selmon->gappoh + arg->i, 1678 | selmon->gappov + arg->i, 1679 | selmon->gappih + arg->i, 1680 | selmon->gappiv + arg->i 1681 | ); 1682 | } 1683 | 1684 | void 1685 | incrigaps(const Arg *arg) 1686 | { 1687 | setgaps( 1688 | selmon->gappoh, 1689 | selmon->gappov, 1690 | selmon->gappih + arg->i, 1691 | selmon->gappiv + arg->i 1692 | ); 1693 | } 1694 | 1695 | void 1696 | incrogaps(const Arg *arg) 1697 | { 1698 | setgaps( 1699 | selmon->gappoh + arg->i, 1700 | selmon->gappov + arg->i, 1701 | selmon->gappih, 1702 | selmon->gappiv 1703 | ); 1704 | } 1705 | 1706 | void 1707 | incrohgaps(const Arg *arg) 1708 | { 1709 | setgaps( 1710 | selmon->gappoh + arg->i, 1711 | selmon->gappov, 1712 | selmon->gappih, 1713 | selmon->gappiv 1714 | ); 1715 | } 1716 | 1717 | void 1718 | incrovgaps(const Arg *arg) 1719 | { 1720 | setgaps( 1721 | selmon->gappoh, 1722 | selmon->gappov + arg->i, 1723 | selmon->gappih, 1724 | selmon->gappiv 1725 | ); 1726 | } 1727 | 1728 | void 1729 | incrihgaps(const Arg *arg) 1730 | { 1731 | setgaps( 1732 | selmon->gappoh, 1733 | selmon->gappov, 1734 | selmon->gappih + arg->i, 1735 | selmon->gappiv 1736 | ); 1737 | } 1738 | 1739 | void 1740 | incrivgaps(const Arg *arg) 1741 | { 1742 | setgaps( 1743 | selmon->gappoh, 1744 | selmon->gappov, 1745 | selmon->gappih, 1746 | selmon->gappiv + arg->i 1747 | ); 1748 | } 1749 | 1750 | void 1751 | setlayout(const Arg *arg) 1752 | { 1753 | if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 1754 | selmon->sellt ^= 1; 1755 | if (arg && arg->v) 1756 | selmon->lt[selmon->sellt] = (Layout *)arg->v; 1757 | strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); 1758 | if (selmon->sel) 1759 | arrange(selmon); 1760 | else 1761 | drawbar(selmon); 1762 | } 1763 | 1764 | /* arg > 1.0 will set mfact absolutely */ 1765 | void 1766 | setmfact(const Arg *arg) 1767 | { 1768 | float f; 1769 | 1770 | if (!arg || !selmon->lt[selmon->sellt]->arrange) 1771 | return; 1772 | f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; 1773 | if (f < 0.05 || f > 0.95) 1774 | return; 1775 | selmon->mfact = f; 1776 | arrange(selmon); 1777 | } 1778 | 1779 | void 1780 | setup(void) 1781 | { 1782 | int i; 1783 | XSetWindowAttributes wa; 1784 | Atom utf8string; 1785 | 1786 | /* clean up any zombies immediately */ 1787 | sigchld(0); 1788 | 1789 | /* init screen */ 1790 | screen = DefaultScreen(dpy); 1791 | sw = DisplayWidth(dpy, screen); 1792 | sh = DisplayHeight(dpy, screen); 1793 | root = RootWindow(dpy, screen); 1794 | drw = drw_create(dpy, screen, root, sw, sh); 1795 | if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) 1796 | die("no fonts could be loaded."); 1797 | lrpad = drw->fonts->h + horizpadbar; 1798 | bh = drw->fonts->h + vertpadbar; 1799 | sp = sidepad; 1800 | vp = (topbar == 1) ? vertpad : - vertpad; 1801 | updategeom(); 1802 | /* init atoms */ 1803 | utf8string = XInternAtom(dpy, "UTF8_STRING", False); 1804 | wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 1805 | wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 1806 | wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); 1807 | wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False); 1808 | netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); 1809 | netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); 1810 | netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); 1811 | netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); 1812 | netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); 1813 | netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); 1814 | netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); 1815 | netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); 1816 | netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); 1817 | /* init cursors */ 1818 | cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); 1819 | cursor[CurResize] = drw_cur_create(drw, XC_sizing); 1820 | cursor[CurMove] = drw_cur_create(drw, XC_fleur); 1821 | /* init appearance */ 1822 | scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); 1823 | scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3); 1824 | for (i = 0; i < LENGTH(colors); i++) 1825 | scheme[i] = drw_scm_create(drw, colors[i], 3); 1826 | /* init bars */ 1827 | updatebars(); 1828 | updatestatus(); 1829 | /* supporting window for NetWMCheck */ 1830 | wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); 1831 | XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, 1832 | PropModeReplace, (unsigned char *) &wmcheckwin, 1); 1833 | XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8, 1834 | PropModeReplace, (unsigned char *) "dwm", 3); 1835 | XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, 1836 | PropModeReplace, (unsigned char *) &wmcheckwin, 1); 1837 | /* EWMH support per view */ 1838 | XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, 1839 | PropModeReplace, (unsigned char *) netatom, NetLast); 1840 | XDeleteProperty(dpy, root, netatom[NetClientList]); 1841 | /* select events */ 1842 | wa.cursor = cursor[CurNormal]->cursor; 1843 | wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask 1844 | |ButtonPressMask|PointerMotionMask|EnterWindowMask 1845 | |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; 1846 | XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); 1847 | XSelectInput(dpy, root, wa.event_mask); 1848 | grabkeys(); 1849 | focus(NULL); 1850 | } 1851 | 1852 | void 1853 | seturgent(Client *c, int urg) 1854 | { 1855 | XWMHints *wmh; 1856 | 1857 | c->isurgent = urg; 1858 | if (!(wmh = XGetWMHints(dpy, c->win))) 1859 | return; 1860 | wmh->flags = urg ? (wmh->flags | XUrgencyHint) : (wmh->flags & ~XUrgencyHint); 1861 | XSetWMHints(dpy, c->win, wmh); 1862 | XFree(wmh); 1863 | } 1864 | 1865 | void 1866 | showhide(Client *c) 1867 | { 1868 | if (!c) 1869 | return; 1870 | if (ISVISIBLE(c)) { 1871 | /* show clients top down */ 1872 | XMoveWindow(dpy, c->win, c->x, c->y); 1873 | if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen) 1874 | resize(c, c->x, c->y, c->w, c->h, 0); 1875 | showhide(c->snext); 1876 | } else { 1877 | /* hide clients bottom up */ 1878 | showhide(c->snext); 1879 | XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); 1880 | } 1881 | } 1882 | 1883 | void 1884 | sigchld(int unused) 1885 | { 1886 | if (signal(SIGCHLD, sigchld) == SIG_ERR) 1887 | die("can't install SIGCHLD handler:"); 1888 | while (0 < waitpid(-1, NULL, WNOHANG)); 1889 | } 1890 | 1891 | void 1892 | spawn(const Arg *arg) 1893 | { 1894 | if (fork() == 0) { 1895 | if (dpy) 1896 | close(ConnectionNumber(dpy)); 1897 | setsid(); 1898 | execvp(((char **)arg->v)[0], (char **)arg->v); 1899 | die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]); 1900 | } 1901 | } 1902 | 1903 | void 1904 | tag(const Arg *arg) 1905 | { 1906 | if (selmon->sel && arg->ui & TAGMASK) { 1907 | selmon->sel->tags = arg->ui & TAGMASK; 1908 | focus(NULL); 1909 | arrange(selmon); 1910 | } 1911 | } 1912 | 1913 | void 1914 | tagmon(const Arg *arg) 1915 | { 1916 | if (!selmon->sel || !mons->next) 1917 | return; 1918 | sendmon(selmon->sel, dirtomon(arg->i)); 1919 | } 1920 | 1921 | void 1922 | tile(Monitor *m) 1923 | { 1924 | unsigned int i, n, h, r, oe = enablegaps, ie = enablegaps, mw, my, ty; 1925 | Client *c; 1926 | 1927 | for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); 1928 | if (n == 0) 1929 | return; 1930 | 1931 | if (smartgaps == n) { 1932 | oe = 0; // outer gaps disabled 1933 | } 1934 | 1935 | if (n > m->nmaster) 1936 | mw = m->nmaster ? (m->ww + m->gappiv*ie) * m->mfact : 0; 1937 | else 1938 | mw = m->ww - 2*m->gappov*oe + m->gappiv*ie; 1939 | for (i = 0, my = ty = m->gappoh*oe, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) 1940 | if (i < m->nmaster) { 1941 | r = MIN(n, m->nmaster) - i; 1942 | h = (m->wh - my - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; 1943 | resize(c, m->wx + m->gappov*oe, m->wy + my, mw - (2*c->bw) - m->gappiv*ie, h - (2*c->bw), 0); 1944 | if (my + HEIGHT(c) + m->gappih*ie < m->wh) 1945 | my += HEIGHT(c) + m->gappih*ie; 1946 | } else { 1947 | r = n - i; 1948 | h = (m->wh - ty - m->gappoh*oe - m->gappih*ie * (r - 1)) / r; 1949 | resize(c, m->wx + mw + m->gappov*oe, m->wy + ty, m->ww - mw - (2*c->bw) - 2*m->gappov*oe, h - (2*c->bw), 0); 1950 | if (ty + HEIGHT(c) + m->gappih*ie < m->wh) 1951 | ty += HEIGHT(c) + m->gappih*ie; 1952 | } 1953 | } 1954 | 1955 | void 1956 | togglebar(const Arg *arg) 1957 | { 1958 | selmon->showbar = !selmon->showbar; 1959 | updatebarpos(selmon); 1960 | XMoveResizeWindow(dpy, selmon->barwin, selmon->wx + sp, selmon->by + vp, selmon->ww - 2 * sp, bh); 1961 | arrange(selmon); 1962 | } 1963 | 1964 | void 1965 | togglecolorfultag() 1966 | { 1967 | selmon->colorfultag = !selmon->colorfultag; 1968 | drawbar(selmon); 1969 | } 1970 | 1971 | void 1972 | togglefloating(const Arg *arg) 1973 | { 1974 | if (!selmon->sel) 1975 | return; 1976 | if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ 1977 | return; 1978 | selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; 1979 | if (selmon->sel->isfloating) 1980 | resize(selmon->sel, selmon->sel->x, selmon->sel->y, 1981 | selmon->sel->w, selmon->sel->h, 0); 1982 | arrange(selmon); 1983 | } 1984 | 1985 | void 1986 | togglefullscr(const Arg *arg) 1987 | { 1988 | if(selmon->sel) 1989 | setfullscreen(selmon->sel, !selmon->sel->isfullscreen); 1990 | } 1991 | 1992 | void 1993 | toggletag(const Arg *arg) 1994 | { 1995 | unsigned int newtags; 1996 | 1997 | if (!selmon->sel) 1998 | return; 1999 | newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); 2000 | if (newtags) { 2001 | selmon->sel->tags = newtags; 2002 | focus(NULL); 2003 | arrange(selmon); 2004 | } 2005 | } 2006 | 2007 | void 2008 | toggleview(const Arg *arg) 2009 | { 2010 | unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); 2011 | 2012 | if (newtagset) { 2013 | selmon->tagset[selmon->seltags] = newtagset; 2014 | focus(NULL); 2015 | arrange(selmon); 2016 | } 2017 | } 2018 | 2019 | void 2020 | unfocus(Client *c, int setfocus) 2021 | { 2022 | if (!c) 2023 | return; 2024 | grabbuttons(c, 0); 2025 | XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); 2026 | if (setfocus) { 2027 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 2028 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); 2029 | } 2030 | } 2031 | 2032 | void 2033 | unmanage(Client *c, int destroyed) 2034 | { 2035 | Monitor *m = c->mon; 2036 | XWindowChanges wc; 2037 | 2038 | detach(c); 2039 | detachstack(c); 2040 | if (!destroyed) { 2041 | wc.border_width = c->oldbw; 2042 | XGrabServer(dpy); /* avoid race conditions */ 2043 | XSetErrorHandler(xerrordummy); 2044 | XSelectInput(dpy, c->win, NoEventMask); 2045 | XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ 2046 | XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 2047 | setclientstate(c, WithdrawnState); 2048 | XSync(dpy, False); 2049 | XSetErrorHandler(xerror); 2050 | XUngrabServer(dpy); 2051 | } 2052 | free(c); 2053 | focus(NULL); 2054 | updateclientlist(); 2055 | arrange(m); 2056 | } 2057 | 2058 | void 2059 | unmapnotify(XEvent *e) 2060 | { 2061 | Client *c; 2062 | XUnmapEvent *ev = &e->xunmap; 2063 | 2064 | if ((c = wintoclient(ev->window))) { 2065 | if (ev->send_event) 2066 | setclientstate(c, WithdrawnState); 2067 | else 2068 | unmanage(c, 0); 2069 | } 2070 | } 2071 | 2072 | void 2073 | updatebars(void) 2074 | { 2075 | Monitor *m; 2076 | XSetWindowAttributes wa = { 2077 | .override_redirect = True, 2078 | .background_pixmap = ParentRelative, 2079 | .event_mask = ButtonPressMask|ExposureMask 2080 | }; 2081 | XClassHint ch = {"dwm", "dwm"}; 2082 | for (m = mons; m; m = m->next) { 2083 | if (m->barwin) 2084 | continue; 2085 | m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen), 2086 | CopyFromParent, DefaultVisual(dpy, screen), 2087 | CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); 2088 | XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); 2089 | XMapRaised(dpy, m->barwin); 2090 | XSetClassHint(dpy, m->barwin, &ch); 2091 | } 2092 | } 2093 | 2094 | void 2095 | updatebarpos(Monitor *m) 2096 | { 2097 | m->wy = m->my; 2098 | m->wh = m->mh; 2099 | if (m->showbar) { 2100 | m->wh = m->wh - vertpad - bh; 2101 | m->by = m->topbar ? m->wy : m->wy + m->wh + vertpad; 2102 | m->wy = m->topbar ? m->wy + bh + vp : m->wy; 2103 | } else 2104 | m->by = -bh - vp; 2105 | } 2106 | 2107 | void 2108 | updateclientlist() 2109 | { 2110 | Client *c; 2111 | Monitor *m; 2112 | 2113 | XDeleteProperty(dpy, root, netatom[NetClientList]); 2114 | for (m = mons; m; m = m->next) 2115 | for (c = m->clients; c; c = c->next) 2116 | XChangeProperty(dpy, root, netatom[NetClientList], 2117 | XA_WINDOW, 32, PropModeAppend, 2118 | (unsigned char *) &(c->win), 1); 2119 | } 2120 | 2121 | int 2122 | updategeom(void) 2123 | { 2124 | int dirty = 0; 2125 | 2126 | #ifdef XINERAMA 2127 | if (XineramaIsActive(dpy)) { 2128 | int i, j, n, nn; 2129 | Client *c; 2130 | Monitor *m; 2131 | XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); 2132 | XineramaScreenInfo *unique = NULL; 2133 | 2134 | for (n = 0, m = mons; m; m = m->next, n++); 2135 | /* only consider unique geometries as separate screens */ 2136 | unique = ecalloc(nn, sizeof(XineramaScreenInfo)); 2137 | for (i = 0, j = 0; i < nn; i++) 2138 | if (isuniquegeom(unique, j, &info[i])) 2139 | memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); 2140 | XFree(info); 2141 | nn = j; 2142 | 2143 | /* new monitors if nn > n */ 2144 | for (i = n; i < nn; i++) { 2145 | for (m = mons; m && m->next; m = m->next); 2146 | if (m) 2147 | m->next = createmon(); 2148 | else 2149 | mons = createmon(); 2150 | } 2151 | for (i = 0, m = mons; i < nn && m; m = m->next, i++) 2152 | if (i >= n 2153 | || unique[i].x_org != m->mx || unique[i].y_org != m->my 2154 | || unique[i].width != m->mw || unique[i].height != m->mh) 2155 | { 2156 | dirty = 1; 2157 | m->num = i; 2158 | m->mx = m->wx = unique[i].x_org; 2159 | m->my = m->wy = unique[i].y_org; 2160 | m->mw = m->ww = unique[i].width; 2161 | m->mh = m->wh = unique[i].height; 2162 | updatebarpos(m); 2163 | } 2164 | /* removed monitors if n > nn */ 2165 | for (i = nn; i < n; i++) { 2166 | for (m = mons; m && m->next; m = m->next); 2167 | while ((c = m->clients)) { 2168 | dirty = 1; 2169 | m->clients = c->next; 2170 | detachstack(c); 2171 | c->mon = mons; 2172 | attach(c); 2173 | attachstack(c); 2174 | } 2175 | if (m == selmon) 2176 | selmon = mons; 2177 | cleanupmon(m); 2178 | } 2179 | free(unique); 2180 | } else 2181 | #endif /* XINERAMA */ 2182 | { /* default monitor setup */ 2183 | if (!mons) 2184 | mons = createmon(); 2185 | if (mons->mw != sw || mons->mh != sh) { 2186 | dirty = 1; 2187 | mons->mw = mons->ww = sw; 2188 | mons->mh = mons->wh = sh; 2189 | updatebarpos(mons); 2190 | } 2191 | } 2192 | if (dirty) { 2193 | selmon = mons; 2194 | selmon = wintomon(root); 2195 | } 2196 | return dirty; 2197 | } 2198 | 2199 | void 2200 | updatenumlockmask(void) 2201 | { 2202 | unsigned int i, j; 2203 | XModifierKeymap *modmap; 2204 | 2205 | numlockmask = 0; 2206 | modmap = XGetModifierMapping(dpy); 2207 | for (i = 0; i < 8; i++) 2208 | for (j = 0; j < modmap->max_keypermod; j++) 2209 | if (modmap->modifiermap[i * modmap->max_keypermod + j] 2210 | == XKeysymToKeycode(dpy, XK_Num_Lock)) 2211 | numlockmask = (1 << i); 2212 | XFreeModifiermap(modmap); 2213 | } 2214 | 2215 | void 2216 | updatesizehints(Client *c) 2217 | { 2218 | long msize; 2219 | XSizeHints size; 2220 | 2221 | if (!XGetWMNormalHints(dpy, c->win, &size, &msize)) 2222 | /* size is uninitialized, ensure that size.flags aren't used */ 2223 | size.flags = PSize; 2224 | if (size.flags & PBaseSize) { 2225 | c->basew = size.base_width; 2226 | c->baseh = size.base_height; 2227 | } else if (size.flags & PMinSize) { 2228 | c->basew = size.min_width; 2229 | c->baseh = size.min_height; 2230 | } else 2231 | c->basew = c->baseh = 0; 2232 | if (size.flags & PResizeInc) { 2233 | c->incw = size.width_inc; 2234 | c->inch = size.height_inc; 2235 | } else 2236 | c->incw = c->inch = 0; 2237 | if (size.flags & PMaxSize) { 2238 | c->maxw = size.max_width; 2239 | c->maxh = size.max_height; 2240 | } else 2241 | c->maxw = c->maxh = 0; 2242 | if (size.flags & PMinSize) { 2243 | c->minw = size.min_width; 2244 | c->minh = size.min_height; 2245 | } else if (size.flags & PBaseSize) { 2246 | c->minw = size.base_width; 2247 | c->minh = size.base_height; 2248 | } else 2249 | c->minw = c->minh = 0; 2250 | if (size.flags & PAspect) { 2251 | c->mina = (float)size.min_aspect.y / size.min_aspect.x; 2252 | c->maxa = (float)size.max_aspect.x / size.max_aspect.y; 2253 | } else 2254 | c->maxa = c->mina = 0.0; 2255 | c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); 2256 | c->hintsvalid = 1; 2257 | } 2258 | 2259 | void 2260 | updatestatus(void) 2261 | { 2262 | if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) 2263 | strcpy(stext, "dwm-"VERSION); 2264 | drawbar(selmon); 2265 | } 2266 | 2267 | void 2268 | updatetitle(Client *c) 2269 | { 2270 | if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) 2271 | gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); 2272 | if (c->name[0] == '\0') /* hack to mark broken clients */ 2273 | strcpy(c->name, broken); 2274 | } 2275 | 2276 | void 2277 | updatewindowtype(Client *c) 2278 | { 2279 | Atom state = getatomprop(c, netatom[NetWMState]); 2280 | Atom wtype = getatomprop(c, netatom[NetWMWindowType]); 2281 | 2282 | if (state == netatom[NetWMFullscreen]) 2283 | setfullscreen(c, 1); 2284 | if (wtype == netatom[NetWMWindowTypeDialog]) 2285 | c->isfloating = 1; 2286 | } 2287 | 2288 | void 2289 | updatewmhints(Client *c) 2290 | { 2291 | XWMHints *wmh; 2292 | 2293 | if ((wmh = XGetWMHints(dpy, c->win))) { 2294 | if (c == selmon->sel && wmh->flags & XUrgencyHint) { 2295 | wmh->flags &= ~XUrgencyHint; 2296 | XSetWMHints(dpy, c->win, wmh); 2297 | } else 2298 | c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0; 2299 | if (wmh->flags & InputHint) 2300 | c->neverfocus = !wmh->input; 2301 | else 2302 | c->neverfocus = 0; 2303 | XFree(wmh); 2304 | } 2305 | } 2306 | 2307 | void 2308 | view(const Arg *arg) 2309 | { 2310 | if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) 2311 | return; 2312 | selmon->seltags ^= 1; /* toggle sel tagset */ 2313 | if (arg->ui & TAGMASK) 2314 | selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; 2315 | focus(NULL); 2316 | arrange(selmon); 2317 | } 2318 | 2319 | Client * 2320 | wintoclient(Window w) 2321 | { 2322 | Client *c; 2323 | Monitor *m; 2324 | 2325 | for (m = mons; m; m = m->next) 2326 | for (c = m->clients; c; c = c->next) 2327 | if (c->win == w) 2328 | return c; 2329 | return NULL; 2330 | } 2331 | 2332 | Monitor * 2333 | wintomon(Window w) 2334 | { 2335 | int x, y; 2336 | Client *c; 2337 | Monitor *m; 2338 | 2339 | if (w == root && getrootptr(&x, &y)) 2340 | return recttomon(x, y, 1, 1); 2341 | for (m = mons; m; m = m->next) 2342 | if (w == m->barwin) 2343 | return m; 2344 | if ((c = wintoclient(w))) 2345 | return c->mon; 2346 | return selmon; 2347 | } 2348 | 2349 | /* There's no way to check accesses to destroyed windows, thus those cases are 2350 | * ignored (especially on UnmapNotify's). Other types of errors call Xlibs 2351 | * default error handler, which may call exit. */ 2352 | int 2353 | xerror(Display *dpy, XErrorEvent *ee) 2354 | { 2355 | if (ee->error_code == BadWindow 2356 | || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) 2357 | || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) 2358 | || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) 2359 | || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) 2360 | || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) 2361 | || (ee->request_code == X_GrabButton && ee->error_code == BadAccess) 2362 | || (ee->request_code == X_GrabKey && ee->error_code == BadAccess) 2363 | || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) 2364 | return 0; 2365 | fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", 2366 | ee->request_code, ee->error_code); 2367 | return xerrorxlib(dpy, ee); /* may call exit */ 2368 | } 2369 | 2370 | int 2371 | xerrordummy(Display *dpy, XErrorEvent *ee) 2372 | { 2373 | return 0; 2374 | } 2375 | 2376 | /* Startup Error handler to check if another window manager 2377 | * is already running. */ 2378 | int 2379 | xerrorstart(Display *dpy, XErrorEvent *ee) 2380 | { 2381 | die("dwm: another window manager is already running"); 2382 | return -1; 2383 | } 2384 | 2385 | void 2386 | zoom(const Arg *arg) 2387 | { 2388 | Client *c = selmon->sel; 2389 | 2390 | if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating) 2391 | return; 2392 | if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next))) 2393 | return; 2394 | pop(c); 2395 | } 2396 | 2397 | int 2398 | main(int argc, char *argv[]) 2399 | { 2400 | if (argc == 2 && !strcmp("-v", argv[1])) 2401 | die("dwm-"VERSION); 2402 | else if (argc != 1) 2403 | die("usage: dwm [-v]"); 2404 | if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 2405 | fputs("warning: no locale support\n", stderr); 2406 | if (!(dpy = XOpenDisplay(NULL))) 2407 | die("dwm: cannot open display"); 2408 | checkotherwm(); 2409 | setup(); 2410 | #ifdef __OpenBSD__ 2411 | if (pledge("stdio rpath proc exec", NULL) == -1) 2412 | die("pledge"); 2413 | #endif /* __OpenBSD__ */ 2414 | scan(); 2415 | runAutostart(); 2416 | run(); 2417 | cleanup(); 2418 | XCloseDisplay(dpy); 2419 | return EXIT_SUCCESS; 2420 | } 2421 | -------------------------------------------------------------------------------- /dwm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/dwm.o -------------------------------------------------------------------------------- /dwm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/dwm.png -------------------------------------------------------------------------------- /dwmclean: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cp config.def.h config.h; make; sudo make install 3 | -------------------------------------------------------------------------------- /movestack.c: -------------------------------------------------------------------------------- 1 | void 2 | movestack(const Arg *arg) { 3 | Client *c = NULL, *p = NULL, *pc = NULL, *i; 4 | 5 | if(arg->i > 0) { 6 | /* find the client after selmon->sel */ 7 | for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); 8 | if(!c) 9 | for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); 10 | 11 | } 12 | else { 13 | /* find the client before selmon->sel */ 14 | for(i = selmon->clients; i != selmon->sel; i = i->next) 15 | if(ISVISIBLE(i) && !i->isfloating) 16 | c = i; 17 | if(!c) 18 | for(; i; i = i->next) 19 | if(ISVISIBLE(i) && !i->isfloating) 20 | c = i; 21 | } 22 | /* find the client before selmon->sel and c */ 23 | for(i = selmon->clients; i && (!p || !pc); i = i->next) { 24 | if(i->next == selmon->sel) 25 | p = i; 26 | if(i->next == c) 27 | pc = i; 28 | } 29 | 30 | /* swap c and selmon->sel selmon->clients in the selmon->clients list */ 31 | if(c && c != selmon->sel) { 32 | Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; 33 | selmon->sel->next = c->next==selmon->sel?c:c->next; 34 | c->next = temp; 35 | 36 | if(p && p != c) 37 | p->next = c; 38 | if(pc && pc != selmon->sel) 39 | pc->next = selmon->sel; 40 | 41 | if(selmon->sel == selmon->clients) 42 | selmon->clients = c; 43 | else if(c == selmon->clients) 44 | selmon->clients = selmon->sel; 45 | 46 | arrange(selmon); 47 | } 48 | } -------------------------------------------------------------------------------- /transient.c: -------------------------------------------------------------------------------- 1 | /* cc transient.c -o transient -lX11 */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(void) { 9 | Display *d; 10 | Window r, f, t = None; 11 | XSizeHints h; 12 | XEvent e; 13 | 14 | d = XOpenDisplay(NULL); 15 | if (!d) 16 | exit(1); 17 | r = DefaultRootWindow(d); 18 | 19 | f = XCreateSimpleWindow(d, r, 100, 100, 400, 400, 0, 0, 0); 20 | h.min_width = h.max_width = h.min_height = h.max_height = 400; 21 | h.flags = PMinSize | PMaxSize; 22 | XSetWMNormalHints(d, f, &h); 23 | XStoreName(d, f, "floating"); 24 | XMapWindow(d, f); 25 | 26 | XSelectInput(d, f, ExposureMask); 27 | while (1) { 28 | XNextEvent(d, &e); 29 | 30 | if (t == None) { 31 | sleep(5); 32 | t = XCreateSimpleWindow(d, r, 50, 50, 100, 100, 0, 0, 0); 33 | XSetTransientForHint(d, t, f); 34 | XStoreName(d, t, "transient"); 35 | XMapWindow(d, t); 36 | XSelectInput(d, t, ExposureMask); 37 | } 38 | } 39 | 40 | XCloseDisplay(d); 41 | exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "util.h" 8 | 9 | void 10 | die(const char *fmt, ...) 11 | { 12 | va_list ap; 13 | 14 | va_start(ap, fmt); 15 | vfprintf(stderr, fmt, ap); 16 | va_end(ap); 17 | 18 | if (fmt[0] && fmt[strlen(fmt)-1] == ':') { 19 | fputc(' ', stderr); 20 | perror(NULL); 21 | } else { 22 | fputc('\n', stderr); 23 | } 24 | 25 | exit(1); 26 | } 27 | 28 | void * 29 | ecalloc(size_t nmemb, size_t size) 30 | { 31 | void *p; 32 | 33 | if (!(p = calloc(nmemb, size))) 34 | die("calloc:"); 35 | return p; 36 | } 37 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | /* See LICENSE file for copyright and license details. */ 2 | 3 | #define MAX(A, B) ((A) > (B) ? (A) : (B)) 4 | #define MIN(A, B) ((A) < (B) ? (A) : (B)) 5 | #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) 6 | 7 | void die(const char *fmt, ...); 8 | void *ecalloc(size_t nmemb, size_t size); 9 | -------------------------------------------------------------------------------- /util.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/motolla/dwm-rose/79d69e7199ddf1fc4e015746aa2f9b8738c3915b/util.o --------------------------------------------------------------------------------