xmonad-config/lib/KeyBindings.hs

119 lines
3.9 KiB
Haskell
Raw Normal View History

module KeyBindings (
KeyBindings.modify
) where
2018-05-27 15:39:24 +02:00
import Control.Monad (void)
2021-08-25 19:08:49 +02:00
import Data.Foldable (forM_)
import Data.List (sort, isSuffixOf)
2018-05-27 15:39:24 +02:00
import Data.Maybe (isJust)
import Graphics.X11.Types
import System.Exit
2019-01-27 20:20:08 +01:00
-- import Text.EditDistance
import XMonad
import XMonad.Actions.CycleWS
import XMonad.Actions.DynamicProjects
import XMonad.Core
import XMonad.Layout.ToggleLayouts
import XMonad.Operations
import XMonad.Prompt
import XMonad.Prompt.ConfirmPrompt
2023-08-01 11:21:23 +02:00
import XMonad.Prompt.FuzzyMatch
import XMonad.Prompt.Shell
import XMonad.Util.EZConfig
2018-05-27 15:39:24 +02:00
import XMonad.Util.NamedScratchpad
2020-03-08 08:51:14 +01:00
import qualified Nord as N
2018-05-27 15:39:24 +02:00
import qualified Scratchpad as R
import qualified XMonad.StackSet as W
-- Custom (in libs)
import Password (passPrompt)
modify :: XConfig l -> XConfig l
modify conf = conf
{ modMask = mod4Mask -- Use the "Win" key for the mod key
}
`additionalKeysP` -- Add some extra key bindings:
[ ("M-S-q", confirmPrompt promptConfig "exit" (io exitSuccess))
, ("<XF86MonBrightnessDown>", spawn "/run/current-system/sw/bin/xbacklight -10")
, ("<XF86MonBrightnessUp>", spawn "/run/current-system/sw/bin/xbacklight +10")
2019-04-17 16:14:19 +02:00
, ("<XF86AudioPlay>", spawn "/run/current-system/sw/bin/mpc toggle")
, ("<XF86AudioNext>", spawn "/run/current-system/sw/bin/mpc next")
, ("<XF86AudioPrev>", spawn "/run/current-system/sw/bin/mpc prev")
, ("M-<Delete>", kill)
, ("M-<Down>", windows W.focusDown)
, ("M-<Esc>", sendMessage (Toggle "Full"))
, ("M-$", sendMessage (Toggle "Full"))
, ("M-<Left>", prevWS)
2018-05-29 08:20:58 +02:00
, ("M-i", prevScreen)
, ("M-e", nextScreen)
, ("M-<Right>", nextWS)
2018-05-28 19:53:36 +02:00
, ("M-<Tab>", toggleWS' ["NSP"])
, ("M-<Up>", windows W.focusUp)
2019-04-17 16:14:19 +02:00
, ("M-S-<Delete>", spawn "/run/current-system/sw/bin/mpc pause; /run/current-system/sw/bin/xset s activate")
, ("M-S-<Left>", shiftToPrev >> prevWS)
, ("M-S-<Right>", shiftToNext >> nextWS)
2019-09-28 14:55:07 +02:00
, ("M-s s", spawn "flameshot gui")
, ("M-s t", spawn "/run/current-system/sw/bin/scrot /tmp/screen.png")
-- Workspace and tasks
2018-05-28 19:53:36 +02:00
, ("M-b", switchProjectPrompt promptConfig)
, ("M-p m", shiftToProjectPrompt promptConfig)
2018-05-27 15:39:24 +02:00
, ("M-p n", switchProjectPrompt promptConfig)
, ("M-p r", renameProjectPrompt promptConfig)
, ("M-p s", shellPrompt promptConfig)
, ("M-p c", withFocused centerWindow)
, ("M-d", passPrompt promptConfig)
2018-05-27 15:39:24 +02:00
-- Scratchpads
, ("M-p p", namedScratchpadAction R.pads "htop")
2021-11-04 19:41:24 +01:00
-- Dunst
, ("C-<Space>", spawn "dunstctl close")
, ("C-S-<Space>", spawn "dunstctl close-all")
]
2018-05-27 15:39:24 +02:00
viewProject :: WorkspaceId -> X ()
viewProject id = do
project <- lookupProject id
2021-08-25 19:08:49 +02:00
forM_ project switchProject
2018-05-27 15:39:24 +02:00
-- Borrowed from https://www.reddit.com/r/xmonad/comments/gzq316/how_can_i_centre_a_floating_window_without/fthtx29/
centerWindow :: Window -> X ()
centerWindow win = do
(_, W.RationalRect x y w h) <- floatLocation win
windows $ W.float win (W.RationalRect ((1 - w) / 2) ((1 - h) / 2) w h)
return ()
promptConfig = def
2018-05-28 19:53:36 +02:00
{ position = Bottom
, alwaysHighlight = True
2020-03-08 08:51:14 +01:00
, borderColor = N.nord9
-- Normal
, bgColor = N.nord9
, fgColor = N.background
-- Selection
, bgHLight = N.nord6
, fgHLight = N.background
--
, defaultText = ""
2021-08-25 19:08:49 +02:00
, font = "xft:Iosevka Samae:style=Regular:size=8:charwidth=5"
, height = 24
, promptBorderWidth = 5
2023-08-01 11:21:23 +02:00
-- Fuzzysearch by default
, searchPredicate = fuzzyMatch
, sorter = fuzzySort
}
2019-01-27 20:20:08 +01:00
-- -- Slightly taken from
-- -- https://mail.haskell.org/pipermail/xmonad/2010-October/010671.html
-- data FuzzySpawn = FuzzySpawn deriving (Read, Show)
-- instance XPrompt FuzzySpawn where showXPrompt _ = "RunC: "
-- fuzzyPrompt config = do
-- cmds <- io getCommands
-- let compl s
-- | null s = []
-- | otherwise = let weight c = levenshteinDistance defaultEditCosts s c
-- in map snd $ take 20 $ sort $ map (\c -> (weight c,c)) cmds
-- mkXPrompt FuzzySpawn config (return . compl) spawn
2019-09-28 14:55:07 +02:00
--