Another Alt+Tab possibility

Hi!

It seems Alt+Tab is a hot topic now :slight_smile:

Anyway, this is one of the few things I never managed to get exactly they way I like. I want some behaviour similar to FAQ 3.3, i.e. If I’m in window A and cycle to window B, the next time I press Alt+Tab I want to come back to window A. But I want to do this without using the window list, I want the windows rising as I cycle through them.

The most natural way to do this (I think) would be to bind the update of the window list to the release of the alt key, but this is not possible at the moment AFAIK. The solution I came up with works like this (BTW, I speak about Alt+Tab, but for my config it is Super+Tab):

Key Super_L A A SetEnv FVWMFirstAltTab YES
Key Tab A 3 AltTab

DestroyFunc AltTab
AddToFunc AltTab
+ I PipeRead 'if [ "$$FVWMFirstAltTab" != "NO" ]; then \
                 echo FirstAltTab; \
              else \
                 echo NthAltTab; \
              fi'
+ I SetEnv FVWMFirstAltTab NO

DestroyFunc FocusAltTab
AddToFunc FocusAltTab
+ I FlipFocus
+ I Raise

DestroyFunc FocusFirstAltTab
AddToFunc FocusFirstAltTab
+ I FocusAltTab
+ I State 15 Off
+ I WindowId $0 State 15 On

DestroyFunc FirstAltTab
AddToFunc FirstAltTab
+ I Current (State 15) NthAltTab
+ I TestRc (NoMatch) Next (CurrentPage, State 15, !Iconic, !Shaded, !Sticky, AcceptsFocus) FocusFirstAltTab $[w.id]
+ I TestRc (NoMatch) Next (CurrentPage, !Iconic, !Shaded, !Sticky, AcceptsFocus) FocusFirstAltTab $[w.id]

DestroyFunc NthAltTab
AddToFunc NthAltTab
+ I Next (CurrentPage, !Iconic, !Shaded, !Sticky, AcceptsFocus) FocusAltTab

Here’s how the code works: In each Super+Tab cycle, I mark the window I started from (thus the window I would like to return to with the next Super+Tab) with state 15. When pressing Super+Tab, if it is the first time I press the key combination I jump to the window with State 15. If it is the second or greater time (without releasing Super_L) I continue cycling through the window ring.

How do I differentiate the first time I press Super+Tab? I use the trick of binding a function to Super_L and also using it as a modifier. If I press Super_L the env. variable FVWMFirstAltTab gets set to YES. If tab is pressed the function AltTab gets called, which sets FVWMFirstAltTab to NO, so I can distinguish the first and subsequent calls to AltTab.

Now comes the question part: Is this method reliable or it is possible that it stops working in future releases? And this gets a bit messed up if I change the focus with other methods e.g. with the mouse (therefore the first test in FirstAltTab). Any ideas how to solve it? I though about using FvwmEvent, but I expect it to interfere with the above code and I’m not sure how to solve it. Has anybody found a better solution?

Regards.

There’s always the remote possibility it could, but looking at your functions, you’re using pretty standard stuff that have persisted across FVWM releases.

Well, you could use FvwmEvent just fine — I suppose if you listen for the focus_change event, although there’s still no reliable way of being able to detect whether you’re using the mouse or not. There might be some hope though if you used ‘ClickToFocus’ (or something similar), since that has some finer control about what happens to the window when it is clicked on to receive focus. You can’t do this (AFAICT) with sloppyfocus or mousefocus.

– Thomas Adam

My main concern was with binding a function to a modifier key, which is a non standard use, I think. I guess the functions won’t have any problems.

I’m using SloppyFocus (and I can’t live without it). I will investigate a bit more the use of FvwmEvent (maybe setting another variable in the spirit of “changedViaAltTab”?). If I get it, I will post my solution.

Regards,

David

If you do use FvwmEvent, be sure to separate out some of the logic contained in your existing function, otherwise you might find that you get some unexpected results. So for instance, if you do switch to using FvwmEvent (which would allow for using either the mouse or key to focus a window) let the function the event trigger calls, set the state variable, etc.

– Thomas Adam