From a7129b68fb7fa4f7cea52513fad7223dcbba9801 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Fri, 25 Mar 2022 15:55:54 -0600 Subject: Another Chrome binding added. There's a bug where it seems the mappings are applied inconsistently after a restart. Not sure what causes that. Seems bouncing XMonad again fixes it. --- src/Internal/Intercept.hs | 17 ++++++----------- src/Main.hs | 6 ++++-- 2 files changed, 10 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/Internal/Intercept.hs b/src/Internal/Intercept.hs index 987733b..c99ce09 100644 --- a/src/Internal/Intercept.hs +++ b/src/Internal/Intercept.hs @@ -1,3 +1,7 @@ + +-- Module for intercepting key presses not explicity mapped in the key bindings. +-- This uses some deep magic with grabKey and windows and everything else, but +-- it makes window-specific key bindings awesome! module Internal.Intercept where import XMonad @@ -111,19 +115,10 @@ getKeyCodesForKeysym dpy keysym = do doGrab :: Display -> Window -> (KeyMask, KeySym) -> X () doGrab dpy win (keyMask, keysym) = do let grab kc m = io $ grabKey dpy kc m win True grabModeAsync grabModeAsync - (minCode, maxCode) = displayKeycodes dpy - allCodes = [fromIntegral minCode .. fromIntegral maxCode] - -- build a map from keysyms to lists of keysyms (doing what - -- XGetKeyboardMapping would do if the X11 package bound it) - syms <- forM allCodes $ \code -> io (keycodeToKeysym dpy code 0) - let keysymMap' = Map.fromListWith (++) (zip syms [[code] | code <- allCodes]) - -- keycodeToKeysym returns noSymbol for all unbound keycodes, and we don't - -- want to grab those whenever someone accidentally uses def :: KeySym - let keysymMap = Map.delete noSymbol keysymMap' - let keysymToKeycodes sym = Map.findWithDefault [] keysym keysymMap + codes <- io $ getKeyCodesForKeysym dpy keysym - forM_ (keysymToKeycodes keysym) $ \kc -> + forM_ codes $ \kc -> mapM_ (grab kc . (keyMask .|.)) =<< extraModifiers disableKey :: (KeyMask, KeySym) -> WindowHook diff --git a/src/Main.hs b/src/Main.hs index b2a20d7..19050ab 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -40,8 +40,10 @@ main = do -- The geniuses that made chrome decided that Ctrl+W should kill -- the current tab! This makes it consistent with the rest of the -- world ... ctrl+w deletes the last word (ctrl+backspace). - rebindKey (controlMask, xK_w) (controlMask, xK_BackSpace), - rebindKey (controlMask, xK_h) (0, xK_BackSpace) + rebindKey (controlMask, xK_w) (controlMask, xK_BackSpace) + , rebindKey (controlMask, xK_h) (0, xK_BackSpace) + , rebindKey (controlMask, xK_u) (controlMask .|. shiftMask, xK_BackSpace) + , rebindKey (controlMask, xK_b) (controlMask, xK_w) ] ]) $ def { terminal = "alacritty" -- cgit