Compare commits

...

61 Commits

Author SHA1 Message Date
accdbc9491 chore: more rules 2026-04-15 21:34:49 +09:30
7618877b6d chore: more rules 2026-04-15 21:32:55 +09:30
481166edbc chore: more rules and docs 2026-04-14 10:12:47 +09:30
fed6dfe8b6 fix: bad rebase... 2026-04-02 20:45:03 +10:30
0f895285c2 Merge branch 'patch/swapwindows' into config 2026-04-02 20:44:05 +10:30
a2c3113e1f Merge branch 'patch/swapmonitors' into config 2026-04-02 20:24:36 +10:30
505b6573e9 feat: patched swapmonitors 2026-04-02 20:13:14 +10:30
3801367f23 feat: added patch file for swapmonitors 2026-04-02 20:12:48 +10:30
bae8a1588e feat: applied swapwindows patch 2026-04-02 20:03:20 +10:30
16fd459352 feat: added patch file for swapwindows 2026-04-02 20:02:57 +10:30
475ac01b5c chore: revert rule change :P 2026-03-24 17:34:52 +10:30
7c2c708d54 chore: update rules 2026-03-23 21:23:24 +10:30
2c5e4e179b chore: updated scratchpad cmd 2026-03-20 18:19:27 +10:30
a069b3ea66 Merge branch 'patch/named-scratchpads' into config 2026-03-20 18:09:57 +10:30
298967b6ce feat: applied named scratchpads patch 2026-03-20 18:04:45 +10:30
40dfc558de chore: added named scratchpads patch 2026-03-20 18:04:07 +10:30
e880bb20fe Merge branch 'patch/steam' into config 2026-03-20 18:01:47 +10:30
dde6cf659f feat: added steam patch 2026-03-20 17:59:54 +10:30
cb76cc485e chore: added steam patch 2026-03-20 17:59:38 +10:30
24c04ef800 Merge branch 'patch/hide-vacant-tags' into config 2026-03-20 17:58:26 +10:30
7dd271426d feat: added hide vacant tags patch 2026-03-20 17:57:59 +10:30
f59fb74381 chore: added hide vacant tags patch 2026-03-20 17:57:30 +10:30
38f1d2b44b merge: merged allowkillrule 2026-03-20 17:56:13 +10:30
9599d4233d feat: applied allow kill rule 2026-03-20 13:18:27 +10:30
0c36b86ec0 chore: added patch file 2026-03-20 13:15:47 +10:30
7b555451ae chore: remove trayer 2026-03-14 21:27:49 +10:30
049d59cb62 chore: better systray spacing, color still off 2026-03-14 21:25:05 +10:30
c53b9adb0b fix: resolved merge with statuscmd patch 2026-03-14 21:00:17 +10:30
bd32ae7251 chore: added feishin to rules 2026-03-14 17:19:03 +10:30
2b79eebe56 more window rules 2026-03-14 17:19:03 +10:30
2be742a10a minor changes to class names/ window rules 2026-03-14 17:19:03 +10:30
ff84964004 calcurse 2026-03-14 17:19:03 +10:30
8b5a2450b0 cleen 2026-03-14 17:19:03 +10:30
7870806dee bit better, double chords cause issues 2026-03-14 17:19:03 +10:30
15c551aeac minor change trial 2026-03-14 17:19:03 +10:30
7000a285ac updates, updates, updates 2026-03-14 17:19:03 +10:30
c4c5c2f629 updates again, need to specify number of chords 2026-03-14 17:19:03 +10:30
aa2e57b45c new things, thanks luke 2026-03-14 17:19:03 +10:30
2f534f3c72 aaah, now I understand 2026-03-14 17:19:03 +10:30
1d76082949 merged and updated config 2026-03-14 17:19:03 +10:30
d5974cfd68 forgot to add patch file 2026-03-14 17:19:03 +10:30
48176963e1 patched keychord, bye bye keychain :( 2026-03-14 17:19:03 +10:30
2e3b858e90 patched statuscmd 2026-03-14 17:19:03 +10:30
eaf51e9509 patched uselessgap 2026-03-14 17:14:35 +10:30
c6404b0bd5 added patch file 2026-03-14 17:14:35 +10:30
8917f73a90 shift-tools patched? 2026-03-14 17:14:35 +10:30
6eebc90a68 patch file 2026-03-14 17:14:35 +10:30
0a2c925e7f patched restartsig 2026-03-14 17:14:35 +10:30
a96e1620b6 added patch file 2026-03-14 16:29:06 +10:30
2d6f8885aa patched pertag 2026-03-14 16:29:06 +10:30
0f418b662f added patch file 2026-03-14 16:29:06 +10:30
bbfa3173a5 patched movestack 2026-03-14 16:29:06 +10:30
43499f4084 added patch file 2026-03-14 16:29:06 +10:30
bb1a1e099f patched fullscreen 2026-03-14 16:29:06 +10:30
cc5663b239 added patch file 2026-03-14 16:29:06 +10:30
1865b2e608 patched attachtop 2026-03-14 16:29:06 +10:30
b3cd617256 added patch file 2026-03-14 16:29:06 +10:30
92c3f398a6 don't forget to fix keychain to keychord changes 2026-03-14 16:29:06 +10:30
ce10409f36 added my default config file, might need tweaking 2026-03-14 16:29:06 +10:30
cb6069c7e9 patched systray 2026-03-14 16:15:27 +10:30
9024a63920 added patch file 2026-03-14 15:26:59 +10:30
24 changed files with 4204 additions and 542 deletions

View File

@ -20,7 +20,7 @@ dwm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS} ${CC} -o $@ ${OBJ} ${LDFLAGS}
clean: clean:
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz config.h
dist: clean dist: clean
mkdir -p dwm-${VERSION} mkdir -p dwm-${VERSION}

View File

@ -1,117 +1,226 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
/* appearance */ /* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */ static const unsigned int gappx = 6; /* gaps between windows */
static const int showbar = 1; /* 0 means no bar */ static const unsigned int snap = 32;/* snap pixel */
static const int topbar = 1; /* 0 means bottom bar */ static const unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const char *fonts[] = { "monospace:size=10" }; static const unsigned int systrayonleft = 0; /* 0: systray in the right corner, >0: systray on left of status text */
static const char dmenufont[] = "monospace:size=10"; static const unsigned int systrayspacing = 3; /* systray spacing */
static const char col_gray1[] = "#222222"; static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
static const char col_gray2[] = "#444444"; static const int showsystray = 1; /* 0 means no systray */
static const char col_gray3[] = "#bbbbbb"; static const int showbar = 1; /* 0 means no bar */
static const char col_gray4[] = "#eeeeee"; static const int topbar = 1; /* 0 means bottom bar */
static const char col_cyan[] = "#005577"; static const int allowkill = 1; /* allow killing clients by default? */
static const char *colors[][3] = { static const char *fonts[] = {"FiraCode Nerd Font:size=10:antialias=true:hinting=true"};
/* fg bg border */ static const char dmenufont[] = "FiraCode Nerd Font:size=10:antialias=true:hinting=true";
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
[SchemeSel] = { col_gray4, col_cyan, col_cyan }, static const char norm_fg[] = "#D5C4A1";
static const char norm_bg[] = "#262626";
static const char norm_border[] = "#665c54";
static const char sel_fg[] = "#262626";
static const char sel_bg[] = "#FE8019";
static const char sel_border[] = "#fbf1c7";
static const char *colors[][3] = {
/* fg bg border */
[SchemeNorm] = {norm_fg, norm_bg, norm_border}, // unfocused wins
[SchemeSel] = {sel_fg, sel_bg, sel_border}, // the focused win
}; };
static const unsigned int baralpha = 0xd0;
static const unsigned int borderalpha = 0xd0;
/* tagging */ /* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static const char *tags[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
static const Rule rules[] = { static const Rule rules[] = {
/* xprop(1): /* xprop(1):
* WM_CLASS(STRING) = instance, class * WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title * WM_NAME(STRING) = title
*/ */
/* class instance title tags mask isfloating monitor */ /* class instance title tags mask allowkill isfloating monitor scratchpad char*/
{ "Gimp", NULL, NULL, 0, 1, -1 }, {"firefox", NULL, NULL, 1 << 0, 0, 0, -1, 0},
{ "Firefox", NULL, NULL, 1 << 8, 0, -1 }, {"thunderbird", NULL, NULL, 1 << 6, 1, 0, -1, 0},
{"org.mozilla.Thunderbird", NULL, NULL, 1 << 6, 1, 0, -1, 0},
{"ManagerDesktop", NULL, NULL, 1 << 7, 1, 0, -1, 0},
{"Manager", NULL, NULL, 1 << 7, 1, 0, -1, 0},
{"InputLeap", NULL, NULL, 1 << 8, 1, 1, -1, 0},
{"Nextcloud", NULL, NULL, 1 << 8, 1, 0, -1, 0},
{"feishin", NULL, NULL, 1 << 2, 0, 0, -1, 0},
{"discord", NULL, NULL, 1 << 2, 1, 0, -1, 0},
{"telegram-desktop", NULL, NULL, 1 << 2, 1, 0, -1, 0},
{"TelegramDesktop", NULL, NULL, 1 << 2, 1, 0, -1, 0},
{ NULL, NULL, "scratchpad", 0, 1, 0, -1, 's'}
}; };
/* layout(s) */ /* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */ static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */ static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */
static const Layout layouts[] = { static const Layout layouts[] = {
/* symbol arrange function */ /* symbol arrange function */
{ "[]=", tile }, /* first entry is default */ {"[]=", tile}, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */ {"[M]", monocle},
{ "[M]", monocle }, {"><>", NULL}, /* no layout function means floating behavior */
}; };
/* key definitions */ /* key definitions */
#define MODKEY Mod1Mask #define MODKEY Mod1Mask
#define TAGKEYS(KEY,TAG) \
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \ #define TAGKEYS(KEY, TAG) \
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ &((Keychord){1, {{MODKEY, KEY}}, view, {.ui = 1 << TAG}}), \
{ MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ &((Keychord){1, {{MODKEY | ControlMask, KEY}}, toggleview, {.ui = 1 << TAG}}), \
{ MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, &((Keychord){1, {{MODKEY | ShiftMask, KEY}}, tag, {.ui = 1 << TAG}}), \
&((Keychord){1, {{MODKEY | ControlMask | ShiftMask, KEY}}, toggletag, {.ui = 1 << TAG}}),
/* helper for spawning shell commands in the pre dwm-5.0 fashion */ /* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } #define SHCMD(cmd) \
{ \
.v = (const char *[]) { "/bin/sh", "-c", cmd, NULL } \
}
/* some defaults */
#define TERMINAL "st"
#define STATUSBAR "dwmblocks"
/* commands */ /* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *dmenucmd[] = {"dmenu_run", NULL};
static const char *termcmd[] = { "st", NULL }; static const char *slockcmd[] = {"slock", NULL};
static const char *termcmd[] = {TERMINAL, "-t", "st", "-e", "tmux-worker", NULL};
/*First arg only serves to match against scratchpad char in rules above */
static const char *scratchpadcmd[] = {"s", TERMINAL, "-t", "scratchpad", "-e", "tmux-worker", NULL};
static const Key keys[] = { #include "movestack.c"
/* modifier key function argument */ #include "shift-tools.c"
{ MODKEY, XK_p, spawn, {.v = dmenucmd } }, #include <X11/XF86keysym.h>
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} }, static const Keychord *keychords[] = {
{ MODKEY, XK_j, focusstack, {.i = +1 } }, // &((Keychord){1, {{MODKEY, XK_}}, spawn, {}}),
{ MODKEY, XK_k, focusstack, {.i = -1 } }, /* key count key chords function argument */
{ MODKEY, XK_i, incnmaster, {.i = +1 } }, &((Keychord){1, {{MODKEY | ControlMask | ShiftMask, XK_apostrophe}}, quit, {0}}),
{ MODKEY, XK_d, incnmaster, {.i = -1 } }, &((Keychord){1, {{MODKEY | ShiftMask, XK_apostrophe}}, quit, {1}}),
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} }, &((Keychord){1, {{MODKEY, XK_grave}}, togglescratch, {.v = scratchpadcmd }}),
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} }, &((Keychord){1, {{MODKEY, XK_apostrophe}}, killclient, {0}}),
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, &((Keychord){1, {{MODKEY, XK_a}}, spawn, {.v = dmenucmd}}),
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, &((Keychord){1, {{MODKEY | ShiftMask, XK_Return}}, spawn, {.v = termcmd}}),
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, &((Keychord){1, {{MODKEY, XK_Escape}}, spawn, {.v = slockcmd}}),
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} }, &((Keychord){1, {{MODKEY, XK_l}}, shiftview, {.i = +1}}),
{ MODKEY, XK_0, view, {.ui = ~0 } }, &((Keychord){1, {{MODKEY, XK_h}}, shiftview, {.i = -1}}),
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, &((Keychord){1, {{MODKEY | ShiftMask, XK_l}}, shiftboth, {.i = +1}}),
{ MODKEY, XK_comma, focusmon, {.i = -1 } }, &((Keychord){1, {{MODKEY | ShiftMask, XK_h}}, shiftboth, {.i = -1}}),
{ MODKEY, XK_period, focusmon, {.i = +1 } }, &((Keychord){1, {{MODKEY | ControlMask, XK_l}}, swapwindow, {0}}),
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, &((Keychord){1, {{MODKEY | ControlMask | ShiftMask, XK_l}}, swapmon, {0}}),
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
TAGKEYS( XK_1, 0) &((Keychord){1, {{MODKEY, XK_j}}, focusstack, {.i = +1}}),
TAGKEYS( XK_2, 1) &((Keychord){1, {{MODKEY, XK_k}}, focusstack, {.i = -1}}),
TAGKEYS( XK_3, 2) &((Keychord){1, {{MODKEY | ShiftMask, XK_v}}, incnmaster, {.i = +1}}),
TAGKEYS( XK_4, 3) &((Keychord){1, {{MODKEY | ShiftMask, XK_w}}, incnmaster, {.i = -1}}),
TAGKEYS( XK_5, 4) &((Keychord){1, {{MODKEY, XK_equal}}, setmfact, {.f = +0.05}}),
TAGKEYS( XK_6, 5) &((Keychord){1, {{MODKEY, XK_minus}}, setmfact, {.f = -0.05}}),
TAGKEYS( XK_7, 6) &((Keychord){1, {{MODKEY | ShiftMask, XK_j}}, movestack, {.i = +1}}),
TAGKEYS( XK_8, 7) &((Keychord){1, {{MODKEY | ShiftMask, XK_k}}, movestack, {.i = -1}}),
TAGKEYS( XK_9, 8) &((Keychord){1, {{MODKEY, XK_Return}}, zoom, {0}}),
{ MODKEY|ShiftMask, XK_q, quit, {0} }, &((Keychord){1, {{MODKEY, XK_Tab}}, view, {0}}),
&((Keychord){2, {{MODKEY, XK_w}, {MODKEY, XK_t}}, setlayout, {.v = &layouts[0]}}),
&((Keychord){2, {{MODKEY, XK_w}, {MODKEY, XK_m}}, setlayout, {.v = &layouts[1]}}),
&((Keychord){2, {{MODKEY, XK_w}, {MODKEY, XK_f}}, setlayout, {.v = &layouts[2]}}),
&((Keychord){1, {{MODKEY, XK_F11}}, fullscreen, {0}}),
&((Keychord){1, {{MODKEY, XK_space}}, setlayout, {0}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_space}}, togglefloating, {0}}),
&((Keychord){1, {{MODKEY, XK_b}}, togglebar, {0}}),
&((Keychord){1, {{MODKEY, XK_0}}, view, {.ui = ~0}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_0}}, tag, {.ui = ~0}}),
&((Keychord){1, {{MODKEY, XK_comma}}, focusmon, {.i = -1}}),
&((Keychord){1, {{MODKEY, XK_period}}, focusmon, {.i = +1}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_comma}}, tagmon, {.i = -1}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_period}}, tagmon, {.i = +1}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_s}}, spawn, {.v = (const char *[]){"sysact", NULL}}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_o}}, spawn, {.v = (const char *[]){"set-default-sink", NULL}}}),
&((Keychord){1, {{MODKEY | ShiftMask, XK_i}}, spawn, {.v = (const char *[]){"set-default-source", NULL}}}),
&((Keychord){2, {{MODKEY, XK_m}, {MODKEY, XK_a}}, spawn, {.v = (const char *[]){"dmenumusic", NULL}}}),
&((Keychord){2, {{MODKEY, XK_m}, {MODKEY, XK_p}}, spawn, {.v = (const char *[]){"mpc", "toggle", NULL}}}),
&((Keychord){2, {{MODKEY, XK_m}, {MODKEY, XK_l}}, spawn, {.v = (const char *[]){"mpc", "next", NULL}}}),
&((Keychord){2, {{MODKEY, XK_m}, {MODKEY, XK_h}}, spawn, {.v = (const char *[]){"mpc", "prev", NULL}}}),
&((Keychord){1, {{MODKEY, XF86XK_AudioPlay}}, spawn, {.v = (const char *[]){"mpc", "toggle", NULL}}}),
&((Keychord){1, {{MODKEY, XF86XK_AudioNext}}, spawn, {.v = (const char *[]){"mpc", "next", NULL}}}),
&((Keychord){1, {{MODKEY, XF86XK_AudioPrev}}, spawn, {.v = (const char *[]){"mpc", "prev", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_l}}, spawn, {.v = (const char *[]){TERMINAL, "-e", "lf", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_f}}, spawn, {.v = (const char *[]){"firefox", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_n}}, spawn, {.v = (const char *[]){TERMINAL, "-e", "ncmpcpp", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_m}}, spawn, {.v = (const char *[]){TERMINAL, "-e", "gotop", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_t}}, spawn, {.v = (const char *[]){"thunar", NULL}}}),
&((Keychord){2, {{MODKEY, XK_o}, {MODKEY, XK_c}}, spawn, {.v = (const char *[]){"calcurse-select", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_h}}, spawn, {.v = (const char *[]){"dmenuhandler", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_m}}, spawn, {.v = (const char *[]){"mounter", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_c}}, spawn, {.v = (const char *[]){"dmenumountcifs", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_u}}, spawn, {.v = (const char *[]){"unmounter", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_s}}, spawn, {.v = (const char *[]){"dmenusearch", "duckduckgo", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_l}}, spawn, {.v = (const char *[]){"linkhandler", NULL}}}),
&((Keychord){2, {{MODKEY, XK_d}, {MODKEY, XK_b}}, spawn, SHCMD("dmenu-bluetooth -i -l 25")}),
&((Keychord){1, {{MODKEY | ControlMask, XK_period}}, spawn, {.v = (const char *[]){"sd", NULL}}}),
&((Keychord){1, {{MODKEY, XK_f}}, spawn, {.v = (const char *[]){"screenlayout", NULL}}}),
&((Keychord){1, {{MODKEY, XK_F1}}, spawn, {.v = (const char *[]){"kbswitcher", NULL}}}),
&((Keychord){1, {{0, XF86XK_AudioMute}}, spawn, SHCMD("wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle; kill -37 $(pidof " "dwmblocks)")}),
&((Keychord){1, {{0, XF86XK_AudioRaiseVolume}}, spawn, SHCMD("wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+; kill -37 $(pidof " "dwmblocks)")}),
&((Keychord){1, {{0, XF86XK_AudioLowerVolume}}, spawn, SHCMD("wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-; kill -37 $(pidof " "dwmblocks)")}),
&((Keychord){1, {{0, XF86XK_AudioMicMute}}, spawn, SHCMD("wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle; kill -37 $(pidof " "dwmblocks)")}),
&((Keychord){1, {{MODKEY, XK_v}}, spawn, {.v = (const char *[]){"setvol", NULL}}}),
&((Keychord){1, {{0, XF86XK_MonBrightnessUp}}, spawn, {.v = (const char *[]){"mod_backlight", "up", NULL}}}),
&((Keychord){1, {{0, XF86XK_MonBrightnessDown}}, spawn, {.v = (const char *[]){"mod_backlight", "down", NULL}}}),
TAGKEYS(XK_1, 0)
TAGKEYS(XK_2, 1)
TAGKEYS(XK_3, 2)
TAGKEYS(XK_4, 3)
TAGKEYS(XK_5, 4)
TAGKEYS(XK_6, 5)
TAGKEYS(XK_7, 6)
TAGKEYS(XK_8, 7)
TAGKEYS(XK_9, 8)
}; };
/* button definitions */ /* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
static const Button buttons[] = { * ClkClientWin, or ClkRootWin */
/* click event mask button function argument */ static Button buttons[] = {
{ ClkLtSymbol, 0, Button1, setlayout, {0} }, /* click event mask button function argument */
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, {ClkLtSymbol, 0, Button1, setlayout, {0}},
{ ClkWinTitle, 0, Button2, zoom, {0} }, {ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]}},
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, {ClkWinTitle, 0, Button2, zoom, {0}},
{ ClkClientWin, MODKEY, Button1, movemouse, {0} }, {ClkStatusText, 0, Button1, sigstatusbar, {.i = 1}},
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} }, {ClkStatusText, 0, Button2, sigstatusbar, {.i = 2}},
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} }, {ClkStatusText, 0, Button3, sigstatusbar, {.i = 3}},
{ ClkTagBar, 0, Button1, view, {0} }, {ClkStatusText, 0, Button4, sigstatusbar, {.i = 4}},
{ ClkTagBar, 0, Button3, toggleview, {0} }, {ClkStatusText, 0, Button5, sigstatusbar, {.i = 5}},
{ ClkTagBar, MODKEY, Button1, tag, {0} }, {ClkStatusText, ShiftMask, Button1, sigstatusbar, {.i = 6}},
{ ClkTagBar, MODKEY, Button3, toggletag, {0} }, {ClkClientWin, MODKEY, Button1, movemouse, {0}},
{ClkClientWin, MODKEY, Button2, togglefloating, {0}},
{ClkClientWin, MODKEY, Button3, resizemouse, {0}},
{ClkTagBar, 0, Button1, view, {0}},
{ClkTagBar, 0, Button3, toggleview, {0}},
{ClkTagBar, MODKEY, Button1, tag, {0}},
{ClkTagBar, MODKEY, Button3, toggletag, {0}},
}; };

