Advertisement
Guest User

xmonad.hs

a guest
May 8th, 2023
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | None | 0 0
  1. -- xmonad.hs
  2.  
  3. import XMonad
  4. import Data.Monoid
  5. import System.Exit
  6. import Graphics.X11.ExtraTypes.XF86
  7.  
  8. import XMonad.Hooks.DynamicLog
  9. import XMonad.Hooks.EwmhDesktops
  10. import XMonad.Hooks.WindowSwallowing
  11.  
  12. import XMonad.Layout.NoBorders
  13. import XMonad.Layout.Spacing
  14.  
  15. import qualified XMonad.StackSet as W
  16. import qualified Data.Map as M
  17.  
  18. myTerminal = "urxvt"
  19.  
  20. myFocusFollowsMouse :: Bool
  21. myFocusFollowsMouse = True
  22.  
  23. myClickJustFocuses :: Bool
  24. myClickJustFocuses = False
  25.  
  26. myBorderWidth = 3
  27.  
  28. myModMask = mod4Mask
  29.  
  30. myWorkspaces = ["1","2","3","4","5","6","7","8","9"]
  31.  
  32. myNormalBorderColor = "#dcdfe4"
  33. myFocusedBorderColor = "#0184bc"
  34.  
  35. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  36. [ ((modm, xK_Return), spawn $ XMonad.terminal conf)
  37. , ((modm .|. shiftMask, xK_Return), spawn "emacsclient -c -n --eval '(fancy-startup-screen)'")
  38. , ((0, xF86XK_AudioMute), spawn "pactl set-sink-mute @DEFAULT_SINK@ toggle")
  39. , ((0, xF86XK_AudioLowerVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ -10%")
  40. , ((0, xF86XK_AudioRaiseVolume), spawn "pactl set-sink-volume @DEFAULT_SINK@ +10%")
  41. , ((0, xF86XK_AudioMicMute), spawn "pactl set-source-mute @DEFAULT_SOURCE@ toggle")
  42. , ((0, xF86XK_MonBrightnessUp), spawn "brightnessctl set +5%")
  43. , ((0, xF86XK_MonBrightnessDown), spawn "brightnessctl set 5%-")
  44. , ((0, xK_Print), spawn "scrot -s")
  45. , ((modm, xK_p ), spawn "dmenu_run") -- now conflicts with "move to screen 3"
  46. , ((modm, xK_r ), spawn "rofi -show drun")
  47. , ((modm .|. shiftMask, xK_p ), spawn "gmrun")
  48. , ((modm .|. shiftMask, xK_c ), kill)
  49. , ((modm, xK_space ), sendMessage NextLayout)
  50. , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  51. , ((modm, xK_n ), refresh)
  52. , ((modm, xK_Tab ), windows W.focusDown)
  53. , ((modm, xK_j ), windows W.focusDown)
  54. , ((modm, xK_k ), windows W.focusUp )
  55. , ((modm, xK_m ), windows W.focusMaster )
  56. , ((modm .|. shiftMask, xK_m ), windows W.swapMaster)
  57. , ((modm .|. shiftMask, xK_j ), windows W.swapDown )
  58. , ((modm .|. shiftMask, xK_k ), windows W.swapUp )
  59. , ((modm, xK_h ), sendMessage Shrink) -- resize: shrink master area
  60. , ((modm, xK_l ), sendMessage Expand) -- resize: expand master area
  61. , ((modm, xK_t ), withFocused $ windows . W.sink) -- set window to tiling
  62. , ((modm , xK_comma ), sendMessage (IncMasterN 1))
  63. , ((modm , xK_period), sendMessage (IncMasterN (-1)))
  64. , ((modm .|. shiftMask, xK_q ), io (exitWith ExitSuccess)) -- quit xmonad
  65. , ((modm , xK_q ), spawn "xmonad --recompile; xmonad --restart") -- restart xmonad
  66. , ((modm .|. shiftMask, xK_slash ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -"))
  67. ]
  68. ++
  69.  
  70. [((m .|. modm, k), windows $ f i)
  71. | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  72. , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  73. ++
  74.  
  75. --
  76. -- mod-{w,e,p}, Switch to physical/Xinerama screens 1, 2, or 3
  77. -- mod-shift-{w,e,p}, Move client to screen 1, 2, or 3
  78. --
  79. [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  80. | (key, sc) <- zip [xK_w, xK_e, xK_p] [0..]
  81. , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  82.  
  83. -- Mouse bindings:
  84. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  85.  
  86. -- mod-button1, Set the window to floating mode and move by dragging
  87. [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  88. >> windows W.shiftMaster))
  89.  
  90. -- mod-button2, Raise the window to the top of the stack
  91. , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
  92.  
  93. -- mod-button3, Set the window to floating mode and resize by dragging
  94. , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  95. >> windows W.shiftMaster))
  96.  
  97. -- you may also bind events to the mouse scroll wheel (button4 and button5)
  98. ]
  99.  
  100. ------------------------------------------------------------------------
  101. -- Layouts:
  102.  
  103. -- You can specify and transform your layouts by modifying these values.
  104. -- If you change layout bindings be sure to use 'mod-shift-space' after
  105. -- restarting (with 'mod-q') to reset your layout state to the new
  106. -- defaults, as xmonad preserves your old layout settings by default.
  107. --
  108. -- The available layouts. Note that each layout is separated by |||,
  109. -- which denotes layout choice.
  110. --
  111. myLayout = tiled ||| Mirror tiled ||| noBorders Full
  112. where
  113. -- default tiling algorithm partitions the screen into two panes
  114. tiled = Tall nmaster delta ratio
  115. -- The default number of windows in the master pane
  116. nmaster = 1
  117. -- Default proportion of screen occupied by master pane
  118. ratio = 1/2
  119. -- Percent of screen to increment by when resizing panes
  120. delta = 3/100
  121. ------------------------------------------------------------------------
  122. -- Window rules:
  123.  
  124. -- Execute arbitrary actions and WindowSet manipulations when managing
  125. -- a new window. You can use this to, for example, always float a
  126. -- particular program, or have a client always appear on a particular
  127. -- workspace.
  128. --
  129. -- To find the property name associated with a program, use
  130. -- > xprop | grep WM_CLASS
  131. -- and click on the client you're interested in.
  132. --
  133. -- To match on the WM_NAME, you can use 'title' in the same way that
  134. -- 'className' and 'resource' are used below.
  135. --
  136. myManageHook = composeAll
  137. [ className =? "MPlayer" --> doFloat,
  138. className =? "Gimp" --> doFloat,
  139. className =? "Steam" --> doFloat,
  140. className =? "TeamSpeak 3" --> doFloat,
  141. resource =? "desktop_window" --> doIgnore,
  142. resource =? "kdesktop" --> doIgnore ]
  143. ------------------------------------------------------------------------
  144. -- Event handling
  145.  
  146. -- EwmhDesktops users should change this to ewmhDesktopsEventHook
  147. --
  148. -- Defines a custom handler function for X Events. The function should
  149. -- return (All True) if the default handler is to be run afterwards. To
  150. -- combine event hooks use mappend or mconcat from Data.Monoid.
  151. --
  152. myEventHook = swallowEventHook (className =? "URxvt") (return True)
  153.  
  154. ------------------------------------------------------------------------
  155. -- Status bars and logging
  156.  
  157. -- Perform an arbitrary action on each internal state change or X event.
  158. -- See the 'XMonad.Hooks.DynamicLog' extension for examples.
  159. --
  160. myLogHook = return ()
  161.  
  162. ------------------------------------------------------------------------
  163. -- Startup hook
  164.  
  165. -- Perform an arbitrary action each time xmonad starts or is restarted
  166. -- with mod-q. Used by, e.g., XMonad.Layout.PerWorkspace to initialize
  167. -- per-workspace layout choices.
  168. --
  169. -- By default, do nothing.
  170. myStartupHook :: X()
  171. myStartupHook = do
  172. spawn "feh --bg-fill ~/Bilder/dt-wallpapers/0053.jpg"
  173. spawn "/usr/bin/emacs --daemon --eval '(load-file \"~/.emacs\")' &"
  174.  
  175. ------------------------------------------------------------------------
  176. -- Command to launch the bar.
  177. myBar = "xmobar"
  178.  
  179. -- Custom PP, configure it as you like. It determines what is being written to the bar.
  180.  
  181. myPP = xmobarPP {ppCurrent = xmobarColor "white" "",
  182. ppTitle = xmobarColor "white" "" . shorten 50,
  183. ppLayout = xmobarColor "grey" "" . wrap " ~ " " ~ " . myLayoutPrinter,
  184. ppSep = " "}
  185.  
  186. myLayoutPrinter :: String -> String
  187. myLayoutPrinter "Tall" = "tile"
  188. myLayoutPrinter "Mirror Tall" = "htile"
  189. myLayoutPrinter "Full" = "full"
  190. myLayoutPrinter x = x
  191.  
  192. -- Key binding to toggle the gap for the bar.
  193. toggleStrutsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
  194.  
  195. ------------------------------------------------------------------------
  196. -- Now run xmonad with all the defaults we set up.
  197.  
  198. -- Run xmonad with the settings you specify. No need to modify this.
  199. --
  200. main :: IO()
  201. main = xmonad .
  202. ewmhFullscreen .
  203. ewmh =<<
  204. statusBar myBar myPP toggleStrutsKey defaults
  205.  
  206. -- A structure containing your configuration settings, overriding
  207. -- fields in the default config. Any you don't override, will
  208. -- use the defaults defined in xmonad/XMonad/Config.hs
  209. --
  210. -- No need to modify this.
  211. --
  212. defaults = def {
  213. -- simple stuff
  214. terminal = myTerminal,
  215. focusFollowsMouse = myFocusFollowsMouse,
  216. clickJustFocuses = myClickJustFocuses,
  217. borderWidth = myBorderWidth,
  218. modMask = myModMask,
  219. workspaces = myWorkspaces,
  220. normalBorderColor = myNormalBorderColor,
  221. focusedBorderColor = myFocusedBorderColor,
  222.  
  223. -- key bindings
  224. keys = myKeys,
  225. mouseBindings = myMouseBindings,
  226.  
  227. -- hooks, layouts
  228. layoutHook = myLayout,
  229. manageHook = myManageHook,
  230. handleEventHook = myEventHook,
  231. logHook = myLogHook,
  232. startupHook = myStartupHook
  233. }
  234.  
  235. -- | Finally, a copy of the default bindings in simple textual tabular format.
  236. help :: String
  237. help = unlines ["The default modifier key is 'alt'. Default keybindings:",
  238. "",
  239. "-- launching and killing programs",
  240. "mod-Shift-Enter Launch xterminal",
  241. "mod-p Launch dmenu",
  242. "mod-Shift-p Launch gmrun",
  243. "mod-Shift-c Close/kill the focused window",
  244. "mod-Space Rotate through the available layout algorithms",
  245. "mod-Shift-Space Reset the layouts on the current workSpace to default",
  246. "mod-n Resize/refresh viewed windows to the correct size",
  247. "",
  248. "-- move focus up or down the window stack",
  249. "mod-Tab Move focus to the next window",
  250. "mod-Shift-Tab Move focus to the previous window",
  251. "mod-j Move focus to the next window",
  252. "mod-k Move focus to the previous window",
  253. "mod-m Move focus to the master window",
  254. "",
  255. "-- modifying the window order",
  256. "mod-Return Swap the focused window and the master window",
  257. "mod-Shift-j Swap the focused window with the next window",
  258. "mod-Shift-k Swap the focused window with the previous window",
  259. "",
  260. "-- resizing the master/slave ratio",
  261. "mod-h Shrink the master area",
  262. "mod-l Expand the master area",
  263. "",
  264. "-- floating layer support",
  265. "mod-t Push window back into tiling; unfloat and re-tile it",
  266. "",
  267. "-- increase or decrease number of windows in the master area",
  268. "mod-comma (mod-,) Increment the number of windows in the master area",
  269. "mod-period (mod-.) Deincrement the number of windows in the master area",
  270. "",
  271. "-- quit, or restart",
  272. "mod-Shift-q Quit xmonad",
  273. "mod-q Restart xmonad",
  274. "mod-[1..9] Switch to workSpace N",
  275. "",
  276. "-- Workspaces & screens",
  277. "mod-Shift-[1..9] Move client to workspace N",
  278. "mod-{w,e,r} Switch to physical/Xinerama screens 1, 2, or 3",
  279. "mod-Shift-{w,e,r} Move client to screen 1, 2, or 3",
  280. "",
  281. "-- Mouse bindings: default actions bound to mouse events",
  282. "mod-button1 Set the window to floating mode and move by dragging",
  283. "mod-button2 Raise the window to the top of the stack",
  284. "mod-button3 Set the window to floating mode and resize by dragging"]
  285.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement