Hi,
I find it useful to move and resize windows without the mouse in dwm. Here's
a revision of an old patch that was out there. Mine is based on 5.6.1.
Caveat emptor: I'm not sure about some of the innards of dwm. I have some
comments in the code below which I'd like answers to, if anyone has them.
At any rate, it "works for me".
To run, just add the function to config.h or an #include "moveresize.c" in
config.h. The configure keybindings. Here is an example:
{ CAPKEY|ShiftMask, XK_Up, movetotum, {.v = "0x -25y 0w 0h" } },
{ CAPKEY|ShiftMask, XK_Down, movetotum, {.v = "0x 25y 0w 0h" } },
{ CAPKEY|ShiftMask, XK_Right, movetotum, {.v = "25x 0y 0w 0h" } },
{ CAPKEY|ShiftMask, XK_Left, movetotum, {.v = "-25x 0y 0w 0h" } },
{ CAPKEY|ControlMask, XK_Right, movetotum, {.v = "0x 0y 25w 0h" } },
{ CAPKEY|ControlMask, XK_Left, movetotum, {.v = "0x 0y -25w 0h" } },
{ CAPKEY|ControlMask, XK_Down, movetotum, {.v = "0x 0y 0w 25h" } },
{ CAPKEY|ControlMask, XK_Up, movetotum, {.v = "0x 0y 0w -25h" } },
{ CAPKEY, XK_1, movetotum, {.v = "800X 900Y 0w 0h } },
// NB the last entry "warps" the window to the absolute coordinate (800,
// 900). The others just increment it in the relevent direction/width.
=========================== movetotum function =======================================
void movetotum(const Arg *arg) {
int nx, ny, nw, nh;
int x, y, w, h;
char xAbs, yAbs, wAbs, hAbs;
Client *c;
int ox, oy, ow, oh;
int msx, msy, dx, dy, nmx, nmy;
unsigned int dui;
Window dummy;
if(!(c = selmon->sel))
return;
if (!c->isfloating && selmon->lt[selmon->sellt]->arrange) // could togglefloating(NULL)?
return;
restack(selmon); // this is in movemouse; do i need it?
if(sscanf(arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8)
return;
// config.h examples:
// "0x 25y 0h 0w" --> moves up 25 on the y-axis
// "9000X 0y 0h 0w" --> goes straight to 9000 on the x-axis
nx = xAbs == 'X' ? x : c->x + x;
ny = yAbs == 'Y' ? y : c->y + y;
nw = wAbs == 'W' ? w : c->w + w;
nh = hAbs == 'H' ? h : c->h + h;
ox = c->x;
oy = c->y;
ow = c->w;
oh = c->h;
// could add some code to keep resizing in opposite dir when window is resized to 0, i.e. if shrinking horizontally from right once
// window width is 0 then start growing horizontally towards the left.
XRaiseWindow(dpy, selmon->sel->win); // do i still need to do this (from old patch)
Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
resize(c, nx, ny, nw, nh, True);
//XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy) {
nmx = msx-ox+c->w-ow-1 < 0 ? 0 : msx-ox+c->w-ow-1;
nmy = msy-oy+c->h-oh-1 < 0 ? 0 : msy-oy+c->h-oh-1;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, nmx, nmy);
}
}
============================= end function =================================
Yours, peter
Received on Wed Nov 18 2009 - 13:54:36 UTC
This archive was generated by hypermail 2.2.0 : Wed Nov 18 2009 - 14:00:03 UTC