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
|
{-# OPTIONS_GHC -Wno-name-shadowing #-}
-- |
-- Module : XMonad.Custom.Bindings
-- Description : Key bindings and keys configuration
-- Copyright : (c) Azat Bahawi 2018-2022
-- SPDX-License-Identifier : GPL-3.0-or-later
-- Maintainer : azat@bahawi.net
-- Stability : experimental
-- Portability : non-portable
--
module XMonad.Custom.Bindings
( ngKeys
, ngModMask
, ngMouseBindings
) where
import qualified Data.Map as M
import System.Exit
import XMonad
import XMonad.Actions.CopyWindow
import XMonad.Actions.CycleWS
import XMonad.Actions.DynamicProjects
import XMonad.Actions.DynamicWorkspaces
import qualified XMonad.Actions.FlexibleManipulate
as F
import XMonad.Actions.FloatSnap
import XMonad.Actions.MessageFeedback
import XMonad.Actions.Navigation2D
import XMonad.Actions.Promote
import XMonad.Actions.UpdatePointer
import XMonad.Actions.WithAll
import qualified XMonad.Custom.Misc as C
import XMonad.Custom.Scratchpads
import XMonad.Custom.Theme
import XMonad.Hooks.UrgencyHook
import XMonad.Layout.BinarySpacePartition
import XMonad.Layout.Hidden
import XMonad.Layout.ResizableTile
import XMonad.Layout.SubLayouts
import XMonad.Prompt.ConfirmPrompt
import XMonad.Prompt.Shell
import XMonad.Prompt.Window
import XMonad.Prompt.Workspace
import qualified XMonad.StackSet as S
import XMonad.Util.EZConfig
import XMonad.Util.NamedScratchpad
ngModMask :: KeyMask
ngModMask = mod4Mask
ngKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
ngKeys c = mkKeymap c (rawKeys c)
ngMouseBindings :: XConfig Layout -> M.Map (KeyMask, Button) (Window -> X ())
ngMouseBindings XConfig { XMonad.modMask = ngModMask } = M.fromList
[ ( (ngModMask, button1)
, \w ->
focus w
>> F.mouseWindow F.position w
>> ifClick (snapMagicMove (Just 50) (Just 50) w)
>> windows S.shiftMaster
)
, ( (ngModMask, button3)
, \w ->
focus w
>> F.mouseWindow F.linear w
>> ifClick (snapMagicResize [L, R, U, D] (Just 50) (Just 50) w)
>> windows S.shiftMaster
)
]
zipKeys :: [a] -> [[a]] -> [t1] -> (t1 -> b) -> [([a], b)]
zipKeys m ks as f = zipWith (\k d -> (m ++ k, f d)) ks as
zipKeys' :: [a] -> [[a]] -> [t1] -> (t1 -> t2 -> b) -> t2 -> [([a], b)]
zipKeys' m ks as f b = zipWith (\k d -> (m ++ k, f d b)) ks as
rawKeys :: XConfig Layout -> [(String, X ())]
rawKeys c = withUpdatePointer $ concatMap ($ c) keymaps
where
keymaps =
[ keysBase
, keysSystem
, keysMedia
, keysWorkspaces
, keysSpawnables
, keysWindows
, keysLayout
, keysResize
]
withUpdatePointer :: [(String, X ())] -> [(String, X ())]
withUpdatePointer = map addAction
where
addAction :: (String, X ()) -> (String, X ())
addAction (key, action) =
(key, action >> updatePointer (0.98, 0.01) (0, 0))
keysBase :: XConfig Layout -> [(String, X ())]
keysBase _ =
[ ("M-S-q", confirmPrompt hotPromptTheme "Quit?" $ io exitSuccess)
, ("M-x" , shellPrompt promptTheme)
, ("M-w" , windowPrompt promptTheme Goto allWindows)
, ("M-S-w", windowPrompt promptTheme Bring allWindows)
]
keysSystem :: XConfig Layout -> [(String, X ())]
keysSystem _ = [("M-C-g", return ())]
keysMedia :: XConfig Layout -> [(String, X ())]
keysMedia _ =
[ ("<XF86AudioMicMute>", spawn "pactl set-source-mute 1 toggle")
, ("<XF86AudioMute>" , spawn "pactl set-sink-mute 0 toggle")
, ( "<XF86AudioLowerVolume>"
, spawn "pactl set-sink-mute 0 false && pactl set-sink-volume 0 -10%"
)
, ( "<XF86AudioRaiseVolume>"
, spawn "pactl set-sink-mute 0 false && pactl set-sink-volume 0 +10%"
)
, ("<XF86AudioPlay>", spawn "mpc toggle")
, ("<XF86AudioStop>", spawn "mpc stop")
, ("<XF86AudioPrev>", spawn "mpc prev")
, ("<XF86AudioNext>", spawn "mpc next")
]
keysWorkspaces :: XConfig Layout -> [(String, X ())]
keysWorkspaces _ =
[ ("M-S-o", switchProjectPrompt promptTheme)
, ("M-S-p", shiftToProjectPrompt promptTheme)
, ("M-i" , toggleWS' ["NSP"])
, ("M-n" , workspacePrompt promptTheme $ windows . S.shift)
]
++ zipKeys "M-" wsKeys [0 ..] (withNthWorkspace S.greedyView)
++ zipKeys "M-S-" wsKeys [0 ..] (withNthWorkspace S.shift)
++ zipKeys "M-C-S-" wsKeys [0 ..] (withNthWorkspace copy)
where wsKeys = map show [1 .. 9 :: Int]
keysSpawnables :: XConfig Layout -> [(String, X ())]
keysSpawnables _ =
[ ("M-<Return>", spawn (C.term C.applications))
, ("M-c" , namedScratchpadAction scratchpads "console")
, ("M-m" , namedScratchpadAction scratchpads "music")
, ("M-t" , namedScratchpadAction scratchpads "top")
, ("M-v" , namedScratchpadAction scratchpads "volume")
]
keysWindows :: XConfig Layout -> [(String, X ())]
keysWindows _ =
[ ("M-d" , kill)
, ("M-S-d", confirmPrompt hotPromptTheme "Kill all" killAll)
, ("M-e" , withFocused hideWindow)
, ("M-S-e", popOldestHiddenWindow)
, ("M-p" , promote)
, ("M-g", withFocused $ sendMessage . MergeAll)
, ("M-S-g", withFocused $ sendMessage . UnMerge)
, ("M-u" , focusUrgent)
, ("M-s" , windows S.focusMaster)
, ("M-S-'", windows S.swapDown)
, ("M-S-;", windows S.swapUp)
]
++ zipKeys' "M-" vimKeys directions windowGo True -- TODO W moving
++ zipKeys' "M-S-" vimKeys directions windowSwap True
++ zipKeys "M-C-" vimKeys directions (sendMessage . pullGroup)
++ zipKeys' "M-" arrowKeys directions screenGo True
++ zipKeys' "M-S-" arrowKeys directions windowToScreen True
++ zipKeys' "M-C-" arrowKeys directions screenSwap True
where
directions = [D, U, L, R]
arrowKeys = ["<D>", "<U>", "<L>", "<R>"]
vimKeys = ["j", "k", "h", "l"]
keysLayout :: XConfig Layout -> [(String, X ())]
keysLayout c =
[ ("M-<Tab>" , sendMessage NextLayout)
, ("M-C-<Tab>", toSubl NextLayout)
, ("M-S-<Tab>", setLayout $ XMonad.layoutHook c)
, ("M-S-," , sendMessage $ IncMasterN (-1))
, ("M-S-." , sendMessage $ IncMasterN 1)
]
keysResize :: XConfig Layout -> [(String, X ())]
keysResize _ =
[ ("M-[" , tryMessageR_ (ExpandTowards L) Shrink)
, ("M-]" , tryMessageR_ (ExpandTowards R) Expand)
, ("M-S-[" , tryMessageR_ (ExpandTowards U) MirrorShrink)
, ("M-S-]" , tryMessageR_ (ExpandTowards D) MirrorExpand)
, ("M-C-[" , tryMessageR_ (ShrinkFrom R) Shrink)
, ("M-C-]" , tryMessageR_ (ShrinkFrom L) Expand)
, ("M-S-C-[", tryMessageR_ (ShrinkFrom D) MirrorShrink)
, ("M-S-C-]", tryMessageR_ (ShrinkFrom U) MirrorExpand)
]
where
tryMessageR_ :: (Message a, Message b) => a -> b -> X ()
tryMessageR_ x y = sequence_ [tryMessageWithNoRefreshToCurrent x y, refresh]
|