From b194555e98c79ddf658d62eb847d73a42a595e89 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 19 Mar 2024 10:45:43 -0600 Subject: Change KeysM to use a ContT monad instead of rolling my own. Turns out the haskell geniuses already figured out how to encapsulate such asynchronous control flow. --- src/Config.hs | 65 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'src/Config.hs') diff --git a/src/Config.hs b/src/Config.hs index 4521cc1..04d13c6 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -2,13 +2,12 @@ module Config (config) where import Control.Monad.IO.Class import Control.Monad.Loops -import Control.Monad.RWS (MonadReader (ask)) -import qualified Wetterhorn.Core.KeyEvent as KeyEvent +import Wetterhorn.Core.KeyEvent qualified as KeyEvent import Wetterhorn.Core.Keys import Wetterhorn.Core.W import Wetterhorn.Layout.Full -alsoLog :: KeyHandler -> W () +alsoLog :: KeyContinuation -> W () alsoLog kh = putKeyHandler ( \ke -> do @@ -21,36 +20,36 @@ config = defaultConfig { hooks = defaultHooks - { keyHook = keysWithHandler alsoLog $ do - ignoreReleaseEvents - - bind (Mod1 .+ 'r') (shellExec "wofi --show run") - bind (Shift .+ Mod1 .+ 'R') requestHotReload - bind (Mod1 .+ 't') (shellExec "alacritty") - - subbind (Mod1 .+ 'l') $ do - bind 'l' $ wio $ putStrLn "lololololo" - bind 'j' $ wio $ putStrLn "JOGGING!" - - subbind (Mod1 .+ 'p') $ do - str <- - unfoldM - ( do - ke <- ask - if KeyEvent.codepoint ke == '\r' - then return Nothing - else do - Just (KeyEvent.codepoint ke) <$ nextKeyPress - ) - - liftIO $ putStrLn $ "You input: " ++ str - bind (str == "hello") $ do - liftIO $ putStrLn "You Win! *\\o/*" - liftIO $ putStrLn "You Lose :(" - - forwardEvent, - surfaceHook = do + { surfaceHook = do handleSurface }, - layout = WindowLayout Full + layout = WindowLayout Full, + resetHook = do + useKeysWithContinuation alsoLog $ do + kp <- nextKeyPress + + bind kp (Mod1 .+ 'r') (shellExec "wofi --show run") + + bind kp (Shift .+ Mod1 .+ 'R') requestHotReload + + bind kp (Mod1 .+ 't') (shellExec "alacritty") + + bind kp (weak $ Mod1 .+ '∫') (shellExec "gxmessage hi") + + bind kp (Mod1 .+ 'p') $ do + str <- + unfoldM + ( do + ke <- nextKeyPress + return $ + if KeyEvent.codepoint ke == '\r' + then Nothing + else Just (KeyEvent.codepoint ke) + ) + liftIO $ putStrLn $ "You input: " ++ str + bind kp (str == "hello") $ do + wio $ putStrLn "You Win! *\\o/*" + liftIO $ putStrLn "You lose :(" + + forwardEvent kp } -- cgit