mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
X.Prompt: Add isModifier
It seems sensible to abstract this away, if only to make the code a tad more readable.
This commit is contained in:
parent
3cd1b066a2
commit
8c0ca8b9fe
@ -627,6 +627,10 @@ runXP st = do
|
|||||||
|
|
||||||
type KeyStroke = (KeySym, String)
|
type KeyStroke = (KeySym, String)
|
||||||
|
|
||||||
|
-- | Check whether the given key stroke is a modifier.
|
||||||
|
isModifier :: KeyStroke -> Bool
|
||||||
|
isModifier (_, keyString) = null keyString
|
||||||
|
|
||||||
-- | Main event "loop". Gives priority to events from the state's event buffer.
|
-- | Main event "loop". Gives priority to events from the state's event buffer.
|
||||||
eventLoop :: (KeyStroke -> Event -> XP ())
|
eventLoop :: (KeyStroke -> Event -> XP ())
|
||||||
-> XP Bool
|
-> XP Bool
|
||||||
@ -649,7 +653,7 @@ eventLoop handle stopAction = do
|
|||||||
modify $ \s -> s { eventBuffer = tail l }
|
modify $ \s -> s { eventBuffer = tail l }
|
||||||
return $ head l
|
return $ head l
|
||||||
handle (keysym,keystr) event
|
handle (keysym,keystr) event
|
||||||
stopAction >>= flip unless (eventLoop handle stopAction)
|
stopAction >>= \stop -> unless stop (eventLoop handle stopAction)
|
||||||
|
|
||||||
-- | Default event loop stop condition.
|
-- | Default event loop stop condition.
|
||||||
evDefaultStop :: XP Bool
|
evDefaultStop :: XP Bool
|
||||||
@ -702,7 +706,7 @@ handleMain stroke@(keysym, keystr) = \case
|
|||||||
getCurrentCompletions >>= handleCompletionMain Next
|
getCurrentCompletions >>= handleCompletionMain Next
|
||||||
| (keymask, keysym) == prevCompKey ->
|
| (keymask, keysym) == prevCompKey ->
|
||||||
getCurrentCompletions >>= handleCompletionMain Prev
|
getCurrentCompletions >>= handleCompletionMain Prev
|
||||||
| otherwise -> unless (null keystr) $ do -- null keystr = only a modifier was pressed
|
| otherwise -> unless (isModifier stroke) $ do
|
||||||
setCurrentCompletions Nothing
|
setCurrentCompletions Nothing
|
||||||
if keysym == modeKey
|
if keysym == modeKey
|
||||||
then modify setNextMode >> updateWindows
|
then modify setNextMode >> updateWindows
|
||||||
@ -837,10 +841,10 @@ handleInputSubmap :: XP ()
|
|||||||
-> KeyMask
|
-> KeyMask
|
||||||
-> KeyStroke
|
-> KeyStroke
|
||||||
-> XP ()
|
-> XP ()
|
||||||
handleInputSubmap defaultAction keymap keymask (keysym,keystr) =
|
handleInputSubmap defaultAction keymap keymask stroke@(keysym, _) =
|
||||||
case M.lookup (keymask,keysym) keymap of
|
case M.lookup (keymask,keysym) keymap of
|
||||||
Just action -> action >> updateWindows
|
Just action -> action >> updateWindows
|
||||||
Nothing -> unless (null keystr) $ defaultAction >> updateWindows
|
Nothing -> unless (isModifier stroke) $ defaultAction >> updateWindows
|
||||||
|
|
||||||
-- | Initiate a prompt input buffer event loop. Input is sent to a buffer and
|
-- | Initiate a prompt input buffer event loop. Input is sent to a buffer and
|
||||||
-- bypasses the prompt. The provided function is given the existing buffer and
|
-- bypasses the prompt. The provided function is given the existing buffer and
|
||||||
@ -894,8 +898,8 @@ handleInputBuffer :: (String -> String -> (Bool,Bool))
|
|||||||
-> KeyStroke
|
-> KeyStroke
|
||||||
-> Event
|
-> Event
|
||||||
-> XP ()
|
-> XP ()
|
||||||
handleInputBuffer f keymask (keysym,keystr) event =
|
handleInputBuffer f keymask stroke@(keysym, keystr) event =
|
||||||
unless (null keystr || keymask .&. controlMask /= 0) $ do
|
unless (isModifier stroke || keymask .&. controlMask /= 0) $ do
|
||||||
(evB,inB) <- gets (eventBuffer &&& inputBuffer)
|
(evB,inB) <- gets (eventBuffer &&& inputBuffer)
|
||||||
let keystr' = utf8Decode keystr
|
let keystr' = utf8Decode keystr
|
||||||
let (cont,keep) = f inB keystr'
|
let (cont,keep) = f inB keystr'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user