Re: [dwm] move/resize keyboard control

From: Premysl Hruby <dfenze_AT_gmail.com>
Date: Thu, 25 Sep 2008 19:55:24 +0200

On (25/09/08 19:36), Claudio wrote:
> To: dwm mail list <dwm_AT_suckless.org>
> From: Claudio <smoppy_AT_gmail.com>
> Subject: [dwm] move/resize keyboard control
> Reply-To: dwm mail list <dwm_AT_suckless.org>
> List-Id: dwm mail list <dwm.suckless.org>
>
> Hi to all dwm users,
> i was trying to get the moveresize patch from this page[0] but it seems
> to
> point to a server which is not up anymore. Since i really need such feature
> i
> replaced the old code with my own:
>
> static void
> moveresize(const Arg *arg)
> {
> int x, y, w, h;
>
> if( ! (sel && arg && arg->v) )
> return;
>
> sscanf(arg->v, "%d%d%d%d", &x, &y, &w, &h);
>
> x = (x ? x + sel->x : sel->x);
> y = (y ? y + sel->y : sel->y);
> w = (w ? w + sel->w : sel->w);
> h = (h ? h + sel->h : sel->h);
>
> resize(sel, x, y, w, h, resizehints);
>
> } /* moveresize() */
>
> Here is the key bindings part:
>
> { MODKEY, XK_Down, moveresize, {.v = "0 25 0
> 0"} },
> { MODKEY, XK_Up, moveresize, {.v = "0 -25 0
> 0"} },
> { MODKEY, XK_Right, moveresize, {.v = "25 0 0
> 0"} },
> { MODKEY, XK_Left, moveresize, {.v = "-25 0 0
> 0"} },
> { MODKEY|ShiftMask, XK_Down, moveresize, {.v = "0 0 0
> 25"} },
> { MODKEY|ShiftMask, XK_Up, moveresize, {.v = "0 0 0
> -25"} },
> { MODKEY|ShiftMask, XK_Right, moveresize, {.v = "0 0 25
> 0"} },
> { MODKEY|ShiftMask, XK_Left, moveresize, {.v = "0 0 -25
> 0"} },
>
> That's exactly what i need. Hope someone else will found it useful.
>
> [0] http://www.suckless.org/dwm/patches/moveresize.html
>
> Saluti,
> Claudio M. Alessi

I'm using this patch: ( more precise moving/resize with control),
also it clear's event queue from EnterWindow event's so focus is not
changing while moving one window over another. It also automaticaly
toggle floating of window, if it is not floating. And last, it use array
of ints instead of string for passing parameters.

diff -r a2f37186527c config.def.h
--- a/config.def.h Sat Aug 23 09:54:55 2008 +0100
+++ b/config.def.h Sat Aug 23 13:29:59 2008 +0200
@@ -77,6 +77,22 @@
         TAGKEYS( XK_7, 6)
         TAGKEYS( XK_8, 7)
         TAGKEYS( XK_9, 8)
+ { MODKEY, XK_Left, kbmvresize, {.v = (int []){ -40, 0, 0, 0 }}},
+ { MODKEY, XK_Up, kbmvresize, {.v = (int []){ 0, -40, 0, 0 }}},
+ { MODKEY, XK_Right, kbmvresize, {.v = (int []){ 40, 0, 0, 0 }}},
+ { MODKEY, XK_Down, kbmvresize, {.v = (int []){ 0, 40, 0, 0 }}},
+ { MODKEY|ShiftMask, XK_Left, kbmvresize, {.v = (int []){ 0, 0, -40, 0 }}},
+ { MODKEY|ShiftMask, XK_Up, kbmvresize, {.v = (int []){ 0, 0, 0, -40 }}},
+ { MODKEY|ShiftMask, XK_Right, kbmvresize, {.v = (int []){ 0, 0, 40, 0 }}},
+ { MODKEY|ShiftMask, XK_Down, kbmvresize, {.v = (int []){ 0, 0, 0, 40 }}},
+ { MODKEY|ControlMask, XK_Left, kbmvresize, {.v = (int []){ -5, 0, 0, 0 }}},
+ { MODKEY|ControlMask, XK_Up, kbmvresize, {.v = (int []){ 0, -5, 0, 0 }}},
+ { MODKEY|ControlMask, XK_Right, kbmvresize, {.v = (int []){ 5, 0, 0, 0 }}},
+ { MODKEY|ControlMask, XK_Down, kbmvresize, {.v = (int []){ 0, 5, 0, 0 }}},
+ { MODKEY|ShiftMask|ControlMask, XK_Left, kbmvresize, {.v = (int []){ 0, 0, 5, 0 }}},
+ { MODKEY|ShiftMask|ControlMask, XK_Up, kbmvresize, {.v = (int []){ 0, 0, 0, 5 }}},
+ { MODKEY|ShiftMask|ControlMask, XK_Right, kbmvresize, {.v = (int []){ 0, 0, 5, 0 }}},
+ { MODKEY|ShiftMask|ControlMask, XK_Down, kbmvresize, {.v = (int []){ 0, 0, 0, 5 }}},
         { MODKEY|ShiftMask, XK_q, quit, {0} },
 };
 
diff -r a2f37186527c dwm.c
--- a/dwm.c Sat Aug 23 09:54:55 2008 +0100
+++ b/dwm.c Sat Aug 23 13:29:59 2008 +0200
@@ -159,6 +159,7 @@
 static void grabkeys(void);
 static void initfont(const char *fontstr);
 static Bool isprotodel(Client *c);
+static void kbmvresize(const Arg *arg);
 static void keypress(XEvent *e);
 static void killclient(const Arg *arg);
 static void manage(Window w, XWindowAttributes *wa);
@@ -826,6 +827,22 @@
                 XFree(protocols);
         }
         return ret;
+}
+
+void
+kbmvresize(const Arg *arg) {
+ XEvent ev;
+
+ if(!sel)
+ return;
+ if(lt[sellt]->arrange)
+ sel->isfloating = True;
+
+ resize(sel, sel->x + ((int *)arg->v)[0],
+ sel->y + ((int *)arg->v)[1],
+ sel->w + ((int *)arg->v)[2],
+ sel->h + ((int *)arg->v)[3], True);
+ while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
 }
 
 void

-- 
Premysl "Anydot" Hruby, http://www.redrum.cz/
Received on Thu Sep 25 2008 - 17:55:24 UTC

This archive was generated by hypermail 2.2.0 : Thu Sep 25 2008 - 18:00:05 UTC