diff options
Diffstat (limited to 'accounts/gkleen@sif/xmonad/xmonad.hs')
-rw-r--r-- | accounts/gkleen@sif/xmonad/xmonad.hs | 939 |
1 files changed, 0 insertions, 939 deletions
diff --git a/accounts/gkleen@sif/xmonad/xmonad.hs b/accounts/gkleen@sif/xmonad/xmonad.hs deleted file mode 100644 index a44d3bb7..00000000 --- a/accounts/gkleen@sif/xmonad/xmonad.hs +++ /dev/null | |||
@@ -1,939 +0,0 @@ | |||
1 | {-# LANGUAGE TupleSections, ViewPatterns, OverloadedStrings, FlexibleInstances, UndecidableInstances, MultiWayIf, NumDecimals #-} | ||
2 | |||
3 | import XMonad | ||
4 | import XMonad.Hooks.DynamicLog | ||
5 | import XMonad.Hooks.ManageDocks | ||
6 | import XMonad.Util.Run hiding (proc) | ||
7 | import XMonad.Util.Loggers | ||
8 | import XMonad.Util.EZConfig(additionalKeys) | ||
9 | import System.IO | ||
10 | import System.IO.Error | ||
11 | import System.Environment | ||
12 | import Data.Map (Map) | ||
13 | import qualified Data.Map as Map | ||
14 | import qualified XMonad.StackSet as W | ||
15 | import System.Exit | ||
16 | import Control.Monad.State (get) | ||
17 | -- import XMonad.Layout.Spiral | ||
18 | import Data.Ratio | ||
19 | import Data.List | ||
20 | import Data.Char | ||
21 | import Data.Maybe (fromMaybe, listToMaybe, maybeToList, catMaybes, isJust) | ||
22 | import XMonad.Layout.Tabbed | ||
23 | import XMonad.Prompt | ||
24 | import XMonad.Prompt.Input | ||
25 | import XMonad.Util.Scratchpad | ||
26 | import XMonad.Util.NamedScratchpad | ||
27 | import XMonad.Util.Ungrab | ||
28 | import Control.Monad (sequence, liftM, liftM2, join, void) | ||
29 | import XMonad.Util.WorkspaceCompare | ||
30 | import XMonad.Layout.NoBorders | ||
31 | import XMonad.Layout.PerWorkspace | ||
32 | import XMonad.Layout.SimplestFloat | ||
33 | import XMonad.Layout.Renamed | ||
34 | import XMonad.Layout.Reflect | ||
35 | import XMonad.Layout.OnHost | ||
36 | import XMonad.Layout.Combo | ||
37 | import XMonad.Layout.ComboP | ||
38 | import XMonad.Layout.Column | ||
39 | import XMonad.Layout.TwoPane | ||
40 | import XMonad.Layout.IfMax | ||
41 | import XMonad.Layout.LayoutBuilder | ||
42 | import XMonad.Layout.WindowNavigation | ||
43 | import XMonad.Layout.Dwindle | ||
44 | import XMonad.Layout.TrackFloating | ||
45 | import System.Process | ||
46 | import System.Directory (removeFile) | ||
47 | import System.Posix.Files | ||
48 | import System.FilePath ((</>)) | ||
49 | import Control.Concurrent | ||
50 | import System.Posix.Process (getProcessID) | ||
51 | import System.IO.Error | ||
52 | import System.IO | ||
53 | import XMonad.Hooks.ManageHelpers hiding (CW) | ||
54 | import XMonad.Hooks.UrgencyHook as U | ||
55 | import XMonad.Hooks.EwmhDesktops | ||
56 | import XMonad.StackSet (RationalRect (..)) | ||
57 | import Control.Monad (when, filterM, (<=<)) | ||
58 | import Graphics.X11.ExtraTypes.XF86 | ||
59 | import XMonad.Util.Cursor | ||
60 | import XMonad.Actions.Warp | ||
61 | import XMonad.Actions.FloatKeys | ||
62 | import XMonad.Util.SpawnOnce | ||
63 | import System.Directory | ||
64 | import System.FilePath | ||
65 | import XMonad.Actions.CopyWindow | ||
66 | import XMonad.Hooks.ServerMode | ||
67 | import XMonad.Actions.Commands | ||
68 | import XMonad.Actions.CycleWS | ||
69 | import XMonad.Actions.RotSlaves | ||
70 | import XMonad.Actions.UpdatePointer | ||
71 | import XMonad.Prompt.Window | ||
72 | import Data.IORef | ||
73 | import Data.Monoid | ||
74 | import Data.String | ||
75 | import qualified XMonad.Actions.PhysicalScreens as P | ||
76 | |||
77 | import XMonad.Layout.IM | ||
78 | |||
79 | import System.Taffybar.Support.PagerHints (pagerHints) | ||
80 | |||
81 | import XMonad.Prompt.MyShell | ||
82 | import XMonad.Prompt.MyPass | ||
83 | import XMonad.Prompt.MySsh | ||
84 | |||
85 | import XMonad.Mpv | ||
86 | |||
87 | import Network.HostName | ||
88 | |||
89 | import Control.Applicative ((<$>)) | ||
90 | |||
91 | import Libnotify as Notify hiding (appName) | ||
92 | import qualified Libnotify as Notify (appName) | ||
93 | import Libnotify (Notification) | ||
94 | -- import System.Information.Battery | ||
95 | |||
96 | import Data.Int (Int32) | ||
97 | |||
98 | import System.Posix.Process | ||
99 | import System.Posix.Signals | ||
100 | import System.Posix.IO as Posix | ||
101 | import Control.Exception | ||
102 | |||
103 | import System.IO.Unsafe | ||
104 | |||
105 | import Control.Monad.Trans.Class | ||
106 | import Control.Monad.Trans.Maybe | ||
107 | |||
108 | import Data.Fixed (Micro) | ||
109 | |||
110 | import qualified Data.Text as Text | ||
111 | import Data.Ord (comparing) | ||
112 | import Debug.Trace | ||
113 | |||
114 | instance MonadIO m => IsString (m ()) where | ||
115 | fromString = spawn | ||
116 | |||
117 | type KeyMap = Map (ButtonMask, KeySym) (X ()) | ||
118 | |||
119 | data Host = Host | ||
120 | { hName :: HostName | ||
121 | , hManageHook :: ManageHook | ||
122 | , hWsp :: Integer -> WorkspaceId | ||
123 | , hCoWsp :: String -> Maybe WorkspaceId | ||
124 | , hKeysMod :: XConfig Layout -> (KeyMap -> KeyMap) | ||
125 | , hScreens :: [P.PhysicalScreen] | ||
126 | , hKbLayouts :: [(String, Maybe String)] | ||
127 | , hCmds :: X [(String, X ())] | ||
128 | , hKeyUpKeys :: XConfig Layout -> KeyMap | ||
129 | } | ||
130 | |||
131 | defaultHost = Host { hName = "unkown" | ||
132 | , hManageHook = composeOne [manageScratchTerm] | ||
133 | , hWsp = show | ||
134 | , hCoWsp = const Nothing | ||
135 | , hKeysMod = const id | ||
136 | , hScreens = [0,1..] | ||
137 | , hKbLayouts = [ ("us", Just "dvp") | ||
138 | , ("us", Nothing) | ||
139 | , ("de", Nothing) | ||
140 | ] | ||
141 | , hCmds = return [] | ||
142 | , hKeyUpKeys = const Map.empty | ||
143 | } | ||
144 | |||
145 | browser :: String | ||
146 | browser = "env MOZ_USE_XINPUT2=1 firefox" | ||
147 | |||
148 | gray, darkGray, red, green :: String | ||
149 | gray = "#808080" | ||
150 | darkGray = "#202020" | ||
151 | red = "#800000" | ||
152 | green = "#008000" | ||
153 | |||
154 | hostFromName :: HostName -> Host | ||
155 | hostFromName h@("vali") = defaultHost { hName = h | ||
156 | , hManageHook = composeOne $ catMaybes [ Just manageScratchTerm | ||
157 | , assign "web" $ className =? ".dwb-wrapped" | ||
158 | , assign "web" $ className =? "Chromium" | ||
159 | , assign "work" $ className =? "Emacs" | ||
160 | , assign "media" $ className =? "mpv" | ||
161 | ] | ||
162 | , hWsp = hWsp | ||
163 | , hCoWsp = hCoWsp | ||
164 | , hKeysMod = \conf -> Map.union $ (Map.fromList $ join $ map (spawnBindings conf) [ (xK_d, ["chromium", "chromium $(xclip -o)"]) | ||
165 | , (xK_e, ["emacsclient -c"]) | ||
166 | ]) | ||
167 | `Map.union` | ||
168 | ( Map.fromList [ ((XMonad.modMask conf .|. controlMask, xK_Return), scratchpadSpawnActionCustom $ (XMonad.terminal conf) ++ " -name scratchpad -title scratchpad -e tmux new-session -D -s scratch") | ||
169 | ] ) | ||
170 | , hScreens = hScreens defaultHost | ||
171 | } | ||
172 | where | ||
173 | workspaceNames = Map.fromList [ (2, "web") | ||
174 | , (3, "work") | ||
175 | , (10, "media") | ||
176 | ] | ||
177 | hWsp = wspFromMap workspaceNames | ||
178 | hCoWsp = coWspFromMap workspaceNames | ||
179 | assign wsp test = (\wsp -> test -?> doShift wsp) <$> hCoWsp wsp | ||
180 | hostFromName h | ||
181 | | h `elem` ["hel", "sif"] = defaultHost { hName = h | ||
182 | , hManageHook = namedScratchpadManageHook scratchpads <+> composeOne (catMaybes | ||
183 | [ assign "mpv" $ className =? "mpv" | ||
184 | , assign "mpv" $ stringProperty "WM_WINDOW_ROLE" =? "presentation" | ||
185 | , assign "read" $ stringProperty "WM_WINDOW_ROLE" =? "presenter" | ||
186 | , assign "mpv" $ className =? "factorio" | ||
187 | , assign "mpv" $ resource =? "twitch" | ||
188 | , assign "web" $ className =? "chromium-browser" | ||
189 | , assign "web" $ className =? "Google-chrome" | ||
190 | , assign "work" $ (appName =? "Devtools" <&&> className =? "firefox") | ||
191 | , assign "work" $ className =? "Postman" | ||
192 | , assign "web" $ (appName =? "Navigator" <&&> className =? "firefox") | ||
193 | , assign "comm" $ (className =? "Emacs" <&&> title =? "Mail") | ||
194 | , assign "comm" $ className =? "Zulip" | ||
195 | , assign "comm" $ className =? "Element" | ||
196 | , assign "comm" $ className =? "Rocket.Chat" | ||
197 | , assign "comm" $ className =? "Discord" | ||
198 | , assign "comm" $ className =? "Rainbow" | ||
199 | , assign "media" $ resource =? "media" | ||
200 | , assign "monitor" $ className =? "Grafana" | ||
201 | , assign "monitor" $ className =? "Virt-viewer" | ||
202 | , assign "monitor" $ resource =? "htop" | ||
203 | , assign "monitor" $ resource =? "monitor" | ||
204 | , assign "monitor" $ className =? "xfreerdp" | ||
205 | , assign "monitor" $ className =? "org.remmina.Remmina" | ||
206 | , Just $ resource =? "htop" -?> centerFloat | ||
207 | , Just $ (className =? "Scp-dbus-service.py") -?> centerFloat | ||
208 | , Just $ resource =? "log" -?> centerFloat | ||
209 | , assign "work" $ className =? "Alacritty" | ||
210 | , Just $ (appName =? "Edit with Emacs FRAME") -?> centerFloat | ||
211 | , assign' ["work", "uni"] $ (className =? "Emacs" <&&> appName /=? "Edit with Emacs FRAME") | ||
212 | , assign' ["work", "uni"] $ className =? "jetbrains-idea-ce" | ||
213 | , assign "read" $ className =? "llpp" | ||
214 | , assign "read" $ className =? "Evince" | ||
215 | , assign "read" $ className =? "Zathura" | ||
216 | , assign "read" $ className =? "MuPDF" | ||
217 | , assign "read" $ className =? "Xournal" | ||
218 | , assign "read" $ appName =? "libreoffice" | ||
219 | , assign "read" $ appName =? "com-trollworks-gcs-app-GCS" | ||
220 | , assign "read" $ appName =? "Tux.py" | ||
221 | , assign "read" $ className =? "Gnucash" | ||
222 | , assign "comm" $ className =? "Skype" | ||
223 | , assign "comm" $ className =? "Daily" | ||
224 | , assign "comm" $ className =? "Pidgin" | ||
225 | , assign "comm" $ className =? "Thunderbird" | ||
226 | , assign "comm" $ className =? "Slack" | ||
227 | , Just $ (resource =? "xvkbd") -?> doRectFloat $ RationalRect (1 % 8) (3 % 8) (6 % 8) (4 % 8) | ||
228 | , Just $ (stringProperty "_NET_WM_WINDOW_TYPE" =? "_NET_WM_WINDOW_TYPE_DIALOG") -?> doFloat | ||
229 | , Just $ (className =? "Dunst") -?> doFloat | ||
230 | , Just $ (className =? "Xmessage") -?> doCenterFloat | ||
231 | , Just $ (className =? "Nm-openconnect-auth-dialog") -?> centerFloat | ||
232 | , Just $ (className =? "Pinentry") -?> doCenterFloat | ||
233 | , Just $ (className =? "pinentry") -?> doCenterFloat | ||
234 | , Just $ (stringProperty "WM_WINDOW_ROLE" =? "GtkFileChooseDialog") -?> centerFloatSmall | ||
235 | , Just $ (className =? "Nvidia-settings") -?> doCenterFloat | ||
236 | , Just $ fmap ("Minetest" `isInfixOf`) title -?> doIgnore | ||
237 | , Just $ fmap ("Automachef" `isInfixOf`) title -?> doIgnore | ||
238 | , assign "call" $ className =? "zoom" | ||
239 | ]) | ||
240 | , hWsp = hWsp | ||
241 | , hCoWsp = hCoWsp | ||
242 | , hKeysMod = \conf -> Map.union $ (Map.fromList $ join $ map (spawnBindings conf) [ (xK_e, ["emacsclient -c"]) | ||
243 | , (xK_d, [fromString browser, "google-chrome" {- , "notmuch-links" -}]) | ||
244 | , (xK_c, [ inputPrompt xPConfigMonospace "dc" ?+ dc ]) | ||
245 | , (xK_g, ["pidgin"]) | ||
246 | , (xK_s, ["skype"]) | ||
247 | -- , (xK_p, [mkPassPrompt "Type password" pwType xPConfig, mkPassPrompt "Show password" pwShow xPConfig, mkPassPrompt "Copy password" pwClip xPConfig]) | ||
248 | , (xK_w, ["sudo rewacom"]) | ||
249 | , (xK_y, [ "tmux new-window -dt media /var/media/link.hs $(xclip -o)" | ||
250 | , "tmux new-window -dt media /var/media/download.hs $(xclip -o)" | ||
251 | , "tmux new-window -dt media /var/media/download.hs $(xclip -o -selection clipboard)" | ||
252 | ]) | ||
253 | , (xK_l, [ "tmux new-window -dt media mpv $(xclip -o)" | ||
254 | , "tmux new-window -dt media mpv $(xclip -o -selection clipboard)" | ||
255 | , "alacritty --class media -e tmuxp load /var/media" | ||
256 | ]) | ||
257 | {- , (xK_m, [ "emacsclient -c -F \"'(title . \\\"Mail\\\")\" -e '(notmuch)'" | ||
258 | , "emacsclient -c -F \"'(title . \\\"Mail\\\")\" -e '(notmuch-mua-new-mail)'" | ||
259 | , "emacsclient -c -F \"'(title . \\\"Mail\\\")\" -e \"(browse-url-mail \"$(xclip -o)\")\"" | ||
260 | ]) -} | ||
261 | , (xK_Return, ["keynav start,windowzoom", "keynav start"]) | ||
262 | , (xK_t, [inputPrompt xPConfigMonospace "fuzzytime timer" ?+ fuzzytime, fuzzytime "unset", work_fuzzytime]) | ||
263 | , (xK_a, [inputPrompt xPConfigMonospace "adjmix" ?+ adjmix]) | ||
264 | , (xK_s, [ inputPromptWithCompl xPConfigMonospace "start synergy" synergyCompl ?+ synergyStart | ||
265 | , inputPromptWithCompl xPConfigMonospace "stop synergy" synergyCompl ?+ synergyStop | ||
266 | ]) | ||
267 | , (xK_h, [ "alacritty --class htop -e htop" | ||
268 | , "alacritty --class log -e journalctl -xef" | ||
269 | ]) | ||
270 | , (xK_x, [ "autorandr -c" | ||
271 | , "autorandr -fl def" | ||
272 | ]) | ||
273 | , (xK_z, [ "zulip -- --force-device-scale-factor=2" | ||
274 | ]) | ||
275 | ]) | ||
276 | `Map.union` | ||
277 | ( Map.fromList [ ((XMonad.modMask conf .|. controlMask, xK_Return), namedScratchpadAction scratchpads "term") | ||
278 | , ((XMonad.modMask conf .|. controlMask, xK_a), namedScratchpadAction scratchpads "pavucontrol") | ||
279 | , ((XMonad.modMask conf .|. controlMask, xK_o), namedScratchpadAction scratchpads "easyeffects") | ||
280 | , ((XMonad.modMask conf .|. controlMask .|. shiftMask, xK_o), namedScratchpadAction scratchpads "helvum") | ||
281 | , ((XMonad.modMask conf .|. controlMask, xK_w), namedScratchpadAction scratchpads "alarms") | ||
282 | , ((XMonad.modMask conf .|. controlMask, xK_b), namedScratchpadAction scratchpads "blueman") | ||
283 | , ((XMonad.modMask conf .|. controlMask, xK_p), namedScratchpadAction scratchpads "keepassxc") | ||
284 | , ((XMonad.modMask conf .|. controlMask, xK_t), namedScratchpadAction scratchpads "toggl") | ||
285 | , ((XMonad.modMask conf .|. controlMask, xK_e), namedScratchpadAction scratchpads "emacs") | ||
286 | , ((XMonad.modMask conf .|. controlMask, xK_m), namedScratchpadAction scratchpads "calendar") | ||
287 | , ((XMonad.modMask conf .|. controlMask, xK_f), namedScratchpadAction scratchpads "music") | ||
288 | , ((XMonad.modMask conf .|. mod1Mask, xK_Up), rotate U) | ||
289 | , ((XMonad.modMask conf .|. mod1Mask, xK_Down), rotate D) | ||
290 | , ((XMonad.modMask conf .|. mod1Mask, xK_Left), rotate L) | ||
291 | , ((XMonad.modMask conf .|. mod1Mask, xK_Right), rotate R) | ||
292 | , ((controlMask, xK_space ), "dunstctl close" ) | ||
293 | , ((controlMask .|. shiftMask, xK_space ), "dunstctl close-all" ) | ||
294 | , ((controlMask, xK_period), "dunstctl context" ) | ||
295 | , ((controlMask, xK_comma ), "dunstctl history-pop") | ||
296 | -- , ((XMonad.modMask conf .|. shiftMask, xK_a), startMute "hel") | ||
297 | ] ) | ||
298 | , hKeyUpKeys = \conf -> Map.fromList [ -- ((XMonad.modMask conf .|. shiftMask, xK_a), stopMute "hel") | ||
299 | ] | ||
300 | , hScreens = hScreens defaultHost | ||
301 | , hCmds = return [ ("prev-workspace", prevWS) | ||
302 | , ("next-workspace", nextWS) | ||
303 | , ("prev-window", rotAllDown) | ||
304 | , ("next-window", rotAllUp) | ||
305 | , ("banish", banishScreen LowerRight) | ||
306 | , ("update-gpg-tty", safeSpawn "gpg-connect-agent" ["UPDATESTARTUPTTY", "/bye"]) | ||
307 | , ("rescreen", rescreen) | ||
308 | , ("repanel", do | ||
309 | spawn "nm-applet" | ||
310 | spawn "blueman-applet" | ||
311 | spawn "pasystray" | ||
312 | spawn "kdeconnect-indicator" | ||
313 | spawn "dunst -print" | ||
314 | spawn "udiskie" | ||
315 | spawn "autocutsel -s PRIMARY" | ||
316 | spawn "autocutsel -s CLIPBOARD" | ||
317 | ) | ||
318 | , ("pause", mediaMpv $ MpvSetProperty "pause" True) | ||
319 | , ("unpause", mediaMpv $ MpvSetProperty "pause" False) | ||
320 | , ("exit", io $ exitWith ExitSuccess) | ||
321 | ] | ||
322 | } | ||
323 | where | ||
324 | withGdkScale act = void . xfork $ setEnv "GDK_SCALE" "2" >> act | ||
325 | workspaceNames = Map.fromList [ (1, "comm") | ||
326 | , (2, "web") | ||
327 | , (3, "work") | ||
328 | , (4, "read") | ||
329 | , (5, "monitor") | ||
330 | , (6, "uni") | ||
331 | , (8, "call") | ||
332 | , (9, "media") | ||
333 | , (10, "mpv") | ||
334 | ] | ||
335 | scratchpads = [ NS "term" "alacritty --class scratchpad --title scratchpad -e tmux new-session -AD -s scratch" (resource =? "scratchpad") centerFloat | ||
336 | , NS "pavucontrol" "pavucontrol" (resource =? "pavucontrol") centerFloat | ||
337 | , NS "helvum" "helvum" (resource =? "helvum") centerFloat | ||
338 | , NS "easyeffects" "easyeffects" (resource =? "easyeffects") centerFloat | ||
339 | , NS "alarms" "alarm-clock-applet" (className =? "Alarm-clock-applet" <&&> title =? "Alarms") centerFloat | ||
340 | , NS "blueman" "blueman-manager" (className =? ".blueman-manager-wrapped") centerFloat | ||
341 | , NS "keepassxc" "keepassxc" (className =? "KeePassXC") centerFloat | ||
342 | , NS "toggl" "toggldesktop" (className =? "Toggl Desktop") centerFloat | ||
343 | , NS "calendar" "minetime -- --force-device-scale-factor=1.6" (className =? "MineTime") centerFloat | ||
344 | , NS "emacs" "emacsclient -c -F \"'(title . \\\"Scratchpad\\\")\"" (className =? "Emacs" <&&> title =? "Scratchpad") centerFloat | ||
345 | , NS "music" "ytmdesktop" (className =? "youtube-music-desktop-app") centerFloat | ||
346 | ] | ||
347 | centerFloat = customFloating $ RationalRect (1 % 16) (1 % 16) (7 % 8) (7 % 8) | ||
348 | centerFloatSmall = customFloating $ RationalRect (1 % 4) (1 % 4) (1 % 2) (1 % 2) | ||
349 | hWsp = wspFromMap workspaceNames | ||
350 | hCoWsp = coWspFromMap workspaceNames | ||
351 | assign wsp test = (\wsp -> test -?> doShift wsp) <$> hCoWsp wsp | ||
352 | assign' :: [String] -> Query Bool -> Maybe MaybeManageHook | ||
353 | assign' wsps test = do | ||
354 | wsIds <- mapM hCoWsp wsps | ||
355 | return $ test -?> go wsIds | ||
356 | where | ||
357 | go :: [WorkspaceId] -> ManageHook | ||
358 | go wsps = do | ||
359 | visWsps <- liftX $ (\wset -> W.tag . W.workspace <$> W.current wset : W.visible wset) <$> gets windowset | ||
360 | case (filter (`elem` visWsps) wsps, wsps) of | ||
361 | (wsp : _, _) -> doShift wsp | ||
362 | (_, wsp : _) -> doShift wsp | ||
363 | ([], []) -> return mempty | ||
364 | rotate rot = do | ||
365 | safeSpawn "xrandr" ["--output", "eDP-1", "--rotate", xrandrDir] | ||
366 | mapM_ rotTouch touchscreens | ||
367 | where | ||
368 | xrandrDir = case rot of | ||
369 | U -> "normal" | ||
370 | L -> "left" | ||
371 | R -> "right" | ||
372 | D -> "inverted" | ||
373 | matrix = case rot of | ||
374 | U -> [ [ 1, 0, 0] | ||
375 | , [ 0, 1, 0] | ||
376 | , [ 0, 0, 1] | ||
377 | ] | ||
378 | L -> [ [ 0, -1, 1] | ||
379 | , [ 1, 0, 0] | ||
380 | , [ 0, 0, 1] | ||
381 | ] | ||
382 | R -> [ [ 0, 1, 0] | ||
383 | , [-1, 0, 1] | ||
384 | , [ 0, 0, 1] | ||
385 | ] | ||
386 | D -> [ [-1, 0, 1] | ||
387 | , [ 0, -1, 1] | ||
388 | , [ 0, 0, 1] | ||
389 | ] | ||
390 | touchscreens = [ "Wacom Co.,Ltd. Pen and multitouch sensor Finger touch" | ||
391 | , "Wacom Co.,Ltd. Pen and multitouch sensor Pen stylus" | ||
392 | , "Wacom Co.,Ltd. Pen and multitouch sensor Pen eraser" | ||
393 | ] | ||
394 | rotTouch screen = do | ||
395 | safeSpawn "xinput" $ ["set-prop", screen, "Coordinate Transformation Matrix"] ++ map (\n -> show n ++ ",") (concat matrix) | ||
396 | safeSpawn "xinput" ["map-to-output", screen, "eDP-1"] | ||
397 | withPw f label = io . void . forkProcess $ do | ||
398 | uninstallSignalHandlers | ||
399 | void $ createSession | ||
400 | (dropWhileEnd isSpace -> pw) <- readCreateProcess (proc "pass" ["show", label]) "" | ||
401 | void $ f pw | ||
402 | pwType :: String -> X () | ||
403 | pwType = withPw $ readCreateProcess (proc "xdotool" ["type", "--clearmodifiers", "--file", "-"]) | ||
404 | pwClip label = safeSpawn "pass" ["show", "--clip", label] | ||
405 | pwShow :: String -> X () | ||
406 | pwShow = withPw $ \pw -> do | ||
407 | xmessage <- fromMaybe "xmessage" <$> liftIO (lookupEnv "XMONAD_XMESSAGE") | ||
408 | readCreateProcess (proc xmessage ["-file", "-"]) pw | ||
409 | fuzzytime str = safeSpawn "fuzzytime" $ "timer" : words str | ||
410 | work_fuzzytime = io . void . forkProcess $ do | ||
411 | readCreateProcess (proc "worktime" []) "" >>= safeSpawn "fuzzytime" . ("timer" : ) . pure | ||
412 | adjmix str = safeSpawn "adjmix" $ words str | ||
413 | dc expr = void . xfork $ do | ||
414 | result <- readProcess "dc" [] $ expr ++ "f" | ||
415 | let | ||
416 | (first : rest) = filter (not . null) $ lines result | ||
417 | notification = Notify.summary first <> Notify.body (unlines rest) <> Notify.timeout Infinite <> Notify.urgency Normal <> Notify.appName "dc" | ||
418 | void $ Notify.display notification | ||
419 | synergyCompl = mkComplFunFromList' xPConfigMonospace ["mathw86"] | ||
420 | synergyStart host = safeSpawn "systemctl" ["--user", "start", "synergy-rtunnel@" ++ host ++ ".service"] | ||
421 | synergyStop host = safeSpawn "systemctl" ["--user", "stop", "synergy-rtunnel@" ++ host ++ ".service"] | ||
422 | |||
423 | hostFromName _ = defaultHost | ||
424 | |||
425 | -- muteRef :: IORef (Maybe (String, Notification)) | ||
426 | -- {-# NOINLINE muteRef #-} | ||
427 | -- muteRef = unsafePerformIO $ newIORef Nothing | ||
428 | |||
429 | -- startMute, stopMute :: String -> X () | ||
430 | -- startMute sink = liftIO $ do | ||
431 | -- muted <- isJust <$> readIORef muteRef | ||
432 | -- when (not muted) $ do | ||
433 | -- let | ||
434 | -- notification = Notify.summary "Muted" <> Notify.timeout Infinite <> Notify.urgency Normal | ||
435 | -- level = "0.0dB" | ||
436 | -- -- level <- runProcessWithInput "ssh" ["bragi", "cat", "/dev/shm/mix/" ++ sink ++ "/level"] "" | ||
437 | -- -- callProcess "ssh" ["bragi", "adjmix", "-t", sink, "-o", "0"] | ||
438 | -- hPutStrLn stderr "Mute" | ||
439 | -- writeIORef muteRef . Just . (level, ) =<< Notify.display notification | ||
440 | -- stopMute sink = liftIO $ do | ||
441 | -- let | ||
442 | -- unmute (Just (level, notification)) = do | ||
443 | -- hPutStrLn stderr "Unmute" | ||
444 | -- -- callProcess "ssh" ["bragi", "adjmix", "-t", sink, "-o", level] | ||
445 | -- Notify.close notification | ||
446 | -- unmute Nothing = return () | ||
447 | -- muted <- isJust <$> readIORef muteRef | ||
448 | -- when muted . join . atomicModifyIORef muteRef $ (Nothing, ) . unmute | ||
449 | |||
450 | wspFromMap workspaceNames = \i -> case Map.lookup i workspaceNames of | ||
451 | Just str -> show i ++ " " ++ str | ||
452 | Nothing -> show i | ||
453 | |||
454 | coWspFromMap workspaceNames = \str -> case filter ((== str) . snd) $ Map.toList workspaceNames of | ||
455 | [] -> Nothing | ||
456 | [(i, _)] -> Just $ wspFromMap workspaceNames i | ||
457 | _ -> Nothing | ||
458 | |||
459 | spawnModifiers = [0, controlMask, shiftMask .|. controlMask] | ||
460 | spawnBindings :: XConfig layout -> (KeySym, [X ()]) -> [((KeyMask, KeySym), X ())] | ||
461 | spawnBindings conf (k, cmds) = zipWith (\m cmd -> ((modm .|. mod1Mask .|. m, k), cmd)) spawnModifiers cmds | ||
462 | where | ||
463 | modm = XMonad.modMask conf | ||
464 | |||
465 | manageScratchTerm = (resource =? "scratchpad" <||> resource =? "keysetup") -?> doRectFloat $ RationalRect (1 % 16) (1 % 16) (7 % 8) (7 % 8) | ||
466 | |||
467 | tabbedLayout t = renamed [Replace "Tabbed"] $ reflectHoriz $ t CustomShrink $ tabbedTheme | ||
468 | tabbedLayoutHoriz t = renamed [Replace "Tabbed Horiz"] $ reflectVert $ t CustomShrink $ tabbedTheme | ||
469 | tabbedTheme = def | ||
470 | { activeColor = "black" | ||
471 | , inactiveColor = "black" | ||
472 | , urgentColor = "black" | ||
473 | , activeBorderColor = gray | ||
474 | , inactiveBorderColor = darkGray | ||
475 | , urgentBorderColor = red | ||
476 | , activeTextColor = gray | ||
477 | , inactiveTextColor = gray | ||
478 | , urgentTextColor = gray | ||
479 | , decoHeight = 32 | ||
480 | , fontName = "xft:Fira Sans:pixelsize=21" | ||
481 | } | ||
482 | |||
483 | main :: IO () | ||
484 | main = do | ||
485 | arguments <- either (const []) id <$> tryIOError getArgs | ||
486 | case arguments of | ||
487 | ["--command", s] -> do | ||
488 | d <- openDisplay "" | ||
489 | rw <- rootWindow d $ defaultScreen d | ||
490 | a <- internAtom d "XMONAD_COMMAND" False | ||
491 | m <- internAtom d s False | ||
492 | allocaXEvent $ \e -> do | ||
493 | setEventType e clientMessage | ||
494 | setClientMessageEvent e rw a 32 m currentTime | ||
495 | sendEvent d rw False structureNotifyMask e | ||
496 | sync d False | ||
497 | _ -> do | ||
498 | -- batteryMon <- xfork $ monitorBattery Nothing Nothing | ||
499 | hostname <- getHostName | ||
500 | let | ||
501 | host = hostFromName hostname | ||
502 | setEnv "HOST" hostname | ||
503 | let myConfig = withHostUrgency . ewmhFullscreen . ewmh . pagerHints $ docks def | ||
504 | { manageHook = hManageHook host | ||
505 | , terminal = "alacritty" | ||
506 | , layoutHook = smartBorders . avoidStruts $ windowNavigation layout' | ||
507 | , logHook = do | ||
508 | dynamicLogString xmobarPP' >>= writeProps | ||
509 | updatePointer (99 % 100, 98 % 100) (0, 0) | ||
510 | , modMask = mod4Mask | ||
511 | , keys = \conf -> hKeysMod host conf $ myKeys' conf host | ||
512 | , workspaces = take (length numKeys) $ map wsp [1..] | ||
513 | , startupHook = setDefaultCursor xC_left_ptr | ||
514 | , normalBorderColor = darkGray | ||
515 | , focusedBorderColor = gray | ||
516 | , handleEventHook = serverModeEventHookCmd' (hCmds host) <+> keyUpEventHook | ||
517 | } | ||
518 | writeProps str = do | ||
519 | let encodeCChar = map $ fromIntegral . fromEnum | ||
520 | atoms = [ "_XMONAD_WORKSPACES" | ||
521 | , "_XMONAD_LAYOUT" | ||
522 | , "_XMONAD_TITLE" | ||
523 | ] | ||
524 | (flip mapM_) (zip atoms (lines str)) $ \(atom', content) -> do | ||
525 | ustring <- getAtom "UTF8_STRING" | ||
526 | atom <- getAtom atom' | ||
527 | withDisplay $ \dpy -> io $ do | ||
528 | root <- rootWindow dpy $ defaultScreen dpy | ||
529 | changeProperty8 dpy root atom ustring propModeReplace $ encodeCChar content | ||
530 | sync dpy True | ||
531 | wsp = hWsp host | ||
532 | -- We can´t define per-host layout modifiers because we lack dependent types | ||
533 | layout' = onHost "skadhi" ( onWorkspace (wsp 1) (Full ||| withIM (1%5) (Title "Buddy List") tabbedLayout') $ | ||
534 | onWorkspace (wsp 10) Full $ | ||
535 | onWorkspace (wsp 2) (Full ||| tabbedLayout') $ | ||
536 | onWorkspace (wsp 5) tabbedLayout' $ | ||
537 | onWorkspace (wsp 8) (withIM (1%5) (Title "Friends") tabbedLayout') $ | ||
538 | defaultLayouts | ||
539 | ) $ | ||
540 | onHost "vali" ( onWorkspace (wsp 2) (Full ||| tabbedLayout' ||| combineTwo (TwoPane 0.01 0.57) Full tabbedLayout') $ | ||
541 | onWorkspace (wsp 3) workLayouts $ | ||
542 | defaultLayouts | ||
543 | ) $ | ||
544 | onHost "hel" ( onWorkspace (wsp 1) (withIM (1 % 8) (Title "Buddy List") $ trackFloating tabbedLayout') $ | ||
545 | onWorkspace (wsp 2) (tabbedLayout''' ||| Dwindle R CW 1 (5 % 100)) $ | ||
546 | onWorkspace (wsp 3) workLayouts $ | ||
547 | onWorkspace (wsp 6) workLayouts $ | ||
548 | onWorkspace (wsp 4) (tabbedLayout' ||| tabbedLayoutHoriz' ||| Dwindle R CW 1 (5 % 100)) $ | ||
549 | onWorkspace (wsp 5) (tabbedLayout''' ||| Dwindle R CW 1 (5 % 100)) $ | ||
550 | onWorkspace (wsp 10) (tabbedLayout''' ||| combineTwoP (TwoPane (1 % 100) (3 % 4)) tabbedLayout''' tabbedLayout''' (ClassName "mpv") ||| Dwindle R CW 1 (5 % 100)) $ | ||
551 | defaultLayouts | ||
552 | ) $ | ||
553 | onHost "sif" ( onWorkspace (wsp 1) (withIM (1 % 8) (Title "Buddy List") $ trackFloating tabbedLayout') $ | ||
554 | onWorkspace (wsp 2) (tabbedLayout''' ||| Dwindle R CW 1 (5 % 100)) $ | ||
555 | onWorkspace (wsp 3) workLayouts $ | ||
556 | onWorkspace (wsp 6) workLayouts $ | ||
557 | onWorkspace (wsp 4) (tabbedLayout' ||| tabbedLayoutHoriz' ||| Dwindle R CW 1 (5 % 100)) $ | ||
558 | onWorkspace (wsp 5) (tabbedLayout''' ||| Dwindle R CW 1 (5 % 100)) $ | ||
559 | onWorkspace (wsp 8) tabbedLayout''' $ | ||
560 | onWorkspace (wsp 10) (tabbedLayout''' ||| combineTwoP (TwoPane (1 % 100) (3 % 4)) tabbedLayout''' tabbedLayout''' (ClassName "mpv") ||| Dwindle R CW 1 (5 % 100)) $ | ||
561 | defaultLayouts | ||
562 | ) $ | ||
563 | defaultLayouts | ||
564 | -- tabbedLayout''' = renamed [Replace "Tabbed'"] $ IfMax 1 (noBorders Full) (tabbedLayout tabbedBottomAlways) | ||
565 | tabbedLayout''' = tabbedLayout tabbedBottom | ||
566 | tabbedLayout' = tabbedLayout tabbedBottomAlways | ||
567 | tabbedLayoutHoriz' = tabbedLayoutHoriz tabbedLeftAlways | ||
568 | defaultLayouts = {- spiralWithDir East CW (1 % 2) -} Dwindle R CW 1 (5 % 100) ||| tabbedLayout' ||| Full | ||
569 | -- workLayouts = {- spiralWithDir East CW (1 % 2) -} Dwindle R CW (2 % 1) (5 % 100) ||| tabbedLayout' ||| Full | ||
570 | workLayouts = tabbedLayout' ||| (renamed [Replace "Combined"] $ combineTwoP (TwoPane (1 % 100) (1891 % 2560)) tabbedLayout''' (Column 1.6) (ClassName "Postman" `Or` ClassName "Emacs" `Or` ClassName "jetbrains-idea-ce" `Or` (Resource "Devtools" `And` ClassName "Firefox"))) ||| Full ||| Dwindle R CW 1 (5 % 100) | ||
571 | sqrtTwo = approxRational (sqrt 2) (1 / 2560) | ||
572 | xmobarPP' = xmobarPP { ppTitle = shorten 80 | ||
573 | , ppSort = (liftM2 (.)) getSortByIndex $ return scratchpadFilterOutWorkspace | ||
574 | , ppUrgent = wrap "(" ")" . xmobarColor "#800000" "" | ||
575 | , ppHiddenNoWindows = xmobarColor "#202020" "" . wrap "(" ")" | ||
576 | , ppVisible = wrap "(" ")" . xmobarColor "#808000" "" | ||
577 | , ppCurrent = wrap "(" ")" . xmobarColor "#008000" "" | ||
578 | , ppHidden = wrap "(" ")" | ||
579 | , ppWsSep = " " | ||
580 | , ppSep = "\n" | ||
581 | } | ||
582 | withHostUrgency = case hostname of | ||
583 | "sif" -> withUrgencyHookC urgencyHook' $ def { suppressWhen = U.Never, remindWhen = Every 2 } | ||
584 | _ -> id | ||
585 | urgencyHook' window = do | ||
586 | let blinkLight = (lightHigh >> threadDelay 0.5e6) `finally` lightLow | ||
587 | where | ||
588 | lightHigh = | ||
589 | writeFile "/sys/class/leds/input0::capslock/brightness" =<< readFile "/sys/class/leds/input0::capslock/max_brightness" | ||
590 | lightLow = writeFile "/sys/class/leds/input0::capslock/brightness" "0" | ||
591 | runQuery ((resource =? "comm" <||> resource =? "Pidgin" <||> className =? "Gajim" <||> className =? "Skype" <||> className =? "Thunderbird") --> void (xfork blinkLight)) window | ||
592 | urgencyHook (BorderUrgencyHook { urgencyBorderColor = red }) window | ||
593 | shutdown :: SomeException -> IO a | ||
594 | shutdown e = do | ||
595 | let pids = [ -- batteryMon | ||
596 | ] | ||
597 | mapM_ (signalProcess sigTERM) pids | ||
598 | mapM_ (getProcessStatus False False) pids | ||
599 | throw e | ||
600 | keyUpEventHook :: Event -> X All | ||
601 | keyUpEventHook event = handle event >> return (All True) | ||
602 | where | ||
603 | handle (KeyEvent { ev_event_type = t, ev_state = m, ev_keycode = code }) | ||
604 | | t == keyRelease = withDisplay $ \dpy -> do | ||
605 | s <- io $ keycodeToKeysym dpy code 0 | ||
606 | mClean <- cleanMask m | ||
607 | ks <- asks $ hKeyUpKeys host . config | ||
608 | userCodeDef () $ whenJust (Map.lookup (mClean, s) ks) id | ||
609 | | otherwise = return () | ||
610 | handle _ = return () | ||
611 | handle shutdown $ launch myConfig =<< getDirectories | ||
612 | |||
613 | secs :: Int -> Int | ||
614 | secs = (* 1000000) | ||
615 | |||
616 | -- monitorBattery :: Maybe BatteryContext -> Maybe Notification -> IO () | ||
617 | -- monitorBattery Nothing n = do | ||
618 | -- ctx <- batteryContextNew | ||
619 | -- case ctx of | ||
620 | -- Nothing -> threadDelay (secs 10) >> monitorBattery Nothing n | ||
621 | -- Just _ -> monitorBattery ctx n | ||
622 | -- monitorBattery ctx@(Just ctx') n = do | ||
623 | -- batInfo <- getBatteryInfo ctx' | ||
624 | -- case batInfo of | ||
625 | -- Nothing -> threadDelay (secs 1) >> monitorBattery ctx n | ||
626 | -- Just batInfo -> do | ||
627 | -- let n' | ||
628 | -- | batteryState batInfo == BatteryStateDischarging | ||
629 | -- , timeLeft <= 1200 | ||
630 | -- , timeLeft > 0 = Just $ summary "Discharging" <> hint "value" percentage <> urgency u <> body (duz timeLeft ++ "left") | ||
631 | -- | otherwise = Nothing | ||
632 | -- u | ||
633 | -- | timeLeft <= 600 = Critical | ||
634 | -- | timeLeft <= 1800 = Normal | ||
635 | -- | otherwise = Low | ||
636 | -- timeLeft = batteryTimeToEmpty batInfo | ||
637 | -- percentage :: Int32 | ||
638 | -- percentage = round $ batteryPercentage batInfo | ||
639 | -- ts = [("s", 60), ("m", 60), ("h", 24), ("d", 365), ("y", 1)] | ||
640 | -- duz ms = ss | ||
641 | -- where (ss, _) = foldl (\(ss, x) (s, y) -> ((if rem x y > 0 then show (rem x y) ++ s ++ " " else "") ++ ss , quot x y)) ("", ms) ts | ||
642 | -- case n' of | ||
643 | -- Just n' -> Notify.display (maybe mempty reuse n <> Notify.appName "monitorBattery" <> n') >>= (\n -> threadDelay (secs 2) >> monitorBattery ctx (Just n)) | ||
644 | -- Nothing -> threadDelay (secs 30) >> monitorBattery ctx n | ||
645 | |||
646 | disableTouchpad, disableTrackpoint, enableTrackpoint, enableTouchpad :: X () | ||
647 | enableTouchpad = safeSpawn "xinput" ["enable", "SynPS/2 Synaptics TouchPad"] | ||
648 | disableTouchpad = safeSpawn "xinput" ["disable", "SynPS/2 Synaptics TouchPad"] | ||
649 | enableTrackpoint = safeSpawn "xinput" ["enable", "TPPS/2 IBM TrackPoint"] | ||
650 | disableTrackpoint = safeSpawn "xinput" ["disable", "TPPS/2 IBM TrackPoint"] | ||
651 | |||
652 | isDisabled :: String -> X Bool | ||
653 | isDisabled str = do | ||
654 | out <- runProcessWithInput "xinput" ["list", str] "" | ||
655 | return $ "disabled" `isInfixOf` out | ||
656 | |||
657 | |||
658 | spawnKeychain :: X () | ||
659 | spawnKeychain = do | ||
660 | home <- liftIO getHomeDirectory | ||
661 | let keys = (map ((home </>) . (".ssh/" ++)) ["id", "id-rsa"]) ++ ["6B13AA67"] | ||
662 | liftIO (maybe (return ()) (setEnv "SSH_ASKPASS") =<< findAskpass) | ||
663 | safeSpawn "keychain" . (["--agents", "gpg,ssh"] ++)=<< liftIO (filterM doesFileExist keys) | ||
664 | where | ||
665 | findAskpass = filter `liftM` readFile "/etc/zshrc" | ||
666 | filter = listToMaybe . catMaybes . map (stripPrefix "export SSH_ASKPASS=") . lines | ||
667 | |||
668 | assimilateKeychain :: X () | ||
669 | assimilateKeychain = liftIO $ assimilateKeychain' >> return () | ||
670 | assimilateKeychain' = tryIOError $ do | ||
671 | -- pid <- getProcessID | ||
672 | -- tmpDir <- lookupEnv "TMPDIR" | ||
673 | -- let tmpDir' = fromMaybe "/tmp" tmpDir | ||
674 | -- tmpFile = tmpDir' </> "xmonad-keychain" ++ (show pid) ++ ".env" | ||
675 | env <- runProcessWithInput "sh" ["-c", "eval $(keychain --eval --noask --agents gpg,ssh); env"] "" -- > " ++ tmpFile] "" | ||
676 | -- env <- readFile tmpFile | ||
677 | let envVars = Map.fromList $ map (\(k, v) -> (k, tail' v)) $ map (span (/= '=')) $ envLines | ||
678 | envVars' = Map.filterWithKey (\k _ -> k `elem` transfer) envVars | ||
679 | transfer = ["SSH_AUTH_SOCK", "SSH_AGENT_PID", "GPG_AGENT_INFO"] | ||
680 | envLines = filter (elem '=') $ lines env :: [String] | ||
681 | sequence $ map (\(k, c) -> setEnv k c) $ Map.toList envVars' | ||
682 | -- removeFile tmpFile | ||
683 | where | ||
684 | tail' [] = [] | ||
685 | tail' (x:xs) = xs | ||
686 | |||
687 | |||
688 | numKeys = [xK_parenleft, xK_parenright, xK_braceright, xK_plus, xK_braceleft, xK_bracketright, xK_bracketleft, xK_exclam, xK_equal, xK_asterisk] | ||
689 | |||
690 | instance Shrinker CustomShrink where | ||
691 | shrinkIt _ "" = [""] | ||
692 | shrinkIt s cs | ||
693 | | length cs >= 4 = cs : shrinkIt s ((reverse . drop 4 . reverse $ cs) ++ "...") | ||
694 | | otherwise = cs : shrinkIt s (init cs) | ||
695 | |||
696 | xPConfig, xPConfigMonospace :: XPConfig | ||
697 | xPConfig = def | ||
698 | { font = "xft:Fira Sans:pixelsize=21" | ||
699 | , height = 32 | ||
700 | , bgColor = "black" | ||
701 | , fgColor = gray | ||
702 | , fgHLight = green | ||
703 | , bgHLight = "black" | ||
704 | , borderColor = gray | ||
705 | , searchPredicate = (\needle haystack -> all (`isInfixOf` map toLower haystack) . map (map toLower) $ words needle) | ||
706 | , position = Top | ||
707 | } | ||
708 | xPConfigMonospace = xPConfig { font = "xft:Fira Code:pixelsize=21" } | ||
709 | |||
710 | sshOverrides host = map (\h -> mkOverride { oHost = h, oCommand = moshCmd . inTmux host} ) | ||
711 | [ "odin" | ||
712 | , "ymir" | ||
713 | , "surtr" | ||
714 | , "vidhar" | ||
715 | , "srv02.uniworx.de" | ||
716 | ] | ||
717 | ++ | ||
718 | map (\h -> mkOverride { oHost = h, oCommand = moshCmd' "/run/current-system/sw/bin/mosh-server" . withEnv [("TERM", "xterm")] . inTmux host} ) | ||
719 | [ "bragi", "bragi.asgard.yggdrasil" | ||
720 | ] | ||
721 | ++ | ||
722 | map (\h -> mkOverride { oHost = h, oCommand = sshCmd . inTmux host } ) | ||
723 | [ "uni2work-dev1", "srv01.uniworx.de" | ||
724 | ] | ||
725 | ++ | ||
726 | map (\h -> mkOverride { oHost = h, oCommand = sshCmd . withEnv [("TERM", "xterm")] . inTmux host } ) | ||
727 | [ "remote.cip.ifi.lmu.de" | ||
728 | , "uniworx3", "uniworx4", "uniworx5", "uniworxdb2" | ||
729 | , "testworx" | ||
730 | ] | ||
731 | |||
732 | backlight :: (Rational -> Rational) -> X () | ||
733 | backlight f = void . xfork . liftIO $ do | ||
734 | [ _device | ||
735 | , _class | ||
736 | , read . Text.unpack -> currentBright | ||
737 | , _currentPercentage | ||
738 | , read . Text.unpack -> maximumBright | ||
739 | ] <- Text.splitOn "," . Text.pack <$> readProcess "brightnessctl" ["-m"] "" | ||
740 | let current = currentBright % maximumBright | ||
741 | new' = f current * fromIntegral maximumBright | ||
742 | new :: Integer | ||
743 | new | floor new' < 0 = 0 | ||
744 | | ceiling new' > maximumBright = maximumBright | ||
745 | | new' >= maximumBright % 2 = ceiling new' | ||
746 | | otherwise = floor new' | ||
747 | callProcess "brightnessctl" ["-m", "s", show new] | ||
748 | |||
749 | cycleThrough :: [Rational] -> (Rational -> Rational) | ||
750 | cycleThrough opts current = fromMaybe currentOpt $ listToMaybe next' | ||
751 | where currentOpt = minimumBy (comparing $ abs . subtract current) opts | ||
752 | (_, _ : next') = break (== currentOpt) opts | ||
753 | |||
754 | cycleKbLayout :: [(String, Maybe String)] -> X () | ||
755 | cycleKbLayout [] = return () | ||
756 | cycleKbLayout layouts = liftIO $ do | ||
757 | next <- (getNext . extract) `liftM` runProcessWithInput "setxkbmap" ["-query"] "" | ||
758 | let | ||
759 | args = case next of | ||
760 | (l, Just v) -> [l, v] | ||
761 | (l, Nothing) -> [l] | ||
762 | safeSpawn "setxkbmap" args | ||
763 | where | ||
764 | extract :: String -> Maybe (String, Maybe String) | ||
765 | extract str = listToMaybe $ do | ||
766 | ["layout:", l] <- str' | ||
767 | [(l, Just v) | ["variant:", v] <- str'] ++ pure (l, Nothing) | ||
768 | where | ||
769 | str' = map words $ lines str | ||
770 | getNext :: Maybe (String, Maybe String) -> (String, Maybe String) | ||
771 | getNext = maybe (head layouts) getNext' | ||
772 | getNext' x = case elemIndex x layouts of | ||
773 | Nothing -> getNext Nothing | ||
774 | Just i -> layouts !! ((i + 1) `mod` length layouts) | ||
775 | |||
776 | mpvAll' :: MpvCommand -> IO [MpvResponse] | ||
777 | mpvAll' = mpvAll "/var/media/.mpv-ipc" | ||
778 | |||
779 | mpvOne' :: MpvCommand -> IO (Maybe MpvResponse) | ||
780 | mpvOne' = mpvOne "/var/media/.mpv-ipc" | ||
781 | |||
782 | mediaMpv :: MpvCommand -> X () | ||
783 | mediaMpv cmd = void . xfork $ print =<< mpvAll' cmd | ||
784 | |||
785 | mediaMpvTogglePause :: X () | ||
786 | mediaMpvTogglePause = void . xfork $ do | ||
787 | paused <- mapM mpvResponse <=< mpvAll' $ MpvGetProperty "pause" | ||
788 | if | ||
789 | | and paused -> print <=< mpvAll' $ MpvSetProperty "pause" False | ||
790 | | otherwise -> print <=< mpvOne' $ MpvSetProperty "pause" True | ||
791 | |||
792 | myKeys' conf host = Map.fromList $ | ||
793 | -- launch a terminal | ||
794 | [ ((modm, xK_Return), spawn $ (XMonad.terminal conf) ++ " -e tmux") | ||
795 | , ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf) | ||
796 | |||
797 | -- launch dmenu | ||
798 | --, ((modm, xK_d ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"") | ||
799 | , ((modm, xK_d ), shellPrompt "Run: " xPConfigMonospace) | ||
800 | , ((modm .|. shiftMask, xK_d ), prompt "Run in Terminal: " ("alacritty" ++ " -e") xPConfigMonospace) | ||
801 | , ((modm, xK_at ), sshPrompt (sshOverrides . Just $ hName host) xPConfigMonospace) | ||
802 | |||
803 | -- close focused window | ||
804 | , ((modm .|. shiftMask, xK_q ), kill) | ||
805 | , ((modm .|. controlMask .|. shiftMask, xK_q ), spawn "xkill") | ||
806 | |||
807 | -- Rotate through the available layout algorithms | ||
808 | , ((modm, xK_space ), sendMessage NextLayout) | ||
809 | |||
810 | -- Reset the layouts on the current workspace to default | ||
811 | , ((modm .|. controlMask, xK_r ), (setLayout $ XMonad.layoutHook conf) >> refresh) | ||
812 | |||
813 | -- Resize viewed windows to the correct size | ||
814 | , ((modm, xK_r ), refresh) | ||
815 | |||
816 | -- Move focus to the next window | ||
817 | , ((modm, xK_t ), windows W.focusDown) | ||
818 | |||
819 | -- Move focus to the previous window | ||
820 | , ((modm, xK_n ), windows W.focusUp ) | ||
821 | |||
822 | -- Move focus to the master window | ||
823 | , ((modm, xK_m ), windows W.focusMaster ) | ||
824 | |||
825 | -- Swap the focused window and the master window | ||
826 | , ((modm .|. shiftMask, xK_m ), windows W.swapMaster) | ||
827 | |||
828 | -- Swap the focused window with the next window | ||
829 | , ((modm .|. shiftMask, xK_t ), windows W.swapDown ) | ||
830 | |||
831 | -- Swap the focused window with the previous window | ||
832 | , ((modm .|. shiftMask, xK_n ), windows W.swapUp ) | ||
833 | |||
834 | -- Swap the focused window with the previous window | ||
835 | , ((modm .|. shiftMask .|. controlMask, xK_m), sendMessage SwapWindow) | ||
836 | |||
837 | , ((modm, xK_Right), sendMessage $ Go R) | ||
838 | , ((modm, xK_Left ), sendMessage $ Go L) | ||
839 | , ((modm, xK_Up ), sendMessage $ Go U) | ||
840 | , ((modm, xK_Down ), sendMessage $ Go D) | ||
841 | , ((modm .|. shiftMask , xK_Right), sendMessage $ Move R) | ||
842 | , ((modm .|. shiftMask , xK_Left ), sendMessage $ Move L) | ||
843 | , ((modm .|. shiftMask , xK_Up ), sendMessage $ Move U) | ||
844 | , ((modm .|. shiftMask , xK_Down ), sendMessage $ Move D) | ||
845 | -- , ((modm .|. controlMask, xK_Right), withFocused $ keysMoveWindow (10, 0)) | ||
846 | -- , ((modm .|. controlMask, xK_Left ), withFocused $ keysMoveWindow (-10, 0)) | ||
847 | -- , ((modm .|. controlMask, xK_Up ), withFocused $ keysMoveWindow (0, -10)) | ||
848 | -- , ((modm .|. controlMask, xK_Down ), withFocused $ keysMoveWindow (0, 10)) | ||
849 | -- Shrink the master area | ||
850 | , ((modm, xK_h ), sendMessage Shrink) | ||
851 | |||
852 | -- Expand the master area | ||
853 | , ((modm, xK_s ), sendMessage Expand) | ||
854 | |||
855 | -- Push window back into tiling | ||
856 | , ((modm .|. shiftMask, xK_space ), withFocused $ windows . W.sink) | ||
857 | , ((modm, xK_BackSpace), focusUrgent) | ||
858 | , ((modm .|. shiftMask, xK_BackSpace), clearUrgents) | ||
859 | |||
860 | -- Increment the number of windows in the master area | ||
861 | , ((modm , xK_comma ), sendMessage (IncMasterN 1)) | ||
862 | |||
863 | -- Deincrement the number of windows in the master area | ||
864 | , ((modm , xK_period), sendMessage (IncMasterN (-1))) | ||
865 | |||
866 | , ((0, xF86XK_AudioRaiseVolume), safeSpawn "pamixer" ["-i", "2"]) | ||
867 | , ((0, xF86XK_AudioLowerVolume), safeSpawn "pamixer" ["-d", "2"]) | ||
868 | , ((0, xF86XK_AudioMute), safeSpawn "pamixer" ["-t"]) | ||
869 | , ((0, xF86XK_AudioPause), mediaMpv $ MpvSetProperty "pause" False) | ||
870 | , ((0, {-xF86XK_AudioMicMute-} 269025202), safeSpawn "pulseaudio-ctl" ["mute-input"]) | ||
871 | , ((0, xF86XK_AudioPlay), mediaMpvTogglePause) | ||
872 | , ((0, xK_Print), do | ||
873 | home <- liftIO getHomeDirectory | ||
874 | unGrab | ||
875 | safeSpawn "scrot" ["-s", "-F", home </> "screenshots" </> "%Y-%m-%dT%H:%M:%S.png", "-e", "xclip -selection clipboard -t image/png -i $f"] | ||
876 | ) | ||
877 | , ((modm .|. mod1Mask, xK_space), mediaMpvTogglePause) | ||
878 | |||
879 | -- , ((0, xF86XK_MonBrightnessDown), backlight . cycleThrough $ reverse brCycle) | ||
880 | -- , ((0, xF86XK_MonBrightnessUp ), backlight $ cycleThrough brCycle) | ||
881 | , ((modm .|. shiftMask , xK_b), backlight . cycleThrough $ reverse brCycle) | ||
882 | , ((modm .|. shiftMask .|. controlMask, xK_b), backlight $ cycleThrough brCycle) | ||
883 | |||
884 | , ((modm , xK_Escape), cycleKbLayout (hKbLayouts host)) | ||
885 | , ((modm .|. controlMask, xK_Escape), safeSpawn "setxkbmap" $ fst (head $ hKbLayouts host) : maybeToList (snd . head $ hKbLayouts host)) | ||
886 | |||
887 | -- Toggle the status bar gap | ||
888 | -- Use this binding with avoidStruts from Hooks.ManageDocks. | ||
889 | -- See also the statusBar function from Hooks.DynamicLog. | ||
890 | -- | ||
891 | , ((modm , xK_b ), sendMessage ToggleStruts) | ||
892 | |||
893 | , ((modm .|. shiftMask, xK_p ), safeSpawn "playerctl" ["-a", "pause"]) | ||
894 | |||
895 | -- Quit xmonad | ||
896 | , ((modm .|. shiftMask, xK_e ), io (exitWith ExitSuccess)) | ||
897 | |||
898 | -- Restart xmonad | ||
899 | -- , ((modm .|. shiftMask .|. controlMask, xK_r ), void . xfork $ recompile False >>= flip when (safeSpawn "xmonad" ["--restart"])) | ||
900 | , ((modm .|. shiftMask, xK_r ), void . liftIO $ executeFile "xmonad" True [] Nothing) | ||
901 | , ((modm .|. shiftMask, xK_l ), void . xfork $ do | ||
902 | sessId <- getEnv "XDG_SESSION_ID" | ||
903 | safeSpawn "loginctl" ["lock-session", sessId] | ||
904 | ) | ||
905 | , ((modm .|. shiftMask, xK_s ), safeSpawn "systemctl" ["suspend"]) | ||
906 | , ((modm .|. shiftMask, xK_h ), inputPromptWithCompl xPConfigMonospace "systemctl" powerActCompl ?+ powerAct) | ||
907 | , ((modm, xK_v ), windows copyToAll) -- @@ Make focused window always visible | ||
908 | , ((modm .|. shiftMask, xK_v ), killAllOtherCopies) -- @@ Toggle window state back | ||
909 | , ((modm .|. shiftMask, xK_g ), windowPrompt xPConfig Goto wsWindows) | ||
910 | , ((modm , xK_g ), windowPrompt xPConfig Bring allWindows) | ||
911 | ] | ||
912 | ++ | ||
913 | |||
914 | -- | ||
915 | -- mod-[1..9], Switch to workspace N | ||
916 | -- | ||
917 | -- mod-[1..9], Switch to workspace N | ||
918 | -- mod-shift-[1..9], Move client to workspace N | ||
919 | -- | ||
920 | [((m .|. modm, k), windows $ f i) | ||
921 | | (i, k) <- zip (XMonad.workspaces conf) $ numKeys | ||
922 | , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)] | ||
923 | ] | ||
924 | ++ | ||
925 | [((m .|. modm .|. controlMask, k), void . runMaybeT $ | ||
926 | MaybeT (P.getScreen def i) >>= MaybeT . screenWorkspace >>= lift . windows . f | ||
927 | ) | ||
928 | | (i, k) <- zip (hScreens host) [xK_g, xK_c, xK_r, xK_l] | ||
929 | , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] | ||
930 | ] | ||
931 | where | ||
932 | modm = XMonad.modMask conf | ||
933 | |||
934 | brCycle = [0, 1 % 500, 1 % 250, 1 % 100, 1 % 10, 1 % 4, 1 % 2, 3 % 4, 1] | ||
935 | |||
936 | powerActWords = ["poweroff", "reboot", "hibernate", "suspend"] | ||
937 | powerActCompl = mkComplFunFromList' xPConfigMonospace powerActWords | ||
938 | powerAct act | act `elem` powerActWords = safeSpawn "systemctl" $ pure act | ||
939 | | otherwise = return () | ||