Temporarily modify window attributes

I normally use a set of applications in different desks depending on the activity I am doing (working, writing, leisure,…). For example, when working, I normally open vifm, mutt, firefox, urxvt and xboard in different desks. I want to create a function that opens the desired applications associated to a menu.

This is what I have done so far:

1.- Create a menu listing the different activities (working,…) associated with particular functions.

AddToMenu ContextTreball

  • “&1 UAB” F-StartUAB
  • “&2 Music” F-StartMusic

2.- Associate the menu to a key:
Key w A 4 Menu ContextTreball

3.- The definition of the function.

My issue has been that the applications should be opened in a particular desk. I have looked at the style “StartsOnDesk”, but I needed that the style should only be applied when opening the set of applications but not afterwards. I have been reading FvwmEvent: conditional window checking by example, and I have associated the change of style with the FvwmEvent. This is what I have:

[code]DestroyModuleConfig FE-BackToNormalStyle: *
*FE-BackToNormalStyle: Cmd Function
*FE-BackToNormalStyle: add_window F-BackToNormalStyle

Module FvwmEvent FE-BacktoNormalStyle

DestroyFunc F-BackToNormalStyle
AddToFunc F-BackToNormalStyle

  • I ThisWindow (“vifm”) Style vifm StartsAnyWhere,ShowMapping
  • I ThisWindow (“mutt”) Style mutt StartsAnyWhere,ShowMapping
  • I ThisWindow (“Navigator”) Style Navigator StartsAnyWhere,ShowMapping
  • I ThisWindow (“terminal”) Style terminal StartsAnyWhere,ShowMapping
  • I ThisWindow (“xboard”) Style xboard StartsAnyWhere,ShowMapping
  • I ThisWindow (“vifm|mutt|navigator|terminal”,!Maximized) Maximize

DestroyFunc F-StartUAB
AddToFunc F-StartUAB

  • I Style vifm StartsOnDesk 0,SkipMapping
  • I Style mutt StartsOnDesk 1,SkipMapping
  • I Style Navigator StartsOnDesk 3,SkipMapping
  • I Style terminal StartsOnDesk 4,SkipMapping
  • I Style xboard StartsOnDesk 5,SkipMapping
  • I Exec exec urxvtc -name vifm -e vifm ~/ ~/
  • I Exec exec urxvtc -j -ss -name mutt -e Correu.sh correu
  • I Exec exec firefox
  • I Exec exec urxvtc -name terminal
  • I Exec exec /usr/local/bin/Xboard_Crafty.sh [/code]

This is now working. I am posting it here to see if it can be improved or there is another approach to the same issue.

Thanks for your consideration!

You should be starting “Module FvwmEvent FE-BacktoNormalStyle” inside StartFunction as in:

AddToFunc StartFunction I Module FvwmEvent FE-BacktoNormalStyle

What you’re really doing here is setting a Style for each window if the application you start matches what’s in this window – but the “Style” command inherently applies to all instances of the named window. The only reason you’ve not come unstuck here is probably because you’ve never tried launching more than one instance.

Instead what you mean here is to use “WindowStyle”, as in:

DestroyFunc F-BackToNormalStyle
AddToFunc F-BackToNormalStyle
+ I ThisWindow ("vifm") WindowStyle vifm StartsAnyWhere,ShowMapping

Of course, a this looks odd because I’m explaining this backwards. But now, the above applies to the specific instance of the window matched, not any window matched. This is because “WindowStyle” uses the window’s ID which is guaranteed to be unique per running instance of that application. Then to make the windows “normal” again you could have just issued “DestroyWindowStyle”. Of course, coupling all of the above by assigning a State to all of the windows to be treated as special would have made this easier:

+ I All (State 1) DestroyWindowStyle

But we can improve upon this further, which I’ll explain below…

Consider the above – the only reason you don’t clobber two instances of the same program here is because you’ve done things backwards. As soon as these Style lines are run from calling this “F-StartUAB” function you’re making the style apply globally – remember it’s not specific to any one instance of a window.

But given you then launch all of these in one go:

[code]

  • I Exec exec urxvtc -name vifm -e vifm ~/ ~/
  • I Exec exec urxvtc -j -ss -name mutt -e Correu.sh correu
  • I Exec exec firefox
  • I Exec exec urxvtc -name terminal
  • I Exec exec /usr/local/bin/Xboard_Crafty.sh [/code]

