From 190d3cd72d37dba283fc2ee66b3e3dee38c295d0 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Thu, 23 Dec 2021 05:40:26 +0800 Subject: [PATCH] Fixed segfault issues with moving windows between monitors. Still some issues with centerfirst states persistion when moving windows between monitors. --- dwm.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dwm.c b/dwm.c index 6c56a22..a7a8f85 100644 --- a/dwm.c +++ b/dwm.c @@ -132,6 +132,7 @@ struct Monitor { Window barwin; const Layout *lt[2]; Pertag *pertag; + int centerfirst; }; typedef struct { @@ -668,6 +669,7 @@ createmon(void) strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); m->pertag = ecalloc(1, sizeof(Pertag)); m->pertag->curtag = m->pertag->prevtag = 1; + m->centerfirst = centerfirst; for (i = 0; i <= LENGTH(tags); i++) { m->pertag->nmasters[i] = m->nmaster; @@ -679,7 +681,7 @@ createmon(void) m->pertag->showbars[i] = m->showbar; - m->pertag->centerfirst[i] = centerfirst; + m->pertag->centerfirst[i] = m->centerfirst; } return m; @@ -898,7 +900,7 @@ focusstack(const Arg *arg) if (c) { focus(c); restack(selmon); - //XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w/2, c->h/2); } } @@ -1762,13 +1764,13 @@ tile(Monitor *m) return; c = nexttiled(m->clients); - if (n == 1 && m->pertag->centerfirst[m->pertag->curtag] && c && c->iscentered){ + if (n <= 1 && selmon->centerfirst && c && c->iscentered){ resize( c, m->wx + m->ww*(1 - m->mfact)/2, m->wy, - m->ww * m->mfact - 2 * m->sel->bw, - m->wh - 2 * m->sel->bw, + m->ww * m->mfact - 2 * c->bw, + m->wh - 2 * c->bw, 0 ); return; @@ -1857,6 +1859,7 @@ toggleview(const Arg *arg) selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + selmon->centerfirst = selmon->pertag->centerfirst[selmon->pertag->curtag]; if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) togglebar(NULL); @@ -2184,6 +2187,7 @@ view(const Arg *arg) selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + selmon->centerfirst = selmon->pertag->centerfirst[selmon->pertag->curtag]; if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) togglebar(NULL); @@ -2423,7 +2427,7 @@ togglecenterfirst(const Arg* arg) { if (!arg || !selmon->lt[selmon->sellt]->arrange) return; - selmon->pertag->centerfirst[selmon->pertag->curtag] ^= 1; + selmon->centerfirst = selmon->pertag->centerfirst[selmon->pertag->curtag] ^= 1; arrange(selmon); }