window position is misaligned when switching to monocle layout
adetabrani opened this issue · 3 comments
Hi bak, I recently edited the code in the monocle function (more precisely in the call function resizeclient()) to make the monocle layout have an outer gap
void monocle(Monitor *m)
{
unsigned int n = 0;
Client *c;
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
for (c = m->stack; c && (!ISVISIBLE(c) || c->isfloating); c = c->snext);
if (c && !c->isfloating) {
XMoveWindow(dpy, c->win, m->wx, m->wy);
// resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
resize(c, m->wx + m->gap->gappx, m->wy + m->gap->gappx, m->ww - 2 * c->bw - m->gap->gappx * 2, m->wh - 2 * c->bw - m->gap->gappx * 2, 0);
c = c->snext;
}
for (; c; c = c->snext)
if (!c->isfloating && ISVISIBLE(c))
XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y);
}
Here I use fullgaps and alpha monocle patch, but I experienced a bug when there was only one window displayed then I switched to the monocle layout, the position of the window became misaligned, it seems this is related to the alpha monocle patch
simplescreenrecorder.webm
Did you figure this one out yet?
Not particularly relevant, but given that you write m->gap->gappx
makes me think that you have gone with dwm-fullgaps-toggle-20200830.diff patch rather than dwm-fullgaps-6.4.diff as stated.
Your changes to the monocle
function looks fine by the face of it.
My interpretation of what is happening here is:
- you have a single client
- you are using the tile layout with full gaps, which means that the single client has been resized to the size of the window area less the outer gaps
- you change the layout to the monocle layout
- it will first hit this line
XMoveWindow(dpy, c->win, m->wx, m->wy);
and move the window to the top left corner of the window area - it will then hit the
resize
line to give the window the size of the window area less the outer gaps - in the
resize
function it will make a call toapplysizehints
to check if any size hint adjustments are needed - as the size of the window is already the size of the window area less the outer gaps the
applysizehints
function will return 0 to indicate that no change in size is actually needed here - as such the
resizeclient
call is never made and the client remains in the top left corner
When you have two clients then these are resized to fit into the master and stack areas respectively. When you then change to the monocle layout the applysizehints
will return 1 to indicate that a change in size is necessary and it will do the resizeclient
call which both moves and resizes the client accordingly.
Proposal: change the following line
XMoveWindow(dpy, c->win, m->wx, m->wy);
to
XMoveWindow(dpy, c->win, m->wx + m->gap->gappx, m->wy + m->gap->gappx);
Not particularly relevant, but given that you write
m->gap->gappx
makes me think that you have gone with dwm-fullgaps-toggle-20200830.diff patch rather than dwm-fullgaps-6.4.diff as stated.
sorry, i forgot ro mention this 😂
My interpretation of what is happening here is:
- you have a single client
- you are using the tile layout with full gaps, which means that the single client has been resized to the size of the window area less the outer gaps
- you change the layout to the monocle layout
- it will first hit this line
XMoveWindow(dpy, c->win, m->wx, m->wy);
and move the window to the top left corner of the window area- it will then hit the
resize
line to give the window the size of the window area less the outer gaps- in the
resize
function it will make a call toapplysizehints
to check if any size hint adjustments are needed- as the size of the window is already the size of the window area less the outer gaps the
applysizehints
function will return 0 to indicate that no change in size is actually needed here- as such the
resizeclient
call is never made and the client remains in the top left cornerWhen you have two clients then these are resized to fit into the master and stack areas respectively. When you then change to the monocle layout the
applysizehints
will return 1 to indicate that a change in size is necessary and it will do theresizeclient
call which both moves and resizes the client accordingly.Proposal: change the following line
XMoveWindow(dpy, c->win, m->wx, m->wy);to
XMoveWindow(dpy, c->win, m->wx + m->gap->gappx, m->wy + m->gap->gappx);
Great explanation, since I often visit your repo, I seem to be starting to have an interest in C, maybe I should start considering learning it, thanks for the help