list of visible workspaces

How do you get a list of visible workspaces (only those workspaces that are displayed on the monitors)? Currently I get the entire list of workspaces in my xmonad config with (XMonad.workspaces conf). It looks like this command returns a list of strings, each of which denote a workspace (i.e. ["1", "2"... ] ). But not sure how to get a list of only those which are visible (I could also probably work with a list of hidden workspaces). Sorry, my Haskell is weak and I do not understand how to use the documentation here: http://xmonad.org/xmonad-docs/xmonad/XMonad-StackSet.html Thanks!

On Thu, Aug 2, 2012 at 12:29 PM, Bryan Huh
How do you get a list of visible workspaces (only those workspaces that are displayed on the monitors)? Currently I get the entire list of workspaces in my xmonad config with (XMonad.workspaces conf). It looks like this command returns a list of strings, each of which denote a workspace (i.e. ["1", "2"... ] ). But not sure how to get a list of only those which are visible (I could also probably work with a list of hidden workspaces).
This depends to some extent on how you plan to use it; for example, when passing that list to an outside program using ppVisible or ppOrder from XMonad.Hooks.DynamicLog may be more convenient than other mechanisms. The general case, however, is roughly along the lines of visibleWorkspaces :: X [WorkspaceId] visibleWorkspaces = do ws <- gets windowset return $ map W.tag $ W.current ws : W.visible ws Note that this is impure, so you can't simply drop it in place of (workspaces conf). If you give us more detail as to what you're trying to do, we can help you work it into your configuration properly. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

What I'm trying to do is prevent my focus from switching to a different screen if I mistakenly try to switch to an already visible workspace. I already am not using greedyView so I don't have the problem of the visible workspaces swapping on me. But suppose I have two screens and workspace 1 is on the left, workspace 2 is on the right. If I'm focused on the left screen, and I were to press mod-2, the focus switches to the screen on the right. If I now press mod-3 it will be the right screen which switches to workspace 3. This annoys me, because it effectively prevents me from cycling through workspaces on one screen. Greedyview I think would not have this issue, but the screen swapping confuses me. What I want is, when I'm on the left screen and I press mod-2, which is an already visible workspace, nothing should happen. No swapping of screens, and no moving of focus. The part of my config I'm trying to modify to achieve this is the last line below (the commented line). myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ ... (some key mappings) ... [((m .|. modm, k), windows $ f i) | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] -- , i `notelem` (visible workspaces) ] It seemed simple enough, but my understanding of Haskell is not quite there to understand the documentation. Bryan On 08/02/2012 09:53 AM, Brandon Allbery wrote:
On Thu, Aug 2, 2012 at 12:29 PM, Bryan Huh
wrote: How do you get a list of visible workspaces (only those workspaces that are displayed on the monitors)? Currently I get the entire list of workspaces in my xmonad config with (XMonad.workspaces conf). It looks like this command returns a list of strings, each of which denote a workspace (i.e. ["1", "2"... ] ). But not sure how to get a list of only those which are visible (I could also probably work with a list of hidden workspaces).
This depends to some extent on how you plan to use it; for example, when passing that list to an outside program using ppVisible or ppOrder from XMonad.Hooks.DynamicLog may be more convenient than other mechanisms.
The general case, however, is roughly along the lines of
visibleWorkspaces :: X [WorkspaceId] visibleWorkspaces = do ws <- gets windowset return $ map W.tag $ W.current ws : W.visible ws
Note that this is impure, so you can't simply drop it in place of (workspaces conf). If you give us more detail as to what you're trying to do, we can help you work it into your configuration properly.

