aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 507bd432da62e7339f28638597c899857d60dfc3 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import Control.Monad.Reader
  ( MonadReader (ask),
    ReaderT (runReaderT),
  )
import Data.Monoid (Endo (Endo))
import Rahm.Desktop.Common
  ( Location (Location),
    getCurrentWorkspace,
  )
import Rahm.Desktop.DMenu (menuCommandString)
import Rahm.Desktop.History (historyHook)
import Rahm.Desktop.Hooks.WindowChange (withStackChangeHook)
import Rahm.Desktop.Keys (applyKeys)
import Rahm.Desktop.Layout (myLayout)
import Rahm.Desktop.Logger (LogLevel (Debug, Info), logs)
import Rahm.Desktop.Marking (Mark, markAllLocations)
import Rahm.Desktop.RebindKeys (WindowHook, remapHook)
import qualified Rahm.Desktop.StackSet as W
  ( RationalRect (..),
    allWindows,
    float,
  )
import Rahm.Desktop.XMobarLog (spawnXMobar, xMobarLogHook)
import System.Directory (getHomeDirectory)
import System.Environment (setEnv)
import System.FilePath ((</>))
import XMonad
  ( Default (def),
    ManageHook,
    Query (Query),
    X,
    XConfig
      ( borderWidth,
        clickJustFocuses,
        focusFollowsMouse,
        focusedBorderColor,
        handleEventHook,
        keys,
        layoutHook,
        logHook,
        manageHook,
        modMask,
        normalBorderColor,
        startupHook,
        terminal,
        workspaces
      ),
    appName,
    className,
    composeAll,
    doF,
    doFloat,
    floatLocation,
    liftX,
    mod3Mask,
    spawn,
    title,
    withWindowSet,
    (-->),
    (=?), mouseDrag, refresh, modify, XState (dragging),
  )
import qualified XMonad as X (xmonad)
import XMonad.Hooks.DynamicProperty (dynamicTitle)
import XMonad.Hooks.EwmhDesktops (ewmh)
import XMonad.Hooks.ManageDocks (docks)
import XMonad.Hooks.ManageHelpers (doFullFloat, isFullscreen)
import XMonad.Layout.Fullscreen (fullscreenEventHook)
import Data.List (isPrefixOf)
import Rahm.Desktop.Keys.Wml (wmlLogHook)

main = do
  logHook <- xMobarLogHook
  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

  (=<<) X.xmonad $
    applyKeys $
      withStackChangeHook 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,
                      shouldChromeFloat --> 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,
                      dynamicTitle
                        ( composeAll
                            [ title =? "Spotify" --> doMarkWindow "s"
                            ]
                        )
                    ],
                focusFollowsMouse = False,
                clickJustFocuses = False,
                logHook = wmlLogHook >> logHook xmobar
              }

-- Should the chrome window float? Returns false if the window's title starts
-- with "New Tab" because this usually means a new window was launched. If the
-- window name does not start with "New Tab", it is likely the tab was torn out
-- of the browser. These windows should float to avoid screwing with tiling.
shouldChromeFloat :: Query Bool
shouldChromeFloat = do
  className <- className
  title <- title
  return $
    className == "Google-chrome" && not ("New Tab" `isPrefixOf` title)

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)
    }