Want more features on Pastebin? Sign Up, it's FREE!
Guest

xmonad.hs

By: a guest on Jul 3rd, 2011  |  syntax: Haskell  |  size: 15.73 KB  |  views: 1,881  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --
  2. -- xmonad example config file for xmonad-0.9
  3. --
  4. -- A template showing all available configuration hooks,
  5. -- and how to override the defaults in your own xmonad.hs conf file.
  6. --
  7. -- Normally, you'd only override those defaults you care about.
  8. --
  9. -- NOTE: Those updating from earlier xmonad versions, who use
  10. -- EwmhDesktops, safeSpawn, WindowGo, or the simple-status-bar
  11. -- setup functions (dzen, xmobar) probably need to change
  12. -- xmonad.hs, please see the notes below, or the following
  13. -- link for more details:
  14. --
  15. -- http://www.haskell.org/haskellwiki/Xmonad/Notable_changes_since_0.8
  16. --
  17.  
  18. import XMonad
  19. import XMonad.Actions.FindEmptyWorkspace
  20. import XMonad.Hooks.DynamicLog
  21. import XMonad.Hooks.FadeInactive
  22. import XMonad.Hooks.ManageDocks
  23. import XMonad.Hooks.UrgencyHook
  24. import XMonad.Layout
  25. import XMonad.Layout.Grid
  26. import XMonad.Layout.IM
  27. import XMonad.Layout.NoBorders
  28. import XMonad.Layout.Tabbed
  29. import XMonad.Layout.ResizableTile
  30. import XMonad.Layout.Reflect
  31. import XMonad.Layout.Named
  32. import XMonad.Util.Run(spawnPipe)
  33. import Data.Monoid
  34. import Data.Ratio ((%))
  35. import Graphics.X11.ExtraTypes.XF86
  36. import System.Exit
  37. import System.IO
  38.  
  39. import qualified XMonad.StackSet as W
  40. import qualified Data.Map        as M
  41.  
  42. -- The preferred terminal program, which is used in a binding below and by
  43. -- certain contrib modules.
  44. --
  45. myTerminal      = "urxvt"
  46.  
  47. -- Whether focus follows the mouse pointer.
  48. myFocusFollowsMouse :: Bool
  49. myFocusFollowsMouse = True
  50.  
  51. -- Width of the window border in pixels.
  52. --
  53. myBorderWidth   = 1
  54.  
  55. -- modMask lets you specify which modkey you want to use. The default
  56. -- is mod1Mask ("left alt").  You may also consider using mod3Mask
  57. -- ("right alt"), which does not conflict with emacs keybindings. The
  58. -- "windows key" is usually mod4Mask.
  59. --
  60. myModMask       = mod4Mask
  61.  
  62. -- NOTE: from 0.9.1 on numlock mask is set automatically. The numlockMask
  63. -- setting should be removed from configs.
  64. --
  65. -- You can safely remove this even on earlier xmonad versions unless you
  66. -- need to set it to something other than the default mod2Mask, (e.g. OSX).
  67. --
  68. -- The mask for the numlock key. Numlock status is "masked" from the
  69. -- current modifier status, so the keybindings will work with numlock on or
  70. -- off. You may need to change this on some systems.
  71. --
  72. -- You can find the numlock modifier by running "xmodmap" and looking for a
  73. -- modifier with Num_Lock bound to it:
  74. --
  75. -- > $ xmodmap | grep Num
  76. -- > mod2        Num_Lock (0x4d)
  77. --
  78. -- Set numlockMask = 0 if you don't have a numlock key, or want to treat
  79. -- numlock status separately.
  80. --
  81. -- myNumlockMask   = mod2Mask -- deprecated in xmonad-0.9.1
  82. ------------------------------------------------------------
  83.  
  84.  
  85. -- The default number of workspaces (virtual screens) and their names.
  86. -- By default we use numeric strings, but any string may be used as a
  87. -- workspace name. The number of workspaces is determined by the length
  88. -- of this list.
  89. --
  90. -- A tagging example:
  91. --
  92. -- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
  93. --
  94. myWorkspaces    = ["1:net","2:dev","3:chat","4:music","5:misc","6:vbox","7:im","8:email","9:logs","0:*"]
  95.  
  96. -- Border colors for unfocused and focused windows, respectively.
  97. --
  98. myNormalBorderColor  = "#5A5A5A"
  99. myFocusedBorderColor = "#FF7700"
  100.  
  101. ------------------------------------------------------------------------
  102. -- Key bindings. Add, modify or remove key bindings here.
  103. --
  104. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  105.  
  106.     -- launch a terminal
  107.     [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
  108.  
  109.     -- launch dmenu
  110.     , ((modm,               xK_p     ), spawn "exe=`dmenu_path | dmenu -nb Black -nf Gray -sb Black -sf White ` && eval \"exec $exe\"")
  111.  
  112.     -- launch gmrun
  113.     , ((modm .|. shiftMask, xK_p     ), spawn "gmrun")
  114.  
  115.     -- close focused window
  116.     , ((modm .|. shiftMask, xK_c     ), kill)
  117.  
  118.      -- Rotate through the available layout algorithms
  119.     , ((modm,               xK_space ), sendMessage NextLayout)
  120.  
  121.     --  Reset the layouts on the current workspace to default
  122.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  123.  
  124.     -- Resize viewed windows to the correct size
  125.     , ((modm,               xK_n     ), refresh)
  126.  
  127.     -- Move focus to the next window
  128.     , ((modm,               xK_Tab   ), windows W.focusDown)
  129.  
  130.     -- Move focus to the next window
  131.     , ((modm,               xK_j     ), windows W.focusDown)
  132.  
  133.     -- Move focus to the previous window
  134.     , ((modm,               xK_k     ), windows W.focusUp  )
  135.  
  136.     -- Move focus to the master window
  137.     --, ((modm,               xK_m     ), windows W.focusMaster  )
  138.  
  139.     -- Swap the focused window and the master window
  140.     , ((modm,               xK_Return), windows W.swapMaster)
  141.  
  142.     -- Swap the focused window with the next window
  143.     , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
  144.  
  145.     -- Swap the focused window with the previous window
  146.     , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
  147.  
  148.     -- Shrink the master area
  149.     , ((modm,               xK_h     ), sendMessage Shrink)
  150.  
  151.     -- Expand the master area
  152.     , ((modm,               xK_l     ), sendMessage Expand)
  153.  
  154.     -- Push window back into tiling
  155.     , ((modm,               xK_t     ), withFocused $ windows . W.sink)
  156.  
  157.     -- Increment the number of windows in the master area
  158.     , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
  159.  
  160.     -- Deincrement the number of windows in the master area
  161.     , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
  162.  
  163.     -- Toggle the status bar gap
  164.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  165.     -- See also the statusBar function from Hooks.DynamicLog.
  166.     --
  167.     -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
  168.    
  169.     -- Lock screen
  170.         , ((modm .|. shiftMask  , xK_), spawn "xscreensaver-command -lock")
  171.    
  172.     -- Start galculator
  173.     , ((modm                            , xK_), spawn "galculator")
  174.    
  175.     -- Move to next empty workspace
  176.     , ((modm                            , xK_), viewEmptyWorkspace)
  177.    
  178.     -- Move focused window to next empty workspace and view
  179.     , ((modm .|. shiftMask      , xK_), tagToEmptyWorkspace)
  180.  
  181.     -- Quit xmonad
  182.     , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  183.  
  184.     -- Restart xmonad
  185.     , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
  186.    
  187.     -- Multimedia keys
  188.     --
  189.     -- Volume Up
  190.     , ((0, xF86XK_AudioRaiseVolume      ), spawn "amixer sset Master 1%+")
  191.     -- Volume Down
  192.     , ((0, xF86XK_AudioLowerVolume      ), spawn "amixer sset Master 1%-")
  193.     -- Mute On/Off
  194.     , ((0, xF86XK_AudioMute                     ), spawn "amixer sset Master toggle")
  195.     -- Play/Pause
  196.     , ((0, xF86XK_AudioPlay                     ), spawn "gmusicbrowser -launch_or_cmd PlayPause")
  197.     -- Next
  198.     , ((0, xF86XK_AudioNext                     ), spawn "gmusicbrowser -remotecmd NextSong")
  199.     -- Previous
  200.     , ((0, xF86XK_AudioPrev                     ), spawn "gmusicbrowser -remotecmd PrevSong")
  201.     -- Stop
  202.     , ((0, xF86XK_AudioStop                     ), spawn "gmusicbrowser -remotecmd Stop")
  203.     -- Lock screen
  204.     , ((0, xF86XK_Sleep                         ), spawn "gmusicbrowser -remotecmd Stop && xscreensaver-command -lock")
  205.     -- Calculator
  206.     , ((0, xF86XK_Calculator            ), spawn "galculator")
  207.     , ((0, xF86XK_Documents         ), spawn "beagle-search")
  208.     ]
  209.     ++
  210.  
  211.     --
  212.     -- mod-[1..9], Switch to workspace N
  213.     --
  214.     -- mod-[1..9], Switch to workspace N
  215.     -- mod-shift-[1..9], Move client to workspace N
  216.     --
  217.     [((m .|. modm, k), windows $ f i)
  218.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  219.         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  220.     ++
  221.  
  222.     --
  223.     -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  224.     -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  225.     --
  226.     [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  227.         | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  228.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  229.  
  230.  
  231. ------------------------------------------------------------------------
  232. -- Mouse bindings: default actions bound to mouse events
  233. --
  234. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  235.  
  236.     -- mod-button1, Set the window to floating mode and move by dragging
  237.     [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  238.                                        >> windows W.shiftMaster))
  239.  
  240.     -- mod-button2, Raise the window to the top of the stack
  241.     , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  242.  
  243.     -- mod-button3, Set the window to floating mode and resize by dragging
  244.     , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  245.                                        >> windows W.shiftMaster))
  246.  
  247.     -- you may also bind events to the mouse scroll wheel (button4 and button5)
  248.     ]
  249.  
  250. ------------------------------------------------------------------------
  251. -- Layouts:
  252.  
  253. -- You can specify and transform your layouts by modifying these values.
  254. -- If you change layout bindings be sure to use 'mod-shift-space' after
  255. -- restarting (with 'mod-q') to reset your layout state to the new
  256. -- defaults, as xmonad preserves your old layout settings by default.
  257. --
  258. -- * NOTE: XMonad.Hooks.EwmhDesktops users must remove the obsolete
  259. -- ewmhDesktopsLayout modifier from layoutHook. It no longer exists.
  260. -- Instead use the 'ewmh' function from that module to modify your
  261. -- defaultConfig as a whole. (See also logHook, handleEventHook, and
  262. -- startupHook ewmh notes.)
  263. --
  264. -- The available layouts.  Note that each layout is separated by |||,
  265. -- which denotes layout choice.
  266. --
  267. basicLayout = Tall nmaster delta ratio where
  268.     nmaster = 1
  269.     delta   = 3/100
  270.     ratio   = 2/3
  271. wideLayout = smartBorders(      named "wide"    $ Mirror basicLayout )
  272. tallLayout = smartBorders(      named "tall"    $ basicLayout )
  273. tabbedLayout = noBorders(       named "fulltab" $ simpleTabbed )
  274. imLayout = smartBorders(        named "im"              $ reflectHoriz $ gridIM (1%5) (Role "buddy_list"))
  275.  
  276. myLayout = (wideLayout ||| tallLayout ||| tabbedLayout ||| imLayout)
  277.  
  278.  
  279. ------------------------------------------------------------------------
  280. -- Window rules:
  281.  
  282. -- Execute arbitrary actions and WindowSet manipulations when managing
  283. -- a new window. You can use this to, for example, always float a
  284. -- particular program, or have a client always appear on a particular
  285. -- workspace.
  286. --
  287. -- To find the property name associated with a program, use
  288. -- > xprop | grep WM_CLASS
  289. -- and click on the client you're interested in.
  290. --
  291. -- To match on the WM_NAME, you can use 'title' in the same way that
  292. -- 'className' and 'resource' are used below.
  293. --
  294. myManageHook = composeAll
  295.     [ className =? "Vlc"                         --> doFloat
  296.     , className =? "Gimp"                        --> doFloat
  297.     , className =? "Galculator"                  --> doFloat
  298.     , className =? "Xmessage"                    --> doFloat
  299.     , className =? "Select Font"                                 --> doFloat
  300.     , className =? "gtk-chtheme"                                 --> doFloat
  301.     , className =? "search"                      --> doFloat
  302.     , className =? "Firefox Preferences"                 --> doFloat
  303.     , className =? "Firefox"                                     --> doShift "1:net"
  304.     , (className =? "Firefox" <&&> resource =? "Dialog") --> doFloat
  305.     , className =? "Gedit"                       --> doShift "1:net"
  306.     , className =? "Eclipse"                     --> doShift "2:dev"
  307.     , className =? "Geany"                       --> doShift "2:dev"
  308.     , className =? "Gvim"                                                --> doShift "2:dev"
  309.     , className =? "Xchat"                                               --> doShift "3:chat"
  310.     , className =? "Gmusicbrowser"               --> doShift "4:music"
  311.     , className =? "net-minecraft-LauncherFrame" --> doShift "5:misc"
  312.     , className =? "crawl-tiles"                 --> doShift "5:misc"
  313.     , className =? "VirtualBox"                  --> doShift "6:vbox"
  314.     , className =? "Pidgin"                                              --> doShift "7:im"
  315.     , className =? "Skype"                       --> doShift "7:im"
  316.     , className =? "Thunderbird"                                 --> doShift "8:email"
  317.     , resource  =? "desktop_window" --> doIgnore
  318.     , resource  =? "kdesktop"       --> doIgnore
  319.     , className =? "Gvim" --> (ask >>= \w -> liftX (setOpacity w 0xBFFFFFFF) >> idHook)
  320.     , manageDocks
  321.     ]
  322.  
  323. ------------------------------------------------------------------------
  324. -- Event handling
  325.  
  326. -- Defines a custom handler function for X Events. The function should
  327. -- return (All True) if the default handler is to be run afterwards. To
  328. -- combine event hooks use mappend or mconcat from Data.Monoid.
  329. --
  330. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  331. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  332. -- It will add EWMH event handling to your custom event hooks by
  333. -- combining them with ewmhDesktopsEventHook.
  334. --
  335. myEventHook = mempty
  336.  
  337. ------------------------------------------------------------------------
  338. -- Status bars and logging
  339.  
  340. -- Perform an arbitrary action on each internal state change or X event.
  341. -- See the 'XMonad.Hooks.DynamicLog' extension for examples.
  342. --
  343. --
  344. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  345. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  346. -- It will add EWMH logHook actions to your custom log hook by
  347. -- combining it with ewmhDesktopsLogHook.
  348. --
  349. myLogHook = return()
  350.  
  351. ------------------------------------------------------------------------
  352. -- My StatusBar
  353.  
  354. --
  355. -- Initialize all variables here that will be passed onto xmonad
  356. -- to start the StatusBar.
  357. -- myBar                        - Command used to run xmobar, prefer cusutom script over args here
  358. -- myPP                         - Custom appearance, XMonad.Hooks.DyanmicLog Doumentation for more
  359. -- toggetstrutsKey      - Keybinding to pass along with it all, toggles visibility
  360. --
  361.  
  362. myBar = "xmobar /home/kofrad/.xmobarrc"
  363. myPP = xmobarPP { ppCurrent     = xmobarColor "#FFFFFF" "" . wrap "[" "]",
  364.         --ppHiddenNoWindows             = xmobarColor "#5A5A5A" "",
  365.         ppUrgent                                = xmobarColor "#FFFFFF" "#FF0000" . wrap "" "*" . xmobarStrip,
  366.         ppTitle                                 = xmobarColor "#FF7700" "" . shorten 50,
  367.         ppSep                                   = " | "
  368.         }
  369. toggleStrutsKey XConfig {XMonad.modMask = myMmodMask} = (myModMask, xK_b)
  370.  
  371. ------------------------------------------------------------------------
  372. -- Startup hook
  373.  
  374. -- Perform an arbitrary action each time xmonad starts or is restarted
  375. -- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  376. -- per-workspace layout choices.
  377. --
  378. -- By default, do nothing.
  379. --
  380. -- * NOTE: EwmhDesktops users should use the 'ewmh' function from
  381. -- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
  382. -- It will add initialization of EWMH support to your custom startup
  383. -- hook by combining it with ewmhDesktopsStartup.
  384. --
  385. myStartupHook = return ()
  386.  
  387. ------------------------------------------------------------------------
  388. -- Now run xmonad with all the defaults we set up.
  389.  
  390. -- Run xmonad with the settings you specify. No need to modify this.
  391. --
  392. -- The main function.
  393.  
  394. main = xmonad =<< statusBar myBar myPP toggleStrutsKey (withUrgencyHook NoUrgencyHook $ myConfig)
  395.    
  396. myConfig = defaultConfig {
  397.   -- simple stuff
  398.     terminal           = myTerminal,
  399.     focusFollowsMouse  = myFocusFollowsMouse,
  400.     borderWidth        = myBorderWidth,
  401.     modMask            = myModMask,
  402.     -- numlockMask deprecated in 0.9.1
  403.     -- numlockMask        = myNumlockMask,
  404.     workspaces         = myWorkspaces,
  405.     normalBorderColor  = myNormalBorderColor,
  406.     focusedBorderColor = myFocusedBorderColor,
  407.  
  408.   -- key bindings
  409.     keys               = myKeys,
  410.     mouseBindings      = myMouseBindings,
  411.  
  412.   -- hooks, layouts
  413.     layoutHook         = avoidStruts $ myLayout,
  414.     manageHook         = myManageHook,
  415.     handleEventHook    = myEventHook,
  416.     logHook            = myLogHook,
  417.     startupHook        = myStartupHook
  418. }
clone this paste RAW Paste Data