[xmonad] DynamicWorkspaceOrder of a tag

Brent Yorgey byorgey at seas.upenn.edu
Tue Feb 19 22:16:41 CET 2013

Hi Jonas,

On Fri, Feb 08, 2013 at 10:00:04PM +0000, Jonas wrote:
> Hello everyone,
> (I am an "awesome" convert new to xmonad and I hope this is the right
> place to ask this question and I am not unknowingly violating some
> etiquette. If so, please forgive and tell me.)

This is the right place!  Sorry for the long time with no response.
The xmonad mailing list is friendly but not always the most responsive.

> I am using DynamicWorkspaceOrder and want to know the number of a
> workspace in this order.
> Basically I am looking for the number that "withNthWorkspace" would use.
> So given a tag, how can I get its place in the DynamicWorkspaceOrder?
> Alternatively how can I get a list of all the workspaces in their
> DynamicWorkspaceOrder?

It's useful to take a look at how withNthWorkspace is implemented:

withNthWorkspace :: (String -> WindowSet -> WindowSet) -> Int -> X ()
withNthWorkspace job wnum = do
  sort <- getSortByOrder
  ws <- gets (map W.tag . sort . W.workspaces . windowset)
  case drop wnum ws of
    (w:_) -> windows $ job w
    []    -> return ()

The first two lines there result in a list of all the workspace tags
in the order you want.  First we get the appropriate sorting function,
and then grab the xmonad state (with 'gets'), get the list of
workspaces, sort it, and then project out the tags.

Once you have this list you can easily go from tag to index using the
'findIndex' function.  But given what you want to do, it may be easier
to just get the sorted list of tags and then use something like
'zipWith' to combine it with index numbers.


More information about the xmonad mailing list