diff --git a/default-config/config b/default-config/config index e947b2f18..d167a6b50 100644 --- a/default-config/config +++ b/default-config/config @@ -637,10 +637,10 @@ DestroyModuleConfig RightPanel:* Test (x stalonetray) *RightPanel: (120x20, Swallow(NoClose,UseOld) \ stalonetray 'Exec exec stalonetray --config \ "$[FVWM_DATADIR]/default-config/stalonetrayrc"', Frame 0) -Test (x stalonetray) PipeRead 'echo "*RightPanel: (120x$(($[monitor.$[monitor.primary].height]-225)), \ - Top, Swallow FvwmIconMan \'Module FvwmIconMan\', Frame 0)"' -Test (!x stalonetray) PipeRead 'echo "*RightPanel: (120x$(($[monitor.$[monitor.primary].height]-205)),\ - Top, Swallow FvwmIconMan \'Module FvwmIconMan\', Frame 0)"' +Test (x stalonetray) *RightPanel: (120x$[math.-.$[monitor.$[monitor.primary].height].225], \ + Top, Swallow FvwmIconMan \'Module FvwmIconMan\', Frame 0) +Test (!x stalonetray) *RightPanel: (120x$[math.-.$[monitor.$[monitor.primary].height].205], \ + Top, Swallow FvwmIconMan \'Module FvwmIconMan\', Frame 0) *RightPanel: (120x45, Swallow DateTime 'Module FvwmScript FvwmScript-DateTime',\ Frame 0) *RightPanel: (120x5, Frame 0) diff --git a/doc/fvwm3_manpage_source.adoc b/doc/fvwm3_manpage_source.adoc index a74132dba..64e8c3b44 100644 --- a/doc/fvwm3_manpage_source.adoc +++ b/doc/fvwm3_manpage_source.adoc @@ -1616,7 +1616,6 @@ $[screen.count]:: + This is deprecated; use $[monitor.count] instead. - $[fg.cs] $[bg.cs] $[hilight.cs] $[shadow.cs] $[fgsh.cs]:: These parameters are replaced with the name of the foreground (fg), background (bg), hilight (hilight), shadow (shadow), or the font shadow @@ -1636,6 +1635,25 @@ $[bg.cs3.lighten15.hash]. + Please refer to the *Colorsets* section for details about colorsets. +$[math.+..] $[math.-..] $[math.*..] $[math./..] $[math.%..] $[math.^..]:: + The math expansion variables can be used to do some basic arithmetic + on the integers and . These expressions can be used to add + ({plus}), subtract (-), multiply ({asterisk}), divide (/), modulus + (%), and exponentiation ({caret}). This can be useful when computing + the size of panels or locations of windows relative to a monitor, for + example $[math.-.$[monitor.$[monitor.primary].height].200] will + subtract 200 pixels from the height of the primary monitor. These can + also be nested for more complex operations, + $[math.{plus}.$[math.{asterisk}.3.5].$[math.-.4.-2]] + is replaced with 21. ++ +All operations use C integer mathematics. The result of integer +division is the quotient. The modulus can be used to get the remainder +of the integer division. Note that the C modulus returns negative +remainders for negative values. Finally the exponentiation operation +only makes sense for positive values of . If is zero or +negative, exponentiation will return 1. + $[schedule.last]:: This is replaced by the id of the last command that was scheduled with the *Schedule* command, even if this command was already executed. diff --git a/fvwm/expand.c b/fvwm/expand.c index 088de2254..967dd3b2d 100644 --- a/fvwm/expand.c +++ b/fvwm/expand.c @@ -73,6 +73,7 @@ static char *partial_function_vars[] = "infostore.", "monitor.", "shadow.cs", + "math.", NULL }; @@ -164,7 +165,8 @@ enum VAR_HILIGHT_CS, VAR_INFOSTORE_, VAR_MONITOR_, - VAR_SHADOW_CS + VAR_SHADOW_CS, + VAR_MATH_, } partial_extended_vars; enum @@ -672,6 +674,56 @@ static signed int expand_vars_extended( } break; } + case VAR_MATH_: + if (rest == NULL || rest[1] != '.') + { + /* parsing error */ + return -1; + } + l = rest[0]; + rest += 2; + if (sscanf(rest, "%d.%d%n", &x, &y, &n) < 2) + { + /* parsing error */ + return -1; + } + if (*(rest + n) != 0) + { + /* trailing characters */ + return -1; + } + switch (l) { + case '+': + val = x + y; + break; + case '-': + val = x - y; + break; + case '*': + val = x * y; + break; + case '/': + val = x / y; + break; + case '%': + val = x % y; + break; + case '^': + val = 1; + /* Should we limit the value of y here? */ + for (i = 0; i < y; i++) + { + val *= x; + } + break; + default: + /* undefined operation */ + return -1; + } + + is_numeric = True; + goto GOT_STRING; + break; default: break; }