From 09ab72f2cac9078532d0c308905cd7c2b0f812ed Mon Sep 17 00:00:00 2001 From: pml68 Date: Fri, 9 Aug 2024 01:25:50 +0200 Subject: feat(dwm): add holdbar patch --- dwm/dwm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'dwm/dwm.c') diff --git a/dwm/dwm.c b/dwm/dwm.c index 5552e2f..c736fd7 100644 --- a/dwm/dwm.c +++ b/dwm/dwm.c @@ -180,6 +180,7 @@ static void grabbuttons(Client *c, int focused); static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); +static void keyrelease(XEvent *e); static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); @@ -214,6 +215,7 @@ 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 holdbar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -221,6 +223,7 @@ static void unfocus(Client *c, int setfocus); static void unmanage(Client *c, int destroyed); static void unmapnotify(XEvent *e); static void updatebarpos(Monitor *m); +static void updateholdbarpos(Monitor *m); static void updatebars(void); static void updateclientlist(void); static int updategeom(void); @@ -251,6 +254,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, @@ -258,6 +262,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { [EnterNotify] = enternotify, [Expose] = expose, [FocusIn] = focusin, + [KeyRelease] = keyrelease, [KeyPress] = keypress, [MappingNotify] = mappingnotify, [MapRequest] = maprequest, @@ -295,6 +300,51 @@ struct Pertag { struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; /* function implementations */ + + +void +holdbar(const Arg *arg) +{ + selmon->showbar = 1; + updateholdbarpos(selmon); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); +} + + +void +keyrelease(XEvent *e) +{ + if (XEventsQueued(dpy, QueuedAfterReading)) { + XEvent ne; + XPeekEvent(dpy, &ne); + + if (ne.type == KeyPress && ne.xkey.time == e->xkey.time && + ne.xkey.keycode == e->xkey.keycode) { + XNextEvent(dpy, &ne); + return; + } + } + if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY)) { + selmon->showbar = 0; + updateholdbarpos(selmon); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); + arrange(selmon); + } +} + +void +updateholdbarpos(Monitor *m) +{ + m->wy = m->my; + m->wh = m->mh; + if (m->showbar) { + m->by = m->topbar ? m->wy : m->wy + m->wh - bh; + m->wy = m->topbar ? m->wy - bh + bh : m->wy; + } else { + m->by = -bh; + } +} + void applyrules(Client *c) { -- cgit v1.2.3