Skip to content

Commit

Permalink
StartsOnScreen: honour expanded variables
Browse files Browse the repository at this point in the history
With FVWM3 being per-monitor aware, there is now a need to be able to
specify the current screen.  However, since that is dynamic, we need to
ensure that the expansion of the current screen happens just in time.

For example:

    Style foo StartsOnScreen $[ponter.screen]

won't work, because when FVWM reads in that line from its config, it
will have expanded $[pointer.screen] to be whatever value is correct at
that time, which means any window named "foo" would start on an
incorrect screen.

Therefore, support expansion of variables at the point we need them for
StartOnScreen.

To achieve this, the following line would be needed:

    Style foo StartsOnScreen $$[pointer.screen]

Which would mean that on the first pass, FVWM would have used:

    Style foo StartsOnScreen $[pointer.screen]

... and then when the value for 'StartsOnScreen' is used, it will
expand $[pointer.screen] to the name of a monitor.
  • Loading branch information
ThomasAdam committed Apr 29, 2020
1 parent 09edf3a commit 211a17f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions fvwm/placement.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "ewmh.h"
#include "icons.h"
#include "add_window.h"
#include "expand.h"

/* ---------------------------- local definitions -------------------------- */

Expand Down Expand Up @@ -1673,11 +1674,32 @@ static int __place_window(
{
fscreen_scr_arg arg;
arg.mouse_ev = NULL;
arg.name = SGET_START_SCREEN(*pstyle);

/* FIXME: expand the screen name here. It's possible
* we have been specified as:
*
* Style foo StartsOnScreen $$[screen.pointer]
*
* we need to double-up the variable expansion, as the
* Style command will expand it first, and we want to
* expand $[pointer.screen] here.
*/
char *sc = SGET_START_SCREEN(*pstyle);
char *e = expand_vars(sc, NULL, False, True, NULL, exc);

arg.name = e;

FScreenGetScrRect(&arg, FSCREEN_BY_NAME,
&screen_g.x, &screen_g.y,
&screen_g.width, &screen_g.height);
free(e);

/* FIXME: Set the monitor here, but make
* UPDATE_FVWM_SCREEN aware of how to do this.
*
* This is necessary for StartsOnScreen
*/
fw->m = monitor_by_name(arg.name);
}
else
{
Expand Down Expand Up @@ -2296,10 +2318,29 @@ Bool setup_window_placement(
start_style.desk = SGET_START_DESK(*pstyle);
start_style.page_x = SGET_START_PAGE_X(*pstyle);
start_style.page_y = SGET_START_PAGE_Y(*pstyle);
start_style.screen = SGET_START_SCREEN(*pstyle);

/* FIXME: expand the screen name here. It's possible
* we have been specified as:
*
* Style foo StartsOnScreen $$[screen.pointer]
*
* we need to double-up the variable expansion, as the
* Style command will expand it first, and we want to
* expand $[pointer.screen] here.
*/
char *sc = SGET_START_SCREEN(*pstyle);
char *e = NULL;

if (sc != NULL)
expand_vars(sc, NULL, False, True, NULL, exc);

start_style.screen = e;
rc = __place_window(
exc, pstyle, attr_g, start_style, mode, win_opts, &reason);

exc_destroy_context(exc);
free(e);

if (Scr.bo.do_explain_window_placement == 1)
{
__explain_placement(fw, &reason);
Expand Down

0 comments on commit 211a17f

Please sign in to comment.