aboutsummaryrefslogtreecommitdiff
path: root/src/Main.hs
blob: 0018fa23aa46391f0c414d56db4a9ce15930f696 (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
import XMonad

import Control.Monad.Trans.Class
import Control.Monad.Reader
import XMonad.Hooks.ManageDocks (docks)
import System.Directory (getHomeDirectory)
import System.FilePath ((</>))
import XMonad.Hooks.EwmhDesktops (ewmh)
import XMonad.Hooks.ManageHelpers (isFullscreen, doFullFloat)
import XMonad.Layout.Fullscreen (fullscreenEventHook)
import System.Environment (setEnv)
import Data.Monoid

import Internal.Swallow
import Internal.Windows
import Internal.XMobarLog
import Internal.Keys
import Internal.Layout
import Internal.Logger
import Internal.DMenu (menuCommandString)
import Internal.RebindKeys

import qualified XMonad as X
import qualified XMonad.StackSet as W


main = do

  -- 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 $ ewmh $ docks $ windowHooks (composeAll [
           (className =? "Google-chrome" <||> className =? "Brave-browser") --> composeAll [
             -- The geniuses that made chrome decided that Ctrl+W should kill
             -- the current tab! This makes it consistent with the rest of the
             -- world ... ctrl+w deletes the last word (ctrl+backspace).
             rebindKey (controlMask, xK_w) (controlMask, xK_BackSpace)

             -- Terminal Ctrl-H sends a backspace. (Technically not, but that's
             -- usually the semantics). Make it this way in Chrome.
           , rebindKey (controlMask, xK_h) (0, xK_BackSpace)

             -- Ctrl+u usually deletes the whole line. This is roughly
             -- ctrl+shift+backspace
           , rebindKey (controlMask, xK_u) (controlMask .|. shiftMask, xK_BackSpace)

             -- Make it to ctrl+d deletes the current tab instead of ctrl+w.
           , rebindKey (controlMask, xK_e) (controlMask, xK_w)

             -- Vim-ish keybindings to go back and forward.
           , rebindKey (controlMask, xK_b) (controlMask, xK_Left)
           , rebindKey (controlMask, xK_e) (controlMask, xK_Right)
           , rebindKey (controlMask .|. shiftMask, xK_b) (controlMask .|. shiftMask, xK_Left)
           , rebindKey (controlMask .|. shiftMask, xK_e) (controlMask .|. shiftMask, xK_Right)

             -- Baskic Vim-like motion with the alt key.
           , rebindKey (mod1Mask, xK_h) (0, xK_Left)
           , rebindKey (mod1Mask, xK_j) (0, xK_Down)
           , rebindKey (mod1Mask, xK_k) (0, xK_Up)
           , rebindKey (mod1Mask, xK_l) (0, xK_Right)

           , rebindKey (shiftMask .|. mod1Mask, xK_h) (shiftMask, xK_Left)
           , rebindKey (shiftMask .|. mod1Mask, xK_j) (shiftMask, xK_Down)
           , rebindKey (shiftMask .|. mod1Mask, xK_k) (shiftMask, xK_Up)
           , rebindKey (shiftMask .|. mod1Mask, xK_l) (shiftMask, xK_Right)

           , rebindKey (controlMask .|. mod1Mask, xK_h) (controlMask, xK_Left)
           , rebindKey (controlMask .|. mod1Mask, xK_j) (controlMask, xK_Down)
           , rebindKey (controlMask .|. mod1Mask, xK_k) (controlMask, xK_Up)
           , rebindKey (controlMask .|. mod1Mask, xK_l) (controlMask, xK_Right)
           ]
        ]) $ def
       { terminal    = "alacritty"
       , modMask     = mod3Mask
       , borderWidth = 2
       , keys = const mempty
       , focusedBorderColor = "#ff6c00"
       , normalBorderColor = "#404040"
       , layoutHook = myLayout
       , startupHook = spawn fp
       , manageHook = composeAll [
           isFullscreen --> doFullFloat
         , 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
         ]
       , workspaces = map return (['0'..'9'] ++ ['a'..'z'])
       , handleEventHook =
           composeAll [
             fullscreenEventHook,
             remapHook,
             swallowHook]
       , focusFollowsMouse = False
       , clickJustFocuses = False
       , logHook = xMobarLogHook xmobar
       }

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
      forAllWindows $ \w -> runReaderT readerT w
      startupHook config,

    manageHook = mappend (Query readerT >> return (Endo id)) (manageHook config)
  }