~vonfry/dotfiles

ref: fa912c03ca59d02b33ac45e1c294ba4a11018fec dotfiles/etc/nixos/modules/user/files/xmonad/lib/XMonad/Config/Vonfry/Key.hs -rw-r--r-- 9.7 KiB
fa912c03Vonfry Merge branch 'release/20220701' 5 months ago
                                                                                
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
module XMonad.Config.Vonfry.Key (key) where

import qualified XMonad.Config.Vonfry.Const as C
import qualified XMonad.Config.Vonfry.Color as Color

import XMonad ( refresh, io, spawn
              , def, windows , withFocused, whenJust

              , layoutHook, setLayout, Resize(..)

              , kill, float, killWindow

              , XConfig(..)
              , xK_a, xK_o, xK_e, xK_u, xK_i, xK_d, xK_h, xK_t, xK_n, xK_s, xK_q

              , sendMessage, ChangeLayout(NextLayout)
              , IncMasterN(IncMasterN)
              )
import XMonad.StackSet ( focusDown, focusUp, focusMaster
                       , focusWindow
                       , swapMaster, swapDown, swapUp
                       , sink, shift, view
                       )
import XMonad.Actions.Navigation2D ( windowGo, windowSwap
                                   , screenGo, screenSwap, windowToScreen
                                   )

import XMonad.Util.EZConfig (mkKeymap)

import XMonad.Util.Run (runInTerm)
import XMonad.Util.Types (Direction1D(..), Direction2D(..))

import XMonad.Prompt (XPConfig(..))
import XMonad.Prompt.Shell (shellPrompt)
import XMonad.Prompt.FuzzyMatch (fuzzyMatch, fuzzySort)
import XMonad.Prompt.Pass (passPrompt, passOTPPrompt)
import XMonad.Prompt.Man (manPrompt)
import XMonad.Prompt.Ssh (sshPrompt)
import XMonad.Prompt.XMonad (xmonadPrompt)
import XMonad.Actions.Search (promptSearch, multi)

import XMonad.Prompt.Window ( windowMultiPrompt, allWindows, wsWindows
                            , WindowPrompt(..)
                            )
import XMonad.Actions.EasyMotion ( EasyMotionConfig(..), ChordKeys(..)
                                 , selectWindow
                                 )

import XMonad.Layout.LayoutCombinators (JumpToLayout(JumpToLayout))
import XMonad.Actions.Minimize ( minimizeWindow, maximizeWindow
                               , withFirstMinimized, withLastMinimized
                               , withMinimized
                               )

import XMonad.Prompt.Workspace (workspacePrompt)
import XMonad.Actions.CycleWS ( nextWS, prevWS, shiftToNext, shiftToPrev
                              , toggleWS
                              )
import XMonad.Actions.DynamicWorkspaces ( addWorkspacePrompt, removeWorkspace
                                        , renameWorkspace
                                        )
import XMonad.Actions.WorkspaceNames (swapTo)
import XMonad.Layout.WorkspaceDir (changeDir)
import XMonad.Actions.GroupNavigation (nextMatch, Direction(History))

import System.Exit (exitWith, ExitCode(ExitSuccess))

import Data.Function (on)

