Re: [hackers] [dwm][PATCH] Sort screens by horizontal origin

2019-09-27 Thread Dave Woodfall
On Fri 27 Sep 2019 15:58,
Sebastian Sareyko  put forth the proposition:
> On Fri, Sep 27, 2019, at 15:36, Hiltjo Posthuma wrote:
>
> > Have you tried xrandr to reorder the screens? It should probably be solved 
> > in a
> > different way.
>
> Yeah, I tried that.
>
> Here's how I use xrandr to configure a simple three screen setup:
>
> xrandr --output eDP1 --mode 1920x1080 --left-of HDMI1 \
> --output HDMI1 --mode 1920x1080 --primary --left-of VGA1 \
> --output VGA1 --mode 1680x1050
>
> This should result in the following screen order: eDP1, HDMI1, VGA1
> Moving the mouse cursor works as expected even without my patch.
>
> The resulting screen order as returned by XineramaQueryScreens() however 
> depends on wether VGA1 is plugged in at boot time or not. Right now, just 
> after executing the above xrandr command, Xinerama tells me my screens are 
> ordered as follows: HDMI1, eDP1, VGA1
>
> As far as I can tell this behavior is somehow dependent on the graphics 
> driver.
>
> Kind regards,
> Sebastian
>

Can't you try to detect whether VGA1 is plugged in or not?  I use
the following:

xrandr | grep -q "VGA1 connected" && xrandr --output LVDS1 --off \
--output VGA1 --primary --auto

If my VGA is connected then it makes it the primary and turns off my
laptop screen.

This is in a file sourced from my ~/.xinitrc.

-DW




Re: [hackers] [dwm][PATCH] Sort screens by horizontal origin

2019-09-27 Thread Abdullah

I never faced a single problem with multihead with dwm. But I'll try this patch.
I use xrandr. 


On 27/09, Hiltjo Posthuma wrote:

On Fri, Sep 27, 2019 at 03:28:39PM +0200, Sebastian Sareyko wrote:

Doing a multi-head setup using other means than Xinerama may lead to
XineramaQueryScreens() returning the screens in an order that does not
actually represent the actual screen layout. This in turn may result
in dwm using the "wrong" monitor in monitor related
functions (focusmon(), tagmon(), applying rules, ...).

This change sorts the list of unique screens by their horizontal
origin to alleviate this problem.
The change does not solve (and may even provoke) the described issue
when screens are not only placed next to each other in a horizontal
way but also vertically.
---
 dwm.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/dwm.c b/dwm.c
index 4465af1..a8e9467 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1847,6 +1847,24 @@ updateclientlist()
(unsigned char *) &(c->win), 1);
 }

