module KeyBindings ( KeyBindings.modify ) where import Control.Monad (void) import Data.Foldable (forM_) import Data.List (sort, isSuffixOf) import Data.Maybe (isJust) import Graphics.X11.Types import System.Exit -- import Text.EditDistance import XMonad import XMonad.Actions.CopyWindow (kill1,copy) 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 import XMonad.Prompt.FuzzyMatch import XMonad.Prompt.Shell import XMonad.Prompt.Workspace (workspacePrompt) import XMonad.Util.EZConfig import XMonad.Util.NamedScratchpad import qualified Catppuccin as C import qualified Scratchpad as R import qualified XMonad.StackSet as W -- Custom (in libs) import Password (passPrompt) lockScreenCmd = spawn "/etc/profiles/per-user/e/bin/mpc pause; /run/current-system/sw/bin/xset s activate" 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)) , ("", spawn "/run/current-system/sw/bin/light -U 10") , ("", spawn "/run/current-system/sw/bin/light -A 10") , ("", spawn "/etc/profiles/per-user/e/bin/mpc toggle") , ("", spawn "/etc/profiles/per-user/e/bin/mpc next") , ("", spawn "/etc/profiles/per-user/e/bin/mpc prev") -- KP_1 -> KP_6 macros , ("", viewProject "sound") , ("", viewProject "frs") , ("", viewProject "chat") , ("", viewProject "isengard") , ("", viewProject "moria") , ("", viewProject "fre") -- KP_Delete , ("Cancel", lockScreenCmd) , ("M-", windows W.focusDown) , ("M-", sendMessage (Toggle "Full")) , ("M-$", sendMessage (Toggle "Full")) , ("M-", prevWS) , ("M-i", prevScreen) , ("M-e", nextScreen) , ("M-", nextWS) , ("M-", toggleWS' ["NSP"]) , ("M-", windows W.focusUp) , ("M-S-", lockScreenCmd) , ("M-S-", shiftToPrev >> prevWS) , ("M-S-", shiftToNext >> nextWS) , ("M-s s", spawn "/etc/profiles/per-user/e/bin/flameshot gui") , ("M-s t", spawn "/run/current-system/sw/bin/scrot /tmp/screen.png") -- Workspace and tasks , ("M-b", switchProjectPrompt promptConfig) , ("M-p c", withFocused centerWindow) , ("M-p m", shiftToProjectPrompt promptConfig) , ("M-p n", switchProjectPrompt promptConfig) , ("M-p r", renameProjectPrompt promptConfig) , ("M-p s", shellPrompt promptConfig) , ("M-d", passPrompt promptConfig) -- Scratchpads , ("M-p p", namedScratchpadAction R.pads "htop") -- Copy windows to workspaces , ("M-", kill1) , ("M-c", workspacePrompt promptConfig (\name -> windows $ copy name)) -- Mouse stuff , ("", spawn "find-cursor") -- , ("M-$ $", spawn "xdotool click 3") -- , ("M-$ M-$", spawn "xdotool click 3") -- helpfull to combine M + right click -- resizing the master/slave ratio , ("M-h", sendMessage Shrink) -- Shrink the master area , ("M-l", sendMessage Expand) -- Expand the master area -- dunstctl calls -- , ("C-", spawn "dunstctl close") , ("C-S-", spawn "dunstctl close-all") , ("M-n p", spawn "dunstctl set-paused toggle") ] -- 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 () viewProject :: WorkspaceId -> X () viewProject id = do project <- lookupProject id case project of Just p -> switchProject p Nothing -> return () promptConfig = def { position = Bottom , alwaysHighlight = True , bgColor = C.lavender , bgHLight = C.surface0 , borderColor = C.lavender , defaultText = "" , fgColor = C.surface2 , fgHLight = C.text , font = "xft:Iosevka Samae:style=Regular:size=10:charwidth=6.5" , height = 24 , promptBorderWidth = 5 -- Fuzzysearch by default , searchPredicate = fuzzyMatch , sorter = fuzzySort } -- -- 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 --