key conf = mkKeymap conf
    [ ("M-x"  , shellPrompt promptConfig           )
    , ("M-S-x", shellPrompt promptConfigNoAc       )
    , ("M-C-x", xmonadPrompt promptConfig          )
    , ("M-/"  , promptSearch promptConfigNoAc multi)
    , ("M-z"  , sshPrompt promptConfig             )

    , ("M-<F1>"  , manPrompt promptConfig)

    , ("M-o d", spawn "zeal"        )
    , ("M-o b", spawn "qutebrowser" )
    , ("M-o o", spawn "libreoffice" )
    , ("M-o v", spawn "virt-manager")
    , ("M-o f", spawn "zathura"     )
    , ("M-o k", spawn "pavucontrol" )
    , ("M-o a", spawn "dragon"      )
    , ("M-o '", runInTerm "-t cmatrix" "cmatrix")

    , ("M-$", runInTerm "-t top"  "btop")

    , ("M-S-s r", spawn "systemctl reboot"   )
    , ("M-S-s s", spawn "systemctl suspend"  )
    , ("M-S-s h", spawn "systemctl hibernate")
    , ("M-S-s o", spawn "systemctl poweroff" )
    , ("M-s",     spawn "screenlocker"       ) -- a wrapped script

    , ("M-n",   spawn "dunstctl close"      )
    , ("M-S-n", spawn "dunstctl close-all"  )
    , ("M-C-n", spawn "dunstctl history-pop")

    -- basic window
    , ("M-<Return>"  , spawn $ terminal conf      )
    , ("M-C-<Return>", spawn "emacsclient -c ."   )
    , ("M-S-<Return>", spawn "emacsclient -c"     )
    , ("M-S-c"       , kill                       )
    , ("M-S-<Space>" , sendMessage NextLayout     )
    , ("M-C-<Space>" , setLayout $ layoutHook conf)
    , ("M-r"         , refresh                    )
    -- We use M-<Space> for input methods

    -- move focus up or down the window stack
    , ("M-<Tab>"    , windows focusDown  )
    , ("M-S-<Tab>"  , windows focusUp    )
    , ("M-C-<Tab>"  , windows swapDown   )
    , ("M-C-S-<Tab>", windows swapUp     )
    , ("M-m"        , windows focusMaster)
    , ("M-S-m"      , windows swapMaster )

    -- resizing the master/slave ratio
    , ("M-(", sendMessage Shrink)
    , ("M-)", sendMessage Expand)

    -- floating layer support
    , ("M-t"  , withFocused $ windows . sink)
    , ("M-S-t", withFocused float           )

    -- increase or decrease number of windows in the master area
    , ("M-S-(", sendMessage (IncMasterN (-1)))
    , ("M-S-)", sendMessage (IncMasterN 1   ))

    -- quit, or restart
    , ("M-S-q", io (exitWith ExitSuccess))
    , ("M-q"  , spawn "xmonad --recompile && xmonad --restart")

    -- screenshot
    , ("M-a"  , spawn "flameshot gui   ")
    , ("M-S-a", spawn "flameshot screen")
    , ("M-C-a", spawn "flameshot full  ")

    -- switch window
    , ("M-.", windowMultiPrompt promptConfig $
        (\d -> (d, allWindows)) <$> [ Goto
                                    , Bring
                                    , BringToMaster
                                    , BringCopy
                                    ])
    , ("M-S-.", windowMultiPrompt promptConfig $
        (\d -> (d, wsWindows)) <$> [ Goto
                                   , Bring
                                   , BringToMaster
                                   , BringCopy
                                   ])

    -- window navigation
    , ("M-C-.", nextMatch History (pure True))

    -- layout select
    , ("M-; d"  , sendMessage $ JumpToLayout "DragV"  )
    , ("M-; g"  , sendMessage $ JumpToLayout "Grid"   )
    , ("M-; v"  , sendMessage $ JumpToLayout "GridL"  )
    , ("M-; c"  , sendMessage $ JumpToLayout "Column" )
    , ("M-; t"  , sendMessage $ JumpToLayout "Tiled"  )
    , ("M-; f"  , sendMessage $ JumpToLayout "Full"   )
    , ("M-S-; t", sendMessage $ JumpToLayout "MTiled" )
    , ("M-S-; c", sendMessage $ JumpToLayout "MColumn")
    , ("M-S-; d", sendMessage $ JumpToLayout "DragH"  )

    -- Directional navigation of windows
    -- keybind for dvorak like vim but different
    , ("M-e", windowGo L True)
    , ("M-j", windowGo D True)
    , ("M-k", windowGo U True)
    , ("M-u", windowGo R True)

    -- Swap adjacent windows
    -- keybind for dvorak like vim but different
    , ("M-S-e", windowSwap L True)
    , ("M-S-j", windowSwap D True)
    , ("M-S-k", windowSwap U True)
    , ("M-S-u", windowSwap R True)

    -- Directional navigation of screens
    , ("M-<Left>" , screenGo L True)
    , ("M-<Up>"   , screenGo U True)
    , ("M-<Down>" , screenGo D True)
    , ("M-<Right>", screenGo R True)

    -- Swap workspaces on adjacent screens
    , ("M-S-<Left>" , screenSwap L True)
    , ("M-S-<Down>" , screenSwap D True)
    , ("M-S-<Up>"   , screenSwap U True)
    , ("M-S-<Right>", screenSwap R True)

    -- Send window to adjacent screen
    , ("M-C-<Left>" , windowToScreen L True)
    , ("M-C-<Down>" , windowToScreen D True)
    , ("M-C-<Up>"   , windowToScreen U True)
    , ("M-C-<Right>", windowToScreen R True)

    -- cycle workspace
    , ("M-}"  , nextWS     )
    , ("M-{"  , prevWS     )
    , ("M-S-}", shiftToNext)
    , ("M-S-{", shiftToPrev)
    , ("M-C-{", swapTo Prev)
    , ("M-C-}", swapTo Next)
    , ("M-C-,", toggleWS   )

    -- easy motion
    , ("M-g"  , selectWindow emConfig >>= (`whenJust` windows . focusWindow))
    , ("M-S-g", selectWindow emConfig >>= (`whenJust` killWindow))
    , ("M-C-g", selectWindow emConfig >>= (`whenJust` on (flip (<>)) windows swapMaster . focusWindow))

    -- dynamic workspace
    , ("M-,"  , workspacePrompt promptConfig (windows . view ))
    , ("M-S-,", workspacePrompt promptConfig (windows . shift))
    , ("M-w"  , addWorkspacePrompt promptConfigNoAc)
    , ("M-S-w", removeWorkspace                    )
    , ("M-C-w", renameWorkspace    promptConfigNoAc)

    -- change pwd for current workspace
    , ("M-c", changeDir promptConfigNoAc)

    -- hide windows
    , ("M-d"  , withFocused minimizeWindow)
    , ("M-S-d", withFocused maximizeWindow)
    , ("M-h"  , withFirstMinimized maximizeWindow)
    , ("M-S-h", withLastMinimized maximizeWindow)
    , ("M-C-h", withMinimized $ foldr ((<>) . maximizeWindow) mempty)

    -- fcitx clipboard history to paste

    -- password-store
    , ("M-'"  , passPrompt    promptConfig)
    , ("M-S-'", passOTPPrompt promptConfig)

    -- midia keys
    , ("<XF86AudioLowerVolume>", spawn "pactl set-sink-volume @DEFAULT_SINK@ 1%-"   )
    , ("<XF86AudioRaiseVolume>", spawn "pactl set-sink-volume @DEFAULT_SINK@ 1%+"   )
    , ("<XF86AudioMute>"       , spawn "pactl set-sink-mute   @DEFAULT_SINK@ toggle")
    ]

promptConfig = def
    { font              = C.font
    , searchPredicate   = fuzzyMatch
    , sorter            = fuzzySort
    , bgColor           = Color.background
    , fgColor           = Color.foreground
    , bgHLight          = Color.yellow
    , fgHLight          = Color.selection
    , borderColor       = Color.purple
    , promptBorderWidth = 2
    -- use this to avoid pass unexpected key to applications
    , autoComplete      = Just $ 2 * 10 ^ 5
    , height            = 30
    }

promptConfigNoAc = promptConfig { autoComplete = Nothing }

emConfig = def { txtCol      = Color.foreground
               , bgCol       = Color.background
               , borderCol   = Color.purple
               , borderPx    = 2
               , sKeys       = AnyKeys [xK_a, xK_o, xK_e, xK_u, xK_i, xK_d,
                                        xK_h, xK_t, xK_n, xK_s]
               , cancelKey   = xK_q
               , emFont      = C.fontXL
               }