+#ifdef XINERAMA
+void
+sortscreens(XineramaScreenInfo *screens, int n)
+{
+   int i, j;
+   XineramaScreenInfo *screen = ecalloc(1, sizeof(XineramaScreenInfo));
+
+   for (i = 0; i < n; i++)
+   for (j = i + 1; j < n; j++)
+   if (screens[i].x_org > screens[j].x_org) {
+   memcpy(&screen[0], &screens[i], 
sizeof(XineramaScreenInfo));
+   memcpy(&screens[i], &screens[j], 
sizeof(XineramaScreenInfo));
+   memcpy(&screens[j], &screen[0], 
sizeof(XineramaScreenInfo));
+   }
+   XFree(screen);
+}
+#endif /* XINERAMA */
+
 int
 updategeom(void)
 {
@@ -1868,6 +1886,7 @@ updategeom(void)
memcpy(&unique[j++], &info[i], 
sizeof(XineramaScreenInfo));
XFree(info);
nn = j;
+   sortscreens(unique, nn);
if (n <= nn) { /* new monitors available */
for (i = 0; i < (nn - n); i++) {
for (m = mons; m && m->next; m = m->next);
--
2.21.0




Have you tried xrandr to reorder the screens? It should probably be solved in a
different way.

--
Kind regards,
Hiltjo




Abdullah

https://abdullah.today

C20F 2707 3025 2569 BAC5
534B 7820 6670 C19D 1580


signature.asc
Description: PGP signature


Re: [hackers] [dwm][PATCH] Sort screens by horizontal origin

2019-09-27 Thread Sebastian Sareyko
On Fri, Sep 27, 2019, at 15:36, Hiltjo Posthuma wrote:

> Have you tried xrandr to reorder the screens? It should probably be solved in 
> a
> different way.

Yeah, I tried that.

Here's how I use xrandr to configure a simple three screen setup:

xrandr --output eDP1 --mode 1920x1080 --left-of HDMI1 \
--output HDMI1 --mode 1920x1080 --primary --left-of VGA1 \
--output VGA1 --mode 1680x1050

This should result in the following screen order: eDP1, HDMI1, VGA1
Moving the mouse cursor works as expected even without my patch.

The resulting screen order as returned by XineramaQueryScreens() however 
depends on wether VGA1 is plugged in at boot time or not. Right now, just after 
executing the above xrandr command, Xinerama tells me my screens are ordered as 
follows: HDMI1, eDP1, VGA1

As far as I can tell this behavior is somehow dependent on the graphics driver.

Kind regards,
Sebastian



Re: [hackers] [dwm][PATCH] Sort screens by horizontal origin

2019-09-27 Thread Hiltjo Posthuma
On Fri, Sep 27, 2019 at 03:28:39PM +0200, Sebastian Sareyko wrote:
> Doing a multi-head setup using other means than Xinerama may lead to
> XineramaQueryScreens() returning the screens in an order that does not
> actually represent the actual screen layout. This in turn may result
> in dwm using the "wrong" monitor in monitor related
> functions (focusmon(), tagmon(), applying rules, ...).
> 
> This change sorts the list of unique screens by their horizontal
> origin to alleviate this problem.
> The change does not solve (and may even provoke) the described issue
> when screens are not only placed next to each other in a horizontal
> way but also vertically.
> ---
>  dwm.c | 19 +++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/dwm.c b/dwm.c
> index 4465af1..a8e9467 100644
> --- a/dwm.c
> +++ b/dwm.c
> @@ -1847,6 +1847,24 @@ updateclientlist()
>   (unsigned char *) &(c->win), 1);
>  }
>  
> +#ifdef XINERAMA
> +void
> +sortscreens(XineramaScreenInfo *screens, int n)
> +{
> + int i, j;
> + XineramaScreenInfo *screen = ecalloc(1, sizeof(XineramaScreenInfo));
> +
> + for (i = 0; i < n; i++)
> + for (j = i + 1; j < n; j++)
> + if (screens[i].x_org > screens[j].x_org) {
> + memcpy(&screen[0], &screens[i], 
> sizeof(XineramaScreenInfo));
> + memcpy(&screens[i], &screens[j], 
> sizeof(XineramaScreenInfo));
> + memcpy(&screens[j], &screen[0], 
> sizeof(XineramaScreenInfo));
> + }
> + XFree(screen);
> +}
> +#endif /* XINERAMA */
> +
>  int
>  updategeom(void)
>  {
> @@ -1868,6 +1886,7 @@ updategeom(void)
>   memcpy(&unique[j++], &info[i], 
> sizeof(XineramaScreenInfo));
>   XFree(info);
>   nn = j;
> + sortscreens(unique, nn);
>   if (n <= nn) { /* new monitors available */
>   for (i = 0; i < (nn - n); i++) {
>   for (m = mons; m && m->next; m = m->next);
> -- 
> 2.21.0
> 
> 

Have you tried xrandr to reorder the screens? It should probably be solved in a
different way.

-- 
Kind regards,
Hiltjo



[hackers] [dwm][PATCH] Sort screens by horizontal origin

2019-09-27 Thread Sebastian Sareyko
Doing a multi-head setup using other means than Xinerama may lead to
XineramaQueryScreens() returning the screens in an order that does not
actually represent the actual screen layout. This in turn may result
in dwm using the "wrong" monitor in monitor related
functions (focusmon(), tagmon(), applying rules, ...).

This change sorts the list of unique screens by their horizontal
origin to alleviate this problem.
The change does not solve (and may even provoke) the described issue
when screens are not only placed next to each other in a horizontal
way but also vertically.
---
 dwm.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/dwm.c b/dwm.c
index 4465af1..a8e9467 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1847,6 +1847,24 @@ updateclientlist()
(unsigned char *) &(c->win), 1);
 }
 
+#ifdef XINERAMA
+void
+sortscreens(XineramaScreenInfo *screens, int n)
+{
+   int i, j;
+   XineramaScreenInfo *screen = ecalloc(1, sizeof(XineramaScreenInfo));
+
+   for (i = 0; i < n; i++)
+   for (j = i + 1; j < n; j++)
+   if (screens[i].x_org > screens[j].x_org) {
+   memcpy(&screen[0], &screens[i], 
sizeof(XineramaScreenInfo));
+   memcpy(&screens[i], &screens[j], 
sizeof(XineramaScreenInfo));
+   memcpy(&screens[j], &screen[0], 
sizeof(XineramaScreenInfo));
+   }
+   XFree(screen);
+}
+#endif /* XINERAMA */
+
 int
 updategeom(void)
 {
@@ -1868,6 +1886,7 @@ updategeom(void)
memcpy(&unique[j++], &info[i], 
sizeof(XineramaScreenInfo));
XFree(info);
nn = j;
+   sortscreens(unique, nn);
if (n <= nn) { /* new monitors available */
for (i = 0; i < (nn - n); i++) {
for (m = mons; m && m->next; m = m->next);
-- 
2.21.0