720
drw.c
View File

@ -1,471 +1,441 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
#include "drw.h" #include "drw.h"
#include "util.h" #include "util.h"
#define UTF_INVALID 0xFFFD #define UTF_INVALID 0xFFFD
static int static int utf8decode(const char *s_in, long *u, int *err) {
utf8decode(const char *s_in, long *u, int *err) static const unsigned char lens[] = {
{ /* 0XXXX */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
static const unsigned char lens[] = { /* 10XXX */ 0, 0, 0, 0, 0, 0, 0, 0, /* invalid */
/* 0XXXX */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 110XX */ 2, 2, 2, 2,
/* 10XXX */ 0, 0, 0, 0, 0, 0, 0, 0, /* invalid */ /* 1110X */ 3, 3,
/* 110XX */ 2, 2, 2, 2, /* 11110 */ 4,
/* 1110X */ 3, 3, /* 11111 */ 0, /* invalid */
/* 11110 */ 4, };
/* 11111 */ 0, /* invalid */ static const unsigned char leading_mask[] = {0x7F, 0x1F, 0x0F, 0x07};
}; static const unsigned int overlong[] = {0x0, 0x80, 0x0800, 0x10000};
static const unsigned char leading_mask[] = { 0x7F, 0x1F, 0x0F, 0x07 };
static const unsigned int overlong[] = { 0x0, 0x80, 0x0800, 0x10000 };
const unsigned char *s = (const unsigned char *)s_in; const unsigned char *s = (const unsigned char *)s_in;
int len = lens[*s >> 3]; int len = lens[*s >> 3];
*u = UTF_INVALID; *u = UTF_INVALID;
*err = 1; *err = 1;
if (len == 0) if (len == 0)
return 1; return 1;
long cp = s[0] & leading_mask[len - 1]; long cp = s[0] & leading_mask[len - 1];
for (int i = 1; i < len; ++i) { for (int i = 1; i < len; ++i) {
if (s[i] == '\0' || (s[i] & 0xC0) != 0x80) if (s[i] == '\0' || (s[i] & 0xC0) != 0x80)
return i; return i;
cp = (cp << 6) | (s[i] & 0x3F); cp = (cp << 6) | (s[i] & 0x3F);
} }
/* out of range, surrogate, overlong encoding */ /* out of range, surrogate, overlong encoding */
if (cp > 0x10FFFF || (cp >> 11) == 0x1B || cp < overlong[len - 1]) if (cp > 0x10FFFF || (cp >> 11) == 0x1B || cp < overlong[len - 1])
return len; return len;
*err = 0; *err = 0;
*u = cp; *u = cp;
return len; return len;
} }
Drw * Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w,
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) unsigned int h) {
{ Drw *drw = ecalloc(1, sizeof(Drw));
Drw *drw = ecalloc(1, sizeof(Drw));
drw->dpy = dpy; drw->dpy = dpy;
drw->screen = screen; drw->screen = screen;
drw->root = root; drw->root = root;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen)); drw->drawable = XCreatePixmap(dpy, root, w, h, DefaultDepth(dpy, screen));
drw->gc = XCreateGC(dpy, root, 0, NULL); drw->gc = XCreateGC(dpy, root, 0, NULL);
XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter); XSetLineAttributes(dpy, drw->gc, 1, LineSolid, CapButt, JoinMiter);
return drw; return drw;
} }
void void drw_resize(Drw *drw, unsigned int w, unsigned int h) {
drw_resize(Drw *drw, unsigned int w, unsigned int h) if (!drw)
{ return;
if (!drw)
return;
drw->w = w; drw->w = w;
drw->h = h; drw->h = h;
if (drw->drawable) if (drw->drawable)
XFreePixmap(drw->dpy, drw->drawable); XFreePixmap(drw->dpy, drw->drawable);
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen)); drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h,
DefaultDepth(drw->dpy, drw->screen));
} }
void void drw_free(Drw *drw) {
drw_free(Drw *drw) XFreePixmap(drw->dpy, drw->drawable);
{ XFreeGC(drw->dpy, drw->gc);
XFreePixmap(drw->dpy, drw->drawable); drw_fontset_free(drw->fonts);
XFreeGC(drw->dpy, drw->gc); free(drw);
drw_fontset_free(drw->fonts);
free(drw);
} }
/* This function is an implementation detail. Library users should use /* This function is an implementation detail. Library users should use
* drw_fontset_create instead. * drw_fontset_create instead.
*/ */
static Fnt * static Fnt *xfont_create(Drw *drw, const char *fontname,
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) FcPattern *fontpattern) {
{ Fnt *font;
Fnt *font; XftFont *xfont = NULL;
XftFont *xfont = NULL; FcPattern *pattern = NULL;
FcPattern *pattern = NULL;
if (fontname) { if (fontname) {
/* Using the pattern found at font->xfont->pattern does not yield the /* Using the pattern found at font->xfont->pattern does not yield the
* same substitution results as using the pattern returned by * same substitution results as using the pattern returned by
* FcNameParse; using the latter results in the desired fallback * FcNameParse; using the latter results in the desired fallback
* behaviour whereas the former just results in missing-character * behaviour whereas the former just results in missing-character
* rectangles being drawn, at least with some fonts. */ * rectangles being drawn, at least with some fonts. */
if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) { if (!(xfont = XftFontOpenName(drw->dpy, drw->screen, fontname))) {
fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname);
return NULL; return NULL;
} }
if (!(pattern = FcNameParse((FcChar8 *) fontname))) { if (!(pattern = FcNameParse((FcChar8 *)fontname))) {
fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n",
XftFontClose(drw->dpy, xfont); fontname);
return NULL; XftFontClose(drw->dpy, xfont);
} return NULL;
} else if (fontpattern) { }
if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) { } else if (fontpattern) {
fprintf(stderr, "error, cannot load font from pattern.\n"); if (!(xfont = XftFontOpenPattern(drw->dpy, fontpattern))) {
return NULL; fprintf(stderr, "error, cannot load font from pattern.\n");
} return NULL;
} else { }
die("no font specified."); } else {
} die("no font specified.");
}
font = ecalloc(1, sizeof(Fnt)); font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont; font->xfont = xfont;
font->pattern = pattern; font->pattern = pattern;
font->h = xfont->ascent + xfont->descent; font->h = xfont->ascent + xfont->descent;
font->dpy = drw->dpy; font->dpy = drw->dpy;
return font; return font;
} }
static void static void xfont_free(Fnt *font) {
xfont_free(Fnt *font) if (!font)
{ return;
if (!font) if (font->pattern)
return; FcPatternDestroy(font->pattern);
if (font->pattern) XftFontClose(font->dpy, font->xfont);
FcPatternDestroy(font->pattern); free(font);
XftFontClose(font->dpy, font->xfont);
free(font);
} }
Fnt* Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) {
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) Fnt *cur, *ret = NULL;
{ size_t i;
Fnt *cur, *ret = NULL;
size_t i;
if (!drw || !fonts) if (!drw || !fonts)
return NULL; return NULL;
for (i = 1; i <= fontcount; i++) { for (i = 1; i <= fontcount; i++) {
if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) { if ((cur = xfont_create(drw, fonts[fontcount - i], NULL))) {
cur->next = ret; cur->next = ret;
ret = cur; ret = cur;
} }
} }
return (drw->fonts = ret); return (drw->fonts = ret);
} }
void void drw_fontset_free(Fnt *font) {
drw_fontset_free(Fnt *font) if (font) {
{ drw_fontset_free(font->next);
if (font) { xfont_free(font);
drw_fontset_free(font->next); }
xfont_free(font);
}
} }
void void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
drw_clr_create(Drw *drw, Clr *dest, const char *clrname) if (!drw || !dest || !clrname)
{ return;
if (!drw || !dest || !clrname)
return;
if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen), clrname, dest))
clrname, dest)) die("error, cannot allocate color '%s'", clrname);
die("error, cannot allocate color '%s'", clrname);
} }
/* Create color schemes. */ /* Create color schemes. */
Clr * Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) {
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) size_t i;
{ Clr *ret;
size_t i;
Clr *ret;
/* need at least two colors for a scheme */ /* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(Clr)))) if (!drw || !clrnames || clrcount < 2 ||
return NULL; !(ret = ecalloc(clrcount, sizeof(Clr))))
return NULL;
for (i = 0; i < clrcount; i++) for (i = 0; i < clrcount; i++)
drw_clr_create(drw, &ret[i], clrnames[i]); drw_clr_create(drw, &ret[i], clrnames[i]);
return ret; return ret;
} }
void void drw_clr_free(Drw *drw, Clr *c) {
drw_clr_free(Drw *drw, Clr *c) if (!drw || !c)
{ return;
if (!drw || !c)
return;
/* c is typedef XftColor Clr */ /* c is typedef XftColor Clr */
XftColorFree(drw->dpy, DefaultVisual(drw->dpy, drw->screen), XftColorFree(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), c); DefaultColormap(drw->dpy, drw->screen), c);
} }
void void drw_scm_free(Drw *drw, Clr *scm, size_t clrcount) {
drw_scm_free(Drw *drw, Clr *scm, size_t clrcount) size_t i;
{
size_t i;
if (!drw || !scm) if (!drw || !scm)
return; return;
for (i = 0; i < clrcount; i++) for (i = 0; i < clrcount; i++)
drw_clr_free(drw, &scm[i]); drw_clr_free(drw, &scm[i]);
free(scm); free(scm);
} }
void void drw_setfontset(Drw *drw, Fnt *set) {
drw_setfontset(Drw *drw, Fnt *set) if (drw)
{ drw->fonts = set;
if (drw)
drw->fonts = set;
} }
void void drw_setscheme(Drw *drw, Clr *scm) {
drw_setscheme(Drw *drw, Clr *scm) if (drw)
{ drw->scheme = scm;
if (drw)
drw->scheme = scm;
} }
void void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h,
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) int filled, int invert) {
{ if (!drw || !drw->scheme)
if (!drw || !drw->scheme) return;
return; XSetForeground(drw->dpy, drw->gc,
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel); invert ? drw->scheme[ColBg].pixel : drw->scheme[ColFg].pixel);
if (filled) if (filled)
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
else else
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1); XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
} }
int int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) unsigned int lpad, const char *text, int invert) {
{ int ty, ellipsis_x = 0;
int ty, ellipsis_x = 0; unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1;
unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1; XftDraw *d = NULL;
XftDraw *d = NULL; Fnt *usedfont, *curfont, *nextfont;
Fnt *usedfont, *curfont, *nextfont; int utf8strlen, utf8charlen, utf8err, render = x || y || w || h;
int utf8strlen, utf8charlen, utf8err, render = x || y || w || h; long utf8codepoint = 0;
long utf8codepoint = 0; const char *utf8str;
const char *utf8str; FcCharSet *fccharset;
FcCharSet *fccharset; FcPattern *fcpattern;
FcPattern *fcpattern; FcPattern *match;
FcPattern *match; XftResult result;
XftResult result; int charexists = 0, overflow = 0;
int charexists = 0, overflow = 0; /* keep track of a couple codepoints for which we have no match. */
/* keep track of a couple codepoints for which we have no match. */ static unsigned int nomatches[128], ellipsis_width, invalid_width;
static unsigned int nomatches[128], ellipsis_width, invalid_width; static const char invalid[] = "<EFBFBD>";
static const char invalid[] = "<EFBFBD>";
if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
return 0; return 0;
if (!render) { if (!render) {
w = invert ? invert : ~invert; w = invert ? invert : ~invert;
} else { } else {
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel); XSetForeground(drw->dpy, drw->gc,
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h); drw->scheme[invert ? ColFg : ColBg].pixel);
if (w < lpad) XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
return x + w; if (w < lpad)
d = XftDrawCreate(drw->dpy, drw->drawable, return x + w;
DefaultVisual(drw->dpy, drw->screen), d = XftDrawCreate(drw->dpy, drw->drawable,
DefaultColormap(drw->dpy, drw->screen)); DefaultVisual(drw->dpy, drw->screen),
x += lpad; DefaultColormap(drw->dpy, drw->screen));
w -= lpad; x += lpad;
} w -= lpad;
}
usedfont = drw->fonts; usedfont = drw->fonts;
if (!ellipsis_width && render) if (!ellipsis_width && render)
ellipsis_width = drw_fontset_getwidth(drw, "..."); ellipsis_width = drw_fontset_getwidth(drw, "...");
if (!invalid_width && render) if (!invalid_width && render)
invalid_width = drw_fontset_getwidth(drw, invalid); invalid_width = drw_fontset_getwidth(drw, invalid);
while (1) { while (1) {
ew = ellipsis_len = utf8err = utf8charlen = utf8strlen = 0; ew = ellipsis_len = utf8err = utf8charlen = utf8strlen = 0;
utf8str = text; utf8str = text;
nextfont = NULL; nextfont = NULL;
while (*text) { while (*text) {
utf8charlen = utf8decode(text, &utf8codepoint, &utf8err); utf8charlen = utf8decode(text, &utf8codepoint, &utf8err);
for (curfont = drw->fonts; curfont; curfont = curfont->next) { for (curfont = drw->fonts; curfont; curfont = curfont->next) {
charexists = charexists || XftCharExists(drw->dpy, curfont->xfont, utf8codepoint); charexists = charexists ||
if (charexists) { XftCharExists(drw->dpy, curfont->xfont, utf8codepoint);
drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL); if (charexists) {
if (ew + ellipsis_width <= w) { drw_font_getexts(curfont, text, utf8charlen, &tmpw, NULL);
/* keep track where the ellipsis still fits */ if (ew + ellipsis_width <= w) {
ellipsis_x = x + ew; /* keep track where the ellipsis still fits */
ellipsis_w = w - ew; ellipsis_x = x + ew;
ellipsis_len = utf8strlen; ellipsis_w = w - ew;
} ellipsis_len = utf8strlen;
}
if (ew + tmpw > w) { if (ew + tmpw > w) {
overflow = 1; overflow = 1;
/* called from drw_fontset_getwidth_clamp(): /* called from drw_fontset_getwidth_clamp():
* it wants the width AFTER the overflow * it wants the width AFTER the overflow
*/ */
if (!render) if (!render)
x += tmpw; x += tmpw;
else else
utf8strlen = ellipsis_len; utf8strlen = ellipsis_len;
} else if (curfont == usedfont) { } else if (curfont == usedfont) {
text += utf8charlen; text += utf8charlen;
utf8strlen += utf8err ? 0 : utf8charlen; utf8strlen += utf8err ? 0 : utf8charlen;
ew += utf8err ? 0 : tmpw; ew += utf8err ? 0 : tmpw;
} else { } else {
nextfont = curfont; nextfont = curfont;
} }
break; break;
} }
} }
if (overflow || !charexists || nextfont || utf8err) if (overflow || !charexists || nextfont || utf8err)
break; break;
else else
charexists = 0; charexists = 0;
} }
if (utf8strlen) { if (utf8strlen) {
if (render) { if (render) {
ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent;
XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg],
usedfont->xfont, x, ty, (XftChar8 *)utf8str, utf8strlen); usedfont->xfont, x, ty, (XftChar8 *)utf8str,
} utf8strlen);
x += ew; }
w -= ew; x += ew;
} w -= ew;
if (utf8err && (!render || invalid_width < w)) { }
if (render) if (utf8err && (!render || invalid_width < w)) {
drw_text(drw, x, y, w, h, 0, invalid, invert); if (render)
x += invalid_width; drw_text(drw, x, y, w, h, 0, invalid, invert);
w -= invalid_width; x += invalid_width;
} w -= invalid_width;
if (render && overflow) }
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert); if (render && overflow)
drw_text(drw, ellipsis_x, y, ellipsis_w, h, 0, "...", invert);
if (!*text || overflow) { if (!*text || overflow) {
break; break;
} else if (nextfont) { } else if (nextfont) {
charexists = 0; charexists = 0;
usedfont = nextfont; usedfont = nextfont;
} else { } else {
/* Regardless of whether or not a fallback font is found, the /* Regardless of whether or not a fallback font is found, the
* character must be drawn. */ * character must be drawn. */
charexists = 1; charexists = 1;
hash = (unsigned int)utf8codepoint; hash = (unsigned int)utf8codepoint;
hash = ((hash >> 16) ^ hash) * 0x21F0AAAD; hash = ((hash >> 16) ^ hash) * 0x21F0AAAD;
hash = ((hash >> 15) ^ hash) * 0xD35A2D97; hash = ((hash >> 15) ^ hash) * 0xD35A2D97;
h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches); h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches);
h1 = (hash >> 17) % LENGTH(nomatches); h1 = (hash >> 17) % LENGTH(nomatches);
/* avoid expensive XftFontMatch call when we know we won't find a match */ /* avoid expensive XftFontMatch call when we know we won't find a match */
if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint) if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint)
goto no_match; goto no_match;
fccharset = FcCharSetCreate(); fccharset = FcCharSetCreate();
FcCharSetAddChar(fccharset, utf8codepoint); FcCharSetAddChar(fccharset, utf8codepoint);
if (!drw->fonts->pattern) { if (!drw->fonts->pattern) {
/* Refer to the comment in xfont_create for more information. */ /* Refer to the comment in xfont_create for more information. */
die("the first font in the cache must be loaded from a font string."); die("the first font in the cache must be loaded from a font string.");
} }
fcpattern = FcPatternDuplicate(drw->fonts->pattern); fcpattern = FcPatternDuplicate(drw->fonts->pattern);
FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset);
FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue);
FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern);
FcDefaultSubstitute(fcpattern); FcDefaultSubstitute(fcpattern);
match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result); match = XftFontMatch(drw->dpy, drw->screen, fcpattern, &result);
FcCharSetDestroy(fccharset); FcCharSetDestroy(fccharset);
FcPatternDestroy(fcpattern); FcPatternDestroy(fcpattern);
if (match) { if (match) {
usedfont = xfont_create(drw, NULL, match); usedfont = xfont_create(drw, NULL, match);
if (usedfont && XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) { if (usedfont &&
for (curfont = drw->fonts; curfont->next; curfont = curfont->next) XftCharExists(drw->dpy, usedfont->xfont, utf8codepoint)) {
; /* NOP */ for (curfont = drw->fonts; curfont->next; curfont = curfont->next)
curfont->next = usedfont; ; /* NOP */
} else { curfont->next = usedfont;
xfont_free(usedfont); } else {
nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint; xfont_free(usedfont);
no_match: nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint;
usedfont = drw->fonts; no_match:
} usedfont = drw->fonts;
} }
} }
} }
if (d) }
XftDrawDestroy(d); if (d)
XftDrawDestroy(d);
return x + (render ? w : 0); return x + (render ? w : 0);
} }
void void drw_map(Drw *drw, Window win, int x, int y, unsigned int w,
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) unsigned int h) {
{ if (!drw)
if (!drw) return;
return;
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
XSync(drw->dpy, False); XSync(drw->dpy, False);
} }
unsigned int unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {
drw_fontset_getwidth(Drw *drw, const char *text) if (!drw || !drw->fonts || !text)
{ return 0;
if (!drw || !drw->fonts || !text) return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
} }
unsigned int unsigned int drw_fontset_getwidth_clamp(Drw *drw, const char *text,
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n) unsigned int n) {
{ unsigned int tmp = 0;
unsigned int tmp = 0; if (drw && drw->fonts && text && n)
if (drw && drw->fonts && text && n) tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n);
tmp = drw_text(drw, 0, 0, 0, 0, 0, text, n); return MIN(n, tmp);
return MIN(n, tmp);
} }
void void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) unsigned int *w, unsigned int *h) {
{ XGlyphInfo ext;
XGlyphInfo ext;
if (!font || !text) if (!font || !text)
return; return;
XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext);
if (w) if (w)
*w = ext.xOff; *w = ext.xOff;
if (h) if (h)
*h = font->h; *h = font->h;
} }
Cur * Cur *drw_cur_create(Drw *drw, int shape) {
drw_cur_create(Drw *drw, int shape) Cur *cur;
{
Cur *cur;
if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) if (!drw || !(cur = ecalloc(1, sizeof(Cur))))
return NULL; return NULL;
cur->cursor = XCreateFontCursor(drw->dpy, shape); cur->cursor = XCreateFontCursor(drw->dpy, shape);
return cur; return cur;
} }
void void drw_cur_free(Drw *drw, Cur *cursor) {
drw_cur_free(Drw *drw, Cur *cursor) if (!cursor)
{ return;
if (!cursor)
return;
XFreeCursor(drw->dpy, cursor->cursor); XFreeCursor(drw->dpy, cursor->cursor);
free(cursor); free(cursor);
} }

