Skip to content

Commit

Permalink
GotoDesk: avoid over-eager matching
Browse files Browse the repository at this point in the history
When looping round GotoDesk and associated commands (GotoDeskAndPage,
etc.), ensure the matching for which desk and monitor to apply the
request to, doesn't loop on the same value, essentially causing multiple
requests happen.

In the case of DesktopConfiguration shared/global, this would happen per
monitor when it shouldn't.

Fixes #655
  • Loading branch information
ThomasAdam committed Sep 17, 2022
1 parent 224efc9 commit 2e56c20
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions fvwm/virtual.c
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,8 @@ void MoveViewport(struct monitor *m, int newx, int newy, Bool grab)
void goto_desk(int desk, struct monitor *m)
{
struct monitor *m2 = NULL;
bool has_run_globally = false;

/* RBW - the unmapping operations are now removed to their own
* functions so they can also be used by the new GoToDeskAndPage
* command. */
Expand Down Expand Up @@ -1706,24 +1708,46 @@ void goto_desk(int desk, struct monitor *m)
}

TAILQ_FOREACH(m2, &monitor_q, entry) {
/* In global mode, only do this once. */
if (monitor_mode == MONITOR_TRACKING_G &&
has_run_globally)
break;

/* If we're swapping a desktop between monitors for
* shared mode, only do this when the is_swapping flag
* is true, otherwise events would be raised for a
* new_desk for monitors/desks which have not changed.
*/
if (m != m2 && !m2->virtual_scr.is_swapping)
continue;
if (is_tracking_shared) {
if (!m->virtual_scr.is_swapping ||
!m2->virtual_scr.is_swapping) {
continue;
}
BroadcastPacket(M_NEW_DESK, 2,
(long)m2->virtual_scr.CurrentDesk,
(long)m2->si->rr_output);

goto done;
}
if (m != m2) {
m2->Desktops = m->Desktops;
if (!is_tracking_shared) {
m2->virtual_scr.CurrentDesk =
m->virtual_scr.CurrentDesk;
}
}

BroadcastPacket(M_NEW_DESK, 2, (long)m2->virtual_scr.CurrentDesk,
BroadcastPacket(M_NEW_DESK, 2,
(long)m2->virtual_scr.CurrentDesk,
(long)m2->si->rr_output);

if (monitor_mode == MONITOR_TRACKING_G &&
!has_run_globally) {
has_run_globally = true;
goto done;
}
}
done:

/* FIXME: domivogt (22-Apr-2000): Fake a 'restack' for sticky
* window upon desk change. This is a workaround for a
* problem in FvwmPager: The pager has a separate 'root'
Expand Down Expand Up @@ -2594,6 +2618,13 @@ void CMD_GotoDeskAndPage(F_CMD_ARGS)
goto_desk(m->virtual_scr.CurrentDesk, m);
focus_grab_buttons_all();

/* If we're sharing desks between monitors, don't send further
* NEW_DESK packets, as we've already handled this in the call
* to goto_desk above.
*/
if (is_tracking_shared)
goto done;

BroadcastPacket(M_NEW_DESK, 2, (long)m->virtual_scr.CurrentDesk,
(long)m->si->rr_output);
/* FIXME: domivogt (22-Apr-2000): Fake a 'restack' for sticky
Expand All @@ -2612,6 +2643,7 @@ void CMD_GotoDeskAndPage(F_CMD_ARGS)
BroadcastPacket(M_NEW_DESK, 2, (long)m->virtual_scr.CurrentDesk,
(long)m->si->rr_output);
}
done:
BroadcastMonitorList(NULL);
EWMH_SetCurrentDesktop(m);

Expand Down

0 comments on commit 2e56c20

Please sign in to comment.