Change, Save & Use Window Styles

I want to be able to change window styles, save them at the same time and use them when applications restarts.
The following does that: toggles Borders, Button X, and adds/removes !Borders, !Button X from the styles file.
The problem is that when I restart the program, Read command from FvwmReadStyle doesn’t work like when I restart FVWM. Works only for styles with “!StyleOption”.

[code]DestroyFunc FvwmReadStyle
AddToFunc FvwmReadStyle

  • I Read “/home/.fvwm/files/appsstyle2”
  • I Wait
  • I UpdateStyles

DestroyFunc FvwmStyleGen
AddToFunc FvwmStyleGen

  • I PipeRead ‘[[ $(grep “$[w.class].*$0” /home/.fvwm/files/appsstyle2) == “” ]] && echo WindowStyle “!$0” || echo WindowStyle “$0”’
  • I Exec exec /home/.fvwm/files/appsstylegen “$[w.class]” “!$0”

DestroyMenu FvwmToggleMenu
AddToMenu FvwmToggleMenu

  • “Max Button” FvwmStyleGen “Button 4”
  • “Min Button” FvwmStyleGen “Button 6”
  • “Borders” FvwmStyleGen “Borders”

DestroyModuleConfig FvwmEvent: *
*FvwmEvent: add_window FvwmReadStyle
[/code]

Why?

Note that WindowStyle internally uses the windowid of the window to apply the style. When you restart, the window is recaptured and the style for the toplevel window is lost, hence why it’s not working for you.

So rather than giving you idea of a solution, perhaps you’ll tell me what the problem is you’re trying to solve?

– Thomas Adam

Why?
Sure, I can set a style for each application window, but I want to do it from a window options menu. Styles like: !Button, !Borders, StartsOnPage, TitleAt, PositionPlacement.

With the functions above I can restyle the window, I can show/hide buttons/borders, change TitleAt, StartsOnPage, etc and save the options for each application. The problem is when I restart the application.

For example:
At FVWM start I have no style set for urxvt,
then I restyle using the window options menu:

Style "URxvt" !Button 4, !Button 6, TitleAtLeft

If I restart urxvt, the style is fine.
Then I restyle it again and enable min and max buttons, the script removes !Button 4 and !Button 6:

Style "URxvt" TitleAtLeft

If I restart urxvt, the style is like before, no min and max buttons.

I thought “Read” sets buttons, borders, etc to default, like when FVWM starts.

Like I just told you, using WindowStyle is fine, but can never persist across reboots. The only thing I can suggest is using the “State” condition on the window, and then reapply styles based on that.

– Thomas Adam

I’ve made a new ReadStyle function that applies changed style options from styles file on application restart:

[code]DestroyFunc FvwmReadStyle
AddToFunc FvwmReadStyle

  • I PipeRead ‘echo WindowStyle $(grep “$[w.class]” /home/.fvwm/files/appsstyle2 | sed -e “s/Style.*$[w.class].//”)’
  • I UpdateStyles[/code]
    I think it’s working.

You misunderstood me. The above is extremely fragile and will only give the illusion of working.

When I said you can use the State style, I meant just that.

– Thomas Adam

Now I have:

[code]DestroyFunc FvwmReadStyle
AddToFunc FvwmReadStyle

  • I PipeRead ‘echo WindowStyle $(grep “$[w.class]” /home/.fvwm/files/appsstyle2 | sed -e “s/Style.*$[w.class].//”)’
  • I UpdateStyles

DestroyFunc FvwmStyleGen
AddToFunc FvwmStyleGen

  • I PipeRead ‘[[ $(grep “$[w.class].*$0” /home/.fvwm/files/appsstyle2) == “” ]] && echo WindowStyle “!$0” || echo WindowStyle “$0”’
  • I Exec exec /home/.fvwm/files/appsstylegen “$[w.class]” “!$0”

DestroyModuleConfig FvwmEvent: *
*FvwmEvent: add_window FvwmReadStyle

DestroyMenu FvwmToggleMenu
AddToMenu FvwmToggleMenu

  • “Max Button” FvwmStyleGen “Button 4”
  • “Min Button” FvwmStyleGen “Button 6”
  • “Borders” FvwmStyleGen “Borders”[/code]

When I start an application, FvwmReadStyle reads the styles file and sets the window style.
Then I can change window style from window’s options menu, style which will be applied to the window and saved to the styles file with the FvwmStyleGen function.
If I restart the application FvwmReadStyle reads the style file again and applies the new style.

Now, I don’t know where should I use State.

I want to save position and page for a window too. How do I put window’s page numbers and position into a menu?

[code]DestroyMenu FvwmSaveMenu
AddToMenu FvwmSaveMenu

  • “Page” ChangeWindowStyle “change” “StartsOnPage $[page.nx] $[page.ny]”
  • “Position” ChangeWindowStyle “change” “PositionPlacement $[w.x] $[w.y]”[/code]
    Won’t work.

Correct, because PositionPlacement only happens with the window is initially-mapped.

Search these forums – I’ve given a solution to the above already.

– Thomas Adam

Oh – what you’re also looking for here is a session manager. Any other solution to this is wrong.

– Thomas Adam

This is the best I can come up with,
Fvwm:

Shell appsstylegen:

appsstyle="/home/.fvwm/files/appsstyle2" wname=$(echo "$1" | sed -e "s/'//g" -e "s/.*– /*/g") wstyle="$2" [[ "$3" == "toggle" ]] && wstyle="!$wstyle" wstylefr="$wstyle" wstyleto="" if [[ $(echo $wstyle | grep "StartsOnPage") != "" ]]; then wstylefr="StartsOnPage [0-9]\+ [0-9]\+" wstyleto="$wstyle" fi if [[ $(echo $wstyle | grep "PositionPlacement") != "" ]]; then wstylefr="PositionPlacement [0-9]\+p [0-9]\+p" wstyleto="$wstyle" fi if [[ $(echo $wstyle | grep "TitleAt.\{3,6\}") != "" ]]; then wstylefr="TitleAt.\{3,6\}" [[ $wstyle != "TitleAtTop" ]] && wstyleto="$wstyle" echo true fi if [[ $(grep "$wname" $appsstyle) == "" ]]; then addstyle="Style \"$wname\" $wstyle," echo $addstyle >> $appsstyle else if [[ $(grep "$wname.*$wstylefr" $appsstyle) == "" ]]; then sed -i -e "/$wname/ s/$/ $wstyle,/" $appsstyle else if [[ $wstyleto != "" ]]; then sed -i -e "/$wname/ s/ $wstylefr,/ $wstyleto,/" $appsstyle else sed -i -e "/$wname/ s/ $wstylefr,//" $appsstyle fi fi fi

Use a session manager. This “solution” is fraught with problems.

– Thomas Adam