Subject: Re: FVWM: WindowList stack

From: Jochen Klenner <[email-masked]>
Date: Sat, 7 Feb 2004 03:38:16 +0100 (MET)

On Thu, 29 Jan 2004, Hans Fugal wrote:

> I like the most-recently-used stack method of window cycling popularized
> by that other OS. I know this is a FAQ for FVWM, and several 'solutions'
> have been proposed in the FAQ and the archives, but I'm not happy with
> any of them. The crux of the problem is that the alt-tab sequence must
> either do focus or flipfocus. What I really want to do is have alt-tab
> do focus, and then when alt is released after doing several alt-tab
> *then* do a flipfocus. As if I had picked it from the window list, but I
> don't like the window list (which of those 10 xterms did I want?  that's
> no help) However, if there was some visual indication as to which window
> the windowlist entry under the cursor was referring to, that would be
> good enough.
>
> In short, I want to switch to a window with the keyboard and bring it to
> the top of the windowlist without messing up the windowlist order in the
> process.
>
> Can this be done?

This reminded me of an idea I had some time ago. So I hacked together a
patch for 2.5.9 to test it out.
The idea works as follows:
First, the internal windowlist is no longer rotated when the Focus
command is issued. As you noted, this rotation messed up the order of the
list. The menu that is displayed by the WindowList command starts at the
current window anyway.
Second, a new command is introduced, ToWindowListFront. It moves, as it
name suggests, the window to the start of the list, like FlipFocus.

Now you can put the following into your config file:

AddToFunc StartFunction Module FvwmAuto 2000 "Silent Current ToWindowListFront"

DestroyFunc RaiseAndFocus
AddToFunc RaiseAndFocus
 + I Raise
 + I Focus

Key F1 A M Prev (AcceptsFocus) RaiseAndFocus
Key F2 A M Next (AcceptsFocus) RaiseAndFocus

You can cycle through all the windows backwards and forwards by hitting
alt-F1 and alt-F2 respectively (of course you can use any keys you like).
This doesn't have any effect on the sort order of the window list. Only
when you stay with a window for more than 2000 milliseconds (customize
this value), it will be moved to the top of the list. In other words, the
window manager uses a timeout to know if you only 'run' over a window or
if you realy want to focus it. This scheme is not 100% foolproof, but
works pretty well.
There are more ways to use this setup. E. g. with the following command

Key t A 4 Prev (xterm) RaiseAndFocus

you can jump through only the xterms by hitting a key commbo. (Mod4 is the
windows key in my setup) This idea can be further extended. Search the
manpage for "MailFunction" to see a more complex example. The Direction
command is handy, too. Another possibility: if you use MouseFocus or
SloppyFocus you could use

FocusStyle * !SortWindowlistByFocus

So the windowlist is not messed up when the pointer quickly crosses over
other windows.

Be warned though, the patch is by no means considered 'official' or
perfect. It works fine for me so far, but it is not tested thoroughly.
Modules trying to keep track of the windowlist on their own may be
affected. Especially
*FvwmWinList: FollowWindowList
will lead to confusion. The experimental state of the patch is also the
reason I haven't bothered documenting it (I can do that if desired).

How to apply the patch:

You need a fairly recent fvwm source. I used 2.5.9 from CVS, but 2.5.8
should be fine. In the top sfvwm source directory do
patch -p0 < /path/to/focuspatch
Then build fvwm as documented.

Ok, hope that was helpful. Comments, thoughts, suggestions, etc. are
welcome.

Best regards

Jochen