Repeated presses on Mod - [1..9] to toggle between windows in workspace

Hello XMonad, How could one extend the behaviour of Mod - [1..9], so that an initial keypress switches to workspace n, but further keypresses toggle between windows in that workspace? (It is the default behaviour of groups in AutoHotKey, and I must admit it has grown on me: it saves one move reaching for Mod-K). Thanks for any Haskell hints.

In place of `W.greedyView` or `W.view` you would use
`\t ss -> if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss
else W.greedyView t ss`
or define that as a function. Swap `W.greedyView` for `W.view` and/or `
W.focusDown` for `W.focusUp` if you wish.
If you define this as a function (let's say `tagOrFocus`), then the key
definition becomes (assuming `EZConfig`):
++
[ (otherModMasks ++ "M-" ++ key, action tag)
| (tag, key) <- zip workspacen (words "1 2 3 4 5 6 7 8 9 0 - =
<F1> <F2> <F3> <F4>")
, (otherModMasks, action) <- [("", windows . tagOrFocus)
,("S-", windows . W.shift)
]
]
(This is lifted from my own config, adjust as appropriate.)
On Sat, Sep 2, 2023 at 8:08 AM Jean-Baptiste Mestelan
Hello XMonad,
How could one extend the behaviour of Mod - [1..9], so that an initial keypress switches to workspace n, but further keypresses toggle between windows in that workspace? (It is the default behaviour of groups in AutoHotKey, and I must admit it has grown on me: it saves one move reaching for Mod-K).
Thanks for any Haskell hints.
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
-- brandon s allbery kf8nh allbery.b@gmail.com

Many thanks, Brandon, this helps greatly!
I am not quite there yet: the 'move to workspace' part works OK, but the
'focus' part does not. It would seem the condition
(W.tag . W.workspace . W.current) ss == t
is never triggered? Still working on it.
I too use EZConfig, and have added the key definition as provided, along
with the function
tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then
W.focusUp ss else W.view t ss
On Sat, 2 Sept 2023 at 22:11, Brandon Allbery
In place of `W.greedyView` or `W.view` you would use
`\t ss -> if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.greedyView t ss`
or define that as a function. Swap `W.greedyView` for `W.view` and/or ` W.focusDown` for `W.focusUp` if you wish.
If you define this as a function (let's say `tagOrFocus`), then the key definition becomes (assuming `EZConfig`):
++ [ (otherModMasks ++ "M-" ++ key, action tag) | (tag, key) <- zip workspacen (words "1 2 3 4 5 6 7 8 9 0 - = <F1> <F2> <F3> <F4>") , (otherModMasks, action) <- [("", windows . tagOrFocus) ,("S-", windows . W.shift) ] ]
(This is lifted from my own config, adjust as appropriate.)
On Sat, Sep 2, 2023 at 8:08 AM Jean-Baptiste Mestelan
wrote: Hello XMonad,
How could one extend the behaviour of Mod - [1..9], so that an initial keypress switches to workspace n, but further keypresses toggle between windows in that workspace? (It is the default behaviour of groups in AutoHotKey, and I must admit it has grown on me: it saves one move reaching for Mod-K).
Thanks for any Haskell hints.
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
-- brandon s allbery kf8nh allbery.b@gmail.com

To be more precise, here is the function with its inferred type:
tagOrFocus :: (Eq i, Eq s) =>
i -> W.StackSet i l a s sd -> W.StackSet i l a s sd
tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then
W.focusUp ss else W.view t ss
On Sun, 3 Sept 2023 at 08:10, Jean-Baptiste Mestelan
Many thanks, Brandon, this helps greatly!
I am not quite there yet: the 'move to workspace' part works OK, but the 'focus' part does not. It would seem the condition (W.tag . W.workspace . W.current) ss == t is never triggered? Still working on it.
I too use EZConfig, and have added the key definition as provided, along with the function tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.view t ss
On Sat, 2 Sept 2023 at 22:11, Brandon Allbery
wrote: In place of `W.greedyView` or `W.view` you would use
`\t ss -> if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.greedyView t ss`
or define that as a function. Swap `W.greedyView` for `W.view` and/or ` W.focusDown` for `W.focusUp` if you wish.
If you define this as a function (let's say `tagOrFocus`), then the key definition becomes (assuming `EZConfig`):
++ [ (otherModMasks ++ "M-" ++ key, action tag) | (tag, key) <- zip workspacen (words "1 2 3 4 5 6 7 8 9 0 - = <F1> <F2> <F3> <F4>") , (otherModMasks, action) <- [("", windows . tagOrFocus) ,("S-", windows . W.shift) ] ]
(This is lifted from my own config, adjust as appropriate.)
On Sat, Sep 2, 2023 at 8:08 AM Jean-Baptiste Mestelan
wrote: Hello XMonad,
How could one extend the behaviour of Mod - [1..9], so that an initial keypress switches to workspace n, but further keypresses toggle between windows in that workspace? (It is the default behaviour of groups in AutoHotKey, and I must admit it has grown on me: it saves one move reaching for Mod-K).
Thanks for any Haskell hints.
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
-- brandon s allbery kf8nh allbery.b@gmail.com

On Sun, Sep 03 2023 08:10, Jean-Baptiste Mestelan wrote:
I am not quite there yet: the 'move to workspace' part works OK, but the 'focus' part does not. It would seem the condition (W.tag . W.workspace . W.current) ss == t is never triggered? Still working on it.
Did you properly restart XMonad? Make sure that your config compiles; if
tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.view t ss
is a verbatim copy, then you probably have at least one spurious line break in there. (For the record, I tried Brandon's solution just now and it works for me) -- Tony Zorman | https://tony-zorman.com/

Thank you, Tony, for the confirmation.
The behaviour I observe seems due to me using an azerty keyboard. I have
this line in my config:
, keys = azertyKeys <+> keys def
As a consequence, (words "1 2 3 4 5 6 7 8 9 0") does not map to the above
row keys.
I will manually replace each digit by its azerty counterpart, unless a
smarter idea comes up.
Thank you for all the help!
On Sun, 3 Sept 2023 at 08:43, Tony Zorman
On Sun, Sep 03 2023 08:10, Jean-Baptiste Mestelan wrote:
I am not quite there yet: the 'move to workspace' part works OK, but the 'focus' part does not. It would seem the condition (W.tag . W.workspace . W.current) ss == t is never triggered? Still working on it.
Did you properly restart XMonad? Make sure that your config compiles; if
tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.view t ss
is a verbatim copy, then you probably have at least one spurious line break in there.
(For the record, I tried Brandon's solution just now and it works for me)
-- Tony Zorman | https://tony-zorman.com/

Confirmed working, when translated to azerty: (words "& é \" ' ( - è _ ç )")
Not the prettiest-looking config, but I can surely live with it, and the
improved functionality.
Thanks again Brandon and Tony.
On Sun, 3 Sept 2023 at 09:05, Jean-Baptiste Mestelan
Thank you, Tony, for the confirmation.
The behaviour I observe seems due to me using an azerty keyboard. I have this line in my config: , keys = azertyKeys <+> keys def
As a consequence, (words "1 2 3 4 5 6 7 8 9 0") does not map to the above row keys.
I will manually replace each digit by its azerty counterpart, unless a smarter idea comes up. Thank you for all the help!
On Sun, 3 Sept 2023 at 08:43, Tony Zorman
wrote: On Sun, Sep 03 2023 08:10, Jean-Baptiste Mestelan wrote:
I am not quite there yet: the 'move to workspace' part works OK, but the 'focus' part does not. It would seem the condition (W.tag . W.workspace . W.current) ss == t is never triggered? Still working on it.
Did you properly restart XMonad? Make sure that your config compiles; if
tagOrFocus t ss = if (W.tag . W.workspace . W.current) ss == t then W.focusUp ss else W.view t ss
is a verbatim copy, then you probably have at least one spurious line break in there.
(For the record, I tried Brandon's solution just now and it works for me)
-- Tony Zorman | https://tony-zorman.com/
participants (3)
-
Brandon Allbery
-
Jean-Baptiste Mestelan
-
Tony Zorman