Advertisement
Guest User

~/.xmonad/xmonad.hs

a guest
Mar 18th, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 12.96 KB | None | 0 0
  1. -- xmonad example config file.
  2. --
  3. -- A template showing all available configuration hooks,
  4. -- and how to override the defaults in your own xmonad.hs conf file.
  5. --
  6. -- Normally, you'd only override those defaults you care about.
  7. --
  8. import XMonad
  9. import System.Exit
  10. import System.IO (Handle, hPutStrLn)
  11. import XMonad.Actions.MouseResize
  12. import XMonad.Actions.UpdatePointer
  13. import XMonad.Layout.NoBorders
  14. import XMonad.Layout.PerWorkspace
  15. import XMonad.Layout.SimpleFloat
  16. import XMonad.Layout.WindowArranger
  17. import XMonad.Layout.LayoutHints
  18. import XMonad.Hooks.ManageDocks
  19. -- import XMonad.Hooks.UrgencyHook
  20. import XMonad.Hooks.ManageDocks
  21. import XMonad.Hooks.EwmhDesktops
  22. import XMonad.Hooks.DynamicLog
  23. import XMonad.Util.Run
  24.  
  25. import qualified XMonad.StackSet as W
  26. import qualified Data.Map as M
  27.  
  28. -- The preferred terminal program, which is used in a binding below and by
  29. -- certain contrib modules.
  30. --
  31. myTerminal = "urxvt"
  32.  
  33. -- Width of the window border in pixels.
  34. --
  35. myBorderWidth = 2
  36.  
  37. -- modMask lets you specify which modkey you want to use. The default
  38. -- is mod1Mask ("left alt"). You may also consider using mod3Mask
  39. -- ("right alt"), which does not conflict with emacs keybindings. The
  40. -- "windows key" is usually mod4Mask.
  41. --
  42. myModMask = mod4Mask
  43.  
  44. -- The mask for the numlock key. Numlock status is "masked" from the
  45. -- current modifier status, so the keybindings will work with numlock on or
  46. -- off. You may need to change this on some systems.
  47. --
  48. -- You can find the numlock modifier by running "xmodmap" and looking for a
  49. -- modifier with Num_Lock bound to it:
  50. --
  51. -- > $ xmodmap | grep Num
  52. -- > mod2 Num_Lock (0x4d)
  53. --
  54. -- Set numlockMask = 0 if you don't have a numlock key, or want to treat
  55. -- numlock status separately.
  56. --
  57. myNumlockMask = mod2Mask
  58.  
  59. -- The default number of workspaces (virtual screens) and their names.
  60. -- By default we use numeric strings, but any string may be used as a
  61. -- workspace name. The number of workspaces is determined by the length
  62. -- of this list.
  63. --
  64. -- A tagging example:
  65. --
  66. -- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
  67. --
  68. myWorkspaces = ["terminal","web","graphic","float","reader","full"]
  69.  
  70. -- Border colors for unfocused and focused windows, respectively.
  71. --
  72. myNormalBorderColor = "#2e3735"
  73. myFocusedBorderColor = "#afc81c"
  74.  
  75. -- Default offset of drawable screen boundaries from each physical
  76. -- screen. Anything non-zero here will leave a gap of that many pixels
  77. -- on the given edge, on the that screen. A useful gap at top of screen
  78. -- for a menu bar (e.g. 15)
  79. --
  80. -- An example, to set a top gap on monitor 1, and a gap on the bottom of
  81. -- monitor 2, you'd use a list of geometries like so:
  82. --
  83. -- > defaultGaps = [(18,0,0,0),(0,18,0,0)] -- 2 gaps on 2 monitors
  84. --
  85. -- Fields are: top, bottom, left, right.
  86. --
  87. myDefaultGaps = [(14,0,0,0)]
  88.  
  89. ------------------------------------------------------------------------
  90. -- Key bindings. Add, modify or remove key bindings here.
  91. --
  92. myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  93.  
  94.     -- launch a terminal
  95.     -- [ ((modMask .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
  96.  
  97.     -- close focused window
  98.     [ ((modMask .|. shiftMask, xK_c ), kill)
  99.  
  100.      -- Rotate through the available layout algorithms
  101.     , ((modMask, xK_space ), sendMessage NextLayout)
  102.  
  103.     -- Reset the layouts on the current workspace to default
  104.     , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  105.  
  106.     -- Resize viewed windows to the correct size
  107.     -- , ((modMask, xK_n ), refresh)
  108.  
  109.     -- Move focus to the next window
  110.     -- , ((modMask, xK_Tab ), windows W.focusDown)
  111.  
  112.     -- Move focus to the next window
  113.     , ((modMask, xK_j ), windows W.focusDown)
  114.  
  115.     -- Move focus to the previous window
  116.     , ((modMask, xK_k ), windows W.focusUp )
  117.  
  118.     -- Move focus to the master window
  119.     , ((modMask, xK_m ), windows W.focusMaster )
  120.  
  121.     -- Swap the focused window and the master window
  122.     , ((modMask, xK_Return), windows W.swapMaster)
  123.  
  124.     -- Swap the focused window with the next window
  125.     , ((modMask .|. shiftMask, xK_j ), windows W.swapDown )
  126.  
  127.     -- Swap the focused window with the previous window
  128.     , ((modMask .|. shiftMask, xK_k ), windows W.swapUp )
  129.  
  130.     -- Shrink the master area
  131.     , ((modMask, xK_h ), sendMessage Shrink)
  132.  
  133.     -- Expand the master area
  134.     , ((modMask, xK_l ), sendMessage Expand)
  135.  
  136.     -- Push window back into tiling
  137.     , ((modMask, xK_t ), withFocused $ windows . W.sink)
  138.  
  139.     -- Increment the number of windows in the master area
  140.     , ((modMask , xK_comma ), sendMessage (IncMasterN 1))
  141.  
  142.     -- Deincrement the number of windows in the master area
  143.     , ((modMask , xK_period), sendMessage (IncMasterN (-1)))
  144.  
  145.     -- toggle the status bar gap
  146.     , ((modMask , xK_b ), sendMessage ToggleStruts)
  147.  
  148.     -- Quit xmonad
  149.     , ((modMask .|. shiftMask, xK_q ), io (exitWith ExitSuccess))
  150.  
  151.     -- Restart xmonad
  152.     , ((modMask , xK_q ),
  153.           broadcastMessage ReleaseResources >> restart "xmonad" True)
  154.     ]
  155.     ++
  156.  
  157.     --
  158.     -- mod-[1..9], Switch to workspace N
  159.     -- mod-shift-[1..9], Move client to workspace N
  160.     --
  161.     [((m .|. modMask, k), windows $ f i)
  162.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  163.         , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  164.     ++
  165.  
  166.     --
  167.     -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  168.     -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  169.     --
  170.     [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
  171.         | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  172.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  173.  
  174.  
  175. ------------------------------------------------------------------------
  176. -- Mouse bindings: default actions bound to mouse events
  177. --
  178. myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
  179.  
  180.     -- mod-button1, Set the window to floating mode and move by dragging
  181.     [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
  182.  
  183.     -- mod-button2, Raise the window to the top of the stack
  184.     , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
  185.  
  186.     -- mod-button3, Set the window to floating mode and resize by dragging
  187.     , ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
  188.  
  189.     -- you may also bind events to the mouse scroll wheel (button4 and button5)
  190.     ]
  191.  
  192. ------------------------------------------------------------------------
  193. -- Layouts:
  194.  
  195. -- You can specify and transform your layouts by modifying these values.
  196. -- If you change layout bindings be sure to use 'mod-shift-space' after
  197. -- restarting (with 'mod-q') to reset your layout state to the new
  198. -- defaults, as xmonad preserves your old layout settings by default.
  199. --
  200. -- The available layouts. Note that each layout is separated by |||,
  201. -- which denotes layout choice.
  202. --
  203. -- myLayout = layoutHintsToCenter (avoidStruts (mouseResize $ windowArrange
  204. -- $ onWorkspaces ["float"] simpleFloat
  205. -- $ onWorkspaces ["reader", "full"] (noBorders Full ||| tiled1)
  206. -- $ onWorkspace "web" (noBorders Full ||| tiled2)
  207. -- $ (tiled1 ||| noBorders Full)))
  208. myLayout = avoidStruts (mouseResize $ windowArrange
  209.            $ onWorkspaces ["float"] simpleFloat
  210.            $ onWorkspaces ["reader", "full"] (noBorders Full ||| tiled1)
  211.            $ onWorkspace "web" (noBorders Full ||| tiled2)
  212.            $ (tiled1 ||| noBorders Full))
  213.   where
  214.      -- default tiling algorithm partitions the screen into two panes
  215.      tiled1 = Tall nmaster delta ratio1
  216.      tiled2 = Tall nmaster delta ratio2
  217.  
  218.      -- Try to use hinted tile
  219.     -- tiled1 = HintedTile nmaster delta ratio1 TopRight Tall
  220.     -- tiled1 = HintedTile nmaster delta ratio2 TopRight Tall
  221.  
  222.      -- The default number of windows in the master pane
  223.      nmaster = 1
  224.  
  225.      -- Default proportion of screen occupied by master pane
  226.      -- ratio1 = 214/350
  227.      ratio1 = 3/5
  228.      ratio2 = 2/3
  229.  
  230.      -- Percent of screen to increment by when resizing panes
  231.      delta = 1/50
  232.  
  233. ------------------------------------------------------------------------
  234. -- Window rules:
  235.  
  236. -- Execute arbitrary actions and WindowSet manipulations when managing
  237. -- a new window. You can use this to, for example, always float a
  238. -- particular program, or have a client always appear on a particular
  239. -- workspace.
  240. --
  241. -- To find the property name associated with a program, use
  242. -- > xprop | grep WM_CLASS
  243. -- and click on the client you're interested in.
  244. --
  245. -- To match on the WM_NAME, you can use 'title' in the same way that
  246. -- 'className' and 'resource' are used below.
  247. --
  248.  
  249. -- Functions to float Opera widgets
  250. mapFuncQuery f x q = fmap (f x) q
  251. first12Is a str = (take 12 str) == a
  252.  
  253. myManageHook = composeAll . concat $
  254.                [[ className =? c --> doFloat | c <- floats_local]
  255.                , [resource =? r --> doIgnore | r <- ignores]
  256.                -- , [className =? "Xpdf" --> doF (W.shift "reader")]
  257.                , [className =? c --> (doF (W.shift "web")) | c <- webs]
  258.                , [className =? c --> (doF (W.shift "reader")) | c <- readers]
  259.                , [className =? c --> (doF (W.shift "graphic")) | c <- graphics]
  260.                , [className =? c --> (doF (W.shift "full")) | c <- fulls]
  261.                , [className =? c --> (doF (W.shift "float")) | c <- floats]
  262.                , [(stringProperty "WM_ICON_NAME") =? "DX" --> doF (W.shift "float")]
  263.                , [(stringProperty "WM_ICON_NAME") =? "Mayavi2 - The 3D data visualizer" --> doF (W.shift "full")]
  264.                , [(mapFuncQuery first12Is "opera-widget" (stringProperty "WM_WINDOW_ROLE")) --> doFloat]
  265.                ]
  266.     where floats_local = ["MPlayer", "Smplayer", "Savebox", "Wine", "Pho", "Vncviewer",
  267.                     "display", "feh", "Xmessage", "FlightGear", "Tk", "Skype",
  268.                     "qemu-system-x86_64"]
  269.           webs = ["Firefox", "Opera"]
  270.           graphics = ["Gimp", "Inkscape"]
  271.           readers = ["Xpdf", "Okular", "Evince", "Acroread", "Zathura", "Dpv"]
  272.           fulls = ["Ktorrent", "Qbittorrent"]
  273.           floats = ["Pidgin", "Skype", "Gnucash"]
  274.           ignores = ["desktop_window", "kdesktop"]
  275.                    
  276. ------------------------------------------------------------------------
  277. -- Status bars and logging
  278.  
  279. -- Perform an arbitrary action on each internal state change or X event.
  280. -- See the 'DynamicLog' extension for examples.
  281. --
  282. -- To emulate dwm's status bar
  283. --
  284. -- > logHook = dynamicLogDzen
  285. --
  286. -- myLogHook = return ()
  287. ------------------------------------------------------------------------
  288. -- Now run xmonad with all the defaults we set up.
  289.  
  290. -- Run xmonad with the settings you specify. No need to modify this.
  291. --
  292.  
  293. myLogHook :: Handle -> X ()
  294. myLogHook dzen_proc = do
  295.   updatePointer Nearest
  296.   dynamicLogWithPP $ myDzenPP dzen_proc
  297.  
  298. dzenIconPrefix = "/home/corsair/.icons/dzen2/"
  299. dzenIconCurrent = dzenIconPrefix ++ "orig/has_win.xbm"
  300. dzenIconOccupied = dzenIconPrefix ++ "orig/has_win_nv.xbm"
  301. dzenIconFull = dzenIconPrefix ++ "orig/full.xbm"
  302. dzenIconTall = dzenIconPrefix ++ "orig/tall.xbm"
  303.  
  304. dzenIcon :: String -> String -- Path of icon -> dzen formatting str.
  305. dzenIcon icon = "^i(" ++ icon ++ ")"
  306.  
  307. myDzenPP :: Handle -> PP
  308. myDzenPP dzen_proc = defaultPP
  309.              {
  310.                ppCurrent = (\id -> (dzenIcon dzenIconCurrent) ++ (dzenColor "white" "black") id ++ " "),
  311.                ppVisible = (\id -> (dzenIcon dzenIconOccupied) ++ (dzenColor "#afc81c" "black") id ++ " "),
  312.                ppHidden = (\id -> (dzenIcon dzenIconOccupied) ++ (dzenColor "gray" "black") id ++ " "),
  313.                ppHiddenNoWindows = (\id -> " " ++ id ++ " "),
  314.                ppUrgent = dzenColor "red" "black" . dzenStrip,
  315.                ppWsSep = "",
  316.                ppSep = " ",
  317.                ppLayout = dzenColor "#8cad74" "black" .
  318.                             (\ x -> case x of
  319.                                       "Simple Float" -> "[~]"
  320.                                       "Tall" -> dzenIcon dzenIconTall
  321.                                       "Full" -> dzenIcon dzenIconFull
  322.                                       _ -> pad x
  323.                             ),
  324.                -- ppTitle = ("^bg(#324c80) " ++) . dzenEscape,
  325.                ppTitle = const "",
  326.                ppOutput = hPutStrLn dzen_proc
  327.              }
  328.  
  329. xMonadStatusBar = "dzen2 -x '0' -y '0' -h '14' -w '310' -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -ta l"
  330.  
  331. main = do
  332.   dzenProc <- spawnPipe xMonadStatusBar
  333.   xmonad $ ewmh defaultConfig {
  334.       -- simple stuff
  335.         terminal = myTerminal,
  336.         borderWidth = myBorderWidth,
  337.         modMask = myModMask,
  338.         numlockMask = myNumlockMask,
  339.         workspaces = myWorkspaces,
  340.         normalBorderColor = myNormalBorderColor,
  341.         focusedBorderColor = myFocusedBorderColor,
  342.  
  343.       -- key bindings
  344.         keys = myKeys,
  345.         mouseBindings = myMouseBindings,
  346.  
  347.       -- hooks, layouts
  348.         layoutHook = myLayout,
  349.         manageHook = myManageHook,
  350.         logHook = myLogHook dzenProc
  351.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement