Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand: add monitor.prev variable #699

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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