Guest User

Xmonad Config

a guest
Sep 11th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
  2.  
  3. ------------------------------------------
  4. -- Imports
  5. ------------------------------------------
  6. -- Custom
  7. import Custom.MyHotkeys
  8. import Custom.MyScratchpads
  9. ------------------------------------------
  10. -- General
  11. import System.IO
  12. import System.IO.Unsafe
  13. import Graphics.X11.XRM
  14. import Data.Map (fromList)
  15. import Data.Monoid (mappend)
  16. import Data.Ratio
  17. import Data.Maybe
  18. import qualified Data.Bifunctor as BI
  19. import Data.List as DL
  20. import Data.Char as DC
  21. import Control.Arrow ((***), second)
  22. ------------------------------------------
  23. -- Xmonad
  24. import XMonad
  25. import XMonad hiding ((|||))
  26. import qualified XMonad.StackSet as W
  27. ------------------------------------------
  28. -- Hooks
  29. import XMonad.Hooks.DynamicLog
  30. import XMonad.Hooks.ManageDocks
  31. import XMonad.Hooks.EwmhDesktops
  32. import XMonad.Hooks.DynamicProperty
  33. import XMonad.Hooks.ManageHelpers (isFullscreen, doFullFloat)
  34. ------------------------------------------
  35. -- Utilities
  36. --import Xmonad.Util.Dzen
  37. import XMonad.Util.SpawnOnce
  38. import XMonad.Util.Run
  39. import XMonad.Util.EZConfig(removeKeys, additionalKeys)
  40. import XMonad.Util.NamedScratchpad
  41. ------------------------------------------
  42. --Layout
  43. import XMonad.Layout (Mirror)
  44. import XMonad.Layout.Grid
  45. import XMonad.Layout.Spiral
  46. import XMonad.Layout.Spacing
  47. import XMonad.Layout.TwoPane
  48. import XMonad.Layout.NoBorders (noBorders, smartBorders)
  49. import XMonad.Layout.ResizableTile
  50. import XMonad.Layout.Fullscreen (fullscreenSupport)
  51. ------------------------------------------
  52. -- Actions
  53. --import XMonad.Actions.Volume -- couldn't get xmonad-extras installed
  54. import XMonad.Actions.CycleWS
  55. import XMonad.Actions.WindowGo
  56. import XMonad.Actions.FindEmptyWorkspace
  57. ------------------------------------------
  58.  
  59. ------------------------------------------
  60. -- FromXResources
  61. ------------------------------------------
  62.  
  63. getFromXres :: String -> IO String
  64. getFromXres key = fromMaybe "" . findValue key <$> runProcessWithInput "xrdb" ["-query"] ""
  65. where
  66. findValue :: String -> String -> Maybe String
  67. findValue xresKey xres =
  68. snd <$> DL.find ((== xresKey) . fst) (catMaybes
  69. $ splitAtColon
  70. <$> lines xres)
  71.  
  72. splitAtColon :: String -> Maybe (String, String)
  73. splitAtColon str = splitAtTrimming str <$> DL.elemIndex ':' str
  74.  
  75. splitAtTrimming :: String -> Int -> (String, String)
  76. splitAtTrimming str idx = BI.bimap trim trim . BI.second tail $ splitAt idx str
  77.  
  78. trim :: String -> String
  79. trim = DL.dropWhileEnd DC.isSpace . DL.dropWhile DC.isSpace
  80.  
  81. fromXres :: String -> String
  82. fromXres = unsafePerformIO . getFromXres
  83.  
  84.  
  85.  
  86. ------------------------------------------
  87. -- My Layouts
  88. ------------------------------------------
  89. myBorderWidth = 1
  90. myNormalBorderColor = fromXres "xmonad.normBord"--white
  91. myFocusedBorderColor = fromXres "xmonad.focusBord"--spawn "xrdb -query | grep xmonad.focusBord | grep \"#.*\" -o" --red
  92. myTerminal = "st"
  93. myModMask = mod4Mask
  94. myWorkspaces = ["1:Main","2:Media","3:Game","4:Code","5:Work","6:Comm", "7", "8", "9"]
  95. myLayouts = avoidStruts $
  96. myTall ||| myFlipTall ||| myTwoPane ||| myGrid ||| myFull
  97. where
  98. myTall = spacing 6 $ ResizableTall nmaster delta ratio []
  99. myFlipTall = Flip myTall
  100. myGrid = spacing 6 $ Grid
  101. myTwoPane = spacing 4 $ TwoPane delta ratio
  102. myFull = spacing 0 $ noBorders $ Full
  103. nmaster = 1
  104. ratio = 1/2
  105. delta = 3/100
  106.  
  107. -- | Flip a layout, compute its 180 degree rotated form.
  108. newtype Flip l a = Flip (l a) deriving (Show, Read)
  109.  
  110. instance LayoutClass l a => LayoutClass (Flip l) a where
  111. runLayout (W.Workspace i (Flip l) ms) r = (map (second flipRect) *** fmap Flip)
  112. `fmap` runLayout (W.Workspace i l ms) (flipRect r)
  113. where screenWidth = fromIntegral $ rect_width r
  114. flipRect (Rectangle rx ry rw rh) = Rectangle (screenWidth - rx - (fromIntegral rw)) ry rw rh
  115. handleMessage (Flip l) = fmap (fmap Flip) . handleMessage l
  116. description (Flip l) = "Flip "++ description l
  117.  
  118. ------------------------------------------
  119. -- Main Section
  120. ------------------------------------------
  121. main = do
  122. xmproc <- spawnPipe "xmobar ~/.xmonad/.xmobarrc"
  123.  
  124. xmonad $ ewmh $ fullscreenSupport $ defaultConfig
  125. { manageHook = ( isFullscreen --> doFullFloat ) <+> namedScratchpadManageHook myScratchPads <+> manageDocks <+> manageHook defaultConfig
  126. , layoutHook = myLayouts
  127. --, startupHook = do
  128. --spawn "xrandr --output DVI-D-1-1 --primary --left-of DP-3 --auto"
  129. --spawn "xrandr --output DP-3 --right-of DVI-D-1-1"
  130. --spawn "picom -CG --config ~/.config/picom/picom.conf &"
  131. , workspaces = myWorkspaces
  132. , terminal = myTerminal
  133. , logHook = dynamicLogWithPP xmobarPP
  134. { ppOutput = hPutStrLn xmproc
  135. , ppTitle = xmobarColor "#2CE3FF" "" . shorten 50
  136. , ppLayout = const "" -- to disable the layout info on xmobar
  137. }
  138. , modMask = myModMask -- Rebind Mod to the Windows key
  139. , borderWidth = myBorderWidth
  140. , normalBorderColor = myNormalBorderColor
  141. , focusedBorderColor = myFocusedBorderColor
  142. , handleEventHook = handleEventHook defaultConfig <+> docksEventHook
  143. } `additionalKeys` myNewKeys
  144.  
  145. `removeKeys` removedKeys
  146.  
Add Comment
Please, Sign In to add comment