[xmonad] Re: Changing focus with alt-tab as in Windows

Alex Samokhvalov xmonad at rz2013.a7d.de
Tue Jan 6 07:25:15 EST 2009

Roman Cheplyaka wrote:
> * mail at justinbogner.com <mail at justinbogner.com> [2009-01-05 21:41:07-0700]
>> Alex Samokhvalov <xmonad at rz2013.a7d.de>
>> writes:
>>> For example, a workspace contains 5 windows: A,B,C,D,E. The first
>>> window in the list is selected, in this case - A. Then as in the
>>> following scenario:
>>> - alt button down:
>>>   * pressing the tab results in the following window order: B,A,C,D,E
>>>     (whereby B is focused)
>>>   * tab pressed again -> C,A,B,D,E
>>> - alt button up -> "commit" C,A,B,D,E
>>> - alt button down
>>>   * tab pressed -> A,C,B,D,E
>>>   * tab pressed -> B,C,A,D,E
>>>   * tab pressed -> D,C,A,B,E
>>> - alt button up -> "commit" D,C,A,B,E
>>> I find such behavior convenient because usually you work with only a
>>> couple of windows. All others are just for logging, reporting, etc.
>> This is not an easy behaviour to emulate in xmonad, since we don't keep
>> track of the order in which we have focused various windows: we normally
>> only know what the currently focused window is.
> We can store this information in a layout modifier. alt-tab would send a
> message to that layout, and message handler would change the focus.
> Has not anybody written this already?

It seems there are two "problems". The first is the dispatching of the 
keyUp/keyDown event. And the second is how to handle such focus changing.

I don't know but suppose it's not very difficult to add the keyUp event 
dispatching and key binding.

The second "problem" can be eventually solved with the present 
StackSet.Stack data. Currently, the Stack contains the focused window, a 
list of the "windows" above the focused window and a list of the 
"windows" below:

data Stack a = Stack { focus  :: !a        -- focused thing in this set
                      , up     :: [a]       -- clowns to the left
                      , down   :: [a] }     -- jokers to the right
     deriving (Show, Read, Eq)

So we can just use one of the lists to save the focus history. Going 
further, the current Stack could become just a class Stack, something 
like this:

class StackClass a where
   focused  :: !a     -- currently focused window
   others   :: [a]    -- other windows

And the current data Stack could be the default implementation of 
StackClass and the function from StackSet focusUp',focusDown',etc would 
just work with StackClass instances.

What do you think about?


More information about the xmonad mailing list