From bc3ab2403272ddbff646dde2bf50e4fbc56c3648 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Mon, 19 Sep 2022 23:24:30 +0100 Subject: [PATCH] FvwmEvent: flip prev_focused monitor When handling focus between screens (which is predicated on windows receiving focus, rather than the root window), toggle the appropriate monitors so that the previous focused monitor is referenced correctly. While here, improve the matching of the previous monitor. Fixes #604 --- fvwm/events.c | 6 ++++-- libs/FScreen.c | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fvwm/events.c b/fvwm/events.c index 52777733c..945fafcaa 100644 --- a/fvwm/events.c +++ b/fvwm/events.c @@ -2582,11 +2582,13 @@ void HandleFocusIn(const evh_args_t *ea) pfm = monitor_resolve_name(prev_focused_monitor); if (fw != NULL && fw->m != pfm) { - pfm->is_prev = true; - fw->m->is_prev = false; BroadcastName(MX_MONITOR_FOCUS, -1, -1, -1, fw->m->si->name /* Name of the monitor. */ ); + + /* Toggle the state of the previous monitor. */ + pfm->is_prev = false; + fw->m->is_prev = true; if (pfm->virtual_scr.CurrentDesk != fw->m->virtual_scr.CurrentDesk) EWMH_SetCurrentDesktop(fw->m); diff --git a/libs/FScreen.c b/libs/FScreen.c index 2ac92f732..5076c0d8a 100644 --- a/libs/FScreen.c +++ b/libs/FScreen.c @@ -167,8 +167,11 @@ struct monitor * monitor_get_prev(void) { struct monitor *m, *mret = NULL; + struct monitor *this = monitor_get_current(); TAILQ_FOREACH(m, &monitor_q, entry) { + if (m == this) + continue; if (m->is_prev) { mret = m; break; @@ -537,6 +540,7 @@ void FScreenInit(Display *dpy) m->Desktops->next = NULL; m->Desktops->desk = 0; m->flags |= (MONITOR_NEW|MONITOR_ENABLED); + m->is_prev = false; monitor_scan_edges(m); } @@ -572,6 +576,7 @@ monitor_dump_state(struct monitor *m) "\tDisabled:\t%s\n" "\tIs Primary:\t%s\n" "\tIs Current:\t%s\n" + "\tIs Previous:\t%s\n" "\tOutput:\t%d\n" "\tCoords:\t{x: %d, y: %d, w: %d, h: %d}\n" "\tVirtScr: {\n" @@ -586,6 +591,7 @@ monitor_dump_state(struct monitor *m) (m2->flags & MONITOR_DISABLED) ? "true" : "false", (m2->flags & MONITOR_PRIMARY) ? "yes" : "no", (mcur && m2 == mcur) ? "yes" : "no", + m2->is_prev ? "yes" : "no", (int)m2->si->rr_output, m2->si->x, m2->si->y, m2->si->w, m2->si->h, m2->virtual_scr.VxMax, m2->virtual_scr.VyMax,