[xmonad] XMonad.Actions.DynamicWorkspaces selectWorkspace prompt nitpicking

Brent Yorgey byorgey at seas.upenn.edu
Thu Apr 28 17:09:55 CEST 2011


On Wed, Apr 27, 2011 at 09:04:53PM -0500, Joseph Garvin wrote:
> Because selectWorkspace only takes an XPConfig, I don't think there's
> anyway for me to customize it, without diving into the extension's
> code. Am I right? Or is there a better way?

Correct.  However, diving into the code is much easier than you might
think.  Let's take a look at the code for selectWorkspace:

selectWorkspace :: XPConfig -> X ()
selectWorkspace conf = workspacePrompt conf $ \w ->
                       do s <- gets windowset
                          if W.tagMember w s
                            then windows $ W.greedyView w
                            else addWorkspace w

Pretty straightforward.  Create a prompt that autocompletes on
workspace, get the windowset, check whether what the user entered is a
tag in the window set, and if so, view it, otherwise add a new
workspace.

(I'm assuming that you have

  import qualified XMonad.StackSet as W

at the top of your xmonad.hs; if not you can add it.)

> -If I don't type a workspace name and just hit enter, it assumes I
> want to create an unnamed workspace. I'd prefer it did nothing.

This can be accomplished just by changing 'addWorkspace w' to 'return
()' (i.e. do nothing):

selectWorkspace' :: XPConfig -> X ()
selectWorkspace' conf = workspacePrompt conf $ \w ->
                        do s <- gets windowset
                           if W.tagMember w s
                             then windows $ W.greedyView w
                             else return ()

> -selectWorkspace appears to act more like "selectOrAddWorkspace." If
> you type the name of a workspace that doesn't exist, it creates it.
> I'd prefer it pick the workspace I would have gotten had I pressed tab
> to do completion first.

To accomplish this we can change the 'tagMember w s' test, with a
tiny bit of work to implement the search for completions.  Just paste
this in your xmonad.hs and you're set.

  import Data.List    -- be sure to include this at the top of your
                      -- xmonad.hs, for 'find' and 'isPrefixOf'
  import qualified XMonad.StackSet as W  -- this is needed too

  findTag p = find p . map W.tag . W.workspaces

  selectWorkspace' :: XPConfig -> X ()
  selectWorkspace' conf = workspacePrompt conf $ \w ->
                          do s <- gets windowset
                             case findTag (w `isPrefixOf`) s of
                               Just w' -> windows $ W.greedyView w'
                               Nothing -> return ()

There is certainly a good argument to be made that DynamicWorkspaces
ought to be made more general, but this should get you what you want
without too much trouble.

-Brent



More information about the xmonad mailing list