xmonad.hs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import XMonad
  2. import XMonad.Hooks.DynamicLog(dynamicLogWithPP
  3. , xmobarPP
  4. , ppOutput
  5. , ppLayout
  6. , ppTitle)
  7. import XMonad.Hooks.ManageDocks(docks, docksEventHook, manageDocks, avoidStruts)
  8. import XMonad.Util.Run(spawnPipe, hPutStrLn, runProcessWithInput)
  9. import XMonad.Util.SpawnOnce(spawnOnce)
  10. -- Layouts
  11. import XMonad.Layout.Spacing(smartSpacing)
  12. import XMonad.Layout.Tabbed(simpleTabbed)
  13. import XMonad.Layout.NoBorders(withBorder, smartBorders)
  14. import XMonad.Layout.IndependentScreens(countScreens)
  15. -- Shutdown commands and keys
  16. import Data.Map(fromList)
  17. import XMonad.Util.EZConfig(removeKeys)
  18. -- For starting up a list of programs
  19. import Data.List(elemIndex, foldl1')
  20. import qualified XMonad.StackSet as W
  21. import qualified Data.Map as M
  22. import XMonad.Config.Kde(kde4Config, desktopLayoutModifiers)
  23. import XMonad.Hooks.EwmhDesktops(ewmh, fullscreenEventHook)
  24. myModMask = mod4Mask
  25. myTerminal = "konsole"
  26. -- Only show workspaces on xmobar, as everything else will be on KDE's panels
  27. myPP = xmobarPP { ppTitle = \_ -> ""
  28. , ppLayout = \_ -> ""}
  29. main = do
  30. -- Spawn an xmobar on each screen
  31. nScreen <- countScreens
  32. xmprocs <- mapM (\dis -> spawnPipe ("xmobar -x " ++ show dis)) [0..nScreen-1]
  33. xmonad $ ewmh $ docks $ kde4Config {
  34. manageHook = manageDocks <+> myManageHook <+> manageHook kde4Config
  35. , layoutHook = avoidStruts $ desktopLayoutModifiers $ smartBorders $
  36. (smartSpacing 5 $ withBorder 2 $ Tall 1 (3/100) (1/2)) |||
  37. (smartSpacing 5 $ withBorder 2 $ Mirror (Tall 1 (3/100) (1/2))) |||
  38. -- Full |||
  39. -- Tabs are bugged/don't work in ewmh. On the
  40. -- bright side, it makes a window float over KDE's
  41. -- bar, which is what I want fullscreen to do.
  42. -- It's not a bug, it's a feature.
  43. simpleTabbed
  44. -- Write signals to all xmobars.
  45. , logHook = dynamicLogWithPP myPP {
  46. ppOutput = \s -> sequence_ [hPutStrLn h s | h <- xmprocs]
  47. }
  48. , startupHook = sequence_ [spawnOnce s | s <- startupList]
  49. , handleEventHook = handleEventHook kde4Config <+> fullscreenEventHook <+> docksEventHook
  50. , modMask = mod4Mask
  51. , keys = \c -> myKeys c `M.union` keys kde4Config c
  52. }
  53. `removeKeys` myRemoveKeys
  54. myKeys conf@(XConfig {XMonad.modMask = myModMask}) = M.fromList $
  55. -- extra programs
  56. [ ((myModMask, xK_x),
  57. spawn "emacsclient -c")
  58. , ((myModMask, xK_z),
  59. spawn "firefox-nightly")
  60. , ((myModMask, xK_m),
  61. spawn ":")
  62. -- TODO put social stuff here (Discord, Riot) and open it on a particular workspace
  63. -- defaults
  64. -- Spawn terminal.
  65. , ((myModMask .|. shiftMask, xK_Return),
  66. spawn myTerminal)
  67. -- Close focused window.
  68. , ((myModMask .|. shiftMask, xK_c),
  69. kill)
  70. -- Cycle through the available layout algorithms.
  71. , ((myModMask, xK_space),
  72. sendMessage NextLayout)
  73. -- Reset the layouts on the current workspace to default.
  74. , ((myModMask .|. shiftMask, xK_space),
  75. setLayout $ XMonad.layoutHook conf)
  76. -- Resize viewed windows to the correct size.
  77. , ((myModMask, xK_n),
  78. refresh)
  79. -- Move focus to the next window.
  80. , ((myModMask, xK_Tab),
  81. windows W.focusDown)
  82. -- Move focus to the next window.
  83. , ((myModMask, xK_j),
  84. windows W.focusDown)
  85. -- Move focus to the previous window.
  86. , ((myModMask, xK_k),
  87. windows W.focusUp )
  88. -- Move focus to the master window.
  89. , ((myModMask, xK_m),
  90. windows W.focusMaster )
  91. -- Swap the focused window and the master window.
  92. , ((myModMask, xK_Return),
  93. windows W.swapMaster)
  94. -- Swap the focused window with the next window.
  95. , ((myModMask .|. shiftMask, xK_j),
  96. windows W.swapDown )
  97. -- Swap the focused window with the previous window.
  98. , ((myModMask .|. shiftMask, xK_k),
  99. windows W.swapUp )
  100. -- Shrink the master area.
  101. , ((myModMask, xK_h),
  102. sendMessage Shrink)
  103. -- Expand the master area.
  104. , ((myModMask, xK_l),
  105. sendMessage Expand)
  106. -- Push window back into tiling.
  107. , ((myModMask, xK_t),
  108. withFocused $ windows . W.sink)
  109. -- Increment the number of windows in the master area.
  110. , ((myModMask, xK_comma),
  111. sendMessage (IncMasterN 1))
  112. -- Decrement the number of windows in the master area.
  113. , ((myModMask, xK_period),
  114. sendMessage (IncMasterN (-1)))
  115. -- Toggle the status bar gap.
  116. -- Restart xmonad.
  117. , ((myModMask, xK_q),
  118. restart "xmonad" True)
  119. ]
  120. ++
  121. -- mod-[1..9], Switch to workspace N
  122. -- mod-shift-[1..9], Move client to workspace N
  123. [ ((m .|. myModMask, k), windows $ f i)
  124. | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  125. , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]
  126. ]
  127. ++
  128. -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  129. -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  130. [ ((m .|. myModMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
  131. | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  132. , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]
  133. ]
  134. myRemoveKeys =
  135. [ (mod4Mask, xK_Tab)
  136. , (mod4Mask .|. shiftMask, xK_Tab)
  137. , (mod4Mask, xK_p)
  138. ]
  139. myManageHook = composeAll . concat $
  140. [ [ className =? c --> doFloat | c <- myFloats]
  141. , [ title =? p --> doFloat | p <- plasmaWindows]
  142. ]
  143. where myFloats = ["Gimp"]
  144. plasmaWindows =
  145. [ "yakuake"
  146. , "Yakuake"
  147. , "Kmix"
  148. , "kmix"
  149. , "plasma"
  150. , "Plasma"
  151. , "plasma-desktop"
  152. , "Plasma-desktop"
  153. , "krunner"
  154. , "ksplashsimple"
  155. , "ksplashqml"
  156. , "ksplashx"
  157. ]
  158. startupList :: [String]
  159. startupList =
  160. [ "compton"
  161. , "nextcloud"
  162. -- TODO find a way around this dirty hack
  163. , "sleep 5 && for i in `xdotool search --all --name xmobar`; do xdotool windowraise $i; done"
  164. ]