Re: [RFC] Fake a global monitor when RandR is not available.

2021-11-19 Thread Dominik Vogt
On Fri, Nov 19, 2021 at 01:48:51PM +, Thomas Adam wrote:
> On Fri, Nov 19, 2021 at 02:53:32AM +0100, Dominik Vogt wrote:
> > On Fri, Nov 19, 2021 at 02:14:57AM +0100, Dominik Vogt wrote:
> > > For debugging I need to run another fvwm in xnest, but that
> > > doesn't support randr.
> > >
> > > The attached patch mocks up a global monitor to use if init fails.
> > > It works at the first glance, but the patch is not very clean.
> > > Please comment.
> >
> > Sorry, wrong patch, this is the correct one.
>
> I think most people have started to use Xephyr instead of Xnest, which does
> support RANDR

Good.  Works better than xnest.  Forget the patch and thanks for
the hint.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt



Re: [RFC] Fake a global monitor when RandR is not available.

2021-11-19 Thread Thomas Adam
On Fri, Nov 19, 2021 at 02:53:32AM +0100, Dominik Vogt wrote:
> On Fri, Nov 19, 2021 at 02:14:57AM +0100, Dominik Vogt wrote:
> > For debugging I need to run another fvwm in xnest, but that
> > doesn't support randr.
> >
> > The attached patch mocks up a global monitor to use if init fails.
> > It works at the first glance, but the patch is not very clean.
> > Please comment.
> 
> Sorry, wrong patch, this is the correct one.

I think most people have started to use Xephyr instead of Xnest, which does
support RANDR... I'd rather that than maintain a single screen.  For
reference, I did used to support that, but removed it in commit 
6e646e6201051d19dea5fa8e985fcaf884f0d94d

Kindly,
Thomas



Re: [RFC] Fake a global monitor when RandR is not available.

2021-11-18 Thread Dominik Vogt
On Fri, Nov 19, 2021 at 02:14:57AM +0100, Dominik Vogt wrote:
> For debugging I need to run another fvwm in xnest, but that
> doesn't support randr.
>
> The attached patch mocks up a global monitor to use if init fails.
> It works at the first glance, but the patch is not very clean.
> Please comment.

Sorry, wrong patch, this is the correct one.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt
From c821293866fb8c56f00d8cee52b687097e5045a3 Mon Sep 17 00:00:00 2001
From: Dominik Vogt 
Date: Fri, 19 Nov 2021 02:09:28 +0100
Subject: [PATCH 2/3] Fake a global monitor when RandR is not available.

---
 libs/FScreen.c | 69 +-
 1 file changed, 52 insertions(+), 17 deletions(-)

diff --git a/libs/FScreen.c b/libs/FScreen.c
index 32ee78a7..e00af438 100644
--- a/libs/FScreen.c
+++ b/libs/FScreen.c
@@ -125,6 +125,13 @@ monitor_refresh_global(void)
 		monitor_global = monitor_new();
 		monitor_global->si = screen_info_new();
 		monitor_global->si->name = fxstrdup(GLOBAL_SCREEN_NAME);
+		if (!is_randr_present)
+		{
+			TAILQ_INSERT_TAIL(
+_info_q, monitor_global->si, entry);
+			TAILQ_INSERT_TAIL(
+_q, monitor_global, entry);
+		}
 	}

 	/* At this point, the global screen has been initialised.  Refresh the
@@ -342,8 +349,12 @@ monitor_assign_virtual(struct monitor *ref)
 void
 FScreenSelect(Display *dpy)
 {
-	XRRSelectInput(disp, DefaultRootWindow(disp),
-		RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
+	if (is_randr_present)
+	{
+		XRRSelectInput(
+			disp, DefaultRootWindow(disp),
+			RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
+	}
 }

 void
@@ -352,6 +363,10 @@ monitor_output_change(Display *dpy, XRRScreenChangeNotifyEvent *e)
 	XRRScreenResources	*res;
 	struct monitor		*m = NULL;

+	if (!is_randr_present)
+	{
+		return;
+	}
 	fvwm_debug(__func__, "%s: outputs have changed\n", __func__);

 	if ((res = XRRGetScreenResources(dpy, e->root)) == NULL) {
@@ -511,18 +526,19 @@ void FScreenInit(Display *dpy)
 	if (!XRRQueryExtension(dpy, _event, _base) ||
 	!XRRQueryVersion (dpy, , )) {
 		fvwm_debug(__func__, "RandR not present");
-		goto randr_fail;
+		goto no_randr;
 	}

 	if (major == 1 && minor >= 5)
+	{
 		is_randr_present = true;
-
-
-	if (!is_randr_present) {
+	}
+	else
+	{
 		/* Something went wrong. */
 		fvwm_debug(__func__, "Couldn't initialise XRandR: %s\n",
 			   strerror(errno));
-		goto randr_fail;
+		goto no_randr;
 	}

 	fvwm_debug(__func__, "Using RandR %d.%d\n", major, minor);
@@ -533,13 +549,21 @@ void FScreenInit(Display *dpy)
 	if (res == NULL || (res != NULL && res->noutput == 0)) {
 		XRRFreeScreenResources(res);
 		fvwm_debug(__func__, "RandR present, yet no outputs found.");
-		goto randr_fail;
+		is_randr_present = false;
+		goto no_randr;
 	}
 	XRRFreeScreenResources(res);

 	scan_screens(dpy);
+  no_randr:
 	is_tracking_shared = false;

+	if (!is_randr_present)
+	{
+		fprintf(stderr, "Unable to initialise RandR\n");
+		monitor_refresh_global();
+	}
+
 	TAILQ_FOREACH(m, _q, entry) {
 		m->Desktops = fxcalloc(1, sizeof *m->Desktops);
 		m->Desktops->name = NULL;
@@ -552,10 +576,6 @@ void FScreenInit(Display *dpy)
 	monitor_check_primary();

 	return;
-
-randr_fail:
-	fprintf(stderr, "Unable to initialise RandR\n");
-	exit(101);
 }

 void
@@ -620,6 +640,10 @@ monitor_get_count(void)
 	struct monitor	*m = NULL;
 	int		 c = 0;

+	if (!is_randr_present)
+	{
+		return 1;
+	}
 	TAILQ_FOREACH(m, _q, entry) {
 		if (m->flags & MONITOR_DISABLED)
 			continue;
@@ -755,7 +779,18 @@ FScreenOfPointerXY(int x, int y)
 Bool FScreenGetScrRect(fscreen_scr_arg *arg, fscreen_scr_t screen,
 			int *x, int *y, int *w, int *h)
 {
-	struct monitor	*m = FindScreen(arg, screen);
+	struct monitor *m;
+
+	if (is_randr_present)
+	{
+		m = FindScreen(arg, screen);
+	}
+	else
+	{
+		/* make sure a monitor exists */
+		monitor_check_primary();
+		m = monitor_global;
+	}
 	if (m == NULL) {
 		fvwm_debug(__func__, "%s: m is NULL\n", __func__);
 		return (True);
@@ -895,10 +930,10 @@ void FScreenGetResistanceRect(
 Bool FScreenIsRectangleOnScreen(fscreen_scr_arg *arg, fscreen_scr_t screen,
 rectangle *rec)
 {
-	int sx;
-	int sy;
-	int sw;
-	int sh;
+	int sx = 0;
+	int sy = 0;
+	int sw = 0;
+	int sh = 0;

 	FScreenGetScrRect(arg, screen, , , , );

--
2.30.2



[RFC] Fake a global monitor when RandR is not available.

2021-11-18 Thread Dominik Vogt
For debugging I need to run another fvwm in xnest, but that
doesn't support randr.

The attached patch mocks up a global monitor to use if init fails.
It works at the first glance, but the patch is not very clean.
Please comment.

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt
From 4201211293560a2a4f0a8636c36f3d5b37245175 Mon Sep 17 00:00:00 2001
From: Dominik Vogt 
Date: Fri, 19 Nov 2021 02:12:16 +0100
Subject: [PATCH] Fake a global monitor when RandR is not available.

---
 libs/FScreen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libs/FScreen.c b/libs/FScreen.c
index f9fb11d2..e00af438 100644
--- a/libs/FScreen.c
+++ b/libs/FScreen.c
@@ -555,9 +555,9 @@ void FScreenInit(Display *dpy)
 	XRRFreeScreenResources(res);

 	scan_screens(dpy);
+  no_randr:
 	is_tracking_shared = false;

-  no_randr:
 	if (!is_randr_present)
 	{
 		fprintf(stderr, "Unable to initialise RandR\n");
--
2.30.2