diff --git a/config.def.h b/config.def.h index eaae8f3..2180173 100644 --- a/config.def.h +++ b/config.def.h @@ -78,6 +78,10 @@ static Key keys[] = { { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY|ControlMask, XK_Right, togglehorizontalmax, {0} }, + { MODKEY|ControlMask, XK_Left, toggleverticalmax, {0} }, + { MODKEY|ControlMask, XK_Up, togglemaximize, {0} }, + { MODKEY|ControlMask, XK_Down, togglemaximize, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, diff --git a/dwm.c b/dwm.c index 169adcb..37d4b43 100644 --- a/dwm.c +++ b/dwm.c @@ -92,8 +92,8 @@ struct Client { int basew, baseh, incw, inch, maxw, maxh, minw, minh; int bw, oldbw; unsigned int tags; - Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; - Client *next; + Bool ismax, wasfloating, isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + Client *next; Client *snext; Monitor *mon; Window win; @@ -181,6 +181,7 @@ static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); +static void maximize(int x, int y, int w, int h); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); @@ -211,6 +212,9 @@ static void tagmon(const Arg *arg); static void tile(Monitor *); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglehorizontalmax(const Arg *arg); +static void togglemaximize(const Arg *arg); +static void toggleverticalmax(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, Bool setfocus); @@ -1046,6 +1050,8 @@ manage(Window w, XWindowAttributes *wa) { updatewmhints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, False); + c->wasfloating = False; + c->ismax = False; if(!c->isfloating) c->isfloating = c->oldstate = trans != None || c->isfixed; if(c->isfloating) @@ -1087,6 +1093,37 @@ maprequest(XEvent *e) { } void +maximize(int x, int y, int w, int h) { + XEvent ev; + + if(!selmon->sel || selmon->sel->isfixed) + return; + XRaiseWindow(dpy, selmon->sel->win); + if(!selmon->sel->ismax) { + if(!selmon->lt[selmon->sellt]->arrange || selmon->sel->isfloating) + selmon->sel->wasfloating = True; + else { + togglefloating(NULL); + selmon->sel->wasfloating = False; + } + selmon->sel->oldx = selmon->sel->x; + selmon->sel->oldy = selmon->sel->y; + selmon->sel->oldw = selmon->sel->w; + selmon->sel->oldh = selmon->sel->h; + resize(selmon->sel, x, y, w, h, True); + selmon->sel->ismax = True; + } + else { + resize(selmon->sel, selmon->sel->oldx, selmon->sel->oldy, selmon->sel->oldw, selmon->sel->oldh, True); + if(!selmon->sel->wasfloating) + togglefloating(NULL); + selmon->sel->ismax = False; + } + drawbar(selmon); + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); +} + +void monocle(Monitor *m) { unsigned int n = 0; Client *c; @@ -1656,6 +1693,16 @@ togglefloating(const Arg *arg) { } void +togglehorizontalmax(const Arg *arg) { + maximize(selmon->wx, selmon->sel->y, selmon->ww - 2 * borderpx, selmon->sel->h); +} + +void +togglemaximize(const Arg *arg) { + maximize(selmon->wx, selmon->wy, selmon->ww - 2 * borderpx, selmon->wh - 2 * borderpx); +} + +void toggletag(const Arg *arg) { unsigned int newtags; @@ -1670,6 +1717,11 @@ toggletag(const Arg *arg) { } void +toggleverticalmax(const Arg *arg) { + maximize(selmon->sel->x, selmon->wy, selmon->sel->w, selmon->wh - 2 * borderpx); +} + +void toggleview(const Arg *arg) { unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);