From d9c84d600a19b43648f3c1dd8debdaaaf6f8e8b8 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Mon, 23 Oct 2023 21:12:48 +0100 Subject: [PATCH] WIP: Monitor ordering --- libs/FScreen.c | 86 +++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 54 deletions(-) diff --git a/libs/FScreen.c b/libs/FScreen.c index 0c1830202..7a802c53d 100644 --- a/libs/FScreen.c +++ b/libs/FScreen.c @@ -47,7 +47,7 @@ static bool randr_initialised; static void scan_screens(Display *); static struct monitor *monitor_by_name(const char *); -static void monitor_set_ordering(void); +static void monitor_set_coords(struct monitor *, XRRMonitorInfo); enum monitor_tracking monitor_mode; bool is_tracking_shared; @@ -439,6 +439,26 @@ monitor_output_change(Display *dpy, XRRScreenChangeNotifyEvent *e) monitor_check_primary(); } +static void +monitor_set_coords(struct monitor *m, XRRMonitorInfo rrm) +{ + if (m == NULL) + return; + + m->si->x = rrm.x; + m->si->y = rrm.y; + m->si->w = rrm.width; + m->si->h = rrm.height; + m->si->rr_output = *rrm.outputs; + if (rrm.primary > 0) { + m->flags |= MONITOR_PRIMARY; + m->was_primary = false; + } else { + m->flags &= ~MONITOR_PRIMARY; + m->was_primary = true; + } +} + static void scan_screens(Display *dpy) { @@ -475,87 +495,45 @@ scan_screens(Display *dpy) TAILQ_INSERT_TAIL(&screen_info_q, m->si, entry); - if (TAILQ_EMPTY(&monitor_q)) + if (TAILQ_EMPTY(&monitor_q)) { + fvwm_debug(__func__, "MONITORQ EMPTY ADDING: %s", m->si->name); TAILQ_INSERT_HEAD(&monitor_q, m, entry); + monitor_set_coords(m, rrm[i]); + } struct monitor *m2; TAILQ_FOREACH(m2, &monitor_q, entry) { - if (m == m2) + if (m == m2 || (strcmp(m2->si->name, name) == 0)) continue; fvwm_debug(__func__, "LOOKING AT: %s (%d), WANT: %s (%d)", m2->si->name, m2->si->x, m->si->name, rrm[i].x); if (rrm[i].x < m2->si->x) { fvwm_debug(__func__, "INSERTING: %s", m->si->name); - TAILQ_INSERT_HEAD(&monitor_q, m, entry); + TAILQ_INSERT_BEFORE(m2, m, entry); + break; + } else { + TAILQ_INSERT_TAIL(&monitor_q, m, entry); + break; } } - goto set_coords; + monitor_set_coords(m, rrm[i]); } - if ((strcmp(m->si->name, name) == 0) && (m->si->x != rrm[i].x || m->si->y != rrm[i].y || m->si->w != rrm[i].width || m->si->h != rrm[i].height)) { if (m->flags & MONITOR_ENABLED) m->flags |= MONITOR_CHANGED; } - -set_coords: - m->si->x = rrm[i].x; - m->si->y = rrm[i].y; - m->si->w = rrm[i].width; - m->si->h = rrm[i].height; - m->si->rr_output = *rrm[i].outputs; - if (rrm[i].primary > 0) { - m->flags |= MONITOR_PRIMARY; - m->was_primary = false; - } else { - m->flags &= ~MONITOR_PRIMARY; - m->was_primary = true; - } - XFree(name); } monitor_scan_edges(m); monitor_check_primary(); - monitor_set_ordering(); XRRFreeMonitors(rrm); } -static void -monitor_set_ordering(void) -{ -#if 0 - struct screen_info *si, *si_next; - - if (TAILQ_EMPTY(&screen_info_q_temp)) - TAILQ_INIT(&screen_info_q_temp); - - TAILQ_FOREACH(si, &screen_info_q, entry) { - if ((si_next = TAILQ_NEXT(si, entry)) != NULL) { - fvwm_debug(__func__, "SEEING: %s (%d), NEXT: %s (%d)", si->name, si->x, si_next->name, si_next->x); - if (si->x > si_next->x) { - TAILQ_INSERT_TAIL(&screen_info_q_temp, si, entry); - } else { - - TAILQ_INSERT_HEAD(&screen_info_q_temp, si_next, entry); - } - } - } - - TAILQ_FOREACH(si, &screen_info_q_temp, entry) { - fvwm_debug(__func__, "NEW: %s", si->name); - } -#endif - struct monitor *m; - - TAILQ_FOREACH(m, &monitor_q, entry) { - fvwm_debug(__func__, "MON IS: %s (%d)", m->si->name, m->si->x); - } -} - void FScreenInit(Display *dpy) { XRRScreenResources *res = NULL;