dwm-moveresize-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-moveresize-6.2.diff (4355B)
       ---
            1 From 0ac50d43c5a48de34a53db8240143e4fb39239d3 Mon Sep 17 00:00:00 2001
            2 From: bakkeby <bakkeby@gmail.com>
            3 Date: Fri, 22 May 2020 13:51:06 +0200
            4 Subject: [PATCH] The moveresize patch allows floating windows to be resized
            5  and moved using keyboard shortcuts.
            6 
            7 This example keybinding reduces the y position with 25 pixels.
            8 
            9         { MODKEY,                       XK_Up,     moveresize,     {.v = "0x -25y 0w 0h" } },
           10 
           11 Use capital letters to specify absolute size and position should you need it.
           12 
           13     { MODKEY,                       XK_Up,     moveresize,     {.v = "0x 0y 500W 300H" } },
           14 
           15 The above example would set the size of the client to 300x500 pixels, but leave the position as-is.
           16 
           17 Refer to:
           18 https://dwm.suckless.org/patches/moveresize/
           19 ---
           20  config.def.h |  8 +++++++
           21  dwm.c        | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
           22  2 files changed, 74 insertions(+)
           23 
           24 diff --git a/config.def.h b/config.def.h
           25 index 1c0b587..ff863c9 100644
           26 --- a/config.def.h
           27 +++ b/config.def.h
           28 @@ -78,6 +78,14 @@ static Key keys[] = {
           29          { MODKEY,                       XK_m,      setlayout,      {.v = &layouts[2]} },
           30          { MODKEY,                       XK_space,  setlayout,      {0} },
           31          { MODKEY|ShiftMask,             XK_space,  togglefloating, {0} },
           32 +        { MODKEY,                       XK_Down,   moveresize,     {.v = "0x 25y 0w 0h" } },
           33 +        { MODKEY,                       XK_Up,     moveresize,     {.v = "0x -25y 0w 0h" } },
           34 +        { MODKEY,                       XK_Right,  moveresize,     {.v = "25x 0y 0w 0h" } },
           35 +        { MODKEY,                       XK_Left,   moveresize,     {.v = "-25x 0y 0w 0h" } },
           36 +        { MODKEY|ShiftMask,             XK_Down,   moveresize,     {.v = "0x 0y 0w 25h" } },
           37 +        { MODKEY|ShiftMask,             XK_Up,     moveresize,     {.v = "0x 0y 0w -25h" } },
           38 +        { MODKEY|ShiftMask,             XK_Right,  moveresize,     {.v = "0x 0y 25w 0h" } },
           39 +        { MODKEY|ShiftMask,             XK_Left,   moveresize,     {.v = "0x 0y -25w 0h" } },
           40          { MODKEY,                       XK_0,      view,           {.ui = ~0 } },
           41          { MODKEY|ShiftMask,             XK_0,      tag,            {.ui = ~0 } },
           42          { MODKEY,                       XK_comma,  focusmon,       {.i = -1 } },
           43 diff --git a/dwm.c b/dwm.c
           44 index 4465af1..89483c1 100644
           45 --- a/dwm.c
           46 +++ b/dwm.c
           47 @@ -182,6 +182,7 @@ static void mappingnotify(XEvent *e);
           48  static void maprequest(XEvent *e);
           49  static void monocle(Monitor *m);
           50  static void motionnotify(XEvent *e);
           51 +static void moveresize(const Arg *arg);
           52  static void movemouse(const Arg *arg);
           53  static Client *nexttiled(Client *c);
           54  static void pop(Client *);
           55 @@ -1192,6 +1193,71 @@ movemouse(const Arg *arg)
           56          }
           57  }
           58  
           59 +void
           60 +moveresize(const Arg *arg) {
           61 +        /* only floating windows can be moved */
           62 +        Client *c;
           63 +        c = selmon->sel;
           64 +        int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh;
           65 +        char xAbs, yAbs, wAbs, hAbs;
           66 +        int msx, msy, dx, dy, nmx, nmy;
           67 +        unsigned int dui;
           68 +        Window dummy;
           69 +
           70 +        if (!c || !arg)
           71 +                return;
           72 +        if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
           73 +                return;
           74 +        if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8)
           75 +                return;
           76 +
           77 +        /* compute new window position; prevent window from be positioned outside the current monitor */
           78 +        nw = c->w + w;
           79 +        if (wAbs == 'W')
           80 +                nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw;
           81 +
           82 +        nh = c->h + h;
           83 +        if (hAbs == 'H')
           84 +                nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw;
           85 +
           86 +        nx = c->x + x;
           87 +        if (xAbs == 'X') {
           88 +                if (x < selmon->mx)
           89 +                        nx = selmon->mx;
           90 +                else if (x > selmon->mx + selmon->mw)
           91 +                        nx = selmon->mx + selmon->mw - nw - 2 * c->bw;
           92 +                else
           93 +                        nx = x;
           94 +        }
           95 +
           96 +        ny = c->y + y;
           97 +        if (yAbs == 'Y') {
           98 +                if (y < selmon->my)
           99 +                        ny = selmon->my;
          100 +                else if (y > selmon->my + selmon->mh)
          101 +                        ny = selmon->my + selmon->mh - nh - 2 * c->bw;
          102 +                else
          103 +                        ny = y;
          104 +        }
          105 +
          106 +        ox = c->x;
          107 +        oy = c->y;
          108 +        ow = c->w;
          109 +        oh = c->h;
          110 +
          111 +        XRaiseWindow(dpy, c->win);
          112 +        Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
          113 +        resize(c, nx, ny, nw, nh, True);
          114 +
          115 +        /* move cursor along with the window to avoid problems caused by the sloppy focus */
          116 +        if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy)
          117 +        {
          118 +                nmx = c->x - ox + c->w - ow;
          119 +                nmy = c->y - oy + c->h - oh;
          120 +                XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy);
          121 +        }
          122 +}
          123 +
          124  Client *
          125  nexttiled(Client *c)
          126  {
          127 -- 
          128 2.19.1
          129