Skip to content

FvwmPager: Allow dynamic updates via SendToModule #1010

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

Merged
merged 2 commits into from
Apr 18, 2024
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
25 changes: 24 additions & 1 deletion doc/FvwmPager.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,33 @@ is an alias for this option and works the same.
*FvwmPager: NoSeparators::
Turns off the lines separating the pages of the virtual desktop.

== SENDING COMMANDS

Using the _SendToModule_ command, _FvwmPager_ can be sent the following
list of commands: *Monitor*, *CurrentMonitor*, *DeskLabels*, *NoDeskLabels*,
*MonitorLabels*, *NoMonitorLabels*, *CurrentDeskPerMonitor*,
*CurrentDeskGlobal*, *IsShared*, and *IsNotShared*. Each command functions
identically to its configuration option, changing the configuration of the
running pager.

**Note**: these commands work only on the running instance only, to make
any changes permanent, update the relevant config file.

For example, you can tell a running instance of _FvwmPager_ to track a
specific monitor by sending it the following command:

....
SendToModule FvwmPager Monitor RandRname
....

This will either change which monitor is being shown or tell the pager to
only show a specific monitor. Note that the special value of *none* will
show all windows on all monitors.

== AUTHOR

Robert Nation +
DeskColor patch contributed by Alan Wild +
MiniIcons & WindowColors patch contributed by Rob Whapham +
Balloons patch by Ric Lister <ric@giccs.georgetown.edu> +
fvwm-workers: Dominik, Olivier, Hippo and others.
fvwm-workers: Dominik, Olivier, Hippo and others.
92 changes: 78 additions & 14 deletions modules/FvwmPager/FvwmPager.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static void parse_monitor_line(char *);
static void parse_desktop_size_line(char *);
static void parse_desktop_configuration_line(char *);
static PagerWindow *find_pager_window(Window target_w);
static void update_monitor_to_track(struct fpmonitor **, char *, bool);

struct fpmonitor *
fpmonitor_new(struct monitor *m)
Expand Down Expand Up @@ -437,7 +438,7 @@ int main(int argc, char **argv)
M_END_CONFIG_INFO|
M_MINI_ICON|
M_END_WINDOWLIST|
M_RESTACK);
M_RESTACK|M_STRING);
SetMessageMask(fd,
MX_VISIBLE_ICON_NAME|
MX_PROPERTY_CHANGE|
Expand Down Expand Up @@ -635,6 +636,41 @@ void process_message(FvwmPacket* packet)
case MX_REPLY:
list_reply(body);
break;
case M_STRING: {
char *this = (char *)&body[3];
char *token;
char *rest = GetNextToken(this, &token);

if (rest != NULL && StrEquals(token, "Monitor")) {
update_monitor_to_track(
&monitor_to_track, rest, true);
} else if (StrEquals(token, "CurrentMonitor")) {
update_monitor_to_track(
&current_monitor, rest, false);
} else if (StrEquals(token, "DeskLabels")) {
use_desk_label = true;
} else if (StrEquals(token, "NoDeskLabels")) {
use_desk_label = false;
} else if (StrEquals(token, "MonitorLabels")) {
use_monitor_label = true;
} else if (StrEquals(token, "NoMonitorLabels")) {
use_monitor_label = false;
}
else if (StrEquals(token, "CurrentDeskPerMonitor")) {
CurrentDeskPerMonitor = true;
} else if (StrEquals(token, "CurrentDeskGlobal")) {
CurrentDeskPerMonitor = false;
} else if (StrEquals(token, "IsShared")) {
IsShared = true;
} else if (StrEquals(token, "IsNotShared")) {
IsShared = false;
} else {
break;
}
set_desk_size(true);
ReConfigure();
break;
}
default:
/* ignore unknown packet */
break;
Expand Down Expand Up @@ -928,7 +964,12 @@ void list_new_desk(unsigned long *body)
mout != current_monitor->m &&
(monitor_mode == MONITOR_TRACKING_M ||
is_tracking_shared))))
{
/* Still need to update monitor location of other monitors. */
if (current_monitor != NULL && oldDesk != newDesk)
goto update_grid;
return;
}

/* Update the current desk. */
desk_i = newDesk;
Expand Down Expand Up @@ -967,6 +1008,8 @@ void list_new_desk(unsigned long *body)

XStoreName(dpy, Scr.pager_w, style->label);
XSetIconName(dpy, Scr.pager_w, style->label);

update_grid:
MovePage();
draw_desk_grid(oldDesk - desk1);
draw_desk_grid(newDesk - desk1);
Expand Down Expand Up @@ -1553,6 +1596,36 @@ void parse_desktop_configuration_line(char *tline)
}
}

static void update_monitor_to_track(struct fpmonitor **fp_track,
char *name, bool update_prefered)
{
struct fpmonitor *new_fp;

name = SkipSpaces(name, NULL, 0);
if (StrEquals(name, "none")) {
*fp_track = NULL;
if (update_prefered) {
free(preferred_monitor);
preferred_monitor = NULL;
}
return;
}

new_fp = fpmonitor_by_name(name);
/* Fallback to current monitor, if monitor not already set. */
if (new_fp != NULL)
*fp_track = new_fp;
else if (*fp_track == NULL)
*fp_track = fpmonitor_this(NULL);
if (update_prefered) {
/* Set this even if no monitor matches given name.
* That monitor may get enabled later.
*/
free(preferred_monitor);
preferred_monitor = fxstrdup(name);
}
}

/*
* This routine is responsible for reading and parsing the config file
*/
Expand Down Expand Up @@ -1725,20 +1798,11 @@ void ParseOptions(void)

next = SkipSpaces(next, NULL, 0);
if (StrEquals(resource, "Monitor")) {
free(preferred_monitor);
if (StrEquals(next, "none")) {
monitor_to_track = NULL;
preferred_monitor = NULL;
goto free_vars;
}
monitor_to_track = fpmonitor_by_name(next);
/* Fallback to current monitor. */
if (monitor_to_track == NULL)
monitor_to_track = fpmonitor_this(NULL);
preferred_monitor = fxstrdup(next);
update_monitor_to_track(
&monitor_to_track, next, true);
} else if (StrEquals(resource, "CurrentMonitor")) {
current_monitor = (StrEquals(next, "none")) ?
NULL : fpmonitor_by_name(next);
update_monitor_to_track(
&current_monitor, next, false);
} else if(StrEquals(resource, "Colorset")) {
SetDeskStyleColorset(arg1, arg2,
&(((DeskStyle *)(NULL))->cs));
Expand Down
1 change: 1 addition & 0 deletions modules/FvwmPager/FvwmPager.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void initialize_pager(void);
void initialize_fpmonitor_windows(struct fpmonitor *);
void initialize_viz_pager(void);
Pixel GetSimpleColor(char *name);
void set_desk_size(bool);
void DispatchEvent(XEvent *Event);
void ReConfigure(void);
void ReConfigureAll(void);
Expand Down
1 change: 0 additions & 1 deletion modules/FvwmPager/x_pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static rectangle set_vp_size_and_loc(struct fpmonitor *, bool is_icon);
static struct fpmonitor *fpmonitor_from_xy(int x, int y);
static struct fpmonitor *fpmonitor_from_n(int n);
static int fpmonitor_count(void);
static void set_desk_size(bool);
static void fvwmrec_to_pager(rectangle *, bool, struct fpmonitor *);
static void pagerrec_to_fvwm(rectangle *, bool, struct fpmonitor *);
static char *get_label(const PagerWindow *pw,const char *fmt);
Expand Down