dwm-windowfollow-20221002-69d5652.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-windowfollow-20221002-69d5652.diff (5394B)
       ---
            1 From 0d52397649099000d154b65c077fe927608d8d0b Mon Sep 17 00:00:00 2001
            2 From: Aidan Hall <aidan.hall202@gmail.com>
            3 Date: Sun, 2 Oct 2022 18:13:36 +0100
            4 Subject: [PATCH] window following for latest git version
            5 
            6 ---
            7  config.def.h |  7 +++++++
            8  dwm.1        |  6 +++++-
            9  dwm.c        | 24 ++++++++++++++++++++++--
           10  3 files changed, 34 insertions(+), 3 deletions(-)
           11 
           12 diff --git a/config.def.h b/config.def.h
           13 index 061ad66..5eb37ed 100644
           14 --- a/config.def.h
           15 +++ b/config.def.h
           16 @@ -31,6 +31,11 @@ static const Rule rules[] = {
           17          { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
           18  };
           19  
           20 +/* window following */
           21 +#define WFACTIVE '>'
           22 +#define WFINACTIVE 'v'
           23 +#define WFDEFAULT WFINACTIVE
           24 +
           25  /* layout(s) */
           26  static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
           27  static const int nmaster     = 1;    /* number of clients in master area */
           28 @@ -64,6 +69,7 @@ static const Key keys[] = {
           29          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           30          { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
           31          { MODKEY,                       XK_b,      togglebar,      {0} },
           32 +        { MODKEY,                       XK_n,      togglefollow,   {0} },
           33          { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
           34          { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
           35          { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
           36 @@ -102,6 +108,7 @@ static const Button buttons[] = {
           37          /* click                event mask      button          function        argument */
           38          { ClkLtSymbol,          0,              Button1,        setlayout,      {0} },
           39          { ClkLtSymbol,          0,              Button3,        setlayout,      {.v = &layouts[2]} },
           40 +        { ClkFollowSymbol,      0,              Button1,        togglefollow,   {0} },
           41          { ClkWinTitle,          0,              Button2,        zoom,           {0} },
           42          { ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
           43          { ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
           44 diff --git a/dwm.1 b/dwm.1
           45 index ddc8321..67dfbc0 100644
           46 --- a/dwm.1
           47 +++ b/dwm.1
           48 @@ -44,7 +44,8 @@ command.
           49  .TP
           50  .B Button1
           51  click on a tag label to display all windows with that tag, click on the layout
           52 -label toggles between tiled and floating layout.
           53 +label toggles between tiled and floating layout, click on the window follow
           54 +icon toggles it on and off.
           55  .TP
           56  .B Button3
           57  click on a tag label adds/removes all windows with that tag to/from the view.
           58 @@ -80,6 +81,9 @@ Send focused window to next screen, if any.
           59  .B Mod1\-b
           60  Toggles bar on and off.
           61  .TP
           62 +.B Mod1\-n
           63 +Toggles window following on and off.
           64 +.TP
           65  .B Mod1\-t
           66  Sets tiled layout.
           67  .TP
           68 diff --git a/dwm.c b/dwm.c
           69 index e5efb6a..6d86a9c 100644
           70 --- a/dwm.c
           71 +++ b/dwm.c
           72 @@ -65,7 +65,7 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
           73         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
           74  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
           75  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
           76 -       ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
           77 +       ClkClientWin, ClkRootWin, ClkFollowSymbol, ClkLast }; /* clicks */
           78  
           79  typedef union {
           80          int i;
           81 @@ -113,6 +113,7 @@ typedef struct {
           82  
           83  struct Monitor {
           84          char ltsymbol[16];
           85 +        char wfsymbol[2];
           86          float mfact;
           87          int nmaster;
           88          int num;
           89 @@ -212,6 +213,7 @@ static void tagmon(const Arg *arg);
           90  static void tile(Monitor *m);
           91  static void togglebar(const Arg *arg);
           92  static void togglefloating(const Arg *arg);
           93 +static void togglefollow(const Arg *arg);
           94  static void toggletag(const Arg *arg);
           95  static void toggleview(const Arg *arg);
           96  static void unfocus(Client *c, int setfocus);
           97 @@ -440,8 +442,10 @@ buttonpress(XEvent *e)
           98                  if (i < LENGTH(tags)) {
           99                          click = ClkTagBar;
          100                          arg.ui = 1 << i;
          101 -                } else if (ev->x < x + TEXTW(selmon->ltsymbol))
          102 +                } else if (ev->x < (x = (x + TEXTW(selmon->ltsymbol))))
          103                          click = ClkLtSymbol;
          104 +                else if (ev->x < x + TEXTW(selmon->wfsymbol))
          105 +                        click = ClkFollowSymbol;
          106                  else if (ev->x > selmon->ww - (int)TEXTW(stext))
          107                          click = ClkStatusText;
          108                  else
          109 @@ -645,6 +649,8 @@ createmon(void)
          110          m->lt[0] = &layouts[0];
          111          m->lt[1] = &layouts[1 % LENGTH(layouts)];
          112          strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
          113 +        m->wfsymbol[0] = WFDEFAULT;
          114 +        m->wfsymbol[1] = '\0';
          115          return m;
          116  }
          117  
          118 @@ -735,6 +741,9 @@ drawbar(Monitor *m)
          119          drw_setscheme(drw, scheme[SchemeNorm]);
          120          x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
          121  
          122 +        w = TEXTW(m->wfsymbol);
          123 +        x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->wfsymbol, 0);
          124 +
          125          if ((w = m->ww - tw - x) > bh) {
          126                  if (m->sel) {
          127                          drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
          128 @@ -1656,6 +1665,8 @@ tag(const Arg *arg)
          129                  focus(NULL);
          130                  arrange(selmon);
          131          }
          132 +        if (selmon->wfsymbol[0] == WFACTIVE)
          133 +                view(arg);
          134  }
          135  
          136  void
          137 @@ -1664,6 +1675,8 @@ tagmon(const Arg *arg)
          138          if (!selmon->sel || !mons->next)
          139                  return;
          140          sendmon(selmon->sel, dirtomon(arg->i));
          141 +        if (selmon->wfsymbol[0] == WFACTIVE)
          142 +                focusmon(arg);
          143  }
          144  
          145  void
          146 @@ -1703,6 +1716,13 @@ togglebar(const Arg *arg)
          147          arrange(selmon);
          148  }
          149  
          150 +void
          151 +togglefollow(const Arg *arg)
          152 +{
          153 +        selmon->wfsymbol[0] = (selmon->wfsymbol[0] == WFACTIVE) ? WFINACTIVE : WFACTIVE;
          154 +        drawbars();
          155 +}
          156 +
          157  void
          158  togglefloating(const Arg *arg)
          159  {
          160 -- 
          161 2.37.3
          162