diff options
| -rw-r--r-- | src/Internal/Keys.hs | 42 | ||||
| -rw-r--r-- | src/Internal/Lib.hs | 7 | ||||
| -rw-r--r-- | src/Internal/Submap.hs | 28 |
3 files changed, 66 insertions, 11 deletions
diff --git a/src/Internal/Keys.hs b/src/Internal/Keys.hs index 0dd8760..89e2cf1 100644 --- a/src/Internal/Keys.hs +++ b/src/Internal/Keys.hs @@ -25,7 +25,7 @@ import Internal.PromptConfig import System.IO import Text.Printf import XMonad -import XMonad.Actions.Submap +import Internal.Submap import XMonad.Actions.WindowNavigation import XMonad.Prompt import XMonad.Prompt.Input @@ -85,7 +85,7 @@ keymap = runKeys $ do rawMask shiftMask $ subkeys $ do bind xK_F1 $ -- Make it harder to close so I don't accidentally git it. - rawMask shiftMask $ click >> kill + rawMask shiftMask $ click >> CopyWindow.kill1 -- I Don't really use these, but they could be bound to something cool! bind xK_F2 $ @@ -131,20 +131,25 @@ keymap = runKeys $ do bind xK_c $ do justMod runPassMenu - shiftMod kill + shiftMod CopyWindow.kill1 bind xK_f $ do justMod $ sendMessage FlipLayout shiftMod $ sendMessage HFlipLayout bind xK_g $ do - justMod $ subkeys $ do - mapNumbersAndAlpha 0 gotoWorkspace - shiftMod $ subkeys $ do - mapNumbersAndAlpha 0 shiftToWorkspace - mapNumbersAndAlpha shiftMask (\i -> windows (CopyWindow.copy [i])) - shiftAltMod $ subkeys $ do - mapNumbersAndAlpha 0 swapWorkspace + justMod $ mapNextString $ \_ str -> + case str of + [ch] | isAlphaNum ch -> gotoWorkspace ch + _ -> return () + shiftMod $ mapNextString $ \_ str -> + case str of + [ch] | isAlphaNum ch -> shiftToWorkspace ch + _ -> return () + shiftAltMod $ mapNextString $ \_ str -> + case str of + [ch] | isAlphaNum ch -> swapWorkspace ch + _ -> return () bind xK_h $ do justMod $ windows W.focusDown @@ -207,7 +212,24 @@ keymap = runKeys $ do justMod $ sendMessage ToggleStruts bind xK_z $ do + justMod $ subkeys $ do + + bind xK_g $ do + (justMod -|- noMod) $ mapNextString $ \_ s -> + case s of + [ch] | isAlphaNum ch -> windows (CopyWindow.copy s) + _ -> return () + + bind xK_p $ do + (justMod -|- noMod) $ mapNextString $ \_ str -> + spawn $ printf "gxmessage 'typed: \"%s\"\ncodes: \"%s\"\nunicode: รก\n'" + str + (show (map ord str)) + + bind xK_c $ do + shiftMod $ CopyWindow.killAllOtherCopies + -- Double-tap Z to toggle zoom. bind xK_z $ do diff --git a/src/Internal/Lib.hs b/src/Internal/Lib.hs index 1a1d602..c3bdeb9 100644 --- a/src/Internal/Lib.hs +++ b/src/Internal/Lib.hs @@ -3,6 +3,7 @@ module Internal.Lib where import Prelude hiding ((!!)) +import XMonad.Actions.DynamicWorkspaces import XMonad.Util.Run import XMonad.Prompt import XMonad.Prompt.Input @@ -67,13 +68,17 @@ getHorizontallyOrderedScreens windowSet = gotoWorkspace :: WorkspaceName -> X () gotoWorkspace ch = do saveLastMark + addHiddenWorkspace [ch] windows $ greedyView $ return ch shiftToWorkspace :: WorkspaceName -> X () -shiftToWorkspace = windows . shift . return +shiftToWorkspace ch = do + addHiddenWorkspace [ch] + (windows . shift . return) ch swapWorkspace :: WorkspaceName -> X () swapWorkspace toWorkspaceName = do + addHiddenWorkspace [toWorkspaceName] windows $ \ss -> do let fromWorkspace = tag $ workspace $ current ss toWorkspace = [toWorkspaceName] in diff --git a/src/Internal/Submap.hs b/src/Internal/Submap.hs new file mode 100644 index 0000000..cdc2f95 --- /dev/null +++ b/src/Internal/Submap.hs @@ -0,0 +1,28 @@ +module Internal.Submap (mapNextString, module X) where + +import XMonad hiding (keys) +import Control.Monad.Fix (fix) + +import XMonad.Actions.Submap as X + +{- Like submap fram XMonad.Actions.Submap, but sends the string from + - XLookupString to the function rather than the KeySym. + -} +mapNextString :: (KeyMask -> String -> X a) -> X a +mapNextString fn = do + XConf { theRoot = root, display = d } <- ask + io $ grabKeyboard d root False grabModeAsync grabModeAsync currentTime + + (m, str) <- io $ allocaXEvent $ \p -> fix $ \nextkey -> do + maskEvent d keyPressMask p + KeyEvent { ev_keycode = code, ev_state = m } <- getEvent p + keysym <- keycodeToKeysym d code 0 + (_, str) <- lookupString (asKeyEvent p) + + if isModifierKey keysym + then nextkey + else return $ (m, str) + + io $ ungrabKeyboard d currentTime + + fn m str |