all repos — dwm @ 161fa92530879558f394d69a48e5771088b02cd8

my dwm build

add dwm-fullscreen-compilation patch
Prithu Goswami pg@prithu.dev
Wed, 14 Feb 2024 00:30:44 +0530
commit

161fa92530879558f394d69a48e5771088b02cd8

parent

e0b72e49b0dfe59e0cf49d091095193cc6633311

4 files changed, 507 insertions(+), 31 deletions(-)

jump to
M config.def.hconfig.def.h

@@ -90,10 +90,12 @@ { MODKEY, XK_Return, zoom, {0} },

{ MODKEY, XK_Tab, view, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_e, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_f, togglefullscreen, {0} }, + { MODKEY|ShiftMask, XK_f, togglefakefullscreen, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } },
M config.hconfig.h

@@ -95,10 +95,12 @@ { MODKEY, XK_Tab, view, {0} },

{ MODKEY, XK_o, killclient, {0} }, /* { MODKEY|ShiftMask, XK_c, killclient, {0} }, */ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, - { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_e, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_f, togglefullscreen, {0} }, + { MODKEY|ShiftMask, XK_f, togglefakefullscreen, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } },
A dwm-fullscreen-compilation-6.2.diff

@@ -0,0 +1,352 @@

+From f5fe34d1b382795ad47cd63cf43198c79c6845a5 Mon Sep 17 00:00:00 2001 +From: bakkeby <bakkeby@gmail.com> +Date: Sat, 5 Sep 2020 14:32:26 +0200 +Subject: [PATCH] Compilation of fullscreen patches for dwm. + +This aims to provide a comprehensive fullscreen solution with the following features: + - toggle fullscreen for any window using a single keybinding rather than having + to rely on per-application keybindings + - the ability to have windows go fullscreen within the size and position the + window is currently in (fake fullscreen) + - allow a fullscreen window to be moved to an adjacent monitor while remaining + fullscreen + - make fullscreen windows lose fullscreen if another (e.g. new) window on the + same monitor receives focus, while still allowing dialog boxes to show while + in fullscreen + - allow seamless transition between the two fullscreen modes + +The default keybindings are: + - MOD+f to make a window fullscreen + - MOD+Shift+f to make a window fake fullscreen + +This incorporates, and expands on, the following patches: + - fakefullscreenclient + - togglefullscreen (a.k.a. actualfullscreen) + - tagmonfixfs + - losefullscreen +--- + config.def.h | 4 +- + dwm.c | 178 ++++++++++++++++++++++++++++++++++++++++++--------- + 2 files changed, 152 insertions(+), 30 deletions(-) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..5f28f2c 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -74,10 +74,12 @@ static Key keys[] = { + { MODKEY, XK_Tab, view, {0} }, + { MODKEY|ShiftMask, XK_c, killclient, {0} }, + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, +- { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, ++ { MODKEY, XK_e, setlayout, {.v = &layouts[1]} }, + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, ++ { MODKEY, XK_f, togglefullscreen, {0} }, ++ { MODKEY|ShiftMask, XK_f, togglefakefullscreen, {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 4465af1..763c224 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -93,6 +93,7 @@ struct Client { + int bw, oldbw; + unsigned int tags; + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; ++ int fakefullscreen; + Client *next; + Client *snext; + Monitor *mon; +@@ -177,6 +178,7 @@ static void grabkeys(void); + static void incnmaster(const Arg *arg); + static void keypress(XEvent *e); + static void killclient(const Arg *arg); ++static void losefullscreen(Client *next); + static void manage(Window w, XWindowAttributes *wa); + static void mappingnotify(XEvent *e); + static void maprequest(XEvent *e); +@@ -210,7 +212,9 @@ static void tag(const Arg *arg); + static void tagmon(const Arg *arg); + static void tile(Monitor *); + static void togglebar(const Arg *arg); ++static void togglefakefullscreen(const Arg *arg); + static void togglefloating(const Arg *arg); ++static void togglefullscreen(const Arg *arg); + static void toggletag(const Arg *arg); + static void toggleview(const Arg *arg); + static void unfocus(Client *c, int setfocus); +@@ -519,9 +523,12 @@ clientmessage(XEvent *e) + return; + if (cme->message_type == netatom[NetWMState]) { + if (cme->data.l[1] == netatom[NetWMFullscreen] +- || cme->data.l[2] == netatom[NetWMFullscreen]) ++ || cme->data.l[2] == netatom[NetWMFullscreen]) { ++ if (c->fakefullscreen == 2 && c->isfullscreen) ++ c->fakefullscreen = 3; + setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ + || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); ++ } + } else if (cme->message_type == netatom[NetActiveWindow]) { + if (c != selmon->sel && !c->isurgent) + seturgent(c, 1); +@@ -565,7 +572,7 @@ configurenotify(XEvent *e) + updatebars(); + for (m = mons; m; m = m->next) { + for (c = m->clients; c; c = c->next) +- if (c->isfullscreen) ++ if (c->isfullscreen && c->fakefullscreen != 1) + resizeclient(c, m->mx, m->my, m->mw, m->mh); + XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); + } +@@ -785,8 +792,10 @@ focus(Client *c) + { + if (!c || !ISVISIBLE(c)) + for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); +- if (selmon->sel && selmon->sel != c) ++ if (selmon->sel && selmon->sel != c) { ++ losefullscreen(c); + unfocus(selmon->sel, 0); ++ } + if (c) { + if (c->mon != selmon) + selmon = c->mon; +@@ -834,6 +843,12 @@ focusstack(const Arg *arg) + { + Client *c = NULL, *i; + ++ /* Note that this patch is made for dwm 6.2. If applying this on top of the latest master ++ * then the https://dwm.suckless.org/patches/alwaysfullscreen/ patch has been merged ++ * upstream, which prevents focus to drift from windows that are in fake fullscreen. ++ * To address this issue use this if statement instead: ++ * if (!selmon->sel || (selmon->sel->isfullscreen && selmon->sel->fakefullscreen != 1)) ++ */ + if (!selmon->sel) + return; + if (arg->i > 0) { +@@ -1014,6 +1029,16 @@ killclient(const Arg *arg) + } + } + ++void ++losefullscreen(Client *next) ++{ ++ Client *sel = selmon->sel; ++ if (!sel || !next) ++ return; ++ if (sel->isfullscreen && sel->fakefullscreen != 1 && ISVISIBLE(sel) && sel->mon == next->mon && !next->isfloating) ++ setfullscreen(sel, 0); ++} ++ + void + manage(Window w, XWindowAttributes *wa) + { +@@ -1068,8 +1093,10 @@ manage(Window w, XWindowAttributes *wa) + (unsigned char *) &(c->win), 1); + XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ + setclientstate(c, NormalState); +- if (c->mon == selmon) ++ if (c->mon == selmon) { ++ losefullscreen(c); + unfocus(selmon->sel, 0); ++ } + c->mon->sel = c; + arrange(c->mon); + XMapWindow(dpy, c->win); +@@ -1143,7 +1170,7 @@ movemouse(const Arg *arg) + + if (!(c = selmon->sel)) + return; +- if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ ++ if (c->isfullscreen && c->fakefullscreen != 1) /* no support moving fullscreen windows by mouse */ + return; + restack(selmon); + ocx = c->x; +@@ -1298,7 +1325,7 @@ resizemouse(const Arg *arg) + + if (!(c = selmon->sel)) + return; +- if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ ++ if (c->isfullscreen && c->fakefullscreen != 1) /* no support resizing fullscreen windows by mouse */ + return; + restack(selmon); + ocx = c->x; +@@ -1472,29 +1499,79 @@ setfocus(Client *c) + void + setfullscreen(Client *c, int fullscreen) + { +- if (fullscreen && !c->isfullscreen) { +- XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, +- PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); ++ XEvent ev; ++ int savestate = 0, restorestate = 0, restorefakefullscreen = 0; ++ ++ if ((c->fakefullscreen == 0 && fullscreen && !c->isfullscreen) // normal fullscreen ++ || (c->fakefullscreen == 2 && fullscreen)) // fake fullscreen --> actual fullscreen ++ savestate = 1; // go actual fullscreen ++ else if ((c->fakefullscreen == 0 && !fullscreen && c->isfullscreen) // normal fullscreen exit ++ || (c->fakefullscreen >= 2 && !fullscreen)) // fullscreen exit --> fake fullscreen ++ restorestate = 1; // go back into tiled ++ ++ /* If leaving fullscreen and the window was previously fake fullscreen (2), then restore ++ * that while staying in fullscreen. The exception to this is if we are in said state, but ++ * the client itself disables fullscreen (3) then we let the client go out of fullscreen ++ * while keeping fake fullscreen enabled (as otherwise there will be a mismatch between the ++ * client and the window manager's perception of the client's fullscreen state). */ ++ if (c->fakefullscreen == 2 && !fullscreen && c->isfullscreen) { ++ restorefakefullscreen = 1; + c->isfullscreen = 1; +- c->oldstate = c->isfloating; ++ fullscreen = 1; ++ } ++ ++ if (fullscreen != c->isfullscreen) { // only send property change if necessary ++ if (fullscreen) ++ XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, ++ PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); ++ else ++ XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, ++ PropModeReplace, (unsigned char*)0, 0); ++ } ++ ++ c->isfullscreen = fullscreen; ++ ++ /* Some clients, e.g. firefox, will send a client message informing the window manager ++ * that it is going into fullscreen after receiving the above signal. This has the side ++ * effect of this function (setfullscreen) sometimes being called twice when toggling ++ * fullscreen on and off via the window manager as opposed to the application itself. ++ * To protect against obscure issues where the client settings are stored or restored ++ * when they are not supposed to we add an additional bit-lock on the old state so that ++ * settings can only be stored and restored in that precise order. */ ++ if (savestate && !(c->oldstate & (1 << 1))) { + c->oldbw = c->bw; ++ c->oldstate = c->isfloating | (1 << 1); + c->bw = 0; + c->isfloating = 1; + resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); + XRaiseWindow(dpy, c->win); +- } else if (!fullscreen && c->isfullscreen){ +- XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, +- PropModeReplace, (unsigned char*)0, 0); +- c->isfullscreen = 0; +- c->isfloating = c->oldstate; ++ } else if (restorestate && (c->oldstate & (1 << 1))) { + c->bw = c->oldbw; +- c->x = c->oldx; +- c->y = c->oldy; +- c->w = c->oldw; +- c->h = c->oldh; ++ c->isfloating = c->oldstate = c->oldstate & 1; ++ if (restorefakefullscreen || c->fakefullscreen == 3) ++ c->fakefullscreen = 1; ++ /* The client may have been moved to another monitor whilst in fullscreen which if tiled ++ * we address by doing a full arrange of tiled clients. If the client is floating then the ++ * height and width may be larger than the monitor's window area, so we cap that by ++ * ensuring max / min values. */ ++ if (c->isfloating) { ++ c->x = MAX(c->mon->wx, c->oldx); ++ c->y = MAX(c->mon->wy, c->oldy); ++ c->w = MIN(c->mon->ww - c->x - 2*c->bw, c->oldw); ++ c->h = MIN(c->mon->wh - c->y - 2*c->bw, c->oldh); ++ resizeclient(c, c->x, c->y, c->w, c->h); ++ restack(c->mon); ++ } else ++ arrange(c->mon); ++ } else + resizeclient(c, c->x, c->y, c->w, c->h); +- arrange(c->mon); +- } ++ ++ /* Exception: if the client was in actual fullscreen and we exit out to fake fullscreen ++ * mode, then the focus would sometimes drift to whichever window is under the mouse cursor ++ * at the time. To avoid this we ask X for all EnterNotify events and just ignore them. ++ */ ++ if (!c->isfullscreen) ++ while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + } + + void +@@ -1665,9 +1742,19 @@ tag(const Arg *arg) + void + tagmon(const Arg *arg) + { +- if (!selmon->sel || !mons->next) ++ Client *c = selmon->sel; ++ if (!c || !mons->next) + return; +- sendmon(selmon->sel, dirtomon(arg->i)); ++ if (c->isfullscreen) { ++ c->isfullscreen = 0; ++ sendmon(c, dirtomon(arg->i)); ++ c->isfullscreen = 1; ++ if (c->fakefullscreen != 1) { ++ resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); ++ XRaiseWindow(dpy, c->win); ++ } ++ } else ++ sendmon(c, dirtomon(arg->i)); + } + + void +@@ -1705,18 +1792,51 @@ togglebar(const Arg *arg) + arrange(selmon); + } + ++void ++togglefakefullscreen(const Arg *arg) ++{ ++ Client *c = selmon->sel; ++ if (!c) ++ return; ++ ++ if (c->fakefullscreen != 1 && c->isfullscreen) { // exit fullscreen --> fake fullscreen ++ c->fakefullscreen = 2; ++ setfullscreen(c, 0); ++ } else if (c->fakefullscreen == 1) { ++ setfullscreen(c, 0); ++ c->fakefullscreen = 0; ++ } else { ++ c->fakefullscreen = 1; ++ setfullscreen(c, 1); ++ } ++} ++ + void + togglefloating(const Arg *arg) + { +- if (!selmon->sel) ++ Client *c = selmon->sel; ++ if (!c) + return; +- if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ ++ if (c->isfullscreen && c->fakefullscreen != 1) /* no support for fullscreen windows */ + return; +- selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; ++ c->isfloating = !c->isfloating || c->isfixed; + if (selmon->sel->isfloating) +- resize(selmon->sel, selmon->sel->x, selmon->sel->y, +- selmon->sel->w, selmon->sel->h, 0); +- arrange(selmon); ++ resize(c, c->x, c->y, c->w, c->h, 0); ++ arrange(c->mon); ++} ++ ++void ++togglefullscreen(const Arg *arg) ++{ ++ Client *c = selmon->sel; ++ if (!c) ++ return; ++ ++ if (c->fakefullscreen == 1) { // fake fullscreen --> fullscreen ++ c->fakefullscreen = 2; ++ setfullscreen(c, 1); ++ } else ++ setfullscreen(c, !c->isfullscreen); + } + + void +-- +2.19.1 +
M dwm.cdwm.c

@@ -112,6 +112,7 @@ int basew, baseh, incw, inch, maxw, maxh, minw, minh;

int bw, oldbw; unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + int fakefullscreen; Client *next; Client *snext; Monitor *mon;

@@ -215,6 +216,7 @@ static void grabkeys(void);

static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); +static void losefullscreen(Client *next); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e);

@@ -253,7 +255,9 @@ static void tag(const Arg *arg);

static void tagmon(const Arg *arg); static void tile(Monitor *); static void togglebar(const Arg *arg); +static void togglefakefullscreen(const Arg *arg); static void togglefloating(const Arg *arg); +static void togglefullscreen(const Arg *arg); static void togglescratch(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg);

@@ -646,9 +650,12 @@ if (!c)

return; if (cme->message_type == netatom[NetWMState]) { if (cme->data.l[1] == netatom[NetWMFullscreen] - || cme->data.l[2] == netatom[NetWMFullscreen]) + || cme->data.l[2] == netatom[NetWMFullscreen]) { + if (c->fakefullscreen == 2 && c->isfullscreen) + c->fakefullscreen = 3; setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); + } } else if (cme->message_type == netatom[NetActiveWindow]) { if (c != selmon->sel && !c->isurgent) seturgent(c, 1);

@@ -692,7 +699,7 @@ drw_resize(drw, sw, bh);

updatebars(); for (m = mons; m; m = m->next) { for (c = m->clients; c; c = c->next) - if (c->isfullscreen) + if (c->isfullscreen && c->fakefullscreen != 1) resizeclient(c, m->mx, m->my, m->mw, m->mh); resizebarwin(m); }

@@ -1027,8 +1034,10 @@ focus(Client *c)

{ if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); - if (selmon->sel && selmon->sel != c) + if (selmon->sel && selmon->sel != c) { + losefullscreen(c); unfocus(selmon->sel, 0); + } if (c) { if (c->mon != selmon) selmon = c->mon;

@@ -1349,8 +1358,10 @@ XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,

(unsigned char *) &(c->win), 1); XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ setclientstate(c, NormalState); - if (c->mon == selmon) + if (c->mon == selmon) { + losefullscreen(c); unfocus(selmon->sel, 0); + } c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win);

@@ -1430,7 +1441,7 @@ Time lasttime = 0;

if (!(c = selmon->sel)) return; - if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ + if (c->isfullscreen && c->fakefullscreen != 1) /* no support moving fullscreen windows by mouse */ return; restack(selmon); ocx = c->x;

@@ -1619,7 +1630,7 @@ Time lasttime = 0;

if (!(c = selmon->sel)) return; - if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ + if (c->isfullscreen && c->fakefullscreen != 1) /* no support resizing fullscreen windows by mouse */ return; restack(selmon); ocx = c->x;

@@ -1817,29 +1828,78 @@

void setfullscreen(Client *c, int fullscreen) { - if (fullscreen && !c->isfullscreen) { - XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, - PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); + XEvent ev; + int savestate = 0, restorestate = 0, restorefakefullscreen = 0; + + if ((c->fakefullscreen == 0 && fullscreen && !c->isfullscreen) // normal fullscreen + || (c->fakefullscreen == 2 && fullscreen)) // fake fullscreen --> actual fullscreen + savestate = 1; // go actual fullscreen + else if ((c->fakefullscreen == 0 && !fullscreen && c->isfullscreen) // normal fullscreen exit + || (c->fakefullscreen >= 2 && !fullscreen)) // fullscreen exit --> fake fullscreen + restorestate = 1; // go back into tiled + + /* If leaving fullscreen and the window was previously fake fullscreen (2), then restore + * that while staying in fullscreen. The exception to this is if we are in said state, but + * the client itself disables fullscreen (3) then we let the client go out of fullscreen + * while keeping fake fullscreen enabled (as otherwise there will be a mismatch between the + * client and the window manager's perception of the client's fullscreen state). */ + if (c->fakefullscreen == 2 && !fullscreen && c->isfullscreen) { + restorefakefullscreen = 1; c->isfullscreen = 1; - c->oldstate = c->isfloating; + fullscreen = 1; + } + + if (fullscreen != c->isfullscreen) { // only send property change if necessary + if (fullscreen) + XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, + PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); + else + XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, + PropModeReplace, (unsigned char*)0, 0); + } + + c->isfullscreen = fullscreen; + + /* Some clients, e.g. firefox, will send a client message informing the window manager + * that it is going into fullscreen after receiving the above signal. This has the side + * effect of this function (setfullscreen) sometimes being called twice when toggling + * fullscreen on and off via the window manager as opposed to the application itself. + * To protect against obscure issues where the client settings are stored or restored + * when they are not supposed to we add an additional bit-lock on the old state so that + * settings can only be stored and restored in that precise order. */ + if (savestate && !(c->oldstate & (1 << 1))) { c->oldbw = c->bw; + c->oldstate = c->isfloating | (1 << 1); c->bw = 0; c->isfloating = 1; resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); XRaiseWindow(dpy, c->win); - } else if (!fullscreen && c->isfullscreen){ - XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, - PropModeReplace, (unsigned char*)0, 0); - c->isfullscreen = 0; - c->isfloating = c->oldstate; + } else if (restorestate && (c->oldstate & (1 << 1))) { c->bw = c->oldbw; - c->x = c->oldx; - c->y = c->oldy; - c->w = c->oldw; - c->h = c->oldh; + c->isfloating = c->oldstate = c->oldstate & 1; + if (restorefakefullscreen || c->fakefullscreen == 3) + c->fakefullscreen = 1; + /* The client may have been moved to another monitor whilst in fullscreen which if tiled + * we address by doing a full arrange of tiled clients. If the client is floating then the + * height and width may be larger than the monitor's window area, so we cap that by + * ensuring max / min values. */ + if (c->isfloating) { + c->x = MAX(c->mon->wx, c->oldx); + c->y = MAX(c->mon->wy, c->oldy); + c->w = MIN(c->mon->ww - c->x - 2*c->bw, c->oldw); + c->h = MIN(c->mon->wh - c->y - 2*c->bw, c->oldh); + resizeclient(c, c->x, c->y, c->w, c->h); + restack(c->mon); + } else + arrange(c->mon); + } else resizeclient(c, c->x, c->y, c->w, c->h); - arrange(c->mon); - } + /* Exception: if the client was in actual fullscreen and we exit out to fake fullscreen + * mode, then the focus would sometimes drift to whichever window is under the mouse cursor + * at the time. To avoid this we ask X for all EnterNotify events and just ignore them. + */ + if (!c->isfullscreen) + while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } void

@@ -2021,9 +2081,19 @@

void tagmon(const Arg *arg) { - if (!selmon->sel || !mons->next) + Client *c = selmon->sel; + if (!c || !mons->next) return; - sendmon(selmon->sel, dirtomon(arg->i)); + if (c->isfullscreen) { + c->isfullscreen = 0; + sendmon(c, dirtomon(arg->i)); + c->isfullscreen = 1; + if (c->fakefullscreen != 1) { + resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); + XRaiseWindow(dpy, c->win); + } + } else + sendmon(c, dirtomon(arg->i)); } void

@@ -2075,6 +2145,26 @@ arrange(selmon);

} void +togglefakefullscreen(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + + if (c->fakefullscreen != 1 && c->isfullscreen) { // exit fullscreen --> fake fullscreen + c->fakefullscreen = 2; + setfullscreen(c, 0); + } else if (c->fakefullscreen == 1) { + setfullscreen(c, 0); + c->fakefullscreen = 0; + } else { + c->fakefullscreen = 1; + setfullscreen(c, 1); + } +} + + +void tabmode(const Arg *arg) { if(arg && arg->i >= 0)

@@ -2088,15 +2178,29 @@

void togglefloating(const Arg *arg) { - if (!selmon->sel) + Client *c = selmon->sel; + if (!c) return; - if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ + if (c->isfullscreen && c->fakefullscreen != 1) /* no support for fullscreen windows */ return; - selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; + c->isfloating = !c->isfloating || c->isfixed; if (selmon->sel->isfloating) - resize(selmon->sel, selmon->sel->x, selmon->sel->y, - selmon->sel->w, selmon->sel->h, 0); - arrange(selmon); + resize(c, c->x, c->y, c->w, c->h, 0); + arrange(c->mon); +} + +void +togglefullscreen(const Arg *arg) +{ + Client *c = selmon->sel; + if (!c) + return; + + if (c->fakefullscreen == 1) { // fake fullscreen --> fullscreen + c->fakefullscreen = 2; + setfullscreen(c, 1); + } else + setfullscreen(c, !c->isfullscreen); } void

@@ -2126,6 +2230,12 @@ toggletag(const Arg *arg)

{ unsigned int newtags; + /* Note that this patch is made for dwm 6.2. If applying this on top of the latest master + * then the https://dwm.suckless.org/patches/alwaysfullscreen/ patch has been merged + * upstream, which prevents focus to drift from windows that are in fake fullscreen. + * To address this issue use this if statement instead: + * if (!selmon->sel || (selmon->sel->isfullscreen && selmon->sel->fakefullscreen != 1)) + */ if (!selmon->sel) return; newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);

@@ -2269,6 +2379,16 @@ m->wy += th;

} else { m->ty = -th; } +} + +void +losefullscreen(Client *next) +{ + Client *sel = selmon->sel; + if (!sel || !next) + return; + if (sel->isfullscreen && sel->fakefullscreen != 1 && ISVISIBLE(sel) && sel->mon == next->mon && !next->isfloating) + setfullscreen(sel, 0); } void