Skip to content

Commit

Permalink
FvwmEvent: flip prev_focused monitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ThomasAdam committed Sep 28, 2022
1 parent 31d9cb5 commit b484552
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 17 deletions.
70 changes: 53 additions & 17 deletions fvwm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ typedef struct
} _merge_cr_args;

/* ---------------------------- forward declarations ----------------------- */
static void toggle_prev_monitor_state(struct monitor *, struct monitor *,
FvwmWindow *);

/* ---------------------------- local variables ---------------------------- */

Expand Down Expand Up @@ -1981,6 +1983,35 @@ void HandleDestroyNotify(const evh_args_t *ea)
return;
}

static void
toggle_prev_monitor_state(struct monitor *this, struct monitor *prev,
FvwmWindow *fw)
{
if (fw == NULL) {
/* Assume root window. */
if (this != prev) {
BroadcastName(MX_MONITOR_FOCUS, -1, -1, -1,
this->si->name /* Name of the monitor. */
);
}
/* Toggle the state of the previous monitor. */
prev->is_prev = false;
this->is_prev = true;

return;
}

if (fw->m != prev) {
BroadcastName(MX_MONITOR_FOCUS, -1, -1, -1,
this->si->name /* Name of the monitor. */
);

/* Toggle the state of the previous monitor. */
prev->is_prev = false;
this->is_prev = true;
}
}

#if DEBUG_ENTERNOTIFY
static int ecount=0;
#define ENTER_DBG(x) fprintf x;
Expand Down Expand Up @@ -2223,6 +2254,14 @@ void HandleEnterNotify(const evh_args_t *ea)
InstallWindowColormaps(NULL);
}
focus_grab_buttons(lf);

struct monitor *pfm, *this_m;
pfm = monitor_resolve_name(prev_focused_monitor);
this_m = monitor_get_current();

/* Send MX_MONITOR_FOCUS event. */
toggle_prev_monitor_state(this_m, pfm, NULL);

return;
}
else
Expand Down Expand Up @@ -2312,9 +2351,20 @@ void HandleEnterNotify(const evh_args_t *ea)
ewp->window == FW_W_ICON_TITLE(fw) ||
ewp->window == FW_W_ICON_PIXMAP(fw))
{
BroadcastPacket(
MX_ENTER_WINDOW, 3, (long)FW_W(fw),
(long)FW_W_FRAME(fw), (unsigned long)fw);
struct monitor *pfm;
pfm = monitor_resolve_name(prev_focused_monitor);

BroadcastPacket(MX_ENTER_WINDOW, 3, (long)FW_W(fw),
(long)FW_W_FRAME(fw), (unsigned long)fw);

if (fw != NULL) {
/* Send MX_MONITOR_FOCUS event. */
toggle_prev_monitor_state(fw->m, pfm, fw);

if (pfm->virtual_scr.CurrentDesk !=
fw->m->virtual_scr.CurrentDesk)
EWMH_SetCurrentDesktop(fw->m);
}
}
sf = get_focus_window();
if (sf && fw != sf && FP_DO_UNFOCUS_LEAVE(FW_FOCUS_POLICY(sf)))
Expand Down Expand Up @@ -2577,20 +2627,6 @@ void HandleFocusIn(const evh_args_t *ea)
(unsigned long)IsLastFocusSetByMouse(),
(long)fc, (long)bc);
EWMH_SetActiveWindow(focus_w);

struct monitor *pfm;
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. */
);
if (pfm->virtual_scr.CurrentDesk !=
fw->m->virtual_scr.CurrentDesk)
EWMH_SetCurrentDesktop(fw->m);
}
}
last_focus_w = focus_w;
last_focus_fw = focus_fw;
Expand Down
6 changes: 6 additions & 0 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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"
Expand All @@ -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,
Expand Down

0 comments on commit b484552

Please sign in to comment.