dwm-holdbar-6.2.diff (4087B)
1 From 58507fca3c3c334f540700c5ed81815d9335138e Mon Sep 17 00:00:00 2001 2 From: Nihal Jere <noocsharp@gmail.com> 3 Date: Thu, 12 Mar 2020 10:16:48 -0500 4 Subject: [PATCH] holdbar: fixed bar flickering caused by repeated key events 5 6 --- 7 config.def.h | 2 ++ 8 dwm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 9 2 files changed, 52 insertions(+) 10 11 diff --git a/config.def.h b/config.def.h 12 index 1c0b587..0e19b5d 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -50,6 +50,7 @@ static const Layout layouts[] = { 16 { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ 17 { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ 18 { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, 19 +#define HOLDKEY 0 // replace 0 with the keysym to activate holdbar 20 21 /* helper for spawning shell commands in the pre dwm-5.0 fashion */ 22 #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } 23 @@ -94,6 +95,7 @@ static Key keys[] = { 24 TAGKEYS( XK_8, 7) 25 TAGKEYS( XK_9, 8) 26 { MODKEY|ShiftMask, XK_q, quit, {0} }, 27 + { 0, HOLDKEY, holdbar, {0} }, 28 }; 29 30 /* button definitions */ 31 diff --git a/dwm.c b/dwm.c 32 index 4465af1..9437707 100644 33 --- a/dwm.c 34 +++ b/dwm.c 35 @@ -176,6 +176,7 @@ static void grabbuttons(Client *c, int focused); 36 static void grabkeys(void); 37 static void incnmaster(const Arg *arg); 38 static void keypress(XEvent *e); 39 +static void keyrelease(XEvent *e); 40 static void killclient(const Arg *arg); 41 static void manage(Window w, XWindowAttributes *wa); 42 static void mappingnotify(XEvent *e); 43 @@ -210,6 +211,7 @@ static void tag(const Arg *arg); 44 static void tagmon(const Arg *arg); 45 static void tile(Monitor *); 46 static void togglebar(const Arg *arg); 47 +static void holdbar(const Arg *arg); 48 static void togglefloating(const Arg *arg); 49 static void toggletag(const Arg *arg); 50 static void toggleview(const Arg *arg); 51 @@ -217,6 +219,7 @@ static void unfocus(Client *c, int setfocus); 52 static void unmanage(Client *c, int destroyed); 53 static void unmapnotify(XEvent *e); 54 static void updatebarpos(Monitor *m); 55 +static void updateholdbarpos(Monitor *m); 56 static void updatebars(void); 57 static void updateclientlist(void); 58 static int updategeom(void); 59 @@ -245,6 +248,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *); 60 static unsigned int numlockmask = 0; 61 static void (*handler[LASTEvent]) (XEvent *) = { 62 [ButtonPress] = buttonpress, 63 + [ButtonRelease] = keyrelease, 64 [ClientMessage] = clientmessage, 65 [ConfigureRequest] = configurerequest, 66 [ConfigureNotify] = configurenotify, 67 @@ -252,6 +256,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { 68 [EnterNotify] = enternotify, 69 [Expose] = expose, 70 [FocusIn] = focusin, 71 + [KeyRelease] = keyrelease, 72 [KeyPress] = keypress, 73 [MappingNotify] = mappingnotify, 74 [MapRequest] = maprequest, 75 @@ -275,6 +280,51 @@ static Window root, wmcheckwin; 76 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 77 78 /* function implementations */ 79 + 80 + 81 +void 82 +holdbar(const Arg *arg) 83 +{ 84 + selmon->showbar = 1; 85 + updateholdbarpos(selmon); 86 + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); 87 +} 88 + 89 + 90 +void 91 +keyrelease(XEvent *e) 92 +{ 93 + if (XEventsQueued(dpy, QueuedAfterReading)) { 94 + XEvent ne; 95 + XPeekEvent(dpy, &ne); 96 + 97 + if (ne.type == KeyPress && ne.xkey.time == e->xkey.time && 98 + ne.xkey.keycode == e->xkey.keycode) { 99 + XNextEvent(dpy, &ne); 100 + return; 101 + } 102 + } 103 + if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY)) { 104 + selmon->showbar = 0; 105 + updateholdbarpos(selmon); 106 + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); 107 + arrange(selmon); 108 + } 109 +} 110 + 111 +void 112 +updateholdbarpos(Monitor *m) 113 +{ 114 + m->wy = m->my; 115 + m->wh = m->mh; 116 + if (m->showbar) { 117 + m->by = m->topbar ? m->wy : m->wy + m->wh - bh; 118 + m->wy = m->topbar ? m->wy - bh + bh : m->wy; 119 + } else { 120 + m->by = -bh; 121 + } 122 +} 123 + 124 void 125 applyrules(Client *c) 126 { 127 -- 128 2.25.1 129