moveresize

Description

This changes allows you to move and resize dwm’s clients using keyboard bindings.

Usage

  1. Put the following moveresize() function somewhere in your dwm.c, after the line which includes the config.h file:

    static void moveresize(const Arg *arg) {

    XEvent ev;
    Monitor *m = selmon;
    
    if(!(m->sel && arg && arg->v && m->sel->isfloating))
        return;
    
    resize(m->sel, m->sel->x + ((int *)arg->v)[0],
        m->sel->y + ((int *)arg->v)[1],
        m->sel->w + ((int *)arg->v)[2],
        m->sel->h + ((int *)arg->v)[3],
        True);
    
    while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
    

    }

  2. Insert the bindings into the keys list. Here is an example which uses the arrow keys to move (mod+arrow) or resize (mod+shift+arrow) the selected client:

    { MODKEY, XK_Down, moveresize, {.v = “0x 25y 0w 0h”}}, { MODKEY, XK_Up, moveresize, {.v = “0x -25y 0w 0h”}}, { MODKEY, XK_Right, moveresize, {.v = “25x 0y 0w 0h”}}, { MODKEY, XK_Left, moveresize, {.v = “-25x 0y 0w 0h”}}, { MODKEY|ShiftMask, XK_Down, moveresize, {.v = “0x 0y 0w 25h”}}, { MODKEY|ShiftMask, XK_Up, moveresize, {.v = “0x 0y 0w -25h”}}, { MODKEY|ShiftMask, XK_Right, moveresize, {.v = “0x 0y 25w 0h”}}, { MODKEY|ShiftMask, XK_Left, moveresize, {.v = “0x 0y -25w 0h”}},

If you want to automatically toggle the client floating when move/resize, replace the if() statement above with this code:

if(!(m->sel && arg && arg->v))
    return;
if(m->lt[m->sellt]->arrange && !m->sel->isfloating)
    togglefloating(NULL);

Multi-head

From dwm 6.0 onward there’s the following patch which is aware of the screen sizes in a multi monitor setup. A second patch allows you to maximize windows.

Download

Patches against different versions of dwm are available at dwm-clean-patches.

Authors