From a9768a23bfc341561f22a3ca65d48af44c6687d4 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 2 Feb 2023 16:15:46 -0800 Subject: [PATCH] Added ability to select multiple tags for viewing/assignment. --- config.def.h | 10 +++++----- config.h | 10 +++++----- dwm.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/config.def.h b/config.def.h index 061ad66..5205f64 100644 --- a/config.def.h +++ b/config.def.h @@ -71,15 +71,15 @@ static const Key keys[] = { { 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, XK_Tab, comboview, {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_0, comboview, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, combotag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, @@ -107,9 +107,9 @@ static const Button buttons[] = { { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, - { ClkTagBar, 0, Button1, view, {0} }, + { ClkTagBar, 0, Button1, comboview, {0} }, { ClkTagBar, 0, Button3, toggleview, {0} }, - { ClkTagBar, MODKEY, Button1, tag, {0} }, + { ClkTagBar, MODKEY, Button1, combotag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; diff --git a/config.h b/config.h index 061ad66..5205f64 100644 --- a/config.h +++ b/config.h @@ -71,15 +71,15 @@ static const Key keys[] = { { 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, XK_Tab, comboview, {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_0, comboview, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, combotag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, { MODKEY, XK_period, focusmon, {.i = +1 } }, { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, @@ -107,9 +107,9 @@ static const Button buttons[] = { { ClkClientWin, MODKEY, Button1, movemouse, {0} }, { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, - { ClkTagBar, 0, Button1, view, {0} }, + { ClkTagBar, 0, Button1, comboview, {0} }, { ClkTagBar, 0, Button3, toggleview, {0} }, - { ClkTagBar, MODKEY, Button1, tag, {0} }, + { ClkTagBar, MODKEY, Button1, combotag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; diff --git a/dwm.c b/dwm.c index a507385..6c81540 100644 --- a/dwm.c +++ b/dwm.c @@ -235,6 +235,11 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +static void keyrelease(XEvent *e); +static void combotag(const Arg *arg); +static void comboview(const Arg *arg); + + /* variables */ static const char broken[] = "broken"; static char stext[256]; @@ -246,6 +251,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, + [ButtonRelease] = keyrelease, [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, [ConfigureNotify] = configurenotify, @@ -253,6 +259,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { [EnterNotify] = enternotify, [Expose] = expose, [FocusIn] = focusin, + [KeyRelease] = keyrelease, [KeyPress] = keypress, [MappingNotify] = mappingnotify, [MapRequest] = maprequest, @@ -276,6 +283,42 @@ static Window root, wmcheckwin; struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; /* function implementations */ +static int combo = 0; + +void +keyrelease(XEvent *e) { + combo = 0; +} + +void +combotag(const Arg *arg) { + if(selmon->sel && arg->ui & TAGMASK) { + if (combo) { + selmon->sel->tags |= arg->ui & TAGMASK; + } else { + combo = 1; + selmon->sel->tags = arg->ui & TAGMASK; + } + focus(NULL); + arrange(selmon); + } +} + +void +comboview(const Arg *arg) { + unsigned newtags = arg->ui & TAGMASK; + if (combo) { + selmon->tagset[selmon->seltags] |= newtags; + } else { + selmon->seltags ^= 1; /*toggle tagset*/ + combo = 1; + if (newtags) + selmon->tagset[selmon->seltags] = newtags; + } + focus(NULL); + arrange(selmon); +} + void applyrules(Client *c) { -- 2.20.1