How would I save the active window, run sthg, reactivate it?

Hello,
In my code of my .fvwm2rc, I would like : how would I save which activated window, run my yakuake-like up/down, and reactivate my previous window ?

Thanks if somebdy by chance pass by and knows…

Greetings @ fvwm!

Can you try and rephrase your question? It doesn’t make any sense.

– Thomas Adam

I think he wants to save the id for the focused window, then run whatever (to display the kuake or something) and then give back the focus to the window that was focused before opening the kuake.

This highly depends on how you implemented your kuake, but generally, you would do something along the lines of:

DestroyFunc toggle_kuake
AddToFunc toggle_kuake
+ I SetEnv current_focus_id $[w.id]
+ I All (FvwmKuakeTerm, CurrentPage, Overlapped, !State 0) Nop
+ I TestRc (Match) All (FvwmKuakeTerm) Focus
+ I TestRc (Match) All (FvwmKuakeTerm) Raise
+ I TestRc (Match) Break
+ I All (FvwmKuakeTerm, State 0) Move screen 0 +0p +0p
+ I TestRc (Match) All (FvwmKuakeTerm) Focus
+ I TestRc (Match) All (FvwmKuakeTerm) Raise
+ I TestRc (Match) All (FvwmKuakeTerm) State 0 False
+ I TestRc (Match) Break
+ I All (FvwmKuakeTerm) Move -$[vp.width]p +0p
+ I All (FvwmKuakeTerm) State 0 True
+ I WindowId $[current_focus_id] Raise
+ I WindowId $[current_focus_id] Focus
+ I UnSetEnv i
+ I UnSetEnv current_focus_id

This is the one I use, the key is to save the $[w.id] after you focus the kuake, and then use it with WindowId to focus and raise it again.

Really? Why go through all that elaborateness when you can do it using Next/Prev?

I hate second-guessing, so I’ll wait.

– Thomas Adam

I don’t have the time to check it now.

I just remember that I did it this way because it was the only way I could get the behavior I wanted. I have tried a couple dozens of alternative implementations amongst all these years of fvwm and this is the one I am using right now.

It’s not perfect either, but the closest I could get in fvwm. The whole kuake concept has some inherent problems itself.

ISTR suggesting now it can be improved: viewtopic.php?p=10122#p10122

– Thomas Adam

Thanks guys !!
I confirm above that it is for the kuake like and its focus.

I tried your given fvwmkuake, and this is not yet working …maybe events in my configs … hmmm

I have the kuake working with this (but focus). the focus do not return to the previous window:

DestroyFunc ToggleTerminal
AddToFunc ToggleTerminal
+ I SetEnv current_focus_id $[w.id]
#+ I Thiswindow SetEnv focused_window_id $[w.id]
#+ I SetEnv OpenedTerm "False"
+ I None (GameConsole) StartTerminal
+ I Next (GameConsole) Focus
+ I Next (GameConsole) Raise
+ I Next (GameConsole, Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, !Shaded) WindowShade True
+ I Next (GameConsole, !Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, Shaded) WindowShade True
+ I WindowId $[current_focus_id] Raise
+ I WindowId $[current_focus_id] Focus
+ I UnSetEnv i
+ I UnSetEnv current_focus_id

I unfortunately cannot get it right with the focus …
pff :frowning:

Then if all you want is to return focus to the previous window after you have run something from kuake (or anywhere else) then you will need to use FvwmEvent.

DestroyModuleConfig FE-aw:*
*FE-aw: add_window SomeFunc

AddToFunc StartFunc I Module FvwmEvent FE-aw

So we’re telling FvwmEvent it has a new module alias to listen for, specifically on the add_window event. What defines SomeFunc is the following:

DestroyFunc SomeFunc
AddToFunc   SomeFunc
+ I Current (WhateverKuakeIsCalled) Prev (AcceptsFocus, CurrentPage, !Overlapped) FlipFocus

Which says that if a new window is opened whilst this kuake window has the focus, then move the focus to the previous window if it accepts focus and is on the current page. Now, this assumes a few things:

  1. That the Kuake window is opened after it has been given a command.
  2. That some other program doesn’t open whilst kuake is focused (think transient window).
  3. That you’re not using GrabFocus or similar which will then try and revert focus back to an erroneous window.

