dwm-multimon-6-swap_focus-6.4.patch - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-multimon-6-swap_focus-6.4.patch (6495B)
       ---
            1 From de73c72af0250f56f9ac30a5c3f4520da250282a Mon Sep 17 00:00:00 2001
            2 From: "Gary B. Genett" <me@garybgenett.net>
            3 Date: Sun, 19 Feb 2023 09:40:00 -0800
            4 Subject: patches/swapfocus: dwm-swapfocus-20160731-56a31dc.diff
            5 MIME-Version: 1.0
            6 Content-Type: multipart/mixed; boundary="------------2.37.4"
            7 
            8 This is a multi-part message in MIME format.
            9 --------------2.37.4
           10 Content-Type: text/plain; charset=UTF-8; format=fixed
           11 Content-Transfer-Encoding: 8bit
           12 
           13 
           14         modified from sites: 38b351cf3689ff3fa4845d35ce9894fd9253dbb8
           15 ---
           16  config.def.h |  1 +
           17  dwm.c        | 19 ++++++++++++++++++-
           18  2 files changed, 19 insertions(+), 1 deletion(-)
           19 
           20 
           21 --------------2.37.4
           22 Content-Type: text/x-patch; name="0006-patches-swapfocus-dwm-swapfocus-20160731-56a31dc.dif.patch"
           23 Content-Transfer-Encoding: 8bit
           24 Content-Disposition: attachment; filename="0006-patches-swapfocus-dwm-swapfocus-20160731-56a31dc.dif.patch"
           25 
           26 diff --git a/config.def.h b/config.def.h
           27 index fd00f7080db9271912d0e4352434739d3c08e1b3..9a1118791c3a2f875b58bf3979db5074416b8634 100644
           28 --- a/config.def.h
           29 +++ b/config.def.h
           30 @@ -79,20 +79,21 @@ static const Key keys[] = {
           31          { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
           32          { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
           33          { MODKEY|ShiftMask,             XK_j,      pushdown,       {0} },
           34          { MODKEY|ShiftMask,             XK_k,      pushup,         {0} },
           35          { MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
           36          { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
           37          { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
           38          { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
           39          { MODKEY,                       XK_Return, zoom,           {0} },
           40          { MODKEY,                       XK_Tab,    view,           {0} },
           41 +        { MODKEY|ShiftMask,             XK_Tab,    swapfocus,      {0} },
           42          { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
           43          { MODKEY,                       XK_t,      setlayout,      {.v = &layouts[0]} },
           44          { MODKEY,                       XK_f,      setlayout,      {.v = &layouts[1]} },
           45          { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
           46          { MODKEY,                       XK_space,  setlayout,      {0} },
           47          { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
           48          { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
           49          { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
           50          { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
           51          { MODKEY,                       XK_period, focusmon,       {.i = +1 } },
           52 diff --git a/dwm.c b/dwm.c
           53 index 5aa229611a27b8aa943308314b494c10e2364137..ac52b8c25991a073db15b55fae774e9c47a05708 100644
           54 --- a/dwm.c
           55 +++ b/dwm.c
           56 @@ -203,20 +203,21 @@ static int sendevent(Client *c, Atom proto);
           57  static void sendmon(Client *c, Monitor *m);
           58  static void setclientstate(Client *c, long state);
           59  static void setfocus(Client *c);
           60  static void setfullscreen(Client *c, int fullscreen);
           61  static void setlayout(const Arg *arg);
           62  static void setmfact(const Arg *arg);
           63  static void setup(void);
           64  static void seturgent(Client *c, int urg);
           65  static void showhide(Client *c);
           66  static void spawn(const Arg *arg);
           67 +static void swapfocus(const Arg *arg);
           68  static void tag(const Arg *arg);
           69  static void tagmon(const Arg *arg);
           70  static void tile(Monitor *m);
           71  static void togglebar(const Arg *arg);
           72  static void togglefloating(const Arg *arg);
           73  static void toggletag(const Arg *arg);
           74  static void ntoggleview(const Arg *arg);
           75  static void toggleview(const Arg *arg);
           76  static void unfocus(Client *c, int setfocus);
           77  static void unmanage(Client *c, int destroyed);
           78 @@ -235,20 +236,21 @@ static void nview(const Arg *arg);
           79  static void view(const Arg *arg);
           80  static Client *wintoclient(Window w);
           81  static Monitor *wintomon(Window w);
           82  static int xerror(Display *dpy, XErrorEvent *ee);
           83  static int xerrordummy(Display *dpy, XErrorEvent *ee);
           84  static int xerrorstart(Display *dpy, XErrorEvent *ee);
           85  static void zoom(const Arg *arg);
           86  static void reset_view(const Arg *arg);
           87  
           88  /* variables */
           89 +static Client *prevclient = NULL;
           90  static const char broken[] = "broken";
           91  static char stext[256];
           92  static int screen;
           93  static int sw, sh;           /* X display screen geometry width, height */
           94  static int bh;               /* bar height */
           95  static int lrpad;            /* sum of left and right padding for text */
           96  static int (*xerrorxlib)(Display *, XErrorEvent *);
           97  static unsigned int numlockmask = 0;
           98  static void (*handler[LASTEvent]) (XEvent *) = {
           99          [ButtonPress] = buttonpress,
          100 @@ -1721,20 +1723,32 @@ spawn(const Arg *arg)
          101                  dmenumon[0] = '0' + selmon->num;
          102          if (fork() == 0) {
          103                  if (dpy)
          104                          close(ConnectionNumber(dpy));
          105                  setsid();
          106                  execvp(((char **)arg->v)[0], (char **)arg->v);
          107                  die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
          108          }
          109  }
          110  
          111 +void
          112 +swapfocus(const Arg *arg)
          113 +{
          114 +        Client *c;
          115 +
          116 +        for(c = selmon->clients; c && c != prevclient; c = c->next) ;
          117 +        if(c == prevclient) {
          118 +                focus(prevclient);
          119 +                restack(prevclient->mon);
          120 +        }
          121 +}
          122 +
          123  void
          124  tag(const Arg *arg)
          125  {
          126          if (selmon->sel && arg->ui & TAGMASK) {
          127                  selmon->sel->tags = arg->ui & TAGMASK;
          128                  focus(NULL);
          129                  arrange(selmon);
          130          }
          131  }
          132  
          133 @@ -1834,20 +1848,21 @@ toggleview(const Arg *arg)
          134                  focus(NULL);
          135                  arrange(selmon);
          136          }
          137  }
          138  
          139  void
          140  unfocus(Client *c, int setfocus)
          141  {
          142          if (!c)
          143                  return;
          144 +        prevclient = c;
          145          grabbuttons(c, 0);
          146          XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
          147          if (setfocus) {
          148                  XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
          149                  XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
          150          }
          151  }
          152  
          153  void
          154  unmanage(Client *c, int destroyed)
          155 @@ -2213,25 +2228,27 @@ int
          156  xerrorstart(Display *dpy, XErrorEvent *ee)
          157  {
          158          die("dwm: another window manager is already running");
          159          return -1;
          160  }
          161  
          162  void
          163  zoom(const Arg *arg)
          164  {
          165          Client *c = selmon->sel;
          166 +        prevclient = nexttiled(selmon->clients);
          167  
          168          if (!selmon->lt[selmon->sellt]->arrange || !c || c->isfloating)
          169                  return;
          170          if (c == nexttiled(selmon->clients) && !(c = nexttiled(c->next)))
          171 -                return;
          172 +                if (!c || !(c = prevclient = nexttiled(c->next)))
          173 +                        return;
          174          pop(c);
          175  }
          176  
          177  void
          178  reset_view(const Arg *arg) {
          179          const int mon = selmon->num;
          180          Arg n = {.i = +1};        // focusmon(next monitor)
          181          Arg m = {.f = 0};        // mfact -> facts[]
          182          Arg i = {.i = 0};        // nmaster -> masters[]
          183          Arg v = {.ui = 0};        // nviews -> views[]
          184 
          185 --------------2.37.4--
          186 
          187