Adding exresize patch

This commit is contained in:
bakkeby 2019-10-24 08:47:00 +02:00
parent d82be5a65d
commit 2112ea927f
8 changed files with 422 additions and 150 deletions

View File

@ -15,7 +15,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
2019-10-24 - Added dragmfact, extrabar and nodmenu patches
2019-10-24 - Added dragmfact, extrabar, exresize and nodmenu patches
2019-10-22 - Added ispermanent and swallow patches
@ -128,6 +128,10 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- [ewmhtags](https://dwm.suckless.org/patches/ewmhtags/)
- adds EWMH support for \_NET_NUMBER_OF_DESKTOPS, \_NET_CURRENT_DESKTOP, \_NET_DESKTOP_NAMES and \_NET_DESKTOP_VIEWPORT, which allows for compatibility with other bars and programs that request workspace information, e.g. polybar's xworkspaces module
- [exresize](https://dwm.suckless.org/patches/exresize/)
- this patch allows the user to change size and placement of floating windows using only the keyboard
- it also allows for temporary vertical and horizontal extension of windows similar to other WMs fill command
- [extrabar](https://dwm.suckless.org/patches/extrabar/)
- enables an extra status bar in dwm in a similar manner to the dualstatus patch
- if the primary status is at the top via topbar then the extra status bar will be placed at the bottom and vice versa

View File

@ -675,6 +675,34 @@ static Key keys[] = {
{ MODKEY|Mod4Mask, XK_Right, switchtag, { .ui = SWITCHTAG_RIGHT | SWITCHTAG_TAG | SWITCHTAG_VIEW } },
{ MODKEY|Mod4Mask, XK_Left, switchtag, { .ui = SWITCHTAG_LEFT | SWITCHTAG_TAG | SWITCHTAG_VIEW } },
#endif // TAGGRID_PATCH
#if EXRESIZE_PATCH
{ MODKEY, XK_KP_7, explace, {.ui = EX_NW }},
{ MODKEY, XK_KP_8, explace, {.ui = EX_N }},
{ MODKEY, XK_KP_9, explace, {.ui = EX_NE }},
{ MODKEY, XK_KP_4, explace, {.ui = EX_W }},
{ MODKEY, XK_KP_5, explace, {.ui = EX_C }},
{ MODKEY, XK_KP_6, explace, {.ui = EX_E }},
{ MODKEY, XK_KP_1, explace, {.ui = EX_SW }},
{ MODKEY, XK_KP_2, explace, {.ui = EX_S }},
{ MODKEY, XK_KP_3, explace, {.ui = EX_SE }},
{ MODKEY|ShiftMask, XK_KP_8, exresize, {.v = (int []){ 0, 25 }}},
{ MODKEY|ShiftMask, XK_KP_2, exresize, {.v = (int []){ 0, -25 }}},
{ MODKEY|ShiftMask, XK_KP_6, exresize, {.v = (int []){ 25, 0 }}},
{ MODKEY|ShiftMask, XK_KP_4, exresize, {.v = (int []){ -25, 0 }}},
{ MODKEY|ShiftMask, XK_KP_5, exresize, {.v = (int []){ 25, 25 }}},
{ MODKEY|ShiftMask|ControlMask, XK_KP_5, exresize, {.v = (int []){ -25, -25 }}},
{ MODKEY|ControlMask, XK_KP_6, togglehorizontalexpand, {.i = +1} },
{ MODKEY|ControlMask, XK_KP_3, togglehorizontalexpand, {.i = 0} },
{ MODKEY|ControlMask, XK_KP_4, togglehorizontalexpand, {.i = -1} },
{ MODKEY|ControlMask, XK_KP_8, toggleverticalexpand, {.i = +1} },
{ MODKEY|ControlMask, XK_KP_1, toggleverticalexpand, {.i = 0} },
{ MODKEY|ControlMask, XK_KP_2, toggleverticalexpand, {.i = -1} },
{ MODKEY|ControlMask, XK_KP_9, togglemaximize, {.i = -1} },
{ MODKEY|ControlMask, XK_KP_7, togglemaximize, {.i = +1} },
{ MODKEY|ControlMask, XK_KP_5, togglemaximize, {.i = 0} },
#endif // EXRESIZE_PATCH
#if SETBORDERPX_PATCH
{ MODKEY|ShiftMask, XK_minus, setborderpx, {.i = -1 } },
{ MODKEY|ShiftMask, XK_plus, setborderpx, {.i = +1 } },

69
dwm.c
View File

@ -142,14 +142,21 @@ struct Client {
float cfact;
#endif // CFACTS_PATCH
int x, y, w, h;
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
int sfx, sfy, sfw, sfh; /* stored float geometry, used on mode revert */
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
int oldx, oldy, oldw, oldh;
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
unsigned int tags;
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
#if EXRESIZE_PATCH
unsigned char expandmask;
int expandx1, expandy1, expandx2, expandy2;
#if !MAXIMIZE_PATCH
int wasfloating;
#endif // MAXIMIZE_PATCH
#endif // EXRESIZE_PATCH
#if MAXIMIZE_PATCH
int ismax, wasfloating;
#endif // MAXIMIZE_PATCH
@ -1992,19 +1999,22 @@ manage(Window w, XWindowAttributes *wa)
c->y = c->mon->my + (c->mon->mh - HEIGHT(c)) / 2;
}
#endif // CENTER_PATCH
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
c->sfx = -9999;
c->sfy = -9999;
c->sfw = c->w;
c->sfh = c->h;
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, 0);
#if MAXIMIZE_PATCH
c->wasfloating = 0;
c->ismax = 0;
#endif // MAXIMIZE_PATCH
#elif EXRESIZE_PATCH
c->wasfloating = 0;
#endif // MAXIMIZE_PATCH / EXRESIZE_PATCH
if (!c->isfloating)
c->isfloating = c->oldstate = trans != None || c->isfixed;
if (c->isfloating)
@ -2147,14 +2157,14 @@ movemouse(const Arg *arg)
&& (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
togglefloating(NULL);
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
resize(c, nx, ny, c->w, c->h, 1);
/* save last known float coordinates */
c->sfx = nx;
c->sfy = ny;
#else
resize(c, nx, ny, c->w, c->h, 1);
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
}
break;
}
@ -2304,6 +2314,9 @@ resizeclient(Client *c, int x, int y, int w, int h)
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
#if EXRESIZE_PATCH
c->expandmask = 0;
#endif // EXRESIZE_PATCH
wc.border_width = c->bw;
#if NOBORDER_PATCH
if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next))
@ -2413,21 +2426,21 @@ resizemouse(const Arg *arg)
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) {
#if RESIZECORNERS_PATCH
resize(c, nx, ny, nw, nh, 1);
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
/* save last known float dimensions */
c->sfx = nx;
c->sfy = ny;
c->sfw = nw;
c->sfh = nh;
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
#else
resize(c, c->x, c->y, nw, nh, 1);
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
c->sfx = c->x;
c->sfy = c->y;
c->sfw = nw;
c->sfh = nh;
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
#endif // RESIZECORNERS_PATCH
}
break;
@ -2539,6 +2552,9 @@ scan(void)
void
sendmon(Client *c, Monitor *m)
{
#if EXRESIZE_PATCH
Monitor *oldm = selmon;
#endif // EXRESIZE_PATCH
if (c->mon == m)
return;
unfocus(c, 1);
@ -2556,8 +2572,16 @@ sendmon(Client *c, Monitor *m)
attach(c);
#endif
attachstack(c);
#if EXRESIZE_PATCH
if (oldm != m)
arrange(oldm);
arrange(m);
focus(c);
restack(m);
#else
focus(NULL);
arrange(NULL);
#endif // EXRESIZE_PATCH
}
void
@ -2687,6 +2711,17 @@ setlayout(const Arg *arg)
#else
selmon->sellt ^= 1;
#endif // PERTAG_PATCH
#if EXRESIZE_PATCH
if (!selmon->lt[selmon->sellt]->arrange) {
for (Client *c = selmon->clients ; c ; c = c->next) {
if (!c->isfloating) {
/*restore last known float dimensions*/
resize(c, selmon->mx + c->sfx, selmon->my + c->sfy,
c->sfw, c->sfh, False);
}
}
}
#endif // EXRESIZE_PATCH
}
if (arg && arg->v)
#if PERTAG_PATCH
@ -2886,14 +2921,14 @@ showhide(Client *c)
return;
if (ISVISIBLE(c)) {
/* show clients top down */
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
if (!c->mon->lt[c->mon->sellt]->arrange && c->sfx != -9999 && !c->isfullscreen) {
XMoveWindow(dpy, c->win, c->sfx, c->sfy);
resize(c, c->sfx, c->sfy, c->sfw, c->sfh, 0);
showhide(c->snext);
return;
}
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
#if AUTORESIZE_PATCH
if (c->needresize) {
c->needresize = 0;
@ -3059,7 +3094,7 @@ togglefloating(const Arg *arg)
XSetWindowBorder(dpy, selmon->sel->win, scheme[SchemeSel][ColBorder].pixel);
#endif // FLOAT_BORDER_COLOR_PATCH
if (selmon->sel->isfloating) {
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
if (selmon->sel->sfx != -9999) {
/* restore last known float dimensions */
resize(selmon->sel, selmon->sel->sfx, selmon->sel->sfy,
@ -3067,17 +3102,17 @@ togglefloating(const Arg *arg)
arrange(selmon);
return;
}
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH // EXRESIZE_PATCH
resize(selmon->sel, selmon->sel->x, selmon->sel->y,
selmon->sel->w, selmon->sel->h, 0);
#if SAVEFLOATS_PATCH
#if SAVEFLOATS_PATCH || EXRESIZE_PATCH
} else {
/* save last known float dimensions */
selmon->sel->sfx = selmon->sel->x;
selmon->sel->sfy = selmon->sel->y;
selmon->sel->sfw = selmon->sel->w;
selmon->sel->sfh = selmon->sel->h;
#endif // SAVEFLOATS_PATCH
#endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH
}
arrange(selmon);
}

184
patch/exresize.c Normal file
View File

@ -0,0 +1,184 @@
#define EXPAND_LEFT (1 << 0)
#define EXPAND_RIGHT (1 << 2)
#define EXPAND_UP (1 << 4)
#define EXPAND_DOWN (1 << 6)
#define IS_SET(q, w) ((q & w) != 0)
#define IS_FORCED(q, w) IS_SET((q << 1), w)
#define EXPANDALL (EXPAND_LEFT | EXPAND_RIGHT | EXPAND_UP | EXPAND_DOWN)
#define UNEXPAND (EXPANDALL << 1) // Force all directions to 0
#define FORCE_EXPANDALL ~0 // Force expand in all directions
void
exresize(const Arg *arg) {
Client *c;
int x, y, nx, ny, nw, nh;
c = selmon->sel;
if (!c || !arg) return;
if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
togglefloating(NULL);
if (c->expandmask != 0)
expand(UNEXPAND);
x = ((int *)arg->v)[0];
y = ((int *)arg->v)[1];
nw = MIN(selmon->ww - c->bw*2, c->w + x);
nh = MIN(selmon->wh - c->bw*2, c->h + y);
nx = c->x - x/2;
ny = c->y - y/2;
if (!((abs(c->x + c->w/2 - (selmon->wx + selmon->ww/2)) < snap))) {
if ((nw == selmon->ww) ||
(nx < selmon->wx) ||
(abs(selmon->wx - c->x) < snap))
nx = selmon->wx;
else if ((nx+nw > (selmon->wx + selmon->ww)) ||
(abs((selmon->wx + selmon->ww) - (c->x + c->w)) < snap))
nx = (selmon->wx + selmon->ww) - nw - c->bw*2;
} else
nx = selmon->wx + selmon->ww/2 - nw/2;
if (!((abs(c->y + c->h/2 - (selmon->wy + selmon->wh/2)) < snap))) {
if ((nh == selmon->wh) ||
(ny < selmon->wy) ||
(abs(selmon->wy - c->y) < snap))
ny = selmon->wy;
else if ((ny+nh > (selmon->wy + selmon->wh)) ||
(abs((selmon->wy + selmon->wh) - (c->y + c->h)) < snap))
ny = (selmon->wy + selmon->wh) - nh - c->bw*2;
} else
ny = selmon->wy + selmon->wh/2 - nh/2;
resizeclient(c, nx, ny, MAX(nw, 32), MAX(nh, 32));
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
}
void
explace(const Arg *arg) {
Client *c;
int nx, ny;
c = selmon->sel;
if (!c || (arg->ui >= 9)) return;
if (selmon->lt[selmon->sellt]->arrange && !c->isfloating)
togglefloating(NULL);
nx = (arg->ui % 3) - 1;
ny = (arg->ui / 3) - 1;
if (nx < 0) nx = selmon->wx;
else if (nx > 0) nx = selmon->wx + selmon->ww - c->w - c->bw*2;
else nx = selmon->wx + selmon->ww/2 - c->w/2;
if (ny < 0) ny = selmon->wy;
else if (ny > 0) ny = selmon->wy + selmon->wh - c->h - c->bw*2;
else ny = selmon->wy + selmon->wh/2 - c->h/2;
resize(c, nx, ny, c->w, c->h, True);
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2);
}
int
calculate_expand(unsigned char mask, unsigned char curmask,
unsigned char *newmask, unsigned char key,
int *reset_value, int new_reset_value,
int max_value, int old_value) {
if (IS_SET(key, mask) ||
(IS_SET(key, curmask) && (!IS_SET(key, mask) && IS_FORCED(key, mask))) ||
(!IS_SET(key, curmask) && (IS_SET(key, mask) && IS_FORCED(key, mask)))) {
if (IS_SET(key, mask) && (!IS_SET(key,curmask) || IS_FORCED(key,mask)))
{
if (!IS_SET(key, curmask))
*reset_value = new_reset_value;
*newmask |= key;
return max_value;
} else if ((IS_SET(key,curmask) && IS_SET(key, mask)) ||
(!IS_SET(key, mask) && IS_FORCED(key, mask))) {
*newmask &= ~key;
return *reset_value;
} else {
*newmask &= ~key;
return old_value;
}
} else
return new_reset_value;
}
void
expand(unsigned char mask) {
XEvent ev;
int nx1, ny1, nx2, ny2;
unsigned char curmask;
unsigned char newmask;
if(!selmon->sel || selmon->sel->isfixed)
return;
XRaiseWindow(dpy, selmon->sel->win);
newmask = curmask = selmon->sel->expandmask;
if (curmask == 0) {
if(!selmon->lt[selmon->sellt]->arrange || selmon->sel->isfloating)
selmon->sel->wasfloating = 1;
else {
togglefloating(NULL);
selmon->sel->wasfloating = 0;
}
}
nx1 = calculate_expand(mask, curmask, &newmask,
EXPAND_LEFT, &selmon->sel->expandx1,
selmon->sel->x,
selmon->wx,
selmon->sel->oldx);
nx2 = calculate_expand(mask, curmask, &newmask,
EXPAND_RIGHT, &selmon->sel->expandx2,
selmon->sel->x + selmon->sel->w,
selmon->wx + selmon->ww - 2*borderpx,
selmon->sel->oldw + selmon->sel->x);
ny1 = calculate_expand(mask, curmask, &newmask,
EXPAND_UP, &selmon->sel->expandy1,
selmon->sel->y,
selmon->wy,
selmon->sel->oldy);
ny2 = calculate_expand(mask, curmask, &newmask,
EXPAND_DOWN, &selmon->sel->expandy2,
selmon->sel->y + selmon->sel->h,
selmon->wy + selmon->wh - 2*borderpx,
selmon->sel->oldh + selmon->sel->y);
resizeclient(selmon->sel, nx1, ny1, MAX(nx2-nx1, 32), MAX(ny2-ny1, 32));
if ((newmask == 0) && (!selmon->sel->wasfloating))
togglefloating(NULL);
selmon->sel->expandmask = newmask;
drawbar(selmon);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void
togglemaximize(const Arg *arg) {
if (arg->i > 0) expand(FORCE_EXPANDALL);
else if (arg->i < 0) expand(UNEXPAND);
else expand(EXPANDALL);
}
void
toggleverticalexpand(const Arg *arg) {
if (arg->i < 0) expand(EXPAND_DOWN);
else if (arg->i > 0) expand(EXPAND_UP);
else expand(EXPAND_DOWN | EXPAND_UP);
}
void
togglehorizontalexpand(const Arg *arg) {
if (arg->i < 0) expand(EXPAND_LEFT);
else if (arg->i > 0) expand(EXPAND_RIGHT);
else expand(EXPAND_LEFT | EXPAND_RIGHT);
}

8
patch/exresize.h Normal file
View File

@ -0,0 +1,8 @@
enum { EX_NW, EX_N, EX_NE, EX_W, EX_C, EX_E, EX_SW, EX_S, EX_SE };
void expand(unsigned char mask);
void togglemaximize(const Arg *arg);
void toggleverticalexpand(const Arg *arg);
void togglehorizontalexpand(const Arg *arg);
void exresize(const Arg *arg);
void explace(const Arg *arg);

View File

@ -44,6 +44,9 @@
#if HOLDBAR_PATCH
#include "holdbar.c"
#endif
#if EXRESIZE_PATCH
#include "exresize.c"
#endif
#if KILLUNSEL_PATCH
#include "killunsel.c"
#endif

View File

@ -32,6 +32,9 @@
#if EWMHTAGS_PATCH
#include "ewmhtags.h"
#endif
#if EXRESIZE_PATCH
#include "exresize.h"
#endif
#if FOCUSADJACENTTAG_PATCH
#include "focusadjacenttag.h"
#endif

View File

@ -143,6 +143,13 @@
*/
#define EWMHTAGS_PATCH 0
/* This patch allows the user to change size and placement of floating windows using only the
* keyboard. It also allows for temporary vertical and horizontal extension of windows similar
* to other WMs fill command.
* https://dwm.suckless.org/patches/exresize/
*/
#define EXRESIZE_PATCH 0
/* This patch will enable an extra status bar in dwm in a similar manner to the dualstatus
* patch. If the primary status is at the top via topbar then the extra status bar will be
* placed at the bottom and vice versa.