I’ve used the !Overlapped negation condition to assume the window prior having focus to kuake was fully visible. This might be bogus of course, but it’s up to you.

Also, what you really want to do is throw a:

+ I Wait foo
+ I ...

In there somewhere, which you cannot do since there’s no reliable way of getting the program you’re running from this console to FVWM in order to satisfy the wait condition, so this approach is always going to be potentially flawed.

– Thomas Adam

Thanks Adam for your complete reply.

I added the code to the .fvwm2rc but could not get the focus of the kuake. It remains the same. I tried few position of the throwing of + I foo. here is the code:


DestroyModuleConfig FvwmEvent: *
*FvwmEvent: add_window RestorePosition
*FvwmEvent: close_window SavePosition
#*FvwmEvent: Cmd Function
*FvwmEvent: new_page CurrentPageFocusFunc
*FvwmEvent: new_desk CurrentPageFocusFunc
*FvwmEvent: destroy_window CurrentPageFocusFunc
*FvwmEvent: focus_change MarkWindowAsActiveFunc
#*FvwmEvent: window_name RecaptureWindow
#*FvwmEvent: Delay 1



DestroyFunc ToggleTerminal
AddToFunc ToggleTerminal
+ I SetEnv current_focus_id $[w.id]
#+ I Thiswindow SetEnv focused_window_id $[w.id]
#+ I SetEnv OpenedTerm "False"
+ I None (GameConsole) StartTerminal
+ I Next (GameConsole) Focus
+ I Next (GameConsole) Raise
#+ I Wait foo
+ I Next (GameConsole, Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, !Shaded) WindowShade True
+ I Next (GameConsole, !Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, Shaded) WindowShade True
+ I WindowId $[current_focus_id] Raise
+ I WindowId $[current_focus_id] Focus
+ I UnSetEnv i
+ I UnSetEnv current_focus_id
+ I Wait foo


DestroyModuleConfig FE-aw:*
*FE-aw: add_window SomeFunc

AddToFunc StartFunc I Module FvwmEvent FE-aw


DestroyFunc SomeFunc
AddToFunc   SomeFunc
+ I Current (WhateverKuakeIsCalled) Prev (AcceptsFocus, CurrentPage, !Overlapped) FlipFocus

Greetings Adam

And you actually don’t see anything wrong with that? I was generalising the SomeFunc function hoping you might fill in the blanks. Note that you will need to change “WhateverKuakeIsCalled” to the class of this kuake window.

– Thomas Adam

thanks thomas !
it is now almost working.

the gameconsole/kuake like is now getting into focus when I activate it
but when I roll it up, to unactivate it,
the focus is unfortunately not returning to the window that was.

would you have any idea ?

Greetings !!!

DestroyFunc ToggleTerminal
AddToFunc ToggleTerminal
+ I SetEnv current_focus_id $[w.id]
#+ I Thiswindow SetEnv focused_window_id $[w.id]
#+ I SetEnv OpenedTerm "False"
+ I None (GameConsole) StartTerminal
+ I Next (GameConsole) Focus
+ I Next (GameConsole) Raise
#+ I Wait foo
+ I Next (GameConsole, Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, !Shaded) WindowShade True
+ I Next (GameConsole, !Shaded) WindowShade False
+ I TestRc (NoMatch) Next (GameConsole, Shaded) WindowShade True
+ I Wait foo
+ I WindowId $[current_focus_id] Raise
+ I WindowId $[current_focus_id] Focus
+ I UnSetEnv i
+ I UnSetEnv current_focus_id



DestroyModuleConfig FE-aw:*
*FE-aw: add_window SomeFunc

AddToFunc StartFunc I Module FvwmEvent FE-aw


DestroyFunc SomeFunc
AddToFunc   SomeFunc
+ I Current (GameConsole) Prev (AcceptsFocus, CurrentPage, !Overlapped) FlipFocus

By chance would have anyone an idea what could be wrong with the above code ?

thank and Greetings

I see many things “wrong” with it. But either it’s just not working at all, or it’s not working how you would like, or it’s something else. Any chance you can clarify which bits of it are working how you’d like having used the suggestions above, and which bits are not, and in doing so upload (pastebin, webhost, what have you) your FVWM config also?

– Thomas Adam