View File

@ -0,0 +1,98 @@
diff -up a/config.def.h b/config.def.h
--- a/config.def.h 2022-10-04 19:38:18.000000000 +0200
+++ b/config.def.h 2023-05-06 22:19:27.298742237 +0200
@@ -5,6 +5,7 @@ static const unsigned int borderpx = 1;
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
+static const int allowkill = 1; /* allow killing clients by default? */
static const char *fonts[] = { "monospace:size=10" };
static const char dmenufont[] = "monospace:size=10";
static const char col_gray1[] = "#222222";
@@ -26,9 +27,9 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask allowkill isfloating monitor */
+ { "Gimp", NULL, NULL, 0, 1, 1, -1 },
+ { "Firefox", NULL, NULL, 1 << 8, 1, 0, -1 },
};
/* layout(s) */
@@ -78,6 +79,7 @@ static const Key keys[] = {
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
+ { MODKEY, XK_q, toggleallowkill,{0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
{ MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
{ MODKEY, XK_comma, focusmon, {.i = -1 } },
diff -up a/dwm.c b/dwm.c
--- a/dwm.c 2022-10-04 19:38:18.000000000 +0200
+++ b/dwm.c 2023-05-06 22:18:43.239357744 +0200
@@ -93,6 +93,7 @@ struct Client {
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ int allowkill;
Client *next;
Client *snext;
Monitor *mon;
@@ -137,6 +138,7 @@ typedef struct {
const char *instance;
const char *title;
unsigned int tags;
+ int allowkill;
int isfloating;
int monitor;
} Rule;
@@ -212,6 +214,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void toggleallowkill(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -288,6 +291,7 @@ applyrules(Client *c)
/* rule matching */
c->isfloating = 0;
c->tags = 0;
+ c->allowkill = allowkill;
XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
@@ -300,6 +304,7 @@ applyrules(Client *c)
{
c->isfloating = r->isfloating;
c->tags |= r->tags;
+ c->allowkill = r->allowkill;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
@@ -1006,7 +1011,7 @@ keypress(XEvent *e)
void
killclient(const Arg *arg)
{
- if (!selmon->sel)
+ if (!selmon->sel || !selmon->sel->allowkill)
return;
if (!sendevent(selmon->sel, wmatom[WMDelete])) {
XGrabServer(dpy);
@@ -1704,6 +1709,13 @@ togglebar(const Arg *arg)
}
void
+toggleallowkill(const Arg *arg)
+{
+ if (!selmon->sel) return;
+ selmon->sel->allowkill = !selmon->sel->allowkill;
+}
+
+void
togglefloating(const Arg *arg)
{
if (!selmon->sel)

88
dwm-attachtop-6.2.diff Normal file
View File

@ -0,0 +1,88 @@
From 17acbdcb56d0d2f39507a3f67ef329c14a213ef6 Mon Sep 17 00:00:00 2001
From: MLquest8 <miskuzius@gmail.com>
Date: Thu, 18 Jun 2020 15:34:18 +0400
Subject: [PATCH] attachtop. Attaches new client below the last master/on top
of the stack. In case of nmaster = 1 behaves like attachaside.
---
dwm.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/dwm.c b/dwm.c
index 9fd0286..7ced982 100644
--- a/dwm.c
+++ b/dwm.c
@@ -49,7 +49,8 @@
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
-#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
+#define ISVISIBLEONTAG(C, T) ((C->tags & T))
+#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags])
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
@@ -147,6 +148,7 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac
static void arrange(Monitor *m);
static void arrangemon(Monitor *m);
static void attach(Client *c);
+static void attachtop(Client *c);
static void attachstack(Client *c);
static void buttonpress(XEvent *e);
static void checkotherwm(void);
@@ -407,6 +409,25 @@ attach(Client *c)
c->mon->clients = c;
}
+void
+attachtop(Client *c)
+{
+ int n;
+ Monitor *m = selmon;
+ Client *below;
+
+ for (n = 1, below = c->mon->clients;
+ below && below->next && (below->isfloating || !ISVISIBLEONTAG(below, c->tags) || n != m->nmaster);
+ n = below->isfloating || !ISVISIBLEONTAG(below, c->tags) ? n + 0 : n + 1, below = below->next);
+ c->next = NULL;
+ if (below) {
+ c->next = below->next;
+ below->next = c;
+ }
+ else
+ c->mon->clients = c;
+}
+
void
attachstack(Client *c)
{
@@ -1063,7 +1084,7 @@ manage(Window w, XWindowAttributes *wa)
c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating)
XRaiseWindow(dpy, c->win);
- attach(c);
+ attachtop(c);
attachstack(c);
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
@@ -1418,7 +1439,7 @@ sendmon(Client *c, Monitor *m)
detachstack(c);
c->mon = m;
c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
- attach(c);
+ attachtop(c);
attachstack(c);
focus(NULL);
arrange(NULL);
@@ -1900,7 +1921,7 @@ updategeom(void)
m->clients = c->next;
detachstack(c);
c->mon = mons;
- attach(c);
+ attachtop(c);
attachstack(c);
}
if (m == selmon)
--
2.26.2

56
dwm-fullscreen-6.2.diff Normal file
View File

@ -0,0 +1,56 @@
From 54719285bd1a984e2efce6e8a8eab184fec11abf Mon Sep 17 00:00:00 2001
From: Sermak <sermak@jarvis.com>
Date: Mon, 8 Jul 2019 01:06:44 +0200
Subject: [PATCH] Simulate toggleable fullscreen mode
---
config.def.h | 1 +
dwm.c | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/config.def.h b/config.def.h
index 1c0b587..f774cc5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -76,6 +76,7 @@ static Key keys[] = {
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
+ { MODKEY|ShiftMask, XK_f, fullscreen, {0} },
{ MODKEY, XK_space, setlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_0, view, {.ui = ~0 } },
diff --git a/dwm.c b/dwm.c
index 4465af1..04b1e06 100644
--- a/dwm.c
+++ b/dwm.c
@@ -199,6 +199,7 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
+static void fullscreen(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -1497,6 +1498,19 @@ setfullscreen(Client *c, int fullscreen)
}
}
+Layout *last_layout;
+void
+fullscreen(const Arg *arg)
+{
+ if (selmon->showbar) {
+ for(last_layout = (Layout *)layouts; last_layout != selmon->lt[selmon->sellt]; last_layout++);
+ setlayout(&((Arg) { .v = &layouts[2] }));
+ } else {
+ setlayout(&((Arg) { .v = last_layout }));
+ }
+ togglebar(arg);
+}
+
void
setlayout(const Arg *arg)
{
--
2.22.0

View File

@ -0,0 +1,48 @@
:100644 100644 f1d86b2 0000000 M dwm.c
diff --git a/dwm.c b/dwm.c
index f1d86b2..d41cc14 100644
--- a/dwm.c
+++ b/dwm.c
@@ -433,9 +433,15 @@ buttonpress(XEvent *e)
}
if (ev->window == selmon->barwin) {
i = x = 0;
- do
+ unsigned int occ = 0;
+ for(c = m->clients; c; c=c->next)
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
+ do {
+ /* Do not reserve space for vacant tags */
+ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
+ continue;
x += TEXTW(tags[i]);
- while (ev->x >= x && ++i < LENGTH(tags));
+ } while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
@@ -715,19 +721,18 @@ drawbar(Monitor *m)
}
for (c = m->clients; c; c = c->next) {
- occ |= c->tags;
+ occ |= c->tags == TAGMASK ? 0 : c->tags;
if (c->isurgent)
urg |= c->tags;
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
+ /* Do not draw vacant tags */
+ if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
+ continue;
w = TEXTW(tags[i]);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
- if (occ & 1 << i)
- drw_rect(drw, x + boxs, boxs, boxw, boxw,
- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- urg & 1 << i);
x += w;
}
w = TEXTW(m->ltsymbol);

234
dwm-keychord-6.4.diff Normal file
View File

@ -0,0 +1,234 @@
From cb7ea178ac8e60cf123b333af64df8228762f669 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aaron=20Z=C3=BCger?= <contact@azureorange.xyz>
Date: Wed, 19 Jul 2023 14:17:39 +0200
Subject: [PATCH] Update dwm-keychord patch to comply with the changes in dwm
from version 6.2 to version 6.4. Namely changes in the grabkey function to
match the newer implementation of said function.
---
config.def.h | 81 ++++++++++++++++++++++++++--------------------------
dwm.c | 72 +++++++++++++++++++++++++++++++++++++---------
2 files changed, 99 insertions(+), 54 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9efa774..49f0558 100644
--- a/config.def.h
+++ b/config.def.h
@@ -46,11 +46,11 @@ static const Layout layouts[] = {
/* key definitions */
#define MODKEY Mod1Mask
-#define TAGKEYS(KEY,TAG) \
- { MODKEY, KEY, view, {.ui = 1 << TAG} }, \
- { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
- { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \
- { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} },
+#define TAGKEYS(KEY,TAG) \
+ &((Keychord){1, {{MODKEY, KEY}}, view, {.ui = 1 << TAG} }), \
+ &((Keychord){1, {{MODKEY|ControlMask, KEY}}, toggleview, {.ui = 1 << TAG} }), \
+ &((Keychord){1, {{MODKEY|ShiftMask, KEY}}, tag, {.ui = 1 << TAG} }), \
+ &((Keychord){1, {{MODKEY|ControlMask|ShiftMask, KEY}}, toggletag, {.ui = 1 << TAG} }),
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
@@ -60,41 +60,42 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
-static const Key keys[] = {
- /* modifier key function argument */
- { MODKEY, XK_p, spawn, {.v = dmenucmd } },
- { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
- { MODKEY, XK_b, togglebar, {0} },
- { MODKEY, XK_j, focusstack, {.i = +1 } },
- { MODKEY, XK_k, focusstack, {.i = -1 } },
- { MODKEY, XK_i, incnmaster, {.i = +1 } },
- { MODKEY, XK_d, incnmaster, {.i = -1 } },
- { MODKEY, XK_h, setmfact, {.f = -0.05} },
- { MODKEY, XK_l, setmfact, {.f = +0.05} },
- { MODKEY, XK_Return, zoom, {0} },
- { MODKEY, XK_Tab, view, {0} },
- { MODKEY|ShiftMask, XK_c, killclient, {0} },
- { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
- { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
- { MODKEY, XK_space, setlayout, {0} },
- { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
- { MODKEY, XK_0, view, {.ui = ~0 } },
- { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
- { MODKEY, XK_comma, focusmon, {.i = -1 } },
- { MODKEY, XK_period, focusmon, {.i = +1 } },
- { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
- { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
- TAGKEYS( XK_1, 0)
- TAGKEYS( XK_2, 1)
- TAGKEYS( XK_3, 2)
- TAGKEYS( XK_4, 3)
- TAGKEYS( XK_5, 4)
- TAGKEYS( XK_6, 5)
- TAGKEYS( XK_7, 6)
- TAGKEYS( XK_8, 7)
- TAGKEYS( XK_9, 8)
- { MODKEY|ShiftMask, XK_q, quit, {0} },
+static Keychord *keychords[] = {
+ /* Keys function argument */
+ &((Keychord){1, {{MODKEY, XK_p}}, spawn, {.v = dmenucmd } }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_Return}}, spawn, {.v = termcmd } }),
+ &((Keychord){2, {{MODKEY, XK_e}, {MODKEY, XK_e}}, spawn, {.v = termcmd } }),
+ &((Keychord){1, {{MODKEY, XK_b}}, togglebar, {0} }),
+ &((Keychord){1, {{MODKEY, XK_j}}, focusstack, {.i = +1 } }),
+ &((Keychord){1, {{MODKEY, XK_k}}, focusstack, {.i = -1 } }),
+ &((Keychord){1, {{MODKEY, XK_i}}, incnmaster, {.i = +1 } }),
+ &((Keychord){1, {{MODKEY, XK_d}}, incnmaster, {.i = -1 } }),
+ &((Keychord){1, {{MODKEY, XK_h}}, setmfact, {.f = -0.05} }),
+ &((Keychord){1, {{MODKEY, XK_l}}, setmfact, {.f = +0.05} }),
+ &((Keychord){1, {{MODKEY, XK_Return}}, zoom, {0} }),
+ &((Keychord){1, {{MODKEY, XK_Tab}}, view, {0} }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_c}}, killclient, {0} }),
+ &((Keychord){1, {{MODKEY, XK_t}}, setlayout, {.v = &layouts[0]} }),
+ &((Keychord){1, {{MODKEY, XK_f}}, setlayout, {.v = &layouts[1]} }),
+ &((Keychord){1, {{MODKEY, XK_m}}, setlayout, {.v = &layouts[2]} }),
+ &((Keychord){1, {{MODKEY, XK_space}}, setlayout, {0} }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_space}}, togglefloating, {0} }),
+ &((Keychord){1, {{MODKEY, XK_0}}, view, {.ui = ~0 } }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_0}}, tag, {.ui = ~0 } }),
+ &((Keychord){1, {{MODKEY, XK_comma}}, focusmon, {.i = -1 } }),
+ &((Keychord){1, {{MODKEY, XK_period}}, focusmon, {.i = +1 } }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_comma}}, tagmon, {.i = -1 } }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_period}}, tagmon, {.i = +1 } }),
+ &((Keychord){1, {{MODKEY|ShiftMask, XK_q}}, quit, {0} }),
+ TAGKEYS( XK_1, 0)
+ TAGKEYS( XK_2, 1)
+ TAGKEYS( XK_3, 2)
+ TAGKEYS( XK_4, 3)
+ TAGKEYS( XK_5, 4)
+ TAGKEYS( XK_6, 5)
+ TAGKEYS( XK_7, 6)
+ TAGKEYS( XK_8, 7)
+ TAGKEYS( XK_9, 8)
};
/* button definitions */
diff --git a/dwm.c b/dwm.c
index f1d86b2..e4885a4 100644
--- a/dwm.c
+++ b/dwm.c
@@ -102,9 +102,14 @@ struct Client {
typedef struct {
unsigned int mod;
KeySym keysym;
+} Key;
+
+typedef struct {
+ unsigned int n;
+ const Key keys[5];
void (*func)(const Arg *);
const Arg arg;
-} Key;
+} Keychord;
typedef struct {
const char *symbol;
@@ -267,6 +272,7 @@ static Display *dpy;
static Drw *drw;
static Monitor *mons, *selmon;
static Window root, wmcheckwin;
+unsigned int currentkey = 0;
/* configuration, allows nested code to access above variables */
#include "config.h"
@@ -954,7 +960,8 @@ grabkeys(void)
{
updatenumlockmask();
{
- unsigned int i, j, k;
+ /* unsigned int i, j, k; */
+ unsigned int i, c, k;
unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
int start, end, skip;
KeySym *syms;
@@ -964,15 +971,18 @@ grabkeys(void)
syms = XGetKeyboardMapping(dpy, start, end - start + 1, &skip);
if (!syms)
return;
+
for (k = start; k <= end; k++)
- for (i = 0; i < LENGTH(keys); i++)
+ for (i = 0; i < LENGTH(keychords); i++)
/* skip modifier codes, we do that ourselves */
- if (keys[i].keysym == syms[(k - start) * skip])
- for (j = 0; j < LENGTH(modifiers); j++)
+ if (keychords[i]->keys[currentkey].keysym == syms[(k - start) * skip])
+ for (c = 0; c < LENGTH(modifiers); c++)
XGrabKey(dpy, k,
- keys[i].mod | modifiers[j],
+ keychords[i]->keys[currentkey].mod | modifiers[c],
root, True,
GrabModeAsync, GrabModeAsync);
+ if(currentkey > 0)
+ XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Escape), AnyModifier, root, True, GrabModeAsync, GrabModeAsync);
XFree(syms);
}
}
@@ -999,17 +1009,51 @@ isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info)
void
keypress(XEvent *e)
{
- unsigned int i;
+ /* unsigned int i; */
+ XEvent event = *e;
+ unsigned int ran = 0;
KeySym keysym;
XKeyEvent *ev;
- ev = &e->xkey;
- keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
- for (i = 0; i < LENGTH(keys); i++)
- if (keysym == keys[i].keysym
- && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
- && keys[i].func)
- keys[i].func(&(keys[i].arg));
+ Keychord *arr1[sizeof(keychords) / sizeof(Keychord*)];
+ Keychord *arr2[sizeof(keychords) / sizeof(Keychord*)];
+ memcpy(arr1, keychords, sizeof(keychords));
+ Keychord **rpointer = arr1;
+ Keychord **wpointer = arr2;
+
+ size_t r = sizeof(keychords)/ sizeof(Keychord*);
+
+ while(1){
+ ev = &event.xkey;
+ keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
+ size_t w = 0;
+ for (int i = 0; i < r; i++){
+ if(keysym == (*(rpointer + i))->keys[currentkey].keysym
+ && CLEANMASK((*(rpointer + i))->keys[currentkey].mod) == CLEANMASK(ev->state)
+ && (*(rpointer + i))->func){
+ if((*(rpointer + i))->n == currentkey +1){
+ (*(rpointer + i))->func(&((*(rpointer + i))->arg));
+ ran = 1;
+ }else{
+ *(wpointer + w) = *(rpointer + i);
+ w++;
+ }
+ }
+ }
+ currentkey++;
+ if(w == 0 || ran == 1)
+ break;
+ grabkeys();
+ while (running && !XNextEvent(dpy, &event) && !ran)
+ if(event.type == KeyPress)
+ break;
+ r = w;
+ Keychord **holder = rpointer;
+ rpointer = wpointer;
+ wpointer = holder;
+ }
+ currentkey = 0;
+ grabkeys();
}
void
--
2.41.0

