xmonad.hs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. -- xmonad config used by Vic Fryzel
  2. -- Author: Vic Fryzel
  3. -- http://github.com/vicfryzel/xmonad-config
  4. import System.IO
  5. import System.Exit
  6. import XMonad
  7. import XMonad.Hooks.DynamicLog
  8. import XMonad.Hooks.ManageDocks
  9. import XMonad.Hooks.ManageHelpers
  10. import XMonad.Hooks.SetWMName
  11. import XMonad.Layout.Fullscreen
  12. import XMonad.Layout.NoBorders
  13. import XMonad.Layout.Spiral
  14. import XMonad.Actions.SpawnOn
  15. import XMonad.Layout.PerWorkspace
  16. import XMonad.Layout.Tabbed
  17. import XMonad.Layout.ThreeColumns
  18. import XMonad.Util.Run(spawnPipe)
  19. import XMonad.Util.EZConfig(additionalKeys)
  20. import Graphics.X11.ExtraTypes.XF86
  21. import qualified XMonad.StackSet as W
  22. import qualified Data.Map as M
  23. ------------------------------------------------------------------------
  24. -- Terminal
  25. -- The preferred terminal program, which is used in a binding below and by
  26. -- certain contrib modules.
  27. --
  28. -- myTerminal = "/usr/bin/gnome-terminal"
  29. myTerminal = "/usr/bin/roxterm"
  30. -- The command to lock the screen or show the screensaver.
  31. myScreensaver = "/usr/bin/gnome-screensaver-command --lock"
  32. -- The command to take a selective screenshot, where you select
  33. -- what you'd like to capture on the screen.
  34. mySelectScreenshot = "select-screenshot"
  35. -- The command to take a fullscreen screenshot.
  36. myScreenshot = "screenshot"
  37. -- The command to use as a launcher, to launch commands that don't have
  38. -- preset keybindings.
  39. -- myLauncher = "$(yeganesh -x -- -fn '-*-terminus-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -nb '#000000' -nf '#FFFFFF' -sb '#7C7C7C' -sf '#CEFFAC')"
  40. myLauncher = "$(lxpanelctl run)"
  41. ------------------------------------------------------------------------
  42. -- Workspaces
  43. -- The default number of workspaces (virtual screens) and their names.
  44. --
  45. -- myWorkspaces = ["1:web","2:term","3:code","4:vm","5:media"] ++ map show [6..9]
  46. myWorkspaces = ["1:web","2:term","3:code","4:vm","5:media"] ++ map show [6..9]
  47. ------------------------------------------------------------------------
  48. -- Window rules
  49. -- Execute arbitrary actions and WindowSet manipulations when managing
  50. -- a new window. You can use this to, for example, always float a
  51. -- particular program, or have a client always appear on a particular
  52. -- workspace.
  53. --
  54. -- To find the property name associated with a program, use
  55. -- > xprop | grep WM_CLASS
  56. -- and click on the client you're interested in.
  57. --
  58. -- To match on the WM_NAME, you can use 'title' in the same way that
  59. -- 'className' and 'resource' are used below.
  60. --
  61. myManageHook = composeAll
  62. [ className =? "Chromium" --> doShift "2:web"
  63. , className =? "Google-chrome" --> doShift "2:web"
  64. , className =? "Firefox" --> doShift "1:web"
  65. , className =? "ROXTerm" --> doShift "2:term"
  66. , resource =? "desktop_window" --> doIgnore
  67. , className =? "Galculator" --> doFloat
  68. , className =? "Steam" --> doFloat
  69. , className =? "Gimp" --> doFloat
  70. , resource =? "gpicview" --> doFloat
  71. , className =? "MPlayer" --> doFloat
  72. , className =? "VirtualBox" --> doShift "4:vm"
  73. , className =? "Xchat" --> doShift "5:media"
  74. , className =? "stalonetray" --> doIgnore
  75. , isFullscreen --> (doF W.focusDown <+> doFullFloat)]
  76. ------------------------------------------------------------------------
  77. -- Layouts
  78. -- You can specify and transform your layouts by modifying these values.
  79. -- If you change layout bindings be sure to use 'mod-shift-space' after
  80. -- restarting (with 'mod-q') to reset your layout state to the new
  81. -- defaults, as xmonad preserves your old layout settings by default.
  82. --
  83. -- The available layouts. Note that each layout is separated by |||,
  84. -- which denotes layout choice.
  85. --
  86. myLayout = avoidStruts (
  87. spiral (6/7)) |||
  88. Mirror (Tall 1 (3/100) (1/2)) |||
  89. noBorders (fullscreenFull Full)
  90. -- ThreeColMid 1 (3/100) (1/2) |||
  91. -- Tall 1 (3/100) (1/2) |||
  92. -- tabbed shrinkText tabConfig |||
  93. -- Full |||
  94. ------------------------------------------------------------------------
  95. -- Colors and borders
  96. -- Currently based on the ir_black theme.
  97. --
  98. myNormalBorderColor = "#7c7c7c"
  99. myFocusedBorderColor = "#ffb6b0"
  100. -- Colors for text and backgrounds of each tab when in "Tabbed" layout.
  101. tabConfig = defaultTheme {
  102. activeBorderColor = "#7C7C7C",
  103. activeTextColor = "#CEFFAC",
  104. activeColor = "#000000",
  105. inactiveBorderColor = "#7C7C7C",
  106. inactiveTextColor = "#EEEEEE",
  107. inactiveColor = "#000000"
  108. }
  109. -- Color of current window title in xmobar.
  110. xmobarTitleColor = "#FFB6B0"
  111. -- Color of current workspace in xmobar.
  112. xmobarCurrentWorkspaceColor = "#CEFFAC"
  113. -- Width of the window border in pixels.
  114. myBorderWidth = 1
  115. ------------------------------------------------------------------------
  116. -- Key bindings
  117. --
  118. -- modMask lets you specify which modkey you want to use. The default
  119. -- is mod1Mask ("left alt"). You may also consider using mod3Mask
  120. -- ("right alt"), which does not conflict with emacs keybindings. The
  121. -- "windows key" is usually mod4Mask.
  122. --
  123. -- myModMask = mod1Mask
  124. myModMask = mod4Mask
  125. myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  126. ----------------------------------------------------------------------
  127. -- Custom key bindings
  128. -- Start a terminal. Terminal to start is specified by myTerminal variable.
  129. [ ((modMask .|. shiftMask, xK_Return),
  130. spawn $ XMonad.terminal conf)
  131. -- Lock the screen using command specified by myScreensaver.
  132. , ((modMask .|. controlMask, xK_l),
  133. spawn myScreensaver)
  134. -- Spawn the launcher using command specified by myLauncher.
  135. -- Use this to launch programs without a key binding.
  136. -- , ((modMask, xK_p),
  137. , ((modMask, xK_F2),
  138. spawn myLauncher)
  139. -- Take a selective screenshot using the command specified by mySelectScreenshot.
  140. , ((modMask .|. shiftMask, xK_p),
  141. spawn mySelectScreenshot)
  142. -- Take a full screenshot using the command specified by myScreenshot.
  143. , ((modMask .|. controlMask .|. shiftMask, xK_p),
  144. spawn myScreenshot)
  145. -- Mute volume.
  146. -- , ((0, xF86XK_AudioMute),
  147. -- spawn "amixer -q set Master toggle")
  148. -- Decrease volume.
  149. , ((0, xF86XK_AudioLowerVolume),
  150. -- spawn "amixer -q set Master 10%-")
  151. spawn "pamixer -d 10")
  152. -- Increase volume.
  153. , ((0, xF86XK_AudioRaiseVolume),
  154. -- spawn "amixer -q set Master 10%+")
  155. spawn "pamixer -i 10")
  156. -- Mute volume.
  157. , ((modMask .|. controlMask, xK_m),
  158. spawn "pamixer -t")
  159. -- Decrease volume.
  160. , ((modMask .|. controlMask, xK_j),
  161. spawn "amixer -q set Master 10%-")
  162. -- Increase volume.
  163. , ((modMask .|. controlMask, xK_k),
  164. spawn "amixer -q set Master 10%+")
  165. -- Audio previous.
  166. , ((0, 0x1008FF16),
  167. spawn "")
  168. -- Play/pause.
  169. , ((0, 0x1008FF14),
  170. spawn "")
  171. -- Audio next.
  172. , ((0, 0x1008FF17),
  173. spawn "")
  174. -- Eject CD tray.
  175. , ((0, 0x1008FF2C),
  176. spawn "eject -T")
  177. --------------------------------------------------------------------
  178. -- "Standard" xmonad key bindings
  179. --
  180. -- Close focused window.
  181. , ((modMask .|. shiftMask, xK_c),
  182. kill)
  183. -- Cycle through the available layout algorithms.
  184. , ((modMask, xK_space),
  185. sendMessage NextLayout)
  186. -- Reset the layouts on the current workspace to default.
  187. , ((modMask .|. shiftMask, xK_space),
  188. setLayout $ XMonad.layoutHook conf)
  189. -- Resize viewed windows to the correct size.
  190. , ((modMask, xK_n),
  191. refresh)
  192. -- Move focus to the next window.
  193. , ((modMask, xK_Tab),
  194. windows W.focusDown)
  195. -- Move focus to the next window.
  196. , ((modMask, xK_j),
  197. windows W.focusDown)
  198. -- Move focus to the previous window.
  199. , ((modMask, xK_k),
  200. windows W.focusUp )
  201. -- Move focus to the master window.
  202. , ((modMask, xK_m),
  203. windows W.focusMaster )
  204. -- Swap the focused window and the master window.
  205. , ((modMask, xK_Return),
  206. windows W.swapMaster)
  207. -- Swap the focused window with the next window.
  208. , ((modMask .|. shiftMask, xK_j),
  209. windows W.swapDown )
  210. -- Swap the focused window with the previous window.
  211. , ((modMask .|. shiftMask, xK_k),
  212. windows W.swapUp )
  213. -- Shrink the master area.
  214. , ((modMask, xK_h),
  215. sendMessage Shrink)
  216. -- Expand the master area.
  217. , ((modMask, xK_l),
  218. sendMessage Expand)
  219. -- Push window back into tiling.
  220. , ((modMask, xK_t),
  221. withFocused $ windows . W.sink)
  222. -- Increment the number of windows in the master area.
  223. , ((modMask, xK_comma),
  224. sendMessage (IncMasterN 1))
  225. -- Decrement the number of windows in the master area.
  226. , ((modMask, xK_period),
  227. sendMessage (IncMasterN (-1)))
  228. -- Toggle the status bar gap.
  229. -- TODO: update this binding with avoidStruts, ((modMask, xK_b),
  230. -- Quit xmonad.
  231. , ((modMask .|. shiftMask, xK_q),
  232. io (exitWith ExitSuccess))
  233. -- Restart xmonad.
  234. , ((modMask, xK_q),
  235. restart "xmonad" True)
  236. ]
  237. ++
  238. -- mod-[1..9], Switch to workspace N
  239. -- mod-shift-[1..9], Move client to workspace N
  240. [((m .|. modMask, k), windows $ f i)
  241. | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  242. , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  243. ++
  244. -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  245. -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  246. [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
  247. | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  248. , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  249. ------------------------------------------------------------------------
  250. -- Mouse bindings
  251. --
  252. -- Focus rules
  253. -- True if your focus should follow your mouse cursor.
  254. myFocusFollowsMouse :: Bool
  255. myFocusFollowsMouse = True
  256. myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
  257. [
  258. -- mod-button1, Set the window to floating mode and move by dragging
  259. ((modMask, button1),
  260. (\w -> focus w >> mouseMoveWindow w))
  261. -- mod-button2, Raise the window to the top of the stack
  262. , ((modMask, button2),
  263. (\w -> focus w >> windows W.swapMaster))
  264. -- mod-button3, Set the window to floating mode and resize by dragging
  265. , ((modMask, button3),
  266. (\w -> focus w >> mouseResizeWindow w))
  267. -- you may also bind events to the mouse scroll wheel (button4 and button5)
  268. ]
  269. ------------------------------------------------------------------------
  270. -- Status bars and logging
  271. -- Perform an arbitrary action on each internal state change or X event.
  272. -- See the 'DynamicLog' extension for examples.
  273. --
  274. -- To emulate dwm's status bar
  275. --
  276. -- > logHook = dynamicLogDzen
  277. --
  278. ------------------------------------------------------------------------
  279. -- Startup hook
  280. -- Perform an arbitrary action each time xmonad starts or is restarted
  281. -- with mod-q. Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  282. -- per-workspace layout choices.
  283. --
  284. -- By default, do nothing.
  285. myStartupHook = return ()
  286. ------------------------------------------------------------------------
  287. -- Run xmonad with all the defaults we set up.
  288. --
  289. main = do
  290. -- xmproc <- spawnPipe "xmobar ~/.xmonad/xmobar.hs"
  291. xmproc <- spawnPipe "/usr/bin/xmobar /home/mark-arch/.xmobarrc"
  292. xmonad $ defaults {
  293. manageHook = manageDocks <+> myManageHook
  294. , layoutHook = avoidStruts $ layoutHook defaultConfig
  295. , handleEventHook = handleEventHook defaultConfig <+> docksEventHook
  296. , logHook = dynamicLogWithPP $ xmobarPP {
  297. ppOutput = hPutStrLn xmproc
  298. , ppTitle = xmobarColor xmobarTitleColor "" . shorten 100
  299. , ppCurrent = xmobarColor xmobarCurrentWorkspaceColor ""
  300. , ppSep = " "
  301. }
  302. }
  303. -- xmonad $ defaultConfig {
  304. -- manageHook = manageDocks <+> manageHook defaultConfig
  305. -- , layoutHook = avoidStruts $ layoutHook defaultConfig
  306. -- }
  307. -- , manageHook = manageDocks <+> myManageHook
  308. -- , layoutHook = avoidStruts $ layoutHook defaultConfig -- Does not work
  309. -- , startupHook = setWMName "LG3D"
  310. ------------------------------------------------------------------------
  311. -- Combine it all together
  312. -- A structure containing your configuration settings, overriding
  313. -- fields in the default config. Any you don't override, will
  314. -- use the defaults defined in xmonad/XMonad/Config.hs
  315. --
  316. -- No need to modify this.
  317. --
  318. defaults = defaultConfig {
  319. -- simple stuff
  320. terminal = myTerminal,
  321. focusFollowsMouse = myFocusFollowsMouse,
  322. borderWidth = myBorderWidth,
  323. modMask = myModMask,
  324. workspaces = myWorkspaces,
  325. normalBorderColor = myNormalBorderColor,
  326. focusedBorderColor = myFocusedBorderColor,
  327. -- key bindings
  328. keys = myKeys,
  329. mouseBindings = myMouseBindings,
  330. -- hooks, layouts
  331. layoutHook = smartBorders $ myLayout,
  332. manageHook = myManageHook,
  333. startupHook = myStartupHook
  334. }