Skip to content

Commit

Permalink
randr: quit when no screens found & not active
Browse files Browse the repository at this point in the history
fvwm would quit when there were no screens detected by RandR.  However,
this can be problematic with laptop screens which can be turned off.

If fvwm receives an RandR event to rescan screens, that can therefore
cause RandR to tell us there's no screens found.  This is not true
though since the number of *configured* screens from fvwm's perspective
is still the same.

In such cases then, fvwm should only quit when the number of configured
screens is 0 *and* RandR hasn't detected any screens either.

Problem reported by @farhaven (Gregor Best)
  • Loading branch information
ThomasAdam committed Jan 14, 2023
1 parent 0649794 commit 35e8b41
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static int grav_matrix[3][3] =

static Display *disp;
static bool is_randr_present;
static bool randr_initialised;

static void scan_screens(Display *);
static struct monitor *monitor_by_name(const char *);
Expand Down Expand Up @@ -83,6 +84,9 @@ monitor_scan_edges(struct monitor *m)
{
struct monitor *m_loop;

if (m == NULL)
return;

m->edge.top = m->edge.bottom = m->edge.left = m->edge.right =
MONITOR_OUTSIDE_EDGE;

Expand Down Expand Up @@ -424,12 +428,12 @@ static void
scan_screens(Display *dpy)
{
XRRMonitorInfo *rrm;
struct monitor *m;
struct monitor *m = NULL;
int i, n = 0;
Window root = RootWindow(dpy, DefaultScreen(dpy));

rrm = XRRGetMonitors(dpy, root, false, &n);
if (n <= 0) {
if (n <= 0 && (!randr_initialised && monitor_get_count() == 0)) {
fvwm_debug(__func__, "get monitors failed\n");
exit(101);
}
Expand Down Expand Up @@ -492,9 +496,13 @@ void FScreenInit(Display *dpy)
struct monitor *m;
int err_base = 0, major, minor;

if (randr_initialised)
return;

disp = dpy;
randr_event = 0;
is_randr_present = false;
randr_initialised = false;

if (TAILQ_EMPTY(&monitor_q))
TAILQ_INIT(&monitor_q);
Expand Down Expand Up @@ -532,6 +540,7 @@ void FScreenInit(Display *dpy)
XRRFreeScreenResources(res);

scan_screens(dpy);
randr_initialised = true;
is_tracking_shared = false;

TAILQ_FOREACH(m, &monitor_q, entry) {
Expand Down

0 comments on commit 35e8b41

Please sign in to comment.