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

monitor: add prev_primary logic #826

Merged
merged 1 commit into from
Mar 14, 2023
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
6 changes: 5 additions & 1 deletion doc/fvwm3_manpage_source.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,8 @@ $[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.prev] $[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.prev_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 @@ -1610,6 +1611,9 @@ isn't one.
+
"primary" is the name of the output set as primary via xrandr(1).
+
"prev_primary" is the name of the output which was the previous primary
monitor.
+
"prev_desk" returns the previous desk on the referenced monitor.
+
"prev_pagex" returns the previous X page on the referenced monitor.
Expand Down
12 changes: 12 additions & 0 deletions fvwm/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,18 @@ monitor_emit_broadcast(void)
execute_function_override_window(
NULL, NULL, randrfunc, NULL, 0, NULL);
}

if (m->flags & MONITOR_PRIMARY) {
struct monitor *pm = m, *mnew;

if ((mnew = monitor_by_last_primary()) == NULL)
break;

if (pm != mnew) {
execute_function_override_window(
NULL, NULL, randrfunc, NULL, 0, NULL);
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions fvwm/expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ static signed int expand_vars_extended(
goto GOT_STRING;
}

if (strcmp(rest, "prev_primary") == 0) {
struct monitor *m2 = monitor_by_last_primary();

if (m2 != NULL)
string = m2->si->name;
should_quote = False;
goto GOT_STRING;
}

if (strcmp(rest, "current") == 0) {
struct monitor *m2 = monitor_get_current();

Expand Down
23 changes: 21 additions & 2 deletions libs/FScreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,21 @@ monitor_by_primary(void)
return (m);
}

struct monitor *
monitor_by_last_primary(void)
{
struct monitor *m = NULL, *m_loop;

TAILQ_FOREACH(m_loop, &monitor_q, entry) {
if (m_loop->was_primary && !(m_loop->flags & MONITOR_PRIMARY)) {
m = m_loop;
break;
}
}

return (m);
}

static void
monitor_check_primary(void)
{
Expand Down Expand Up @@ -476,10 +491,13 @@ scan_screens(Display *dpy)
m->si->w = rrm[i].width;
m->si->h = rrm[i].height;
m->si->rr_output = *rrm[i].outputs;
if (rrm[i].primary > 0)
if (rrm[i].primary > 0) {
m->flags |= MONITOR_PRIMARY;
else
m->was_primary = false;
} else {
m->flags &= ~MONITOR_PRIMARY;
m->was_primary = true;
}

XFree(name);
}
Expand Down Expand Up @@ -549,6 +567,7 @@ void FScreenInit(Display *dpy)
m->Desktops->desk = 0;
m->flags |= (MONITOR_NEW|MONITOR_ENABLED);
m->is_prev = false;
m->was_primary = false;
monitor_scan_edges(m);
}

Expand Down
3 changes: 2 additions & 1 deletion libs/FScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct monitor {
int flags;
int emit;
int dx, dy;
bool is_prev;
bool is_prev, was_primary;

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