ToggleTitle and State [solved]

From the description in the man page, I thought I could use State to toggle the titles, and I’m pretty sure I have seen other configs where this was done. However, when I tried to use State, it appeared to have no effect.

Basically, this is what I was trying to do:
The logic:
Call ToggleTitle from a menu that is opened on right-click of a window.

ToggleTitle would set a default action of turning off the title unless the state 1 is set to true, then it must set the action to turning the title back on. Then ToggleTitle would do whatever the action was set as.

The code:

DestroyFunc ToggleTitle
AddToFunc ToggleTitle
+ I SetEnv Action TitleOff
+ I Test (State 1) SetEnv Action TitleOn
+ I $[Action]

DestroyFunc TitleOn
AddToFunc TitleOn
+ I Echo "In TitleOn"
+ I WindowStyle !NoTitle
+ I State 1 False

DestroyFunc TitleOff
AddToFunc TitleOff
+ I Echo "In TitleOff"
+ I WindowStyle NoTitle
+ I State 1 True

The problem:
The state is not actually being set, and TitleOn is never being called. Anybody know why this isn’t working?

[Note: Just before submitting, I did give Taviso’s ToggleTitle function a shot, and it sort of worked, but I’d still like to know why mine does not.]

I once had some problems with $[…] in functions… however, you could try

[code]DestroyFunc ToggleTitle
AddToFunc ToggleTitle

  • I ThisWindow (State 1) TitleOn
  • I TestRc (NoMatch) TitleOff[/code]

Given that $[action] is only ever used once in that function, it seems pointless in declaring a variable for it. Instead, you can just call TitleOn directly. Variable expansion works just fine in functions, providing you get your quoting levels correct. :slight_smile:

– Thomas Adam

zonk: Excellent suggestion and exactly what I was trying to do, but I couldn’t figure out how to use the conditions in conjunction with TestRc from the man page description.

Edit: For some reason, I thought that NoMatch was 1… I should probably update the topic title now…