View File

@ -0,0 +1,95 @@
From 9a4037dc0ef56f91c009317e78e9e3790dafbb58 Mon Sep 17 00:00:00 2001
From: BrunoCooper17 <BrunoCooper17@outlook.com>
Date: Mon, 15 Nov 2021 14:04:53 -0600
Subject: [PATCH] MoveStack patch
This plugin allows you to move clients around in the stack and swap them
with the master. It emulates the behavior off mod+shift+j and mod+shift+k
in Xmonad. movestack(+1) will swap the client with the current focus with
the next client. movestack(-1) will swap the client with the current focus
with the previous client.
---
config.def.h | 3 +++
movestack.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
create mode 100644 movestack.c
diff --git a/config.def.h b/config.def.h
index a2ac963..33efa5b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
+#include "movestack.c"
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@@ -71,6 +72,8 @@ static Key keys[] = {
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
+ { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
diff --git a/movestack.c b/movestack.c
new file mode 100644
index 0000000..520f4ae
--- /dev/null
+++ b/movestack.c
@@ -0,0 +1,48 @@
+void
+movestack(const Arg *arg) {
+ Client *c = NULL, *p = NULL, *pc = NULL, *i;
+
+ if(arg->i > 0) {
+ /* find the client after selmon->sel */
+ for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
+ if(!c)
+ for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
+
+ }
+ else {
+ /* find the client before selmon->sel */
+ for(i = selmon->clients; i != selmon->sel; i = i->next)
+ if(ISVISIBLE(i) && !i->isfloating)
+ c = i;
+ if(!c)
+ for(; i; i = i->next)
+ if(ISVISIBLE(i) && !i->isfloating)
+ c = i;
+ }
+ /* find the client before selmon->sel and c */
+ for(i = selmon->clients; i && (!p || !pc); i = i->next) {
+ if(i->next == selmon->sel)
+ p = i;
+ if(i->next == c)
+ pc = i;
+ }
+
+ /* swap c and selmon->sel selmon->clients in the selmon->clients list */
+ if(c && c != selmon->sel) {
+ Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
+ selmon->sel->next = c->next==selmon->sel?c:c->next;
+ c->next = temp;
+
+ if(p && p != c)
+ p->next = c;
+ if(pc && pc != selmon->sel)
+ pc->next = selmon->sel;
+
+ if(selmon->sel == selmon->clients)
+ selmon->clients = c;
+ else if(c == selmon->clients)
+ selmon->clients = selmon->sel;
+
+ arrange(selmon);
+ }
+}
\ No newline at end of file
--
2.33.1

View File

@ -0,0 +1,148 @@
diff --git a/config.def.h b/config.def.h
index 9efa774..c3e236e 100644
--- a/config.def.h
+++ b/config.def.h
@@ -26,9 +26,10 @@ static const Rule rules[] = {
* WM_CLASS(STRING) = instance, class
* WM_NAME(STRING) = title
*/
- /* class instance title tags mask isfloating monitor */
- { "Gimp", NULL, NULL, 0, 1, -1 },
- { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
+ /* class instance title tags mask isfloating monitor scratch key */
+ { "Gimp", NULL, NULL, 0, 1, -1, 0 },
+ { "firefox", NULL, NULL, 1 << 8, 0, -1, 0 },
+ { NULL, NULL, "scratchpad", 0, 1, -1, 's' },
};
/* layout(s) */
@@ -60,10 +61,14 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
+/*First arg only serves to match against key in rules*/
+static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL};
+
static const Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
+ { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
{ MODKEY, XK_b, togglebar, {0} },
{ MODKEY, XK_j, focusstack, {.i = +1 } },
{ MODKEY, XK_k, focusstack, {.i = -1 } },
diff --git a/dwm.c b/dwm.c
index f1d86b2..be6a754 100644
--- a/dwm.c
+++ b/dwm.c
@@ -93,6 +93,7 @@ struct Client {
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ char scratchkey;
Client *next;
Client *snext;
Monitor *mon;
@@ -139,6 +140,7 @@ typedef struct {
unsigned int tags;
int isfloating;
int monitor;
+ const char scratchkey;
} Rule;
/* function declarations */
@@ -206,11 +208,13 @@ static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void spawn(const Arg *arg);
+static void spawnscratch(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglebar(const Arg *arg);
static void togglefloating(const Arg *arg);
+static void togglescratch(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
@@ -287,6 +291,7 @@ applyrules(Client *c)
/* rule matching */
c->isfloating = 0;
c->tags = 0;
+ c->scratchkey = 0;
XGetClassHint(dpy, c->win, &ch);
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
@@ -299,6 +304,7 @@ applyrules(Client *c)
{
c->isfloating = r->isfloating;
c->tags |= r->tags;
+ c->scratchkey = r->scratchkey;
for (m = mons; m && m->num != r->monitor; m = m->next);
if (m)
c->mon = m;
@@ -308,6 +314,7 @@ applyrules(Client *c)
XFree(ch.res_class);
if (ch.res_name)
XFree(ch.res_name);
+
c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
}
@@ -1666,6 +1673,27 @@ spawn(const Arg *arg)
}
}
+void spawnscratch(const Arg *arg)
+{
+ struct sigaction sa;
+
+ if (fork() == 0) {
+ if (dpy)
+ close(ConnectionNumber(dpy));
+ setsid();
+
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &sa, NULL);
+
+ execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
+ fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
+ perror(" failed");
+ exit(EXIT_SUCCESS);
+ }
+}
+
void
tag(const Arg *arg)
{
@@ -1735,6 +1763,28 @@ togglefloating(const Arg *arg)
arrange(selmon);
}
+void
+togglescratch(const Arg *arg)
+{
+ Client *c;
+ unsigned int found = 0;
+
+ for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next);
+ if (found) {
+ c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags];
+ focus(NULL);
+ arrange(selmon);
+
+ if (ISVISIBLE(c)) {
+ focus(c);
+ restack(selmon);
+ }
+
+ } else{
+ spawnscratch(arg);
+ }
+}
+
void
toggletag(const Arg *arg)
{

View File

@ -0,0 +1,177 @@
diff --git a/dwm.c b/dwm.c
index 664c527..ac8e4ec 100644
--- a/dwm.c
+++ b/dwm.c
@@ -111,6 +111,7 @@ typedef struct {
void (*arrange)(Monitor *);
} Layout;
+typedef struct Pertag Pertag;
struct Monitor {
char ltsymbol[16];
float mfact;
@@ -130,6 +131,7 @@ struct Monitor {
Monitor *next;
Window barwin;
const Layout *lt[2];
+ Pertag *pertag;
};
typedef struct {
@@ -272,6 +274,15 @@ static Window root, wmcheckwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
+struct Pertag {
+ unsigned int curtag, prevtag; /* current and previous tag */
+ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
+ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
+ unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
+ const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */
+ int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
+};
+
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -632,6 +643,7 @@ Monitor *
createmon(void)
{
Monitor *m;
+ unsigned int i;
m = ecalloc(1, sizeof(Monitor));
m->tagset[0] = m->tagset[1] = 1;
@@ -642,6 +654,20 @@ createmon(void)
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+ m->pertag = ecalloc(1, sizeof(Pertag));
+ m->pertag->curtag = m->pertag->prevtag = 1;
+
+ for (i = 0; i <= LENGTH(tags); i++) {
+ m->pertag->nmasters[i] = m->nmaster;
+ m->pertag->mfacts[i] = m->mfact;
+
+ m->pertag->ltidxs[i][0] = m->lt[0];
+ m->pertag->ltidxs[i][1] = m->lt[1];
+ m->pertag->sellts[i] = m->sellt;
+
+ m->pertag->showbars[i] = m->showbar;
+ }
+
return m;
}
@@ -967,7 +993,7 @@ grabkeys(void)
void
incnmaster(const Arg *arg)
{
- selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
arrange(selmon);
}
@@ -1502,9 +1528,9 @@ void
setlayout(const Arg *arg)
{
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
- selmon->sellt ^= 1;
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
if (arg && arg->v)
- selmon->lt[selmon->sellt] = (Layout *)arg->v;
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel)
arrange(selmon);
@@ -1523,7 +1549,7 @@ setmfact(const Arg *arg)
f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
if (f < 0.05 || f > 0.95)
return;
- selmon->mfact = f;
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
arrange(selmon);
}
@@ -1702,7 +1728,7 @@ tile(Monitor *m)
void
togglebar(const Arg *arg)
{
- selmon->showbar = !selmon->showbar;
+ selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
updatebarpos(selmon);
XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
arrange(selmon);
@@ -1741,9 +1767,33 @@ void
toggleview(const Arg *arg)
{
unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+ int i;
if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset;
+
+ if (newtagset == ~0) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = 0;
+ }
+
+ /* test if the user did not select the same tag */
+ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ for (i = 0; !(newtagset & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+
+ /* apply settings for this view */
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
+ togglebar(NULL);
+
focus(NULL);
arrange(selmon);
}
@@ -2038,11 +2088,37 @@ updatewmhints(Client *c)
void
view(const Arg *arg)
{
+ int i;
+ unsigned int tmptag;
+
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
- if (arg->ui & TAGMASK)
+ if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+
+ if (arg->ui == ~0)
+ selmon->pertag->curtag = 0;
+ else {
+ for (i = 0; !(arg->ui & 1 << i); i++) ;
+ selmon->pertag->curtag = i + 1;
+ }
+ } else {
+ tmptag = selmon->pertag->prevtag;
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+ selmon->pertag->curtag = tmptag;
+ }
+
+ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
+ selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
+ selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
+ selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
+ selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
+
+ if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
+ togglebar(NULL);
+
focus(NULL);
arrange(selmon);
}

View File

@ -0,0 +1,139 @@
From 2991f37f0aaf44b9f9b11e7893ff0af8eb88f649 Mon Sep 17 00:00:00 2001
From: Christopher Drelich <cd@cdrakka.com>
Date: Wed, 23 May 2018 22:50:38 -0400
Subject: [PATCH] Modifies quit to handle restarts and adds SIGHUP and SIGTERM
handlers.
Modified quit() to restart if it receives arg .i = 1
MOD+CTRL+SHIFT+Q was added to confid.def.h to do just that.
Signal handlers were handled for SIGHUP and SIGTERM.
If dwm receives these signals it calls quit() with
arg .i = to 1 or 0, respectively.
To restart dwm:
MOD+CTRL+SHIFT+Q
or
kill -HUP dwmpid
To quit dwm cleanly:
MOD+SHIFT+Q
or
kill -TERM dwmpid
---
config.def.h | 1 +
dwm.1 | 10 ++++++++++
dwm.c | 22 ++++++++++++++++++++++
3 files changed, 33 insertions(+)
diff --git a/config.def.h b/config.def.h
index a9ac303..e559429 100644
--- a/config.def.h
+++ b/config.def.h
@@ -94,6 +94,7 @@ static Key keys[] = {
TAGKEYS( XK_8, 7)
TAGKEYS( XK_9, 8)
{ MODKEY|ShiftMask, XK_q, quit, {0} },
+ { MODKEY|ControlMask|ShiftMask, XK_q, quit, {1} },
};
/* button definitions */
diff --git a/dwm.1 b/dwm.1
index 13b3729..36a331c 100644
--- a/dwm.1
+++ b/dwm.1
@@ -142,6 +142,9 @@ Add/remove all windows with nth tag to/from the view.
.TP
.B Mod1\-Shift\-q
Quit dwm.
+.TP
+.B Mod1\-Control\-Shift\-q
+Restart dwm.
.SS Mouse commands
.TP
.B Mod1\-Button1
@@ -155,6 +158,13 @@ Resize focused window while dragging. Tiled windows will be toggled to the float
.SH CUSTOMIZATION
dwm is customized by creating a custom config.h and (re)compiling the source
code. This keeps it fast, secure and simple.
+.SH SIGNALS
+.TP
+.B SIGHUP - 1
+Restart the dwm process.
+.TP
+.B SIGTERM - 15
+Cleanly terminate the dwm process.
.SH SEE ALSO
.BR dmenu (1),
.BR st (1)
diff --git a/dwm.c b/dwm.c
index bb95e26..286eecd 100644
--- a/dwm.c
+++ b/dwm.c
@@ -205,6 +205,8 @@ static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void sigchld(int unused);
+static void sighup(int unused);
+static void sigterm(int unused);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
@@ -260,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[UnmapNotify] = unmapnotify
};
static Atom wmatom[WMLast], netatom[NetLast];
+static int restart = 0;
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
@@ -1248,6 +1251,7 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
+ if(arg->i) restart = 1;
running = 0;
}
@@ -1536,6 +1540,9 @@ setup(void)
/* clean up any zombies immediately */
sigchld(0);
+ signal(SIGHUP, sighup);
+ signal(SIGTERM, sigterm);
+
/* init screen */
screen = DefaultScreen(dpy);
sw = DisplayWidth(dpy, screen);
@@ -1637,6 +1644,20 @@ sigchld(int unused)
}
void
+sighup(int unused)
+{
+ Arg a = {.i = 1};
+ quit(&a);
+}
+
+void
+sigterm(int unused)
+{
+ Arg a = {.i = 0};
+ quit(&a);
+}
+
+void
spawn(const Arg *arg)
{
if (arg->v == dmenucmd)
@@ -2139,6 +2160,7 @@ main(int argc, char *argv[])
setup();
scan();
run();
+ if(restart) execvp(argv[0], argv);
cleanup();
XCloseDisplay(dpy);
return EXIT_SUCCESS;
--
2.7.4

198
dwm-shif-tools-6.2.diff Normal file
View File

@ -0,0 +1,198 @@
From d57c8508c9f26be40667d402a2daaa2b27ae759f Mon Sep 17 00:00:00 2001
From: explosion-mental <explosion0mental@gmail.com>
Date: Wed, 11 Aug 2021 21:05:44 -0500
Subject: [PATCH] shift-tools - shifttag, moves the current selected client to
the adjacent tag - shifttagclients, moves the current selected client to the
adjacent tag that has at least one client else acts as shifttag -
shiftview, view adjacent tag - shiftviewclients, view the closes tag that has
a client. If none acts as shiftview - shiftboth, shifttag and shiftview.
Basically moves the window to the next/prev tag and follows it. -
shiftswaptags, its a shift implementation on the swaptags function (see
https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
for more details), which in short 'swaps tags' (swaps all clients with
the clients on the adjacent tag). A pretty useful example of this is
chosing a tag empty and sending all your clients to that tag. - swapfunction
is the 'helper' function for the shiftswaptags. remember that these functions
**shift**, which means you can go from tag 1 to 9 or 9 to 1. Also remember
that the default argument is 1 and you can change it.
---
config.def.h | 9 ++++
shift-tools.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+)
create mode 100644 shift-tools.c
diff --git a/config.def.h b/config.def.h
index 1c0b587..1390d17 100644
--- a/config.def.h
+++ b/config.def.h
@@ -58,9 +58,14 @@ static const Layout layouts[] = {
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[] = { "st", NULL };
+#include "shift-tools.c"
static Key keys[] = {
/* modifier key function argument */
+ { MODKEY, XK_o, shiftviewclients, { .i = +1 } },
+ { MODKEY|ShiftMask, XK_o, shiftview, { .i = +1 } },
+ { MODKEY|ShiftMask, XK_i, shiftview, { .i = -1 } },
+ { MODKEY, XK_i, shiftviewclients, { .i = -1 } },
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
{ MODKEY, XK_b, togglebar, {0} },
@@ -69,6 +74,10 @@ static Key keys[] = {
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
+ { MODKEY|ShiftMask, XK_h, shiftboth, { .i = -1 } },
+ { MODKEY|ControlMask, XK_h, shiftswaptags, { .i = -1 } },
+ { MODKEY|ControlMask, XK_l, shiftswaptags, { .i = +1 } },
+ { MODKEY|ShiftMask, XK_l, shiftboth, { .i = +1 } },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
diff --git a/shift-tools.c b/shift-tools.c
new file mode 100644
index 0000000..cf130c8
--- /dev/null
+++ b/shift-tools.c
@@ -0,0 +1,135 @@
+/* Sends a window to the next/prev tag */
+void
+shifttag(const Arg *arg)
+{
+ Arg shifted;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+
+ if (arg->i > 0) /* left circular shift */
+ shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
+ else /* right circular shift */
+ shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
+ tag(&shifted);
+}
+/* Sends a window to the next/prev tag that has a client, else it moves it to the next/prev one. */
+void
+shifttagclients(const Arg *arg)
+{
+
+ Arg shifted;
+ Client *c;
+ unsigned int tagmask = 0;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+ for (c = selmon->clients; c; c = c->next)
+ if (!(c->tags))
+ tagmask = tagmask | c->tags;
+
+
+ if (arg->i > 0) /* left circular shift */
+ do {
+ shifted.ui = (shifted.ui << arg->i)
+ | (shifted.ui >> (LENGTH(tags) - arg->i));
+ } while (tagmask && !(shifted.ui & tagmask));
+ else /* right circular shift */
+ do {
+ shifted.ui = (shifted.ui >> (- arg->i)
+ | shifted.ui << (LENGTH(tags) + arg->i));
+ } while (tagmask && !(shifted.ui & tagmask));
+ tag(&shifted);
+}
+/* Navigate to the next/prev tag */
+void
+shiftview(const Arg *arg)
+{
+ Arg shifted;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+ if (arg->i > 0) /* left circular shift */
+ shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i));
+ else /* right circular shift */
+ shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
+ view(&shifted);
+}
+/* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */
+void
+shiftviewclients(const Arg *arg)
+{
+ Arg shifted;
+ Client *c;
+ unsigned int tagmask = 0;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+ for (c = selmon->clients; c; c = c->next)
+ if (!(c->tags))
+ tagmask = tagmask | c->tags;
+
+
+ if (arg->i > 0) /* left circular shift */
+ do {
+ shifted.ui = (shifted.ui << arg->i)
+ | (shifted.ui >> (LENGTH(tags) - arg->i));
+ } while (tagmask && !(shifted.ui & tagmask));
+ else /* right circular shift */
+ do {
+ shifted.ui = (shifted.ui >> (- arg->i)
+ | shifted.ui << (LENGTH(tags) + arg->i));
+ } while (tagmask && !(shifted.ui & tagmask));
+ view(&shifted);
+}
+/* move the current active window to the next/prev tag and view it. More like following the window */
+void
+shiftboth(const Arg *arg)
+{
+ Arg shifted;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+ if (arg->i > 0) /* left circular shift */
+ shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
+ else /* right circular shift */
+ shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
+ tag(&shifted);
+ view(&shifted);
+}
+//helper function for shiftswaptags.
+//see: https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
+void
+swaptags(const Arg *arg)
+{
+ Client *c;
+ unsigned int newtag = arg->ui & TAGMASK;
+ unsigned int curtag = selmon->tagset[selmon->seltags];
+
+ if (newtag == curtag || !curtag || (curtag & (curtag-1)))
+ return;
+
+ for (c = selmon->clients; c != NULL; c = c->next) {
+ if ((c->tags & newtag) || (c->tags & curtag))
+ c->tags ^= curtag ^ newtag;
+
+ if (!c->tags)
+ c->tags = newtag;
+ }
+
+ //move to the swaped tag
+ //selmon->tagset[selmon->seltags] = newtag;
+
+ focus(NULL);
+ arrange(selmon);
+}
+/* swaps "tags" (all the clients) with the next/prev tag. */
+void
+shiftswaptags(const Arg *arg)
+{
+ Arg shifted;
+ shifted.ui = selmon->tagset[selmon->seltags];
+
+ if (arg->i > 0) /* left circular shift */
+ shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
+ else /* right circular shift */
+ shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
+ swaptags(&shifted);
+ // uncomment if you also want to "go" (view) the tag where the the clients are going
+ //view(&shifted);
+}
--
2.32.0

View File

@ -0,0 +1,220 @@
From ca2a2e6386a746ebfc3480787e5d99da11e7abee Mon Sep 17 00:00:00 2001
From: Justinas Grigas <dev@jstnas.com>
Date: Wed, 9 Oct 2024 01:00:20 +0100
Subject: [PATCH] [dwm][statuscmd] better click regions
The main improvement of this patch over the previous version 20210405 is that
the click region now ends on a matching signal raw byte.
The matching byte is optional, and without it dwm will behave as before.
To take advantage of this feature, scripts need to be modified to print the raw
byte at the end as well.
In addition, this patch cleanly applies onto master branch.
---
config.def.h | 6 ++-
dwm.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 104 insertions(+), 6 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9efa774..d008275 100644
--- a/config.def.h
+++ b/config.def.h
@@ -55,6 +55,8 @@ static const Layout layouts[] = {
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
+#define STATUSBAR "dwmblocks"
+
/* commands */
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
@@ -104,7 +106,9 @@ static const Button buttons[] = {
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
+ { ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} },
+ { ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} },
+ { ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
diff --git a/dwm.c b/dwm.c
index 1443802..94ee0c7 100644
--- a/dwm.c
+++ b/dwm.c
@@ -171,6 +171,7 @@ static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
+static pid_t getstatusbarpid();
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused);
static void grabkeys(void);
@@ -204,6 +205,7 @@ static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
+static void sigstatusbar(const Arg *arg);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
@@ -236,6 +238,9 @@ static void zoom(const Arg *arg);
/* variables */
static const char broken[] = "broken";
static char stext[256];
+static int statusw;
+static int statussig;
+static pid_t statuspid = -1;
static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh; /* bar height */
@@ -422,6 +427,7 @@ buttonpress(XEvent *e)
Client *c;
Monitor *m;
XButtonPressedEvent *ev = &e->xbutton;
+ char *text, *s, ch;
click = ClkRootWin;
/* focus monitor if necessary */
@@ -440,9 +446,27 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
click = ClkLtSymbol;
- else if (ev->x > selmon->ww - (int)TEXTW(stext))
+ else if (ev->x > selmon->ww - statusw) {
+ x = selmon->ww - statusw;
click = ClkStatusText;
- else
+ statussig = 0;
+ for (text = s = stext; *s && x <= ev->x; s++) {
+ if ((unsigned char)(*s) < ' ') {
+ ch = *s;
+ *s = '\0';
+ x += TEXTW(text) - lrpad;
+ *s = ch;
+ text = s + 1;
+ if (x >= ev->x)
+ break;
+ /* reset on matching signal raw byte */
+ if (ch == statussig)
+ statussig = 0;
+ else
+ statussig = ch;
+ }
+ }
+ } else
click = ClkWinTitle;
} else if ((c = wintoclient(ev->window))) {
focus(c);
@@ -708,9 +732,24 @@ drawbar(Monitor *m)
/* draw status first so it can be overdrawn by tags later */
if (m == selmon) { /* status is only drawn on selected monitor */
+ char *text, *s, ch;
drw_setscheme(drw, scheme[SchemeNorm]);
- tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+
+ x = 0;
+ for (text = s = stext; *s; s++) {
+ if ((unsigned char)(*s) < ' ') {
+ ch = *s;
+ *s = '\0';
+ tw = TEXTW(text) - lrpad;
+ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
+ x += tw;
+ *s = ch;
+ text = s + 1;
+ }
+ }
+ tw = TEXTW(text) - lrpad + 2;
+ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
+ tw = statusw;
}
for (c = m->clients; c; c = c->next) {
@@ -876,6 +915,30 @@ getatomprop(Client *c, Atom prop)
return atom;
}
+pid_t
+getstatusbarpid()
+{
+ char buf[32], *str = buf, *c;
+ FILE *fp;
+
+ if (statuspid > 0) {
+ snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
+ if ((fp = fopen(buf, "r"))) {
+ fgets(buf, sizeof(buf), fp);
+ while ((c = strchr(str, '/')))
+ str = c + 1;
+ fclose(fp);
+ if (!strcmp(str, STATUSBAR))
+ return statuspid;
+ }
+ }
+ if (!(fp = popen("pidof -s "STATUSBAR, "r")))
+ return -1;
+ fgets(buf, sizeof(buf), fp);
+ pclose(fp);
+ return strtol(buf, NULL, 10);
+}
+
int
getrootptr(int *x, int *y)
{
@@ -1643,6 +1706,20 @@ showhide(Client *c)
}
}
+void
+sigstatusbar(const Arg *arg)
+{
+ union sigval sv;
+
+ if (!statussig)
+ return;
+ sv.sival_int = arg->i;
+ if ((statuspid = getstatusbarpid()) <= 0)
+ return;
+
+ sigqueue(statuspid, SIGRTMIN+statussig, sv);
+}
+
void
spawn(const Arg *arg)
{
@@ -2004,8 +2081,25 @@ updatesizehints(Client *c)
void
updatestatus(void)
{
- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
+ if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) {
strcpy(stext, "dwm-"VERSION);
+ statusw = TEXTW(stext) - lrpad + 2;
+ } else {
+ char *text, *s, ch;
+
+ statusw = 0;
+ for (text = s = stext; *s; s++) {
+ if ((unsigned char)(*s) < ' ') {
+ ch = *s;
+ *s = '\0';
+ statusw += TEXTW(text) - lrpad;
+ *s = ch;
+ text = s + 1;
+ }
+ }
+ statusw += TEXTW(text) - lrpad + 2;
+
+ }
drawbar(selmon);
}
--
2.46.2

63
dwm-steam-6.2.diff Normal file
View File

@ -0,0 +1,63 @@
From 2550931c66e10e667ce56a6761cbadd12b331c52 Mon Sep 17 00:00:00 2001
From: bakkeby <bakkeby@gmail.com>
Date: Mon, 10 Aug 2020 16:45:00 +0200
Subject: [PATCH] Steam patch
Steam, and steam windows (games), trigger a ConfigureNotify request every time the window
gets focus. More so, the configure event passed along from Steam tends to have the wrong
x and y coordinates which can make the window, if floating, jump around the screen.
This patch works around this age-old issue by ignoring the x and y co-ordinates for
ConfigureNotify requests relating to Steam windows.
---
dwm.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/dwm.c b/dwm.c
index 4465af1..598d36d 100644
--- a/dwm.c
+++ b/dwm.c
@@ -93,6 +93,7 @@ struct Client {
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
+ int issteam;
Client *next;
Client *snext;
Monitor *mon;
@@ -291,6 +292,9 @@ applyrules(Client *c)
class = ch.res_class ? ch.res_class : broken;
instance = ch.res_name ? ch.res_name : broken;
+ if (strstr(class, "Steam") || strstr(class, "steam_app_"))
+ c->issteam = 1;
+
for (i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
if ((!r->title || strstr(c->name, r->title))
@@ -588,13 +592,15 @@ configurerequest(XEvent *e)
c->bw = ev->border_width;
else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
m = c->mon;
- if (ev->value_mask & CWX) {
- c->oldx = c->x;
- c->x = m->mx + ev->x;
- }
- if (ev->value_mask & CWY) {
- c->oldy = c->y;
- c->y = m->my + ev->y;
+ if (!c->issteam) {
+ if (ev->value_mask & CWX) {
+ c->oldx = c->x;
+ c->x = m->mx + ev->x;
+ }
+ if (ev->value_mask & CWY) {
+ c->oldy = c->y;
+ c->y = m->my + ev->y;
+ }
}
if (ev->value_mask & CWWidth) {
c->oldw = c->w;
--
2.19.1

View File

@ -0,0 +1,76 @@
From 4cd2832206eca48190463ac2d3e5ba4e1410c517 Mon Sep 17 00:00:00 2001
From: jameel-sawafta <jameelhsawafta@gmail.com>
Date: Fri, 9 May 2025 22:47:04 +0300
Subject: [PATCH] dwm: add swapmon function to swap monitors
---
config.def.h | 1 +
dwm.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/config.def.h b/config.def.h
index 9efa774..7c229cc 100644
--- a/config.def.h
+++ b/config.def.h
@@ -85,6 +85,7 @@ static const Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_apostrophe, swapmon, {0} },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
diff --git a/dwm.c b/dwm.c
index 1443802..adfe8bd 100644
--- a/dwm.c
+++ b/dwm.c
@@ -232,6 +232,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void swapmon(const Arg *arg);
/* variables */
static const char broken[] = "broken";
@@ -2139,6 +2140,38 @@ zoom(const Arg *arg)
pop(c);
}
+void
+swapmon(const Arg *arg)
+{
+ if (mons->next == NULL)
+ return;
+
+ Monitor *m1 = mons;
+ Monitor *m2 = mons->next;
+
+ unsigned int tmp = m1->tagset[m1->seltags];
+ m1->tagset[m1->seltags] = m2->tagset[m2->seltags];
+ m2->tagset[m2->seltags] = tmp;
+
+ Client *c;
+ for (c = m1->clients; c; c = c->next)
+ c->mon = m2;
+ for (c = m2->clients; c; c = c->next)
+ c->mon = m1;
+
+ Client *tmp_clients = m1->clients;
+ m1->clients = m2->clients;
+ m2->clients = tmp_clients;
+
+ Client *tmp_stack = m1->stack;
+ m1->stack = m2->stack;
+ m2->stack = tmp_stack;
+
+ focus(NULL);
+ arrange(m1);
+ arrange(m2);
+}
+
int
main(int argc, char *argv[])
{
--
2.49.0

View File

@ -0,0 +1,90 @@
From 00ea4c4e2d221c7f2979bcf403e4c23abf4b3f79 Mon Sep 17 00:00:00 2001
From: jameel-sawafta <jameelhsawafta@gmail.com>
Date: Fri, 9 May 2025 22:51:56 +0300
Subject: [PATCH] dwm: add swapwindow function to swap focused clients between
monitors
---
config.def.h | 1 +
dwm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/config.def.h b/config.def.h
index 9efa774..ec0a706 100644
--- a/config.def.h
+++ b/config.def.h
@@ -85,6 +85,7 @@ static const Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_slash, swapwindow, {0} },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
diff --git a/dwm.c b/dwm.c
index 1443802..ee7658f 100644
--- a/dwm.c
+++ b/dwm.c
@@ -232,6 +232,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void swapwindow(const Arg *arg);
/* variables */
static const char broken[] = "broken";
@@ -2139,6 +2140,51 @@ zoom(const Arg *arg)
pop(c);
}
+void
+swapwindow(const Arg *arg)
+{
+ if (!selmon || !selmon->sel || !mons->next)
+ return;
+
+ Monitor *m1 = selmon;
+ Monitor *m2 = dirtomon(+1);
+
+ Client *c1 = m1->sel;
+ Client *c2 = m2->sel;
+
+ if (!c2) {
+ detach(c1);
+ detachstack(c1);
+ c1->mon = m2;
+ attach(c1);
+ attachstack(c1);
+ focus(c1);
+ selmon = m2;
+ arrange(m1);
+ arrange(m2);
+ return;
+ }
+
+ detach(c1);
+ detachstack(c1);
+ detach(c2);
+ detachstack(c2);
+
+ c1->mon = m2;
+ attach(c1);
+ attachstack(c1);
+ focus(c1);
+
+ c2->mon = m1;
+ attach(c2);
+ attachstack(c2);
+ focus(c2);
+
+ selmon = m1;
+ arrange(m1);
+ arrange(m2);
+}
+
int
main(int argc, char *argv[])
{
--
2.49.0

748
dwm-systray-6.7.diff Normal file
View File

@ -0,0 +1,748 @@
diff --git a/config.def.h b/config.def.h
index 81c3fc0..364b394 100644
--- a/config.def.h
+++ b/config.def.h
@@ -3,6 +3,11 @@
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
static const unsigned int snap = 32; /* snap pixel */
+static const unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
+static const unsigned int systrayonleft = 0; /* 0: systray in the right corner, >0: systray on left of status text */
+static const unsigned int systrayspacing = 2; /* systray spacing */
+static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
+static const int showsystray = 1; /* 0 means no systray */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "monospace:size=10" };
@@ -102,8 +107,8 @@ static const Key keys[] = {
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static const Button buttons[] = {
/* click event mask button function argument */
- { ClkLtSymbol, 0, Button1, setlayout, {0} },
- { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
+ { ClkTagBar, MODKEY, Button1, tag, {0} },
+ { ClkTagBar, MODKEY, Button3, toggletag, {0} },
{ ClkWinTitle, 0, Button2, zoom, {0} },
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
diff --git a/dwm.c b/dwm.c
index 8f4fa75..4b4fbb2 100644
--- a/dwm.c
+++ b/dwm.c
@@ -56,12 +56,27 @@
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
+#define SYSTEM_TRAY_REQUEST_DOCK 0
+/* XEMBED messages */
+#define XEMBED_EMBEDDED_NOTIFY 0
+#define XEMBED_WINDOW_ACTIVATE 1
+#define XEMBED_FOCUS_IN 4
+#define XEMBED_MODALITY_ON 10
+#define XEMBED_MAPPED (1 << 0)
+#define XEMBED_WINDOW_ACTIVATE 1
+#define XEMBED_WINDOW_DEACTIVATE 2
+#define VERSION_MAJOR 0
+#define VERSION_MINOR 0
+#define XEMBED_EMBEDDED_VERSION (VERSION_MAJOR << 16) | VERSION_MINOR
+
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
+ NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -140,6 +155,12 @@ typedef struct {
int monitor;
} Rule;
+typedef struct Systray Systray;
+struct Systray {
+ Window win;
+ Client *icons;
+};
+
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -171,6 +192,7 @@ static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
+static unsigned int getsystraywidth();
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
static void grabbuttons(Client *c, int focused);
static void grabkeys(void);
@@ -188,13 +210,16 @@ static void pop(Client *c);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
+static void removesystrayicon(Client *i);
static void resize(Client *c, int x, int y, int w, int h, int interact);
+static void resizebarwin(Monitor *m);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resizemouse(const Arg *arg);
+static void resizerequest(XEvent *e);
static void restack(Monitor *m);
static void run(void);
static void scan(void);
-static int sendevent(Client *c, Atom proto);
+static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4);
static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
@@ -205,6 +230,7 @@ static void setup(void);
static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void spawn(const Arg *arg);
+static Monitor *systraytomon(Monitor *m);
static void tag(const Arg *arg);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
@@ -222,18 +248,23 @@ static int updategeom(void);
static void updatenumlockmask(void);
static void updatesizehints(Client *c);
static void updatestatus(void);
+static void updatesystray(void);
+static void updatesystrayicongeom(Client *i, int w, int h);
+static void updatesystrayiconstate(Client *i, XPropertyEvent *ev);
static void updatetitle(Client *c);
static void updatewindowtype(Client *c);
static void updatewmhints(Client *c);
static void view(const Arg *arg);
static Client *wintoclient(Window w);
static Monitor *wintomon(Window w);
+static Client *wintosystrayicon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
/* variables */
+static Systray *systray = NULL;
static const char broken[] = "broken";
static char stext[256];
static int screen;
@@ -256,9 +287,10 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[MapRequest] = maprequest,
[MotionNotify] = motionnotify,
[PropertyNotify] = propertynotify,
+ [ResizeRequest] = resizerequest,
[UnmapNotify] = unmapnotify
};
-static Atom wmatom[WMLast], netatom[NetLast];
+static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
@@ -440,7 +472,7 @@ buttonpress(XEvent *e)
arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
click = ClkLtSymbol;
- else if (ev->x > selmon->ww - (int)TEXTW(stext))
+ else if (ev->x > selmon->ww - (int)TEXTW(stext) - getsystraywidth())
click = ClkStatusText;
else
click = ClkWinTitle;
@@ -483,6 +515,13 @@ cleanup(void)
XUngrabKey(dpy, AnyKey, AnyModifier, root);
while (mons)
cleanupmon(mons);
+
+ if (showsystray) {
+ XUnmapWindow(dpy, systray->win);
+ XDestroyWindow(dpy, systray->win);
+ free(systray);
+ }
+
for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]);
for (i = 0; i < LENGTH(colors); i++)
@@ -514,9 +553,58 @@ cleanupmon(Monitor *mon)
void
clientmessage(XEvent *e)
{
+ XWindowAttributes wa;
+ XSetWindowAttributes swa;
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
+ if (showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
+ /* add systray icons */
+ if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
+ if (!(c = (Client *)calloc(1, sizeof(Client))))
+ die("fatal: could not malloc() %u bytes\n", sizeof(Client));
+ if (!(c->win = cme->data.l[2])) {
+ free(c);
+ return;
+ }
+ c->mon = selmon;
+ c->next = systray->icons;
+ systray->icons = c;
+ if (!XGetWindowAttributes(dpy, c->win, &wa)) {
+ /* use sane defaults */
+ wa.width = bh;
+ wa.height = bh;
+ wa.border_width = 0;
+ }
+ c->x = c->oldx = c->y = c->oldy = 0;
+ c->w = c->oldw = wa.width;
+ c->h = c->oldh = wa.height;
+ c->oldbw = wa.border_width;
+ c->bw = 0;
+ c->isfloating = True;
+ /* reuse tags field as mapped status */
+ c->tags = 1;
+ updatesizehints(c);
+ updatesystrayicongeom(c, wa.width, wa.height);
+ XAddToSaveSet(dpy, c->win);
+ XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
+ XReparentWindow(dpy, c->win, systray->win, 0, 0);
+ /* use parents background color */
+ swa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
+ XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
+ sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+ /* FIXME not sure if I have to send these events, too */
+ sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+ sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+ sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
+ XSync(dpy, False);
+ resizebarwin(selmon);
+ updatesystray();
+ setclientstate(c, NormalState);
+ }
+ return;
+ }
+
if (!c)
return;
if (cme->message_type == netatom[NetWMState]) {
@@ -569,7 +657,7 @@ configurenotify(XEvent *e)
for (c = m->clients; c; c = c->next)
if (c->isfullscreen)
resizeclient(c, m->mx, m->my, m->mw, m->mh);
- XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
+ resizebarwin(m);
}
focus(NULL);
arrange(NULL);
@@ -654,6 +742,11 @@ destroynotify(XEvent *e)
if ((c = wintoclient(ev->window)))
unmanage(c, 1);
+ else if ((c = wintosystrayicon(ev->window))) {
+ removesystrayicon(c);
+ resizebarwin(selmon);
+ updatesystray();
+ }
}
void
@@ -697,7 +790,7 @@ dirtomon(int dir)
void
drawbar(Monitor *m)
{
- int x, w, tw = 0;
+ int x, w, tw = 0, stw = 0;
int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
@@ -706,13 +799,17 @@ drawbar(Monitor *m)
if (!m->showbar)
return;
+ if(showsystray && m == systraytomon(m) && !systrayonleft)
+ stw = getsystraywidth();
+
/* draw status first so it can be overdrawn by tags later */
if (m == selmon) { /* status is only drawn on selected monitor */
drw_setscheme(drw, scheme[SchemeNorm]);
- tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+ tw = TEXTW(stext) - lrpad / 2 + 2; /* 2px extra right padding */
+ drw_text(drw, m->ww - tw - stw, 0, tw, bh, lrpad / 2 - 2, stext, 0);
}
+ resizebarwin(m);
for (c = m->clients; c; c = c->next) {
occ |= c->tags;
if (c->isurgent)
@@ -733,7 +830,7 @@ drawbar(Monitor *m)
drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
- if ((w = m->ww - tw - x) > bh) {
+ if ((w = m->ww - tw - stw - x) > bh) {
if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
@@ -744,7 +841,7 @@ drawbar(Monitor *m)
drw_rect(drw, x, 0, w, bh, 1, 1);
}
}
- drw_map(drw, m->barwin, 0, 0, m->ww, bh);
+ drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
}
void
@@ -781,8 +878,11 @@ expose(XEvent *e)
Monitor *m;
XExposeEvent *ev = &e->xexpose;
- if (ev->count == 0 && (m = wintomon(ev->window)))
+ if (ev->count == 0 && (m = wintomon(ev->window))) {
drawbar(m);
+ if (m == selmon)
+ updatesystray();
+ }
}
void
@@ -868,15 +968,32 @@ getatomprop(Client *c, Atom prop)
unsigned char *p = NULL;
Atom da, atom = None;
- if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
+ /* FIXME getatomprop should return the number of items and a pointer to
+ * the stored data instead of this workaround */
+ Atom req = XA_ATOM;
+ if (prop == xatom[XembedInfo])
+ req = xatom[XembedInfo];
+
+ if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, req,
&da, &di, &nitems, &dl, &p) == Success && p) {
- if (nitems > 0)
- atom = *(Atom *)p;
+ atom = *(Atom *)p;
+ if (da == xatom[XembedInfo] && nitems == 2)
+ atom = ((Atom *)p)[1];
XFree(p);
}
return atom;
}
+unsigned int
+getsystraywidth()
+{
+ unsigned int w = 0;
+ Client *i;
+ if(showsystray)
+ for(i = systray->icons; i; w += i->w + systrayspacing, i = i->next) ;
+ return w ? w + systrayspacing : 1;
+}
+
int
getrootptr(int *x, int *y)
{
@@ -1017,7 +1134,8 @@ killclient(const Arg *arg)
{
if (!selmon->sel)
return;
- if (!sendevent(selmon->sel, wmatom[WMDelete])) {
+
+ if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0 , 0, 0)) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
@@ -1104,6 +1222,13 @@ maprequest(XEvent *e)
static XWindowAttributes wa;
XMapRequestEvent *ev = &e->xmaprequest;
+ Client *i;
+ if ((i = wintosystrayicon(ev->window))) {
+ sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION);
+ resizebarwin(selmon);
+ updatesystray();
+ }
+
if (!XGetWindowAttributes(dpy, ev->window, &wa) || wa.override_redirect)
return;
if (!wintoclient(ev->window))
@@ -1225,6 +1350,17 @@ propertynotify(XEvent *e)
Window trans;
XPropertyEvent *ev = &e->xproperty;
+ if ((c = wintosystrayicon(ev->window))) {
+ if (ev->atom == XA_WM_NORMAL_HINTS) {
+ updatesizehints(c);
+ updatesystrayicongeom(c, c->w, c->h);
+ }
+ else
+ updatesystrayiconstate(c, ev);
+ resizebarwin(selmon);
+ updatesystray();
+ }
+
if ((ev->window == root) && (ev->atom == XA_WM_NAME))
updatestatus();
else if (ev->state == PropertyDelete)
@@ -1275,6 +1411,19 @@ recttomon(int x, int y, int w, int h)
return r;
}
+void
+removesystrayicon(Client *i)
+{
+ Client **ii;
+
+ if (!showsystray || !i)
+ return;
+ for (ii = &systray->icons; *ii && *ii != i; ii = &(*ii)->next);
+ if (ii)
+ *ii = i->next;
+ free(i);
+}
+
void
resize(Client *c, int x, int y, int w, int h, int interact)
{
@@ -1282,6 +1431,14 @@ resize(Client *c, int x, int y, int w, int h, int interact)
resizeclient(c, x, y, w, h);
}
+void
+resizebarwin(Monitor *m) {
+ unsigned int w = m->ww;
+ if (showsystray && m == systraytomon(m) && !systrayonleft)
+ w -= getsystraywidth();
+ XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
+}
+
void
resizeclient(Client *c, int x, int y, int w, int h)
{
@@ -1297,6 +1454,19 @@ resizeclient(Client *c, int x, int y, int w, int h)
XSync(dpy, False);
}
+void
+resizerequest(XEvent *e)
+{
+ XResizeRequestEvent *ev = &e->xresizerequest;
+ Client *i;
+
+ if ((i = wintosystrayicon(ev->window))) {
+ updatesystrayicongeom(i, ev->width, ev->height);
+ resizebarwin(selmon);
+ updatesystray();
+ }
+}
+
void
resizemouse(const Arg *arg)
{
@@ -1443,26 +1613,37 @@ setclientstate(Client *c, long state)
}
int
-sendevent(Client *c, Atom proto)
+sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4)
{
int n;
- Atom *protocols;
+ Atom *protocols, mt;
int exists = 0;
XEvent ev;
- if (XGetWMProtocols(dpy, c->win, &protocols, &n)) {
- while (!exists && n--)
- exists = protocols[n] == proto;
- XFree(protocols);
+ if (proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) {
+ mt = wmatom[WMProtocols];
+ if (XGetWMProtocols(dpy, w, &protocols, &n)) {
+ while (!exists && n--)
+ exists = protocols[n] == proto;
+ XFree(protocols);
+ }
+ }
+ else {
+ exists = True;
+ mt = proto;
}
+
if (exists) {
ev.type = ClientMessage;
- ev.xclient.window = c->win;
- ev.xclient.message_type = wmatom[WMProtocols];
+ ev.xclient.window = w;
+ ev.xclient.message_type = mt;
ev.xclient.format = 32;
- ev.xclient.data.l[0] = proto;
- ev.xclient.data.l[1] = CurrentTime;
- XSendEvent(dpy, c->win, False, NoEventMask, &ev);
+ ev.xclient.data.l[0] = d0;
+ ev.xclient.data.l[1] = d1;
+ ev.xclient.data.l[2] = d2;
+ ev.xclient.data.l[3] = d3;
+ ev.xclient.data.l[4] = d4;
+ XSendEvent(dpy, w, False, mask, &ev);
}
return exists;
}
@@ -1476,7 +1657,7 @@ setfocus(Client *c)
XA_WINDOW, 32, PropModeReplace,
(unsigned char *) &(c->win), 1);
}
- sendevent(c, wmatom[WMTakeFocus]);
+ sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0);
}
void
@@ -1572,6 +1753,10 @@ setup(void)
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
+ netatom[NetSystemTray] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_S0", False);
+ netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False);
+ netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False);
+ netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
@@ -1579,6 +1764,9 @@ setup(void)
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
+ xatom[Manager] = XInternAtom(dpy, "MANAGER", False);
+ xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False);
+ xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False);
/* init cursors */
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
@@ -1587,6 +1775,8 @@ setup(void)
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3);
+ /* init system tray */
+ updatesystray();
/* init bars */
updatebars();
updatestatus();
@@ -1717,7 +1907,18 @@ togglebar(const Arg *arg)
{
selmon->showbar = !selmon->showbar;
updatebarpos(selmon);
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+ resizebarwin(selmon);
+ if (showsystray) {
+ XWindowChanges wc;
+ if (!selmon->showbar)
+ wc.y = -bh;
+ else if (selmon->showbar) {
+ wc.y = 0;
+ if (!selmon->topbar)
+ wc.y = selmon->mh - bh;
+ }
+ XConfigureWindow(dpy, systray->win, CWY, &wc);
+ }
arrange(selmon);
}
@@ -1813,11 +2014,18 @@ unmapnotify(XEvent *e)
else
unmanage(c, 0);
}
+ else if ((c = wintosystrayicon(ev->window))) {
+ /* KLUDGE! sometimes icons occasionally unmap their windows, but do
+ * _not_ destroy them. We map those windows back */
+ XMapRaised(dpy, c->win);
+ updatesystray();
+ }
}
void
updatebars(void)
{
+ unsigned int w;
Monitor *m;
XSetWindowAttributes wa = {
.override_redirect = True,
@@ -1828,10 +2036,15 @@ updatebars(void)
for (m = mons; m; m = m->next) {
if (m->barwin)
continue;
- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
+ w = m->ww;
+ if (showsystray && m == systraytomon(m))
+ w -= getsystraywidth();
+ m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, bh, 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
+ if (showsystray && m == systraytomon(m))
+ XMapRaised(dpy, systray->win);
XMapRaised(dpy, m->barwin);
XSetClassHint(dpy, m->barwin, &ch);
}
@@ -2008,6 +2221,125 @@ updatestatus(void)
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
strcpy(stext, "dwm-"VERSION);
drawbar(selmon);
+ updatesystray();
+}
+
+
+void
+updatesystrayicongeom(Client *i, int w, int h)
+{
+ if (i) {
+ i->h = bh;
+ if (w == h)
+ i->w = bh;
+ else if (h == bh)
+ i->w = w;
+ else
+ i->w = (int) ((float)bh * ((float)w / (float)h));
+ applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False);
+ /* force icons into the systray dimensions if they don't want to */
+ if (i->h > bh) {
+ if (i->w == i->h)
+ i->w = bh;
+ else
+ i->w = (int) ((float)bh * ((float)i->w / (float)i->h));
+ i->h = bh;
+ }
+ }
+}
+
+void
+updatesystrayiconstate(Client *i, XPropertyEvent *ev)
+{
+ long flags;
+ int code = 0;
+
+ if (!showsystray || !i || ev->atom != xatom[XembedInfo] ||
+ !(flags = getatomprop(i, xatom[XembedInfo])))
+ return;
+
+ if (flags & XEMBED_MAPPED && !i->tags) {
+ i->tags = 1;
+ code = XEMBED_WINDOW_ACTIVATE;
+ XMapRaised(dpy, i->win);
+ setclientstate(i, NormalState);
+ }
+ else if (!(flags & XEMBED_MAPPED) && i->tags) {
+ i->tags = 0;
+ code = XEMBED_WINDOW_DEACTIVATE;
+ XUnmapWindow(dpy, i->win);
+ setclientstate(i, WithdrawnState);
+ }
+ else
+ return;
+ sendevent(i->win, xatom[Xembed], StructureNotifyMask, CurrentTime, code, 0,
+ systray->win, XEMBED_EMBEDDED_VERSION);
+}
+
+void
+updatesystray(void)
+{
+ XSetWindowAttributes wa;
+ XWindowChanges wc;
+ Client *i;
+ Monitor *m = systraytomon(NULL);
+ unsigned int x = m->mx + m->mw;
+ unsigned int sw = TEXTW(stext) - lrpad + systrayspacing;
+ unsigned int w = 1;
+
+ if (!showsystray)
+ return;
+ if (systrayonleft)
+ x -= sw + lrpad / 2;
+ if (!systray) {
+ /* init systray */
+ if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
+ die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
+ systray->win = XCreateSimpleWindow(dpy, root, x, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
+ wa.event_mask = ButtonPressMask | ExposureMask;
+ wa.override_redirect = True;
+ wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
+ XSelectInput(dpy, systray->win, SubstructureNotifyMask);
+ XChangeProperty(dpy, systray->win, netatom[NetSystemTrayOrientation], XA_CARDINAL, 32,
+ PropModeReplace, (unsigned char *)&netatom[NetSystemTrayOrientationHorz], 1);
+ XChangeWindowAttributes(dpy, systray->win, CWEventMask|CWOverrideRedirect|CWBackPixel, &wa);
+ XMapRaised(dpy, systray->win);
+ XSetSelectionOwner(dpy, netatom[NetSystemTray], systray->win, CurrentTime);
+ if (XGetSelectionOwner(dpy, netatom[NetSystemTray]) == systray->win) {
+ sendevent(root, xatom[Manager], StructureNotifyMask, CurrentTime, netatom[NetSystemTray], systray->win, 0, 0);
+ XSync(dpy, False);
+ }
+ else {
+ fprintf(stderr, "dwm: unable to obtain system tray.\n");
+ free(systray);
+ systray = NULL;
+ return;
+ }
+ }
+ for (w = 0, i = systray->icons; i; i = i->next) {
+ /* make sure the background color stays the same */
+ wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
+ XChangeWindowAttributes(dpy, i->win, CWBackPixel, &wa);
+ XMapRaised(dpy, i->win);
+ w += systrayspacing;
+ i->x = w;
+ XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h);
+ w += i->w;
+ if (i->mon != m)
+ i->mon = m;
+ }
+ w = w ? w + systrayspacing : 1;
+ x -= w;
+ XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh);
+ wc.x = x; wc.y = m->by; wc.width = w; wc.height = bh;
+ wc.stack_mode = Above; wc.sibling = m->barwin;
+ XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc);
+ XMapWindow(dpy, systray->win);
+ XMapSubwindows(dpy, systray->win);
+ /* redraw background */
+ XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel);
+ XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh);
+ XSync(dpy, False);
}
void
@@ -2075,6 +2407,16 @@ wintoclient(Window w)
return NULL;
}
+Client *
+wintosystrayicon(Window w) {
+ Client *i = NULL;
+
+ if (!showsystray || !w)
+ return i;
+ for (i = systray->icons; i && i->win != w; i = i->next) ;
+ return i;
+}
+
Monitor *
wintomon(Window w)
{
@@ -2128,6 +2470,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
return -1;
}
+Monitor *
+systraytomon(Monitor *m) {
+ Monitor *t;
+ int i, n;
+ if(!systraypinning) {
+ if(!m)
+ return selmon;
+ return m == selmon ? m : NULL;
+ }
+ for(n = 1, t = mons; t && t->next; n++, t = t->next) ;
+ for(i = 1, t = mons; t && t->next && i < systraypinning; i++, t = t->next) ;
+ if(systraypinningfailfirst && n < systraypinning)
+ return mons;
+ return t;
+}
+
void
zoom(const Arg *arg)
{

View File

@ -0,0 +1,101 @@
From 58414bee958f2e7ed91d6fe31f503ec4a406981b Mon Sep 17 00:00:00 2001
From: cirala <thim@cederlund.de>
Date: Fri, 19 Nov 2021 18:14:07 +0100
Subject: [PATCH] Fix for dwm-uselessgap
Previous versions of the patch doubles the
gap between the master and slave stacks.
---
config.def.h | 3 ++-
dwm.c | 38 +++++++++++++++++++++++++++++++-------
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/config.def.h b/config.def.h
index a2ac963..17a205f 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,7 @@
/* appearance */
static const unsigned int borderpx = 1; /* border pixel of windows */
+static const unsigned int gappx = 6; /* gaps between windows */
static const unsigned int snap = 32; /* snap pixel */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
@@ -34,7 +35,7 @@ static const Rule rules[] = {
/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1; /* number of clients in master area */
-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const Layout layouts[] = {
diff --git a/dwm.c b/dwm.c
index 5e4d494..b626e89 100644
--- a/dwm.c
+++ b/dwm.c
@@ -52,8 +52,8 @@
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0])
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
-#define WIDTH(X) ((X)->w + 2 * (X)->bw)
-#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
+#define WIDTH(X) ((X)->w + 2 * (X)->bw + gappx)
+#define HEIGHT(X) ((X)->h + 2 * (X)->bw + gappx)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
@@ -1277,12 +1277,36 @@ void
resizeclient(Client *c, int x, int y, int w, int h)
{
XWindowChanges wc;
+ unsigned int n;
+ unsigned int gapoffset;
+ unsigned int gapincr;
+ Client *nbc;
- c->oldx = c->x; c->x = wc.x = x;
- c->oldy = c->y; c->y = wc.y = y;
- c->oldw = c->w; c->w = wc.width = w;
- c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
+
+ /* Get number of clients for the client's monitor */
+ for (n = 0, nbc = nexttiled(c->mon->clients); nbc; nbc = nexttiled(nbc->next), n++);
+
+ /* Do nothing if layout is floating */
+ if (c->isfloating || c->mon->lt[c->mon->sellt]->arrange == NULL) {
+ gapincr = gapoffset = 0;
+ } else {
+ /* Remove border and gap if layout is monocle or only one client */
+ if (c->mon->lt[c->mon->sellt]->arrange == monocle || n == 1) {
+ gapoffset = 0;
+ gapincr = -2 * borderpx;
+ wc.border_width = 0;
+ } else {
+ gapoffset = gappx;
+ gapincr = 2 * gappx;
+ }
+ }
+
+ c->oldx = c->x; c->x = wc.x = x + gapoffset;
+ c->oldy = c->y; c->y = wc.y = y + gapoffset;
+ c->oldw = c->w; c->w = wc.width = w - gapincr;
+ c->oldh = c->h; c->h = wc.height = h - gapincr;
+
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@@ -1688,7 +1712,7 @@ tile(Monitor *m)
for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
h = (m->wh - my) / (MIN(n, m->nmaster) - i);
- resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
+ resize(c, m->wx, m->wy + my, mw - (2*c->bw) + (n > 1 ? gappx : 0), h - (2*c->bw), 0);
if (my + HEIGHT(c) < m->wh)
my += HEIGHT(c);
} else {
--
2.33.1

10
dwm.1
View File

@ -142,6 +142,9 @@ Add/remove all windows with nth tag to/from the view.
.TP .TP
.B Mod1\-Shift\-q .B Mod1\-Shift\-q
Quit dwm. Quit dwm.
.TP
.B Mod1\-Control\-Shift\-q
Restart dwm.
.SS Mouse commands .SS Mouse commands
.TP .TP
.B Mod1\-Button1 .B Mod1\-Button1
@ -155,6 +158,13 @@ Resize focused window while dragging. Tiled windows will be toggled to the float
.SH CUSTOMIZATION .SH CUSTOMIZATION
dwm is customized by creating a custom config.h and (re)compiling the source dwm is customized by creating a custom config.h and (re)compiling the source
code. This keeps it fast, secure and simple. code. This keeps it fast, secure and simple.
.SH SIGNALS
.TP
.B SIGHUP - 1
Restart the dwm process.
.TP
.B SIGTERM - 15
Cleanly terminate the dwm process.
.SH SEE ALSO .SH SEE ALSO
.BR dmenu (1), .BR dmenu (1),
.BR st (1) .BR st (1)

958
dwm.c

File diff suppressed because it is too large Load Diff

49
movestack.c Normal file
View File

@ -0,0 +1,49 @@
void
movestack(const Arg *arg) {
Client *c = NULL, *p = NULL, *pc = NULL, *i;
if(arg->i > 0) {
/* find the client after selmon->sel */
for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
if(!c)
for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
}
else {
/* find the client before selmon->sel */
for(i = selmon->clients; i != selmon->sel; i = i->next)
if(ISVISIBLE(i) && !i->isfloating)
c = i;
if(!c)
for(; i; i = i->next)
if(ISVISIBLE(i) && !i->isfloating)
c = i;
}
/* find the client before selmon->sel and c */
for(i = selmon->clients; i && (!p || !pc); i = i->next) {
if(i->next == selmon->sel)
p = i;
if(i->next == c)
pc = i;
}
/* swap c and selmon->sel selmon->clients in the selmon->clients list */
if(c && c != selmon->sel) {
Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
selmon->sel->next = c->next==selmon->sel?c:c->next;
c->next = temp;
if(p && p != c)
p->next = c;
if(pc && pc != selmon->sel)
pc->next = selmon->sel;
if(selmon->sel == selmon->clients)
selmon->clients = c;
else if(c == selmon->clients)
selmon->clients = selmon->sel;
arrange(selmon);
}
}

136
shift-tools.c Normal file
View File

@ -0,0 +1,136 @@
/* Sends a window to the next/prev tag */
void
shifttag(const Arg *arg)
{
Arg shifted;
shifted.ui = selmon->tagset[selmon->seltags];
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
else /* right circular shift */
shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
tag(&shifted);
}
/* Sends a window to the next/prev tag that has a client, else it moves it to the next/prev one. */
void
shifttagclients(const Arg *arg)
{
Arg shifted;
Client *c;
unsigned int tagmask = 0;
shifted.ui = selmon->tagset[selmon->seltags];
for (c = selmon->clients; c; c = c->next)
if (!(c->tags))
tagmask = tagmask | c->tags;
if (arg->i > 0) /* left circular shift */
do {
shifted.ui = (shifted.ui << arg->i)
| (shifted.ui >> (LENGTH(tags) - arg->i));
} while (tagmask && !(shifted.ui & tagmask));
else /* right circular shift */
do {
shifted.ui = (shifted.ui >> (- arg->i)
| shifted.ui << (LENGTH(tags) + arg->i));
} while (tagmask && !(shifted.ui & tagmask));
tag(&shifted);
}
/* Navigate to the next/prev tag */
void
shiftview(const Arg *arg)
{
Arg shifted;
shifted.ui = selmon->tagset[selmon->seltags];
if (arg->i > 0) /* left circular shift */
shifted.ui = (shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i));
else /* right circular shift */
shifted.ui = (shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i));
view(&shifted);
}
/* Navigate to the next/prev tag that has a client, else moves it to the next/prev tag */
/* This doesn't work TODO: work out why this isn't working and fix */
void
shiftviewclients(const Arg *arg)
{
Arg shifted;
Client *c;
unsigned int tagmask = 0;
shifted.ui = selmon->tagset[selmon->seltags];
for (c = selmon->clients; c; c = c->next)
if (!(c->tags))
tagmask = tagmask | c->tags;
if (arg->i > 0) /* left circular shift */
do {
shifted.ui = (shifted.ui << arg->i)
| (shifted.ui >> (LENGTH(tags) - arg->i));
} while (tagmask && !(shifted.ui & tagmask));
else /* right circular shift */
do {
shifted.ui = (shifted.ui >> (- arg->i)
| shifted.ui << (LENGTH(tags) + arg->i));
} while (tagmask && !(shifted.ui & tagmask));
view(&shifted);
}
/* move the current active window to the next/prev tag and view it. More like following the window */
void
shiftboth(const Arg *arg)
{
Arg shifted;
shifted.ui = selmon->tagset[selmon->seltags];
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
else /* right circular shift */
shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
tag(&shifted);
view(&shifted);
}
//helper function for shiftswaptags.
//see: https://github.com/moizifty/DWM-Build/blob/65379c62640788881486401a0d8c79333751b02f/config.h#L48
void
swaptags(const Arg *arg)
{
Client *c;
unsigned int newtag = arg->ui & TAGMASK;
unsigned int curtag = selmon->tagset[selmon->seltags];
if (newtag == curtag || !curtag || (curtag & (curtag-1)))
return;
for (c = selmon->clients; c != NULL; c = c->next) {
if ((c->tags & newtag) || (c->tags & curtag))
c->tags ^= curtag ^ newtag;
if (!c->tags)
c->tags = newtag;
}
//move to the swaped tag
//selmon->tagset[selmon->seltags] = newtag;
focus(NULL);
arrange(selmon);
}
/* swaps "tags" (all the clients) with the next/prev tag. */
void
shiftswaptags(const Arg *arg)
{
Arg shifted;
shifted.ui = selmon->tagset[selmon->seltags];
if (arg->i > 0) /* left circular shift */
shifted.ui = ((shifted.ui << arg->i) | (shifted.ui >> (LENGTH(tags) - arg->i)));
else /* right circular shift */
shifted.ui = ((shifted.ui >> (- arg->i) | shifted.ui << (LENGTH(tags) + arg->i)));
swaptags(&shifted);
// uncomment if you also want to "go" (view) the tag where the the clients are going
//view(&shifted);
}

1
util.h
View File

@ -7,3 +7,4 @@
void die(const char *fmt, ...); void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size); void *ecalloc(size_t nmemb, size_t size);