-
Notifications
You must be signed in to change notification settings - Fork 332
Change release button handling to issue passthrough events #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e0cf4ea
1bf9d57
8ebb65f
007677f
a03bc09
a3c96ee
5e13486
d57f0b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -84,16 +84,19 @@ initAppEnv cfg = do | |||||||||||||||||||||
src <- using $ cfg^.keySourceDev | ||||||||||||||||||||||
|
||||||||||||||||||||||
-- Initialize the pull-chain components | ||||||||||||||||||||||
dsp <- Dp.mkDispatch $ awaitKey src | ||||||||||||||||||||||
ihk <- Hs.mkHooks $ Dp.pull dsp | ||||||||||||||||||||||
slc <- Sl.mkSluice $ Hs.pull ihk | ||||||||||||||||||||||
itr <- atomically $ newEmptyTMVar | ||||||||||||||||||||||
dsp <- Dp.mkDispatch (awaitKey src) itr | ||||||||||||||||||||||
ihkPrio <- Hs.mkHooks (Dp.pull dsp) itr | ||||||||||||||||||||||
slc <- Sl.mkSluice $ Hs.pull ihkPrio | ||||||||||||||||||||||
ihk <- Hs.mkHooks (Sl.pull slc) itr | ||||||||||||||||||||||
Comment on lines
+87
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would give
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
-- Initialize the button environments in the keymap | ||||||||||||||||||||||
phl <- Km.mkKeymap (cfg^.firstLayer) (cfg^.keymapCfg) | ||||||||||||||||||||||
|
||||||||||||||||||||||
-- Initialize output components | ||||||||||||||||||||||
otv <- lift . atomically $ newEmptyTMVar | ||||||||||||||||||||||
ohk <- Hs.mkHooks . atomically . takeTMVar $ otv | ||||||||||||||||||||||
otr <- atomically $ newEmptyTMVar | ||||||||||||||||||||||
ohk <- Hs.mkHooks ((atomically . takeTMVar) otv >>= pure . (WrappedKeyEvent NoCatch)) otr | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When changing the parameter order of
Suggested change
* readablitiy is subjective so this is just my opinion. |
||||||||||||||||||||||
|
||||||||||||||||||||||
-- Setup thread to read from outHooks and emit to keysink | ||||||||||||||||||||||
launch_ "emitter_proc" $ do | ||||||||||||||||||||||
|
@@ -107,8 +110,9 @@ initAppEnv cfg = do | |||||||||||||||||||||
, _keySource = src | ||||||||||||||||||||||
|
||||||||||||||||||||||
, _dispatch = dsp | ||||||||||||||||||||||
, _inHooks = ihk | ||||||||||||||||||||||
, _inHooksPrio = ihkPrio | ||||||||||||||||||||||
, _sluice = slc | ||||||||||||||||||||||
, _inHooks = ihk | ||||||||||||||||||||||
|
||||||||||||||||||||||
, _keymap = phl | ||||||||||||||||||||||
, _outHooks = ohk | ||||||||||||||||||||||
|
@@ -163,8 +167,8 @@ pressKey c = | |||||||||||||||||||||
-- 1. Pull from the pull-chain until an unhandled event reaches us. | ||||||||||||||||||||||
-- 2. If that event is a 'Press' we use our keymap to trigger an action. | ||||||||||||||||||||||
loop :: RIO AppEnv () | ||||||||||||||||||||||
loop = forever $ view sluice >>= Sl.pull >>= \case | ||||||||||||||||||||||
e | e^.switch == Press -> pressKey $ e^.keycode | ||||||||||||||||||||||
loop = forever $ view inHooks >>= Hs.pull >>= \case | ||||||||||||||||||||||
WrappedKeyEvent c e | c == NoCatch && e^.switch == Press -> pressKey $ e^.keycode | ||||||||||||||||||||||
_ -> pure () | ||||||||||||||||||||||
|
||||||||||||||||||||||
-- | Run KMonad using the provided configuration | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,6 +26,8 @@ module KMonad.Model.Action | |||||
, HookLocation(..) | ||||||
, Hook(..) | ||||||
|
||||||
, WrappedEvent(..) | ||||||
|
||||||
-- * Lenses | ||||||
, HasHook(..) | ||||||
, HasTimeout(..) | ||||||
|
@@ -58,6 +60,8 @@ module KMonad.Model.Action | |||||
|
||||||
where | ||||||
< 5D39 br> | ||||||
import Data.Unique | ||||||
|
||||||
import KMonad.Prelude hiding (timeout) | ||||||
|
||||||
import KMonad.Keyboard | ||||||
|
@@ -93,8 +97,10 @@ makeClassy ''Trigger | |||||
|
||||||
-- | ADT signalling where to install a hook | ||||||
data HookLocation | ||||||
= InputHook -- ^ Install the hook immediately after receiving a 'KeyEvent' | ||||||
| OutputHook -- ^ Install the hook just before emitting a 'KeyEvent' | ||||||
= InputHookPrio -- ^ Install the hook immediately after receiving a 'KeyEvent' | ||||||
-- and before the sluice | ||||||
| InputHook -- ^ Installthe hook after the sluice | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you missed a space
Suggested change
Comment on lines
+100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have added a parmater to the |
||||||
| OutputHook -- ^ Install the hook just before emitting a 'KeyEvent' | ||||||
deriving (Eq, Show) | ||||||
|
||||||
-- | A 'Timeout' value describes how long to wait and what to do upon timeout | ||||||
|
@@ -111,6 +117,28 @@ data Hook m = Hook | |||||
} | ||||||
makeClassy ''Hook | ||||||
|
||||||
-------------------------------------------------------------------------------- | ||||||
-- $wrapped | ||||||
-- | ||||||
-- A WrappedEvent wraps a KeyEvent or a hook tag. | ||||||
-- This is used to carry enough information to allow re-running an event if it | ||||||
-- was held in the sluice. | ||||||
-- | ||||||
-- TODO: Should this live here? | ||||||
data WrappedEvent = | ||||||
WrappedKeyEvent { | ||||||
_catch :: Catch | ||||||
, _keyEvent :: KeyEvent | ||||||
} | | ||||||
WrappedTag { | ||||||
_tag :: Unique | ||||||
} | ||||||
|
||||||
-- | Print out a WrappedKeyEvent nicely. | ||||||
instance Display WrappedEvent where | ||||||
textDisplay (WrappedKeyEvent c e) = "WrappedKeyEvent " <> textDisplay e <> ", " <> tshow c | ||||||
textDisplay (WrappedTag t) = "WrappedKeyEvent " <> tshow (hashUnique t) | ||||||
|
||||||
|
||||||
-------------------------------------------------------------------------------- | ||||||
-- $lop | ||||||
|
@@ -218,18 +246,19 @@ awaitMy s a = matchMy s >>= flip await (const a) | |||||
-- | Try to call a function on a succesful match of a predicate within a certain | ||||||
-- time period. On a timeout, perform an action. | ||||||
within :: MonadK m | ||||||
=> Milliseconds -- ^ The time within which this filter is active | ||||||
=> HookLocation | ||||||
-> Milliseconds -- ^ The time within which this filter is active | ||||||
-> m KeyPred -- ^ The predicate used to find a match | ||||||
-> m () -- ^ The action to call on timeout | ||||||
-> (Trigger -> m Catch) -- ^ The action to call on a succesful match | ||||||
-> m () -- ^ The resulting action | ||||||
within d p a f = do | ||||||
within l d p a f = do | ||||||
p' <- p | ||||||
-- define f' to run action on predicate match, or rehook on predicate mismatch | ||||||
let f' t = if p' (t^.event) | ||||||
then f t | ||||||
else within (d - t^.elapsed) p a f *> pure NoCatch | ||||||
tHookF InputHook d a f' | ||||||
else within l (d - t^.elapsed) p a f *> pure NoCatch | ||||||
tHookF l d a f' | ||||||
|
||||||
-- | Like `within`, but acquires a hold when starting, and releases when done | ||||||
withinHeld :: MonadK m | ||||||
|
@@ -240,4 +269,4 @@ withinHeld :: MonadK m | |||||
-> m () -- ^ The resulting action | ||||||
withinHeld d p a f = do | ||||||
hold True | ||||||
within d p (a <* hold False) (\x -> f x <* hold False) | ||||||
within InputHookPrio d p (a <* hold False) (\x -> f x <* hold False) |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -43,7 +43,9 @@ where | |||||||||
|
||||||||||
import KMonad.Prelude | ||||||||||
import KMonad.Keyboard | ||||||||||
import KMonad.Model.Action (WrappedEvent(..), Catch(..)) | ||||||||||
|
||||||||||
import Data.Unique | ||||||||||
import RIO.Seq (Seq(..), (><)) | ||||||||||
import qualified RIO.Seq as Seq | ||||||||||
import qualified RIO.Text as T | ||||||||||
|
@@ -58,20 +60,21 @@ import qualified RIO.Text as T | |||||||||
data Dispatch = Dispatch | ||||||||||
{ _eventSrc :: IO KeyEvent -- ^ How to read 1 event | ||||||||||
, _readProc :: TMVar (Async KeyEvent) -- ^ Store for reading process | ||||||||||
, _rerunBuf :: TVar (Seq KeyEvent) -- ^ Buffer for rerunning events | ||||||||||
, _rerunBuf :: TVar (Seq WrappedEvent) -- ^ Buffer for rerunning events | ||||||||||
, _injectTmr :: TMVar Unique -- ^ Used to signal timeouts | ||||||||||
} | ||||||||||
makeLenses ''Dispatch | ||||||||||
|
||||||||||
-- | Create a new 'Dispatch' environment | ||||||||||
mkDispatch' :: MonadUnliftIO m => m KeyEvent -> m Dispatch | ||||||||||
mkDispatch' s = withRunInIO $ \u -> do | ||||||||||
mkDispatch' :: MonadUnliftIO m => m KeyEvent -> TMVar Unique -> m Dispatch | ||||||||||
mkDispatch' s itr = withRunInIO $ \u -> do | ||||||||||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above I would change the order of parameters like this and also for
Suggested change
|
||||||||||
rpc <- atomically $ newEmptyTMVar | ||||||||||
rrb <- atomically $ newTVar Seq.empty | ||||||||||
pure $ Dispatch (u s) rpc rrb | ||||||||||
pure $ Dispatch (u s) rpc rrb itr | ||||||||||
|
||||||||||
-- | Create a new 'Dispatch' environment in a 'ContT' environment | ||||||||||
mkDispatch :: MonadUnliftIO m => m KeyEvent -> ContT r m Dispatch | ||||||||||
mkDispatch = lift . mkDispatch' | ||||||||||
mkDispatch :: MonadUnliftIO m => m KeyEvent -> TMVar Unique -> ContT r m Dispatch | ||||||||||
mkDispatch s itr = lift (mkDispatch' s itr) | ||||||||||
|
||||||||||
-------------------------------------------------------------------------------- | ||||||||||
-- $op | ||||||||||
|
@@ -82,7 +85,7 @@ mkDispatch = lift . mkDispatch' | |||||||||
-- 1. The next item to be rerun | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add the timer in the comments of what is happening. |
||||||||||
-- 2. A new item read from the OS | ||||||||||
-- 3. Pausing until either 1. or 2. triggers | ||||||||||
pull :: (HasLogFunc e) => Dispatch -> RIO e KeyEvent | ||||||||||
pull :: (HasLogFunc e) => Dispatch -> RIO e WrappedEvent | ||||||||||
pull d = do | ||||||||||
-- Check for an unfinished read attempt started previously. If it exists, | ||||||||||
-- fetch it, otherwise, start a new read attempt. | ||||||||||
|
@@ -92,14 +95,22 @@ pull d = do | |||||||||
|
||||||||||
-- First try reading from the rerunBuf, or failing that, from the | ||||||||||
-- read-process. If both fail we enter an STM race. | ||||||||||
atomically ((Left <$> popRerun) `orElse` (Right <$> waitSTM a)) >>= \case | ||||||||||
-- If we take from the rerunBuf, put the running read-process back in place | ||||||||||
Left e' -> do | ||||||||||
logDebug $ "\n" <> display (T.replicate 80 "-") | ||||||||||
<> "\nRerunning event: " <> display e' | ||||||||||
atomically $ putTMVar (d^.readProc) a | ||||||||||
pure e' | ||||||||||
Right e' -> pure e' | ||||||||||
atomically ( | ||||||||||
(Left <$> takeTMVar (d^.injectTmr)) | ||||||||||
`orElse`(Right . Left <$> popRerun) | ||||||||||
`orElse` (Right . Right <$> waitSTM a) | ||||||||||
) >>= \case | ||||||||||
-- If there's a timer, pass it through | ||||||||||
Left t -> do | ||||||||||
atomically $ putTMVar (d^.readProc) a | ||||||||||
pure (WrappedTag t) | ||||||||||
-- If we take from the rerunBuf, put the running read-process back in place | ||||||||||
Right (Left e') -> do | ||||||||||
logDebug $ "\n" <> display (T.replicate 80 "-") | ||||||||||
<> "\nRerunning event: " <> display e' | ||||||||||
atomically $ putTMVar (d^.readProc) a | ||||||||||
pure e' | ||||||||||
Right (Right e') -> pure (WrappedKeyEvent NoCatch e') | ||||||||||
|
||||||||||
where | ||||||||||
-- Pop the head off the rerun-buffer (or 'retrySTM' if empty) | ||||||||||
|
@@ -110,5 +121,5 @@ pull d = do | |||||||||
pure e | ||||||||||
|
||||||||||
-- | Add a list of elements to be rerun. | ||||||||||
rerun :: (HasLogFunc e) => Dispatch -> [KeyEvent] -> RIO e () | ||||||||||
rerun :: (HasLogFunc e) => Dispatch -> [WrappedEvent] -> RIO e () | ||||||||||
rerun d es = atomically $ modifyTVar (d^.rerunBuf) (>< Seq.fromList es) |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply hint
This is a problem at a few points.
Even better rebase on
master
since there it's already fixed.