On Thu, Aug 2, 2012 at 1:19 PM, Bryan Huh
What I'm trying to do is prevent my focus from switching to a different screen if I mistakenly try to switch to an already visible workspace. I already am not using greedyView so I don't have the problem of the visible workspaces swapping on me. But suppose I have two screens and workspace 1 is on the left, workspace 2 is on the right. If I'm focused on the left screen, and I were to press mod-2, the focus switches to the screen on the right. If I now press mod-3 it will be the right screen which switches to workspace 3. This annoys me, because it effectively prevents me from cycling through workspaces on one screen. Greedyview I think would not have this issue, but the screen swapping confuses me. What I want is, when I'm on the left screen and I press mod-2, which is an already visible workspace, nothing should happen. No swapping of screens, and no moving of focus.
viewHidden :: WorkspaceId -> X () viewHidden w = do ws <- gets windowset when (w `notElem` (map W.tag $ W.current ws : W.visible ws)) (W.view w) [((m .|. modm, k), windows $ f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(viewHidden, 0), (W.shift, shiftMask)]
It's not quite as simple as you'd hoped, because of the whole purity thing; "workspaces conf" doesn't change, but whether a workspace is visible or not is dynamic and special care needs to be taken with it. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

I'm sorry if this is a stupid question, but the xmonad.hs doesn't compile saying that "when" is out of scope. It seems to not recognize the keyword "when." I tried "if" as well but then it tells me there's a parse error. Are you sure that what you have compiles for you? On 08/02/2012 11:03 AM, Brandon Allbery wrote:
On Thu, Aug 2, 2012 at 1:19 PM, Bryan Huh
mailto:bhh1988@gmail.com> wrote: What I'm trying to do is prevent my focus from switching to a different screen if I mistakenly try to switch to an already visible workspace. I already am not using greedyView so I don't have the problem of the visible workspaces swapping on me. But suppose I have two screens and workspace 1 is on the left, workspace 2 is on the right. If I'm focused on the left screen, and I were to press mod-2, the focus switches to the screen on the right. If I now press mod-3 it will be the right screen which switches to workspace 3. This annoys me, because it effectively prevents me from cycling through workspaces on one screen. Greedyview I think would not have this issue, but the screen swapping confuses me. What I want is, when I'm on the left screen and I press mod-2, which is an already visible workspace, nothing should happen. No swapping of screens, and no moving of focus.
viewHidden :: WorkspaceId -> X () viewHidden w = do ws <- gets windowset when (w `notElem` (map W.tag $ W.current ws : W.visible ws)) (W.view w)
[((m .|. modm, k), windows $ f i) | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(viewHidden, 0), (W.shift, shiftMask)]
It's not quite as simple as you'd hoped, because of the whole purity thing; "workspaces conf" doesn't change, but whether a workspace is visible or not is dynamic and special care needs to be taken with it.
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Thu, Aug 2, 2012 at 2:20 PM, Bryan Huh
I'm sorry if this is a stupid question, but the xmonad.hs doesn't compile saying that "when" is out of scope. It seems to not recognize the keyword "when." I tried "if" as well but then it tells me there's a parse error. Are you sure that what you have compiles for you?
"when" isn't a keyword; it's a function defined in Control.Monad. (Haskell's laziness means that many things that would have to be baked-in syntax in other languages can be written as functions, and its syntax means those functions behave as if they *were* baked into the language.) So all you should need to do is add import Control.Monad (when) up with the other import statements. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

I see. That solved that problem, but now I get an error saying: Couldn't match expected type `W.Workspace i l a' against inferred type `W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail' In the first argument of `(:)', namely `W.current ws' In the second argument of `($)', namely `W.current ws : W.visible ws' In the second argument of `notElem', namely `(map W.tag $ W.current ws : W.visible ws)' and also in the line where I use viewHidden: Couldn't match expected type `X ()' against inferred type `W.StackSet WorkspaceId l a s sd -> W.StackSet WorkspaceId l a s sd' Expected type: (WorkspaceId -> X (), t) Inferred type: (WorkspaceId -> W.StackSet WorkspaceId l a s sd -> W.StackSet WorkspaceId l a s sd, KeyMask) In the expression: (W.shift, shiftMask) In the expression: [(viewHidden, 0), (W.shift, shiftMask)] I think the second error is probably because of the first, which seems to be a type mismatch. Is there a quick fix for this? Thanks for your help, Bryan On 08/02/2012 11:32 AM, Brandon Allbery wrote:
On Thu, Aug 2, 2012 at 2:20 PM, Bryan Huh
mailto:bhh1988@gmail.com> wrote: I'm sorry if this is a stupid question, but the xmonad.hs doesn't compile saying that "when" is out of scope. It seems to not recognize the keyword "when." I tried "if" as well but then it tells me there's a parse error. Are you sure that what you have compiles for you?
"when" isn't a keyword; it's a function defined in Control.Monad. (Haskell's laziness means that many things that would have to be baked-in syntax in other languages can be written as functions, and its syntax means those functions behave as if they *were* baked into the language.) So all you should need to do is add
import Control.Monad (when)
up with the other import statements.
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Thu, Aug 2, 2012 at 2:42 PM, Bryan Huh
I see. That solved that problem, but now I get an error saying:
*sigh* I tripped over the same problem I was trying to avoid in a different form... this will be harder to do than I'd hoped. (Forgot that it's already in a pure context; have to rearrange the whole thing to compensate) The viewHidden function now looks like viewHidden :: WorkspaceId -> X ()
viewHidden w = do ws <- gets windowset when (w `notElem` (map (W.tag . W.workspace) $ W.current ws : W.visible ws)) (windows $ W.view w)
and the list comprehension defining the workspace switching keys has now been refactored into: [((m .|. modm,k),f i)
| (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(viewHidden,0), (windows . W.shift,shiftMask)] ]
-- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Thanks a lot Brandon, that worked! Mostly based on what you wrote, I wrote another mapping that allows me to swap the left and right screens when I want to (it turns out that with my settings as I've described them to you, it takes a few keystrokes to switch the left and right screens, so I wanted to be able to do it with one keystroke, mod-w). I'm posting that here, in case anyone might ever try the same thing and won't know how to do it: swapView :: X () swapView = do ws <- gets windowset windows $ W.greedyView $ W.tag . W.workspace $ W.visible ws !! 0 And then my keybinding is: ((modm , xK_w), swapView) Probabl On 08/02/2012 12:23 PM, Brandon Allbery wrote:
On Thu, Aug 2, 2012 at 2:42 PM, Bryan Huh
mailto:bhh1988@gmail.com> wrote: I see. That solved that problem, but now I get an error saying:
*sigh* I tripped over the same problem I was trying to avoid in a different form... this will be harder to do than I'd hoped. (Forgot that it's already in a pure context; have to rearrange the whole thing to compensate)
The viewHidden function now looks like
viewHidden :: WorkspaceId -> X () viewHidden w = do ws <- gets windowset when (w `notElem` (map (W.tag . W.workspace) $ W.current ws : W.visible ws)) (windows $ W.view w)
and the list comprehension defining the workspace switching keys has now been refactored into:
[((m .|. modm,k),f i) | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(viewHidden,0), (windows . W.shift,shiftMask)] ]
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

Woops, accidentally sent before finishing my last line. "Probably not the most elegant solution, but it compiles and works great!" Thanks! A lot of this XMonad configuration is still a mystery to me, and any extra tips to understanding it would be appreciated! Bryan On 08/02/2012 12:23 PM, Brandon Allbery wrote:
On Thu, Aug 2, 2012 at 2:42 PM, Bryan Huh
mailto:bhh1988@gmail.com> wrote: I see. That solved that problem, but now I get an error saying:
*sigh* I tripped over the same problem I was trying to avoid in a different form... this will be harder to do than I'd hoped. (Forgot that it's already in a pure context; have to rearrange the whole thing to compensate)
The viewHidden function now looks like
viewHidden :: WorkspaceId -> X () viewHidden w = do ws <- gets windowset when (w `notElem` (map (W.tag . W.workspace) $ W.current ws : W.visible ws)) (windows $ W.view w)
and the list comprehension defining the workspace switching keys has now been refactored into:
[((m .|. modm,k),f i) | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] , (f, m) <- [(viewHidden,0), (windows . W.shift,shiftMask)] ]
-- brandon s allbery allbery.b@gmail.com mailto:allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (2)
-
Brandon Allbery
-
Bryan Huh