dwm-holdbar-modkey-6.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-holdbar-modkey-6.2.diff (4866B)
       ---
            1 From 1004b9406e4b89448cf9d3b18955dbd0d55a571d Mon Sep 17 00:00:00 2001
            2 From: bakkeby <bakkeby@gmail.com>
            3 Date: Wed, 1 Jul 2020 08:05:35 +0200
            4 Subject: [PATCH] holdbar: variant of the patch where holdbar is only active
            5  when the bar is toggled off
            6 
            7 Additionally this allows the use of the primary MOD key to be used as the holdbar key while
            8 still allowing the bar to be toggled on and off using MOD+b. This gives a more intuitive and
            9 flexible feel when using this functionality.
           10 
           11 Use xev to find the keysym for the key that you want to use and add/update the HOLDKEY
           12 definition in config.h.
           13 
           14 E.g. using Alt_L as the HOLDKEY
           15 ---
           16  config.def.h |  2 ++
           17  dwm.c        | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
           18  2 files changed, 52 insertions(+), 1 deletion(-)
           19 
           20 diff --git a/config.def.h b/config.def.h
           21 index 1c0b587..8611189 100644
           22 --- a/config.def.h
           23 +++ b/config.def.h
           24 @@ -50,6 +50,7 @@ static const Layout layouts[] = {
           25          { MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
           26          { MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
           27          { MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
           28 +#define HOLDKEY 0 // replace 0 with the keysym to activate holdbar
           29  
           30  /* helper for spawning shell commands in the pre dwm-5.0 fashion */
           31  #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
           32 @@ -94,6 +95,7 @@ static Key keys[] = {
           33          TAGKEYS(                        XK_8,                      7)
           34          TAGKEYS(                        XK_9,                      8)
           35          { MODKEY|ShiftMask,             XK_q,      quit,           {0} },
           36 +        { 0,                            HOLDKEY,   holdbar,        {0} },
           37  };
           38  
           39  /* button definitions */
           40 diff --git a/dwm.c b/dwm.c
           41 index 4465af1..def5f66 100644
           42 --- a/dwm.c
           43 +++ b/dwm.c
           44 @@ -176,6 +176,7 @@ static void grabbuttons(Client *c, int focused);
           45  static void grabkeys(void);
           46  static void incnmaster(const Arg *arg);
           47  static void keypress(XEvent *e);
           48 +static void keyrelease(XEvent *e);
           49  static void killclient(const Arg *arg);
           50  static void manage(Window w, XWindowAttributes *wa);
           51  static void mappingnotify(XEvent *e);
           52 @@ -210,6 +211,7 @@ static void tag(const Arg *arg);
           53  static void tagmon(const Arg *arg);
           54  static void tile(Monitor *);
           55  static void togglebar(const Arg *arg);
           56 +static void holdbar(const Arg *arg);
           57  static void togglefloating(const Arg *arg);
           58  static void toggletag(const Arg *arg);
           59  static void toggleview(const Arg *arg);
           60 @@ -217,6 +219,7 @@ static void unfocus(Client *c, int setfocus);
           61  static void unmanage(Client *c, int destroyed);
           62  static void unmapnotify(XEvent *e);
           63  static void updatebarpos(Monitor *m);
           64 +static void updateholdbarpos(Monitor *m);
           65  static void updatebars(void);
           66  static void updateclientlist(void);
           67  static int updategeom(void);
           68 @@ -245,6 +248,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
           69  static unsigned int numlockmask = 0;
           70  static void (*handler[LASTEvent]) (XEvent *) = {
           71          [ButtonPress] = buttonpress,
           72 +        [ButtonRelease] = keyrelease,
           73          [ClientMessage] = clientmessage,
           74          [ConfigureRequest] = configurerequest,
           75          [ConfigureNotify] = configurenotify,
           76 @@ -252,6 +256,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
           77          [EnterNotify] = enternotify,
           78          [Expose] = expose,
           79          [FocusIn] = focusin,
           80 +        [KeyRelease] = keyrelease,
           81          [KeyPress] = keypress,
           82          [MappingNotify] = mappingnotify,
           83          [MapRequest] = maprequest,
           84 @@ -275,6 +280,50 @@ static Window root, wmcheckwin;
           85  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
           86  
           87  /* function implementations */
           88 +void
           89 +holdbar(const Arg *arg)
           90 +{
           91 +        if (selmon->showbar)
           92 +                return;
           93 +        selmon->showbar = 2;
           94 +        updateholdbarpos(selmon);
           95 +        XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
           96 +}
           97 +
           98 +void
           99 +keyrelease(XEvent *e)
          100 +{
          101 +        if (XEventsQueued(dpy, QueuedAfterReading)) {
          102 +                XEvent ne;
          103 +                XPeekEvent(dpy, &ne);
          104 +
          105 +                if (ne.type == KeyPress && ne.xkey.time == e->xkey.time &&
          106 +                                ne.xkey.keycode == e->xkey.keycode) {
          107 +                        XNextEvent(dpy, &ne);
          108 +                        return;
          109 +                }
          110 +        }
          111 +        if (e->xkey.keycode == XKeysymToKeycode(dpy, HOLDKEY) && selmon->showbar == 2) {
          112 +                selmon->showbar = 0;
          113 +                updateholdbarpos(selmon);
          114 +                XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
          115 +                arrange(selmon);
          116 +        }
          117 +}
          118 +
          119 +void
          120 +updateholdbarpos(Monitor *m)
          121 +{
          122 +        m->wy = m->my;
          123 +        m->wh = m->mh;
          124 +        if (m->showbar) {
          125 +                m->by = m->topbar ? m->wy : m->wy + m->wh - bh;
          126 +                m->wy = m->topbar ? m->wy - bh + bh : m->wy;
          127 +        } else {
          128 +                m->by = -bh;
          129 +        }
          130 +}
          131 +
          132  void
          133  applyrules(Client *c)
          134  {
          135 @@ -1699,7 +1748,7 @@ tile(Monitor *m)
          136  void
          137  togglebar(const Arg *arg)
          138  {
          139 -        selmon->showbar = !selmon->showbar;
          140 +        selmon->showbar = (selmon->showbar == 2 ? 1 : !selmon->showbar);
          141          updatebarpos(selmon);
          142          XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
          143          arrange(selmon);
          144 -- 
          145 2.19.1
          146