xmonad-nokde.hs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import XMonad
  2. import XMonad.Config.Desktop
  3. import XMonad.Hooks.DynamicLog
  4. import XMonad.Hooks.ManageDocks
  5. import XMonad.Util.Run(spawnPipe, hPutStrLn, runProcessWithInput)
  6. -- Layouts
  7. import XMonad.Layout.Spacing(smartSpacing)
  8. import XMonad.Layout.Tabbed
  9. import XMonad.Layout.NoBorders
  10. -- Shutdown commands and keys
  11. import Data.Map(fromList)
  12. import XMonad.Prompt
  13. import XMonad.Prompt.XMonad
  14. import System.Exit(ExitCode(ExitSuccess), exitWith)
  15. import XMonad.Util.EZConfig(additionalKeys)
  16. -- Brightness and audio keys
  17. import Graphics.X11.ExtraTypes.XF86
  18. import Data.List(elemIndex, foldl1')
  19. -- kde
  20. import XMonad.Config.Kde
  21. main = do
  22. xmproc <- spawnPipe "xmobar"
  23. xmonad $ docks defaultConfig
  24. { manageHook = manageDocks <+> manageHook defaultConfig
  25. , layoutHook = smartBorders $ avoidStruts $
  26. (smartSpacing 5 $ withBorder 2 $ Tall 1 (3/100) (1/2)) |||
  27. (smartSpacing 5 $ withBorder 2 $ Mirror (Tall 1 (3/100) (1/2))) |||
  28. Full |||
  29. tabbed shrinkText def
  30. , logHook = dynamicLogWithPP xmobarPP
  31. { ppOutput = hPutStrLn xmproc
  32. , ppTitle = xmobarColor "green" "" . shorten 50
  33. }
  34. , startupHook = startup
  35. , terminal = "gnome-terminal"
  36. , modMask = mod4Mask
  37. } `additionalKeys` myKeys
  38. startupList :: [String]
  39. startupList = [
  40. "feh --bg-scale ~/Owncloud/Backgrounds/Xmbindings.png"
  41. , "owncloud"
  42. , "trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 10 --transparent true --alpha 0 --tint 0x000000 --height 22"
  43. -- "trayer --transparent true --alpha 0 --tint 0x00000000 --SetDockType true --expand true --edge top --align right --width 15 --height 18"
  44. -- "stalonetray -geometry 1x1+1900 -bg '#000000' --kludges use_icons_hints --grow-gravity NE --icon-gravity NE -i 20 -t false"
  45. , "pasystray"
  46. , "xfce4-clipman"
  47. , "xbacklight -set 12"
  48. , "compton"
  49. , "xscreensaver -nosplash"
  50. ]
  51. startup :: X ()
  52. startup = do
  53. foldl1' (>>) $ map (spawn . ifNotRunning) startupList
  54. -- Wrap a command in Bash that checks if it's running.
  55. ifNotRunning :: String -> String
  56. ifNotRunning s = "if [ `pgrep -c " ++ (basename s) ++ "` == 0 ]; then " ++ s ++ "; fi"
  57. -- Grab the program name from a command (everything up to the space,
  58. -- if there's a space). Doesn't work with escaped spaces.
  59. basename :: String -> String
  60. basename s = case elemIndex ' ' s of
  61. (Just n) -> take n s
  62. Nothing -> s
  63. myKeys = [
  64. -- scrot
  65. ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
  66. , ((0, xK_Print), spawn "scrot")
  67. -- rofi
  68. , ((mod4Mask, xK_p ), spawn "rofi -show run")
  69. -- shutdown
  70. , ((mod4Mask .|. shiftMask, xK_q),
  71. xmonadPrompt defaultXPConfig
  72. { promptKeymap = fromList
  73. [ ((0, xK_r), do
  74. spawn "emacsclient -e '(kill emacs)'"
  75. spawn "systemctl reboot")
  76. , ((0 , xK_s), do
  77. spawn "emacsclient -e '(kill emacs)'"
  78. spawn "sudo poweroff")
  79. , ((0, xK_e), do
  80. spawn "emacsclient -e '(kill emacs)'"
  81. io $ exitWith ExitSuccess)
  82. , ((0, xK_l), do
  83. spawn "xscreensaver-command -lock"
  84. quit)
  85. , ((0, xK_z), do
  86. spawn "xscreensaver-command -lock"
  87. spawn "systemctl suspend"
  88. quit)
  89. , ((0, xK_Escape), quit)
  90. ]
  91. , defaultText = "(r) Reboot, (s) Shutdown, (e) Exit, (l) Lock, (z) Sleep"
  92. })
  93. -- pulseaudio
  94. , ((0, xF86XK_AudioRaiseVolume),
  95. spawn "pactl set-sink-volume alsa_output.pci-0000_00_1f.3.analog-stereo +5%")
  96. , ((0, xF86XK_AudioLowerVolume),
  97. spawn "pactl set-sink-volume alsa_output.pci-0000_00_1f.3.analog-stereo -5%")
  98. , ((0, xF86XK_AudioMute),
  99. spawn "pactl set-sink-mute alsa_output.pci-0000_00_1f.3.analog-stereo toggle")
  100. -- brightness
  101. , ((0, xF86XK_MonBrightnessUp),
  102. let
  103. returnValM = fmap init $ runProcessWithInput "xbacklight" [] ""
  104. in do
  105. currentBrightness <- returnValM
  106. if (read currentBrightness :: Double) == 0 then
  107. spawn "xbacklight -set 2"
  108. else
  109. spawn "xbacklight -inc 5")
  110. , ((0, xF86XK_MonBrightnessDown), spawn "xbacklight -dec 5")
  111. -- Another option for brightness configuration: never let it reach 0.
  112. {-|
  113. let
  114. returnValM = fmap init $ runProcessWithInput "xbacklight" [] ""
  115. in do
  116. currentBrightness <- returnValM
  117. if (read currentBrightness :: Double) - 5 >= 0 then
  118. spawn "xbacklight -dec 5"
  119. else return ())
  120. -}
  121. -- extra programs
  122. , ((mod4Mask, xK_x),
  123. spawn "emacsclient -c")
  124. , ((mod4Mask, xK_z),
  125. spawn "firefox-nightly")
  126. , ((mod4Mask, xK_m),
  127. spawn ":"
  128. -- TODO put social stuff here (Discord, Riot) and open it on a particular workspace
  129. )
  130. ]