aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 1f059aa8cc987e70b3adc10cefac84ecd807e0af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import Control.Monad.Reader
import Control.Monad.Trans.Class
import qualified Data.Map as Map
import Data.Monoid
import Rahm.Desktop.Common
import Rahm.Desktop.DMenu (menuCommandString)
import Rahm.Desktop.History
import Rahm.Desktop.Hooks.WindowChange
import Rahm.Desktop.Keys
import Rahm.Desktop.Layout
import Rahm.Desktop.Logger
import Rahm.Desktop.Marking
import Rahm.Desktop.RebindKeys
import qualified Rahm.Desktop.StackSet as W
import Rahm.Desktop.Swallow
import Rahm.Desktop.XMobarLog
import System.Directory (getHomeDirectory)
import System.Environment (setEnv)
import System.FilePath ((</>))
import Text.Printf
import XMonad
import qualified XMonad as X
import XMonad.Hooks.DynamicProperty
import XMonad.Hooks.EwmhDesktops (ewmh)
import XMonad.Hooks.ManageDocks (docks)
import XMonad.Hooks.ManageHelpers (doFullFloat, isFullscreen)
import XMonad.Layout.Fullscreen (fullscreenEventHook)

main = do
  putStrLn "Welcome To RDE!"

  -- Execute some commands.
  homeDir <- getHomeDirectory
  let fp = homeDir </> ".xmonad" </> "startup"

  setEnv "SUDO_ASKPASS" "/usr/bin/ssh-askpass"
  setEnv "ROFI" menuCommandString

  xmobar <- spawnXMobar
  logHook <- xMobarLogHook

  (=<<) X.xmonad $
    applyKeys $
      withLocationChangeHook historyHook $
        ewmh $
          docks $
            def
              { terminal = "alacritty",
                modMask = mod3Mask,
                borderWidth = 2,
                keys = const mempty,
                focusedBorderColor = "#ff6c00",
                normalBorderColor = "#404040",
                layoutHook = myLayout,
                startupHook = spawn fp,
                manageHook =
                  composeAll
                    [ isFullscreen --> doFullFloat,
                      doLogWindow,
                      className =? "Tilda" --> doFloat,
                      className =? "yakuake" --> doFloat,
                      className =? "MPlayer" --> doFloat,
                      title =? "Event Tester" --> doFloat,
                      title =? "Floating Term" --> doCenterFloat,
                      title =? "Notes" --> doCenterFloat,
                      title =? "xmessage" --> doCenterFloat,
                      title =? "gxmessage" --> doCenterFloat,
                      title =? "Volume Control" --> doCenterFloat,
                      className =? "mpv" --> doFloat,
                      className =? "gnubby_ssh_prompt" --> doFloat
                    ],
                -- This config uses dynamic workspaces, but I have to seed XMonad
                -- with something. However, this configuration only supports 36
                -- monitors on boot. If you need more than 36 monitors, you'll have to
                -- configure those ones after starting XMonad.
                workspaces = map return (['0' .. '9'] ++ ['a' .. 'z']),
                handleEventHook =
                  composeAll
                    [ fullscreenEventHook,
                      remapHook,
                      swallowHook,
                      dynamicTitle
                        ( composeAll
                            [ title =? "Spotify" --> doMarkWindow "s"
                            ]
                        )
                    ],
                focusFollowsMouse = False,
                clickJustFocuses = False,
                logHook = logHook xmobar
              }

changeHook :: Location -> Location -> X ()
changeHook l1 l2 =
  logs Info "Change %s -> %s" (show l1) (show l2)

doLogWindow :: ManageHook
doLogWindow = do
  t <- title
  c <- className
  a <- appName
  liftX $ logs Debug "New Window {title: \"%s\", class: \"%s\", appName: \"%s\"}" t c a
  return (Endo id)

doMarkWindow :: Mark -> ManageHook
doMarkWindow m =
  ask
    >>= ( \w ->
            liftX
              ( do
                  ws <- getCurrentWorkspace
                  markAllLocations m [Location ws (Just w)]
              )
              >> return (Endo id)
        )

doCenterFloat :: ManageHook
doCenterFloat =
  ask >>= \w -> doF . W.float w . centerRect . snd =<< liftX (floatLocation w)

centerRect :: W.RationalRect -> W.RationalRect
centerRect (W.RationalRect x y w h) = W.RationalRect ((1 - w) / 2) ((1 - h) / 2) w h

windowHooks :: WindowHook -> XConfig l -> XConfig l
windowHooks (Query readerT) config = do
  config
    { startupHook = do
        withWindowSet $ mapM_ (runReaderT readerT) . W.allWindows
        startupHook config,
      manageHook = mappend (Query readerT >> return (Endo id)) (manageHook config)
    }