XMonad: set default workspace on startup to specific monitor

xmonad

I'm using xmonad with a dual monitor setup.

Here is a stripped down version of my config:

import XMonad

main = do
  xmonad $ defaultConfig { 
    workspaces  = ["1:db", "2:mail", "3:web", "4:dev", "5", "6", "7", "8:chat", "9", "10"]
  }

Is there a way to configure it so that my left screen defaults to workspace 2:mail and right screen to workspace 3:web ?

Best Answer

Yes. There are two ways to achieve it:

  1. A trick to reorder your workspaces (assuming your left screen is the primary screen, you can use xrandr -q to check) workspaces = ["2:mail", "3:web", "4:dev", "5", "6", "7", "8:chat", "9", "10", "1:db"] associatedKeySyms = [xK_2 .. xK_9] ++ [xK_0, xK_1] The key here is the order of associatedKeySyms, since xmonad does not care the names for your workspaces. If you do not display the workspace names on your status bar, this will work. An even simpler way is to just change associatedKeySyms without changing workspaces. However, if you do need to display the workspace names (you may want to see "1:db" comes first and associated with mod+1), then you need to follow the next solution.

  2. Basically you need to hack StackSet in XMonad.StackSet (https://github.com/xmonad/xmonad/blob/master/src/XMonad/StackSet.hs) to manipulate the binding between screens and workspaces. You need to write the code into a startupHook in your config file so that it will be executed when xmonad is loaded.

You may also need XMonad.Actions.PhysicalScreens if you want to specify right or left screens instead of screen IDs.

I just start using xmonad, and I haven't done exactly what you want. I have similar needs, yet not only at xmonad startup. I try to hack both the startup procedure and the rescreen procedure (new monitor connected/disconnected), and hope you find some pieces of my configuration useful when you write yours. https://github.com/subbyte/subXMonad

Related Question