Advertisement
Guest User

xmonad.hs

a guest
Mar 3rd, 2011
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 11.60 KB | None | 0 0
  1. -- Imported libraries
  2. import XMonad
  3. import XMonad.Core
  4. import XMonad.Layout
  5. import XMonad.Layout.Gaps
  6. import XMonad.Layout.Grid
  7. import XMonad.Layout.Circle
  8. import XMonad.Layout.NoBorders
  9. import XMonad.Layout.ResizableTile
  10. import XMonad.Layout.MultiToggle
  11. import XMonad.Layout.MultiToggle.Instances
  12. import XMonad.Hooks.DynamicLog
  13. import XMonad.Hooks.ManageDocks
  14. import XMonad.Hooks.ManageHelpers
  15. import XMonad.Hooks.UrgencyHook
  16. import XMonad.Util.Run (spawnPipe)
  17. import XMonad.Actions.CycleWS (nextWS,prevWS)
  18. import Data.Monoid
  19. import Graphics.X11.Xlib
  20. import System.Exit
  21. import System.IO (Handle, hPutStrLn)
  22. import qualified XMonad.StackSet as W
  23. import qualified Data.Map        as M
  24. import qualified XMonad.Actions.FlexibleResize as Flex
  25.  
  26. -- Main
  27. main :: IO ()
  28. main = do
  29.     workspaceBar            <- spawnPipe myWorkspaceBar
  30.     trayerBar               <- spawnPipe myTrayerBar
  31.     topStatusBar            <- spawnPipe myTopStatusBar
  32.     xmonad $ withUrgencyHook NoUrgencyHook defaultConfig
  33.         { terminal           = myTerminal
  34.         , modMask            = myModMask
  35.         , focusFollowsMouse  = myFocusFollowsMouse
  36.         , borderWidth        = myBorderWidth
  37.         , normalBorderColor  = myNormalBorderColor
  38.         , focusedBorderColor = myFocusedBorderColor
  39.         , layoutHook         = myLayoutHook
  40.         , workspaces         = myWorkspaces
  41.         , manageHook         = manageDocks <+> manageHook defaultConfig <+> myManageHook
  42.         , logHook            = dynamicLogWithPP $ myDzenPP workspaceBar
  43.         , keys               = myKeys
  44.         , mouseBindings      = myMouseBindings
  45.         }
  46.  
  47. -- StatusBars
  48. myWorkspaceBar, myTrayerBar, myTopStatusBar :: String
  49. myWorkspaceBar = "dzen2 -x '0' -y '784' -h '16' -w '1080' -ta 'l' -fg '#ffffff' -bg '#000000' -fn 'snap:pixelsize=10' -p -e ''"
  50. myTrayerBar    = "/home/nnoell/.scripts/trayerbar.sh"
  51. myTopStatusBar = "/home/nnoell/.scripts/topstatusbar.zsh"
  52.  
  53. -- Terminal
  54. myTerminal :: String
  55. myTerminal = "urxvtc -e tmux"
  56.  
  57. -- ModMask
  58. myModMask :: KeyMask
  59. myModMask = mod4Mask
  60.  
  61. -- Focus follow mouse
  62. myFocusFollowsMouse :: Bool
  63. myFocusFollowsMouse = True
  64.  
  65. -- Border width
  66. myBorderWidth :: Dimension
  67. myBorderWidth = 1
  68.  
  69. -- Border colors
  70. myNormalBorderColor, myFocusedBorderColor :: String
  71. myNormalBorderColor  = "#000000"   --black
  72. myFocusedBorderColor = "#60a0c0"   --blue
  73. --myFocusedBorderColor = "#a488d9"   --purple
  74. --myFocusedBorderColor = "#82ca42"   --green
  75. --myFocusedBorderColor = "#0085cc"   --cyan
  76.  
  77. -- Layout hook
  78. myLayoutHook = gaps [(U,16), (D,16), (L,0), (R,0)]
  79.     $ avoidStruts
  80.     $ mkToggle1 NBFULL
  81.     $ smartBorders (tiled ||| Mirror tiled ||| Circle ||| Grid ||| Full)
  82.     where
  83.         tiled   = ResizableTall nmaster delta ratio []
  84.         nmaster = 1
  85.         ratio   = 1/2
  86.         delta   = 3/100
  87.  
  88. -- Workspaces
  89. myWorkspaces :: [WorkspaceId]
  90. myWorkspaces = clickable $
  91.     [" ^i(/home/nnoell/.icons/subtlexbm/terminal.xbm) term " --0
  92.     ," ^i(/home/nnoell/.icons/subtlexbm/fox.xbm) web "       --1
  93.     ," ^i(/home/nnoell/.icons/subtlexbm/binder.xbm) code "   --2
  94.     ," ^i(/home/nnoell/.icons/subtlexbm/mouse.xbm) gfx "     --3
  95.     ," ^i(/home/nnoell/.icons/subtlexbm/balloon.xbm) chat "  --4
  96.     ," ^i(/home/nnoell/.icons/subtlexbm/note1.xbm) music "   --5
  97.     ," ^i(/home/nnoell/.icons/subtlexbm/movie.xbm) video "   --6
  98.     ," ^i(/home/nnoell/.icons/subtlexbm/shroom.xbm) other "  --7
  99.     ]
  100.     where clickable l = [ "^ca(1,xdotool key super+" ++ show (n) ++ ")" ++ ws ++ "^ca()" |
  101.         (i,ws) <- zip [1..] l,
  102.         let n = if i == 10 then 0 else i ]
  103.  
  104. -- Manage hook
  105. myManageHook :: ManageHook
  106. myManageHook = (composeAll . concat $
  107.     [ [resource     =? r     --> doIgnore                      |   r   <- myIgnores] --ignore desktop
  108.     , [className    =? c     --> doShift (myWorkspaces !! 1)   |   c   <- myWebS   ] --move myWebS windows to workspace 1 by classname
  109.     , [className    =? c     --> doShift (myWorkspaces !! 4)   |   c   <- myChatS  ] --move myChatS windows to workspace 4 by classname
  110.     , [className    =? c     --> doShift (myWorkspaces !! 3)   |   c   <- myGfxS   ] --move myGfxS windows to workspace 4 by classname
  111.     , [className    =? c     --> doShift (myWorkspaces !! 5)   |   c   <- myMusicS ] --move myMusiS windows to workspace 5 by classname
  112.     , [className    =? c     --> doFloat                       |   c   <- myFloatFC] --float geometry by classname
  113.     , [className    =? c     --> doCenterFloat                 |   c   <- myFloatCC] --float center geometry by classname
  114.     , [name         =? n     --> doCenterFloat                 |   n   <- myFloatCN] --float center geometry by name
  115.     , [name         =? n     --> doSideFloat NW                |   n   <- myFloatSN] --float side NW geometry by name
  116.     , [composeOne   [ isFullscreen -?> doFullFloat ]]
  117.     ])
  118.     where
  119.         role      = stringProperty "WM_WINDOW_ROLE"
  120.         name      = stringProperty "WM_NAME"
  121.         myIgnores = ["desktop","desktop_window"]
  122.         myWebS    = ["Chromium","Namoroka"]
  123.         myGfxS    = ["Gimp"]
  124.         myChatS   = ["Pidgin", "Xchat"]
  125.         myMusicS  = ["Clementine"]
  126.         myFloatFC = ["Gimp", "Oblogout"]
  127.         myFloatCC = ["File-roller", "zsnes", "Gmrun", "Gcalctool", "Gnome-power-preferences"]
  128.         myFloatCN = ["ePSXe - Enhanced PSX emulator", "Seleccione Archivo", "Config Video", "Testing plugin", "Config Sound", "Config Cdrom", "Config Bios", "Config Netplay", "Config Memcards", "About ePSXe", "Config Controller", "Config Gamepads", "Select one or more files to open", "Add media", "Choose a file", "Open Image", "File Operation Progress", "Chromium Preferences", "Namoroka Preferences", "Preferences", "Search Engines", "Set up sync", "Passwords and Exceptions", "Autofill Options"]
  129.         myFloatSN = ["gimp-toolbox-color-dialog", "Event Tester"]
  130.  
  131. -- myWorkspaceBar config
  132. myDzenPP h = defaultPP
  133.     { ppOutput          = hPutStrLn h
  134.     , ppSep             = ""
  135.     , ppWsSep           = ""
  136.     , ppCurrent         = wrap "^fg(#ffffff)^bg(#60a0c0)" "^fg()^bg()"
  137.     , ppUrgent          = wrap "^fg(#ffffff)^bg(#aff73e)" "^fg()^bg()"
  138.     , ppVisible         = wrap "^fg(#b8bcb8)^bg(#484848)" "^fg()^bg()"
  139.     , ppHidden          = wrap "^fg(#b8bcb8)^bg(#484848)" "^fg()^bg()"
  140.     , ppHiddenNoWindows = wrap "^fg(#484848)^bg(#000000)" "^fg()^bg()"
  141.     , ppTitle           = wrap "^fg(#9d9d9d)^bg(#000000)" "^fg()^bg()" . wrap "" " ^fg(#a488d9)>^fg(#60a0c0)>^fg(#444444)>"
  142.     , ppLayout          = wrap "^fg(#60a0c0)^bg(#000000)" "^fg()^bg()" .
  143.         (\x -> case x of
  144.             "ResizableTall"        -> " ^i(/home/nnoell/.icons/xbm8x8/tall.xbm) "
  145.             "Mirror ResizableTall" -> " ^i(/home/nnoell/.icons/xbm8x8/mtall.xbm) "
  146.             "Circle"               -> " ^i(/home/nnoell/.icons/xbm8x8/circle.xbm) "
  147.             "Grid"                 -> " ^i(/home/nnoell/.icons/xbm8x8/grid.xbm) "
  148.             "Full"                 -> " ^i(/home/nnoell/.icons/xbm8x8/full2.xbm) "
  149.         )
  150.     }
  151.  
  152. -- Key bindings
  153. myKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
  154. myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  155.     [ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)        --Launch a terminal
  156.     , ((mod1Mask , xK_F2), spawn "gmrun")                                       --Launch gmrun
  157.     , ((modMask , xK_o), spawn "sudo oblogout")                                 --Launch oblogout
  158.     , ((mod1Mask , xK_F3), spawn "chromium")                                    --Launch chromium
  159.     , ((modMask, xK_c), kill)                                                   --Close focused window
  160.     , ((mod1Mask, xK_F4), kill)
  161.     , ((modMask, xK_space), sendMessage NextLayout)                             --Rotate through the available layout algorithms
  162.     , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)  --Reset the layouts on the current workspace to default
  163.     , ((modMask, xK_n), refresh)                                                --Resize viewed windows to the correct size
  164.     , ((mod1Mask, xK_Tab), windows W.focusDown)                                 --Move focus to the next window
  165.     , ((modMask, xK_Tab), windows W.focusDown)
  166.     , ((modMask, xK_j), windows W.focusDown)
  167.     , ((modMask, xK_k), windows W.focusUp  )                                    --Move focus to the previous window
  168.     , ((modMask, xK_m), windows W.focusMaster  )                                --Move focus to the master window
  169.     , ((modMask, xK_Return), windows W.swapMaster)                              --Swap the focused window and the master window
  170.     , ((modMask .|. shiftMask, xK_j), windows W.swapDown  )                     --Swap the focused window with the next window
  171.     , ((modMask .|. shiftMask, xK_k), windows W.swapUp    )                     --Swap the focused window with the previous window
  172.     , ((modMask, xK_h), sendMessage Shrink)                                     --Shrink the master area
  173.     , ((modMask .|. shiftMask, xK_Left), sendMessage Shrink)
  174.     , ((modMask, xK_l), sendMessage Expand)                                     --Expand the master area
  175.     , ((modMask .|. shiftMask, xK_Right), sendMessage Expand)
  176.     , ((modMask .|. shiftMask, xK_h), sendMessage MirrorShrink)                 --MirrorShrink the master area
  177.     , ((modMask .|. shiftMask, xK_Down), sendMessage MirrorShrink)
  178.     , ((modMask .|. shiftMask, xK_l), sendMessage MirrorExpand)                 --MirrorExpand the master area
  179.     , ((modMask .|. shiftMask, xK_Up), sendMessage MirrorExpand)
  180.     , ((modMask, xK_t), withFocused $ windows . W.sink)                         --Push window back into tiling
  181.     , ((modMask, xK_f), sendMessage $ Toggle NBFULL)                            --Push layout into full
  182.     , ((modMask .|. shiftMask, xK_f), fullFloatFocused)                         --Push window into full screen
  183.     , ((modMask, xK_comma), sendMessage (IncMasterN 1))                         --Increment the number of windows in the master area
  184.     , ((modMask, xK_period), sendMessage (IncMasterN (-1)))                     --Deincrement the number of windows in the master area
  185.     , ((modMask , xK_d), spawn "killall dzen2 trayer")                          --Kill dzen2 and trayer
  186.     , ((modMask , xK_s), spawn "xscreensaver-command -lock")                    --Lock screen
  187.     , ((modMask .|. shiftMask, xK_q), io (exitWith ExitSuccess))                --Quit xmonad
  188.     , ((modMask, xK_q), restart "xmonad" True)                                  --Restart xmonad
  189.     , ((mod1Mask .|. controlMask, xK_Left),  prevWS)                            --Move to previous Workspace
  190.     , ((modMask, xK_Left), prevWS)
  191.     , ((modMask, xK_Right), nextWS)                                             --Move to next Workspace
  192.     , ((mod1Mask .|. controlMask, xK_Right),  nextWS)
  193.     ]
  194.     ++
  195.     [((m .|. modMask, k), windows $ f i)                                        --Switch to n workspaces and send client to n workspaces
  196.       | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  197.       , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  198.     ++
  199.     [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f)) --Switch to n screens and send client to n screens
  200.       | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  201.       , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  202.     where
  203.         fullFloatFocused = withFocused $ \f -> windows =<< appEndo `fmap` runQuery doFullFloat f
  204.  
  205. -- Mouse bindings
  206. myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
  207.     [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w >> windows W.shiftMaster)) -- set the window to floating mode and move by dragging
  208.     , ((modMask, button2), (\w -> focus w >> windows W.shiftMaster))                      -- raise the window to the top of the stack
  209.     , ((modMask, button3), (\w -> focus w >> Flex.mouseResizeWindow w))                   -- set the window to floating mode and resize by dragging
  210.     , ((modMask, button4), (\_ -> prevWS))                                                -- switch to previous workspace
  211.     , ((modMask, button5), (\_ -> nextWS))                                                -- switch to next workspace
  212.     ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement