diff options
Diffstat (limited to 'plug/src/Config.hs')
| -rw-r--r-- | plug/src/Config.hs | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/plug/src/Config.hs b/plug/src/Config.hs index 5cf616f..7314604 100644 --- a/plug/src/Config.hs +++ b/plug/src/Config.hs @@ -1,6 +1,7 @@ module Config () where import Control.Monad.IO.Class (liftIO) +import Data.Bits (shiftL, (.&.)) import Data.Maybe (fromMaybe) import Data.Typeable (Typeable) import Data.Void (Void) @@ -12,6 +13,7 @@ import Foreign.Ptr (nullPtr) import Foreign.Storable (peek) import Montis.Base.Foreign.Runtime import Montis.Core +import Montis.Standard.Keys (KeysConfig (KeysConfig), subkeys) foreign export ccall "plugin_cold_start" coldStart :: MontisColdStart @@ -25,15 +27,32 @@ coldStart = coldStartMontis config hotStart :: MontisHotStart hotStart = hotStartMontis config +keys :: KeyEvent -> Montis Bool +keys ev + | keyEvent_modifiers ev .&. mod1Mask == 0 = return False + | otherwise = case keyEvent_codepoint ev of + 'j' -> do + liftIO (putStrLn "j was pressed!") + subkeys $ \ev -> case keyEvent_codepoint ev of + 'k' -> do + liftIO (putStrLn "k was pressed after j!") + return True + _ -> return False + _ -> return False + +mod1Mask :: Word32 +mod1Mask = 1 `shiftL` 3 -- WLR_MODIFIER_ALT + config :: MontisConfig config = - defaultConfig - { startingHooks = - (startingHooks defaultConfig) - { buttonHook = onButton, - motionHook = onMotion - } - } + install (KeysConfig keys) $ + defaultConfig + { startingHooks = + (startingHooks defaultConfig) + { buttonHook = onButton, + motionHook = onMotion + } + } data DragState = DragState { dragToplevel :: Ptr ForeignMontisToplevel, @@ -66,7 +85,7 @@ onButton ev | buttonEvent_button ev /= leftButton = return () | buttonEvent_state ev == ButtonPressed = do self <- getSelfPtr - CursorPosition (x, y) <- fromMaybe (CursorPosition (0, 0)) <$> xStateGet + CursorPosition (x, y) <- xStateGet newDrag <- liftIO $ do tl <- foreign_toplevelAt (unwrapSelf self) (realToFrac x) (realToFrac y) if tl == nullPtr @@ -85,7 +104,7 @@ onMotion :: MotionEvent -> Montis () onMotion ev = do let (x, y) = motionEvent_absolute ev xStatePut (CursorPosition (x, y)) - Dragging mdrag <- fromMaybe (Dragging Nothing) <$> xStateGet + Dragging mdrag <- xStateGet case mdrag of Nothing -> return () Just (DragState tl dx dy) -> do |