Skip to content

Commit

Permalink
expand: add monitor.prev variable
Browse files Browse the repository at this point in the history
Add a new monitor variable -- $[monitor.prev] which prints the
previously focused monitor.

This is tracked via focus based on windows -- so if no window on a
particular monitor has ever been focused, even if the pointer has moved
to its root window, there will be no such value associated with
$[monitor.prev]'s expansion.

If $[monitor.prev] does not contain a monitor, the empty string is
printed in its place.
  • Loading branch information
ThomasAdam committed Sep 18, 2022
1 parent ef0b45d commit 206902c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion doc/fvwm3_manpage_source.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ $[pointer.screen]::
+
This is deprecated; use $[monitor.current] instead.

$[monitor.<n>.x], $[monitor.<n>.y], $[monitor.<n>.width], $[monitor.<n>.height], $[monitor.<n>.desk], $[monitor.<n>.pagex], $[monitor.<n>.pagey] $[monitor.primary], $[monitor.current], $[monitor.output], $[monitor.count], $[monitor.<n>.prev_desk], $[monitor.<n>.prev_pagex], $[monitor.<n>.prev_pagey]::
$[monitor.<n>.x], $[monitor.<n>.y], $[monitor.<n>.width], $[monitor.<n>.height], $[monitor.<n>.desk], $[monitor.<n>.pagex], $[monitor.<n>.pagey] $[monitor.primary], $[monitor.current], $[monitor.prev] $[monitor.output], $[monitor.count], $[monitor.<n>.prev_desk], $[monitor.<n>.prev_pagex], $[monitor.<n>.prev_pagey]::
Returns information about the selected monitor. These can be nested, for
example: $[monitor.$[monitor.primary].width]
+
Expand All @@ -1609,6 +1609,9 @@ returns the monitor's height (in pixels)
"current" is the same as the deprecated $[screen.pointer] variable; the
monitor which has the mouse pointer.
+
"prev" returns the previously focused monitor, or the empty string if there
isn't one.
+
"count" returns the number of active monitors.
+
"desk" returns the current desk displayed on the referenced monitor.
Expand Down
4 changes: 3 additions & 1 deletion fvwm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -2579,9 +2579,11 @@ void HandleFocusIn(const evh_args_t *ea)
EWMH_SetActiveWindow(focus_w);

struct monitor *pfm;
pfm = monitor_resolve_name( prev_focused_monitor);
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. */
);
Expand Down
9 changes: 9 additions & 0 deletions fvwm/expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ static signed int expand_vars_extended(
goto GOT_STRING;
}

if (strcmp(rest, "prev") == 0) {
struct monitor *m2 = monitor_get_prev();

should_quote = False;
string = (m2 != NULL) ? m2->si->name : "";

goto GOT_STRING;
}

/* We could be left with "<NAME>.?" */
char *m_name = NULL;
struct monitor *mon2;
Expand Down
16 changes: 16 additions & 0 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ monitor_get_global(void)
return monitor_global;
}

struct monitor *
monitor_get_prev(void)
{
struct monitor *m, *mret = NULL;

TAILQ_FOREACH(m, &monitor_q, entry) {
if (m->is_prev) {
mret = m;
break;
}
}

/* Can be NULL -- is checked in expand.c */
return (mret);
}

struct monitor *
monitor_get_current(void)
{
Expand Down
2 changes: 2 additions & 0 deletions libs/FScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct monitor {
int flags;
int emit;
int dx, dy;
bool is_prev;

/* info for some desktops; the first entries should be generic info
* correct for any desktop not in the list
Expand Down Expand Up @@ -147,6 +148,7 @@ struct monitor *monitor_by_xy(int, int);
struct monitor *monitor_by_output(int);
struct monitor *monitor_by_primary(void);
struct monitor *monitor_get_current(void);
struct monitor *monitor_get_prev(void);
struct monitor *monitor_get_global(void);
void monitor_init_contents(struct monitor *);
void monitor_dump_state(struct monitor *);
Expand Down

0 comments on commit 206902c

Please sign in to comment.