Re: [hackers] [dwm][PATCH] Update monitor positions also on removal

2022-04-16 Thread Hiltjo Posthuma
On Sun, Apr 10, 2022 at 09:16:43AM +0300, Santtu Lakkala wrote:
> On 9.4.2022 13.51, Hiltjo Posthuma wrote:
> > I've heard similar reports with monitor plugging and unplugging not working 
> > nicely.
> > 
> > Can someone test this patch and report back these conditions or if it 
> > improves things?
> 
> FWIW I've been using this change ever since I submitted it, and plug and
> unplug extra monitors multiple times a day, and have not needed dwm restarts
> ever since (don't even use the restart patch anymore =).
> 
> -- 
> Santtu
> 
> 

Hi,

I'm just going to apply and push this so the community can test their monitor
configurations in the master branch.  I cannot fully test it, but the code
looks good.

Thanks for the patch!

-- 
Kind regards,
Hiltjo



Re: [hackers] [dwm][PATCH] Update monitor positions also on removal

2022-04-10 Thread Santtu Lakkala

On 9.4.2022 13.51, Hiltjo Posthuma wrote:

I've heard similar reports with monitor plugging and unplugging not working 
nicely.

Can someone test this patch and report back these conditions or if it improves 
things?


FWIW I've been using this change ever since I submitted it, and plug and 
unplug extra monitors multiple times a day, and have not needed dwm 
restarts ever since (don't even use the restart patch anymore =).


--
Santtu




Re: [hackers] [dwm][PATCH] Update monitor positions also on removal

2022-04-09 Thread Hiltjo Posthuma
On Mon, Feb 21, 2022 at 04:58:28PM +0200, Santtu Lakkala wrote:
> When monitors are removed, the coordinates of existing monitors may
> change, if the removed monitors had smaller coordinates than the
> remaining ones.
> 
> Remove special case handling so that the same update-if-necessary loop
> is run also in the case when monitors are removed.
> ---
>  dwm.c | 68 +--
>  1 file changed, 34 insertions(+), 34 deletions(-)
> 
> diff --git a/dwm.c b/dwm.c
> index a96f33c..85419e3 100644
> --- a/dwm.c
> +++ b/dwm.c
> @@ -1874,42 +1874,42 @@ updategeom(void)
>   memcpy([j++], [i], 
> sizeof(XineramaScreenInfo));
>   XFree(info);
>   nn = j;
> - if (n <= nn) { /* new monitors available */
> - for (i = 0; i < (nn - n); i++) {
> - for (m = mons; m && m->next; m = m->next);
> - if (m)
> - m->next = createmon();
> - else
> - mons = createmon();
> +
> + /* new monitors if nn > n */
> + for (i = n; i < nn; i++) {
> + for (m = mons; m && m->next; m = m->next);
> + if (m)
> + m->next = createmon();
> + else
> + mons = createmon();
> + }
> + for (i = 0, m = mons; i < nn && m; m = m->next, i++)
> + if (i >= n
> + || unique[i].x_org != m->mx || unique[i].y_org != m->my
> + || unique[i].width != m->mw || unique[i].height != 
> m->mh)
> + {
> + dirty = 1;
> + m->num = i;
> + m->mx = m->wx = unique[i].x_org;
> + m->my = m->wy = unique[i].y_org;
> + m->mw = m->ww = unique[i].width;
> + m->mh = m->wh = unique[i].height;
> + updatebarpos(m);
>   }
> - for (i = 0, m = mons; i < nn && m; m = m->next, i++)
> - if (i >= n
> - || unique[i].x_org != m->mx || unique[i].y_org 
> != m->my
> - || unique[i].width != m->mw || unique[i].height 
> != m->mh)
> - {
> - dirty = 1;
> - m->num = i;
> - m->mx = m->wx = unique[i].x_org;
> - m->my = m->wy = unique[i].y_org;
> - m->mw = m->ww = unique[i].width;
> - m->mh = m->wh = unique[i].height;
> - updatebarpos(m);
> - }
> - } else { /* less monitors available nn < n */
> - for (i = nn; i < n; i++) {
> - for (m = mons; m && m->next; m = m->next);
> - while ((c = m->clients)) {
> - dirty = 1;
> - m->clients = c->next;
> - detachstack(c);
> - c->mon = mons;
> - attach(c);
> - attachstack(c);
> - }
> - if (m == selmon)
> - selmon = mons;
> - cleanupmon(m);
> + /* removed monitors if n > nn */
> + for (i = nn; i < n; i++) {
> + for (m = mons; m && m->next; m = m->next);
> + while ((c = m->clients)) {
> + dirty = 1;
> + m->clients = c->next;
> + detachstack(c);
> + c->mon = mons;
> + attach(c);
> + attachstack(c);
>   }
> + if (m == selmon)
> + selmon = mons;
> + cleanupmon(m);
>   }
>   free(unique);
>   } else
> -- 
> 2.32.0
> 
> 

Hi,

I've heard similar reports with monitor plugging and unplugging not working 
nicely.

Can someone test this patch and report back these conditions or if it improves 
things?

-- 
Kind regards,
Hiltjo



[hackers] [dwm][PATCH] Update monitor positions also on removal

2022-02-21 Thread Santtu Lakkala
When monitors are removed, the coordinates of existing monitors may
change, if the removed monitors had smaller coordinates than the
remaining ones.

Remove special case handling so that the same update-if-necessary loop
is run also in the case when monitors are removed.
---
 dwm.c | 68 +--
 1 file changed, 34 insertions(+), 34 deletions(-)

diff --git a/dwm.c b/dwm.c
index a96f33c..85419e3 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1874,42 +1874,42 @@ updategeom(void)
memcpy([j++], [i], 
sizeof(XineramaScreenInfo));
XFree(info);
nn = j;
-   if (n <= nn) { /* new monitors available */
-   for (i = 0; i < (nn - n); i++) {
-   for (m = mons; m && m->next; m = m->next);
-   if (m)
-   m->next = createmon();
-   else
-   mons = createmon();
+
+   /* new monitors if nn > n */
+   for (i = n; i < nn; i++) {
+   for (m = mons; m && m->next; m = m->next);
+   if (m)
+   m->next = createmon();
+   else
+   mons = createmon();
+   }
+   for (i = 0, m = mons; i < nn && m; m = m->next, i++)
+   if (i >= n
+   || unique[i].x_org != m->mx || unique[i].y_org != m->my
+   || unique[i].width != m->mw || unique[i].height != 
m->mh)
+   {
+   dirty = 1;
+   m->num = i;
+   m->mx = m->wx = unique[i].x_org;
+   m->my = m->wy = unique[i].y_org;
+   m->mw = m->ww = unique[i].width;
+   m->mh = m->wh = unique[i].height;
+   updatebarpos(m);
}
-   for (i = 0, m = mons; i < nn && m; m = m->next, i++)
-   if (i >= n
-   || unique[i].x_org != m->mx || unique[i].y_org 
!= m->my
-   || unique[i].width != m->mw || unique[i].height 
!= m->mh)
-   {
-   dirty = 1;
-   m->num = i;
-   m->mx = m->wx = unique[i].x_org;
-   m->my = m->wy = unique[i].y_org;
-   m->mw = m->ww = unique[i].width;
-   m->mh = m->wh = unique[i].height;
-   updatebarpos(m);
-   }
-   } else { /* less monitors available nn < n */
-   for (i = nn; i < n; i++) {
-   for (m = mons; m && m->next; m = m->next);
-   while ((c = m->clients)) {
-   dirty = 1;
-   m->clients = c->next;
-   detachstack(c);
-   c->mon = mons;
-   attach(c);
-   attachstack(c);
-   }
-   if (m == selmon)
-   selmon = mons;
-   cleanupmon(m);
+   /* removed monitors if n > nn */
+   for (i = nn; i < n; i++) {
+   for (m = mons; m && m->next; m = m->next);
+   while ((c = m->clients)) {
+   dirty = 1;
+   m->clients = c->next;
+   detachstack(c);
+   c->mon = mons;
+   attach(c);
+   attachstack(c);
}
+   if (m == selmon)
+   selmon = mons;
+   cleanupmon(m);
}
free(unique);
} else
-- 
2.32.0