You have two choices:

  1. Use something like this:
DestroyFunc F-StartUAB
AddToFunc F-StartUAB
+ I Exec exec urxvtc -name vifm -e vifm ~/ ~/
+ I Wait vifm
+ I Next (vifm) MoveToPage/Whatever command
+ I Exec exec  urxvtc -j -ss -name mutt -e Correu.sh correu
+ I Wait mutt
+ I Next (mutt) MoveToPage/Whatever command
[...]

Which has the disadvantage of blocking waiting for all of the windows to load in sequence, and should one of them fail to load for whatever reason, the Wait command really will wait around forever waiting for the window to appear – but it’s nothing pressing CTRL, ALT and Esc won’t cure (see EscapeFunc.)

The other option is to use the TitleFormat option from FVWM CVS to give each application a random name you can then just list with a bunch of Style commands, and they’ll forever be separate from other instances because you gave them unique names.

HTH,

– Thomas Adam

Excellent! Thanks very much for the hints on WindowStyle and Sate, and the clarification about the effects of the Style command. This is what I have following your suggestions:

[code]DestroyModuleConfig FE-BackToNormalStyle: *
*FE-BackToNormalStyle: Cmd Function
*FE-BackToNormalStyle: add_window F-BackToNormalStyle

AddToFunc StartFuntion

  • I Module FvwmEvent FE-BacktoNormalStyle

DestroyFunc F-BackToNormalStyle
AddToFunc F-BackToNormalStyle

  • I ThisWindow (“vifm|mutt|navigator|terminal”,!Maximized,State 1) Maximize
  • I All (State 1) DestroyWindowStyle

DestroyFunc F-StartUAB
AddToFunc F-StartUAB

  • I Exec exec urxvtc -name vifm -e vifm ~/ ~/
  • I Wait vifm
  • I Next (vifm) WindowStyle StartsOnDesk 0,SkipMapping,State 1
  • I Exec exec urxvtc -j -ss -name mutt -e Correu.sh correu
  • I Next (mutt) WindowStyle StartsOnDesk 1,SkipMapping,State 1
  • I Exec exec firefox
  • I Next (Navigator) WindowStyle StartsOnDesk 3,SkipMapping,State 1
  • I Exec exec urxvtc -name terminal
  • I Next (terminal) WindowStyle StartsOnDesk 4,SkipMapping,State 1
  • I Exec exec /usr/local/bin/Xboard_Crafty.sh
  • I Next (xboard) WindowStyle StartsOnDesk 5,SkipMapping,State 1[/code]

Really enjoyable to have some spare time to digg into fvwm!

This looks a lot better, yes.

– Thomas Adam

Today things were not working as expected :open_mouth: I discovered that instead of edit-save-restart I did edit-restart, and things seemed to work :blush:

The problem is the following. If I have in my function:

[code]+ I Exec exec urxvtc -name terminal

  • I Wait terminal
  • I Next (terminal) WindowStyle StartsOnDesk 4,SkipMapping,State 1,Title[/code]

The attribute “Title” is applied to the window but not “StartsOnDesk 4” or “SkipMapping”, as the window has already started and been mapped. I then realized the title of the thread is misleading :blush: :blush:. The attribute “StartsOnDesk” and “SkipMapping” has to be set before the window starts so it is not about “tenporarily modifying window attributes”. Therefore, I guess Style is what should be used. A different approach would be to move and maximize the window once it has been mapped:

[code]+ I Exec exec urxvtc -name terminal

  • I Wait terminal
  • I Next (terminal) MoveToDesk 0 4
  • I Next (terminal) Maximize[/code]

Or, as you suggested, use the TitleFormat option.

I am sorry I did not test the improved function correctly and did not frame the question correctly. I will try to see if I can manage to move/maximize windows one the have been mapped.

Thanks very much for the comments!

No, because as I explained earlier, that’s a global option that doesn’t apply to one specific window, it applies to all of them. The reason it works for you is because Style does a Recapture on the window.

So in your case, it really is a case of this:

[code]+ I Exec exec urxvtc -name terminal

  • I Wait terminal
  • I Next (terminal) MoveToDesk 0 4
  • I Next (terminal) Maximize[/code]

– Thomas Adam