module KMonad.Model.Button
(
Button
, HasButton(..)
, onPress
, onRelease
, onTap
, mkButton
, around
, tapOn
, emitB
, pressOnly
, releaseOnly
, modded
, layerToggle
, layerSwitch
, layerAdd
, layerRem
, pass
, cmdButton
, aroundOnly
, aroundWhenAlone
, aroundNext
, aroundNextTimeout
, aroundNextSingle
, beforeAfterNext
, layerDelay
, layerNext
, tapHold
, multiTap
, tapNext
, tapHoldNext
, tapNextRelease
, tapHoldNextRelease
, tapNextPress
, tapHoldNextPress
, tapMacro
, tapMacroRelease
, steppedButton
, stickyKey
)
where
import KMonad.Prelude
import KMonad.Model.Action
import KMonad.Keyboard
import KMonad.Util
import qualified RIO.HashSet as S
data Button = Button
{ Button -> Action
_pressAction :: !Action
, Button -> Action
_releaseAction :: !Action
, Button -> Action
_tapAction :: !Action
}
makeClassy ''Button
mkButton :: AnyK () -> AnyK () -> Button
mkButton :: AnyK () -> AnyK () -> Button
mkButton AnyK ()
a AnyK ()
b = AnyK () -> AnyK () -> AnyK () -> Button
mkButton' m ()
AnyK ()
a m ()
AnyK ()
b (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ m ()
AnyK ()
a m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> m ()
AnyK ()
b
mkButton' :: AnyK () -> AnyK () -> AnyK () -> Button
mkButton' :: AnyK () -> AnyK () -> AnyK () -> Button
mkButton' AnyK ()
a AnyK ()
b AnyK ()
c = Action -> Action -> Action -> Button
Button (AnyK () -> Action
Action m ()
AnyK ()
a) (AnyK () -> Action
Action m ()
AnyK ()
b) (AnyK () -> Action
Action m ()
AnyK ()
c)
onPress :: AnyK () -> Button
onPress :: AnyK () -> Button
onPress AnyK ()
p = AnyK () -> AnyK () -> Button
mkButton m ()
AnyK ()
p (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
onRelease :: AnyK () -> Button
onRelease :: AnyK () -> Button
onRelease = AnyK () -> AnyK () -> Button
mkButton (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
onTap :: AnyK () -> Button
onTap :: AnyK () -> Button
onTap = AnyK () -> AnyK () -> AnyK () -> Button
mkButton' (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
onPress' :: Button -> AnyK () -> Button
onPress' :: Button -> AnyK () -> Button
onPress' (Button{_tapAction :: Button -> Action
_tapAction = Action AnyK ()
t}) AnyK ()
p = AnyK () -> AnyK () -> AnyK () -> Button
mkButton' m ()
AnyK ()
p (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) m ()
AnyK ()
t
tap :: MonadK m => Button -> m ()
tap :: forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b = Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
tapAction
press :: MonadK m => Button -> m ()
press :: forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b = do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
Switch -> m Catch -> m ()
forall (m :: * -> *). MonadK m => Switch -> m Catch -> m ()
awaitMy Switch
Release (m Catch -> m ()) -> m Catch -> m ()
forall a b. (a -> b) -> a -> b
$ do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
emitB :: Keycode -> Button
emitB :: Keycode -> Button
emitB Keycode
c = AnyK () -> AnyK () -> Button
mkButton
(KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
emit (KeyEvent -> m ()) -> KeyEvent -> m ()
forall a b. (a -> b) -> a -> b
$ Keycode -> KeyEvent
mkPress Keycode
c)
(KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
emit (KeyEvent -> m ()) -> KeyEvent -> m ()
forall a b. (a -> b) -> a -> b
$ Keycode -> KeyEvent
mkRelease Keycode
c)
pressOnly :: Keycode -> Button
pressOnly :: Keycode -> Button
pressOnly Keycode
c = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
emit (KeyEvent -> m ()) -> KeyEvent -> m ()
forall a b. (a -> b) -> a -> b
$ Keycode -> KeyEvent
mkPress Keycode
c
releaseOnly :: Keycode -> Button
releaseOnly :: Keycode -> Button
releaseOnly Keycode
c = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
emit (KeyEvent -> m ()) -> KeyEvent -> m ()
forall a b. (a -> b) -> a -> b
$ Keycode -> KeyEvent
mkRelease Keycode
c
modded ::
Keycode
-> Button
-> Button
modded :: Keycode -> Button -> Button
modded Keycode
modder = Button -> Button -> Button
around (Keycode -> Button
emitB Keycode
modder)
layerToggle :: LayerTag -> Button
layerToggle :: LayerTag -> Button
layerToggle LayerTag
t = AnyK () -> AnyK () -> AnyK () -> Button
mkButton'
(LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PushLayer LayerTag
t)
(LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PopLayer LayerTag
t)
(() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
layerSwitch :: LayerTag -> Button
layerSwitch :: LayerTag -> Button
layerSwitch LayerTag
t = AnyK () -> Button
onPress (LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
SetBaseLayer LayerTag
t)
layerAdd :: LayerTag -> Button
layerAdd :: LayerTag -> Button
layerAdd LayerTag
t = AnyK () -> Button
onPress (LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PushLayer LayerTag
t)
layerRem :: LayerTag -> Button
layerRem :: LayerTag -> Button
layerRem LayerTag
t = AnyK () -> Button
onPress (LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PopLayer LayerTag
t)
pass :: Button
pass :: Button
pass = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
cmdButton :: Text -> Maybe Text -> Button
cmdButton :: LayerTag -> Maybe LayerTag -> Button
cmdButton LayerTag
pr Maybe LayerTag
mbR = AnyK () -> AnyK () -> Button
mkButton (LayerTag -> m ()
forall (m :: * -> *). MonadKIO m => LayerTag -> m ()
shellCmd LayerTag
pr) (m () -> (LayerTag -> m ()) -> Maybe LayerTag -> m ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) LayerTag -> m ()
forall (m :: * -> *). MonadKIO m => LayerTag -> m ()
shellCmd Maybe LayerTag
mbR)
around ::
Button
-> Button
-> Button
around :: Button -> Button -> Button
around Button
outer Button
inner = AnyK () -> AnyK () -> Button
mkButton
(Action -> AnyK ()
runAction (Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Action -> AnyK ()
runAction (Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction))
(Action -> AnyK ()
runAction (Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Action -> AnyK ()
runAction (Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction))
aroundOnly ::
Button
-> Button
-> Button
aroundOnly :: Button -> Button -> Button
aroundOnly Button
outer Button
inner = Button -> AnyK () -> Button
onPress' (Button -> Button -> Button
around Button
outer Button
inner) (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
KeyPred -> m ()
forall (m :: * -> *). MonadK m => KeyPred -> m ()
go (KeyPred -> m ()) -> m KeyPred -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
where
go :: MonadK m => KeyPred -> m ()
go :: forall (m :: * -> *). MonadK m => KeyPred -> m ()
go KeyPred
isMyRelease = HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e ->
if
| KeyPred
isMyRelease KeyEvent
e -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
| KeyPred
isPress KeyEvent
e -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isMyRelease ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Action -> AnyK ()
runAction (Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction)
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
| Bool
otherwise ->
KeyPred -> m ()
forall (m :: * -> *). MonadK m => KeyPred -> m ()
go KeyPred
isMyRelease m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
aroundWhenAlone ::
Button
-> Button
-> Button
aroundWhenAlone :: Button -> Button -> Button
aroundWhenAlone Button
outer Button
inner = Button -> AnyK () -> Button
onPress' (Button -> Button -> Button
around Button
outer Button
inner) (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
HashSet Keycode -> KeyPred -> m ()
forall (m :: * -> *).
MonadK m =>
HashSet Keycode -> KeyPred -> m ()
go HashSet Keycode
forall a. HashSet a
S.empty (KeyPred -> m ()) -> m KeyPred -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
where
go :: MonadK m => HashSet Keycode -> KeyPred -> m ()
go :: forall (m :: * -> *).
MonadK m =>
HashSet Keycode -> KeyPred -> m ()
go HashSet Keycode
pressed KeyPred
isMyRelease = HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e ->
if
| KeyPred
isMyRelease KeyEvent
e -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
innerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HashSet Keycode -> Bool
forall a. HashSet a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HashSet Keycode
pressed) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
| KeyPred
isPress KeyEvent
e -> do
let pressed' :: HashSet Keycode
pressed' = Keycode -> HashSet Keycode -> HashSet Keycode
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
S.insert (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) HashSet Keycode
pressed
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (HashSet Keycode -> Bool
forall a. HashSet a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HashSet Keycode
pressed) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
HashSet Keycode -> KeyPred -> m ()
forall (m :: * -> *).
MonadK m =>
HashSet Keycode -> KeyPred -> m ()
go HashSet Keycode
pressed' KeyPred
isMyRelease
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
| Bool
otherwise -> do
let pressed' :: HashSet Keycode
pressed' = Keycode -> HashSet Keycode -> HashSet Keycode
forall a. (Eq a, Hashable a) => a -> HashSet a -> HashSet a
S.delete (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) HashSet Keycode
pressed
let shouldPressOuter :: Bool
shouldPressOuter = Keycode -> HashSet Keycode -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
S.member (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) HashSet Keycode
pressed Bool -> Bool -> Bool
&& HashSet Keycode -> Bool
forall a. HashSet a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HashSet Keycode
pressed'
KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e
Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
shouldPressOuter (m () -> m ()) -> (m () -> m ()) -> m () -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Milliseconds -> m () -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> m () -> m ()
after Milliseconds
3 (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$ Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
outerButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isRelease ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> HashSet Keycode -> KeyPred -> m ()
forall (m :: * -> *).
MonadK m =>
HashSet Keycode -> KeyPred -> m ()
go HashSet Keycode
pressed' KeyPred
isMyRelease m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
aroundNext ::
Button
-> Button
aroundNext :: Button -> Button
aroundNext Button
b = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isPress ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await (Keycode -> KeyPred
isReleaseOf (Keycode -> KeyPred) -> Keycode -> KeyPred
forall a b. (a -> b) -> a -> b
$ KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
aroundNextTimeout ::
Milliseconds
-> Button
-> Button
-> Button
aroundNextTimeout :: Milliseconds -> Button -> Button -> Button
aroundNextTimeout Milliseconds
d Button
b Button
t = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
within Milliseconds
d (KeyPred -> m KeyPred
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KeyPred
isPress) (Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t) ((Trigger -> m Catch) -> m ()) -> (Trigger -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \Trigger
trig -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await (Keycode -> KeyPred
isReleaseOf (Keycode -> KeyPred) -> Keycode -> KeyPred
forall a b. (a -> b) -> a -> b
$ Trigger
trigTrigger -> Getting Keycode Trigger Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.(KeyEvent -> Const Keycode KeyEvent)
-> Trigger -> Const Keycode Trigger
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event((KeyEvent -> Const Keycode KeyEvent)
-> Trigger -> Const Keycode Trigger)
-> Getting Keycode KeyEvent Keycode
-> Getting Keycode Trigger Keycode
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
aroundNextSingle ::
Button
-> Button
aroundNextSingle :: Button -> Button
aroundNextSingle Button
b = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isPress ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await (Bool -> KeyPred
forall a. a -> KeyEvent -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
True) ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
tapOn ::
Switch
-> Button
-> Button
tapOn :: Switch -> Button -> Button
tapOn Switch
Press Button
b = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b
tapOn Switch
Release Button
b = AnyK () -> Button
onRelease (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b
tapHold :: Milliseconds -> Button -> Button -> Button
tapHold :: Milliseconds -> Button -> Button -> Button
tapHold Milliseconds
ms Button
t Button
h = Button -> AnyK () -> Button
onPress' Button
t (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
withinHeld Milliseconds
ms (Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release)
(Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h)
(m Catch -> Trigger -> m Catch
forall a b. a -> b -> a
const (m Catch -> Trigger -> m Catch) -> m Catch -> Trigger -> m Catch
forall a b. (a -> b) -> a -> b
$ Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch)
tapNext :: Button -> Button -> Button
tapNext :: Button -> Button -> Button
tapNext Button
t Button
h = Button -> AnyK () -> Button
onPress' Button
t (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
if KeyPred
p KeyEvent
e
then Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
else Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
tapHoldNext :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNext :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNext Milliseconds
ms Button
t Button
h Maybe Button
mtb = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
within Milliseconds
ms (KeyPred -> m KeyPred
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (KeyPred -> m KeyPred) -> KeyPred -> m KeyPred
forall a b. (a -> b) -> a -> b
$ Bool -> KeyPred
forall a b. a -> b -> a
const Bool
True) m ()
AnyK ()
onTimeout ((Trigger -> m Catch) -> m ()) -> (Trigger -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \Trigger
tr -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
if KeyPred
p KeyPred -> KeyPred
forall a b. (a -> b) -> a -> b
$ Trigger
trTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event
then Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
else Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
where
onTimeout :: MonadK m => m ()
onTimeout :: AnyK ()
onTimeout = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press (Button -> m ()) -> Button -> m ()
forall a b. (a -> b) -> a -> b
$ Button -> Maybe Button -> Button
forall a. a -> Maybe a -> a
fromMaybe Button
h Maybe Button
mtb
beforeAfterNext :: Button -> Button -> Button
beforeAfterNext :: Button -> Button -> Button
beforeAfterNext Button
b Button
a = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isPress ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await (Keycode -> KeyPred
isReleaseOf (Keycode -> KeyPred) -> Keycode -> KeyPred
forall a b. (a -> b) -> a -> b
$ KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode) ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
_ -> do
Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
a
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
Catch -> m Catch
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
NoCatch
tapNextRelease :: Button -> Button -> Button
tapNextRelease :: Button -> Button -> Button
tapNextRelease Button
t Button
h = Button -> AnyK () -> Button
onPress' Button
t (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
True
[Keycode] -> m ()
forall (m :: * -> *). MonadK m => [Keycode] -> m ()
go []
where
go :: MonadK m => [Keycode] -> m ()
go :: forall (m :: * -> *). MonadK m => [Keycode] -> m ()
go [Keycode]
ks = HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
let isRel :: Bool
isRel = KeyPred
isRelease KeyEvent
e
if
| KeyPred
p KeyEvent
e -> m Catch
forall (m :: * -> *). MonadK m => m Catch
doTap
| Bool
isRel Bool -> Bool -> Bool
&& (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode Keycode -> [Keycode] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Keycode]
ks) -> KeyEvent -> m Catch
forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e
| Bool -> Bool
not Bool
isRel -> [Keycode] -> m ()
forall (m :: * -> *). MonadK m => [Keycode] -> m ()
go ((KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode)Keycode -> [Keycode] -> [Keycode]
forall a. a -> [a] -> [a]
:[Keycode]
ks) m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
| Bool
otherwise -> [Keycode] -> m ()
forall (m :: * -> *). MonadK m => [Keycode] -> m ()
go [Keycode]
ks m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
doTap :: MonadK m => m Catch
doTap :: forall (m :: * -> *). MonadK m => m Catch
doTap = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
doHold :: MonadK m => KeyEvent -> m Catch
doHold :: forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
tapHoldNextRelease :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNextRelease :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNextRelease Milliseconds
ms Button
t Button
h Maybe Button
mtb = Button -> AnyK () -> Button
onPress' Button
t (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
True
Milliseconds -> [Keycode] -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> [Keycode] -> m ()
go Milliseconds
ms []
where
go :: MonadK m => Milliseconds -> [Keycode] -> m ()
go :: forall (m :: * -> *). MonadK m => Milliseconds -> [Keycode] -> m ()
go Milliseconds
ms' [Keycode]
ks = HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
tHookF HookLocation
InputHook Milliseconds
ms' m ()
AnyK ()
onTimeout ((Trigger -> m Catch) -> m ()) -> (Trigger -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \Trigger
r -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
let e :: KeyEvent
e = Trigger
rTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event
let isRel :: Bool
isRel = KeyPred
isRelease KeyEvent
e
if
| KeyPred
p KeyEvent
e -> m Catch
forall (m :: * -> *). MonadK m => m Catch
onRelSelf
| Bool
isRel Bool -> Bool -> Bool
&& (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode Keycode -> [Keycode] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Keycode]
ks) -> KeyEvent -> m Catch
forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
onRelOther KeyEvent
e
| Bool -> Bool
not Bool
isRel -> Milliseconds -> [Keycode] -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> [Keycode] -> m ()
go (Milliseconds
ms' Milliseconds -> Milliseconds -> Milliseconds
forall a. Num a => a -> a -> a
- Trigger
rTrigger
-> Getting Milliseconds Trigger Milliseconds -> Milliseconds
forall s a. s -> Getting a s a -> a
^.Getting Milliseconds Trigger Milliseconds
forall c. HasTrigger c => Lens' c Milliseconds
Lens' Trigger Milliseconds
elapsed) (KeyEvent
eKeyEvent -> Getting Keycode KeyEvent Keycode -> Keycode
forall s a. s -> Getting a s a -> a
^.Getting Keycode KeyEvent Keycode
forall c. HasKeyEvent c => Lens' c Keycode
Lens' KeyEvent Keycode
keycode Keycode -> [Keycode] -> [Keycode]
forall a. a -> [a] -> [a]
: [Keycode]
ks) m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
| Bool
otherwise -> Milliseconds -> [Keycode] -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> [Keycode] -> m ()
go (Milliseconds
ms' Milliseconds -> Milliseconds -> Milliseconds
forall a. Num a => a -> a -> a
- Trigger
rTrigger
-> Getting Milliseconds Trigger Milliseconds -> Milliseconds
forall s a. s -> Getting a s a -> a
^.Getting Milliseconds Trigger Milliseconds
forall c. HasTrigger c => Lens' c Milliseconds
Lens' Trigger Milliseconds
elapsed) [Keycode]
ks m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
onTimeout :: MonadK m => m ()
onTimeout :: AnyK ()
onTimeout = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press (Button -> Maybe Button -> Button
forall a. a -> Maybe a -> a
fromMaybe Button
h Maybe Button
mtb) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False
onRelSelf :: MonadK m => m Catch
onRelSelf :: forall (m :: * -> *). MonadK m => m Catch
onRelSelf = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
onRelOther :: MonadK m => KeyEvent -> m Catch
onRelOther :: forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
onRelOther KeyEvent
e = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
tapNextPress :: Button -> Button -> Button
tapNextPress :: Button -> Button -> Button
tapNextPress Button
t Button
h = Button -> AnyK () -> Button
onPress' Button
t m ()
AnyK ()
go
where
go :: MonadK m => m ()
go :: AnyK ()
go = HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
if
| KeyPred
p KeyEvent
e -> m Catch
forall (m :: * -> *). MonadK m => m Catch
doTap
| KeyPred
isPress KeyEvent
e -> KeyEvent -> m Catch
forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e
| Bool
otherwise -> m ()
AnyK ()
go m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
doTap :: MonadK m => m Catch
doTap :: forall (m :: * -> *). MonadK m => m Catch
doTap = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
doHold :: MonadK m => KeyEvent -> m Catch
doHold :: forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
tapHoldNextPress :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNextPress :: Milliseconds -> Button -> Button -> Maybe Button -> Button
tapHoldNextPress Milliseconds
ms Button
t Button
h Maybe Button
mtb = Button -> AnyK () -> Button
onPress' Button
t (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
True
Milliseconds -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> m ()
go Milliseconds
ms
where
go :: MonadK m => Milliseconds -> m ()
go :: forall (m :: * -> *). MonadK m => Milliseconds -> m ()
go Milliseconds
ms' = HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
tHookF HookLocation
InputHook Milliseconds
ms' m ()
AnyK ()
onTimeout ((Trigger -> m Catch) -> m ()) -> (Trigger -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \Trigger
r -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
let e :: KeyEvent
e = Trigger
rTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event
if
| KeyPred
p KeyEvent
e -> m Catch
forall (m :: * -> *). MonadK m => m Catch
doTap
| KeyPred
isPress KeyEvent
e -> KeyEvent -> m Catch
forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e
| Bool
otherwise -> Milliseconds -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> m ()
go (Milliseconds
ms' Milliseconds -> Milliseconds -> Milliseconds
forall a. Num a => a -> a -> a
- Trigger
rTrigger
-> Getting Milliseconds Trigger Milliseconds -> Milliseconds
forall s a. s -> Getting a s a -> a
^.Getting Milliseconds Trigger Milliseconds
forall c. HasTrigger c => Lens' c Milliseconds
Lens' Trigger Milliseconds
elapsed) m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
onTimeout :: MonadK m => m ()
onTimeout :: AnyK ()
onTimeout = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press (Button -> Maybe Button -> Button
forall a. a -> Maybe a -> a
fromMaybe Button
h Maybe Button
mtb) m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False
doTap :: MonadK m => m Catch
doTap :: forall (m :: * -> *). MonadK m => m Catch
doTap = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
t m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
doHold :: MonadK m => KeyEvent -> m Catch
doHold :: forall (m :: * -> *). MonadK m => KeyEvent -> m Catch
doHold KeyEvent
e = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
h m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
multiTap :: Button -> [(Milliseconds, Button)] -> Button
multiTap :: Button -> [(Milliseconds, Button)] -> Button
multiTap Button
l [(Milliseconds, Button)]
bs = Button -> AnyK () -> Button
onPress' Button
tap' (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
True m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [(Milliseconds, Button)] -> m ()
forall (m :: * -> *). MonadK m => [(Milliseconds, Button)] -> m ()
go [(Milliseconds, Button)]
bs
where
tap' :: Button
tap' = case [(Milliseconds, Button)]
bs of
[] -> Button
l
((Milliseconds
_, Button
b) : [(Milliseconds, Button)]
_) -> Button
b
go :: MonadK m => [(Milliseconds, Button)] -> m ()
go :: forall (m :: * -> *). MonadK m => [(Milliseconds, Button)] -> m ()
go [] = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
l m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False
go ((Milliseconds
ms, Button
b):[(Milliseconds, Button)]
bs') = do
let doNext :: m KeyPred
-> m ()
-> (Milliseconds -> m a)
-> (Milliseconds -> m a)
-> Milliseconds
-> m ()
doNext m KeyPred
pred m ()
onTimeout Milliseconds -> m a
next Milliseconds -> m a
cancel Milliseconds
ms = HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
HookLocation
-> Milliseconds -> m () -> (Trigger -> m Catch) -> m ()
tHookF HookLocation
InputHook Milliseconds
ms m ()
onTimeout ((Trigger -> m Catch) -> m ()) -> (Trigger -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \Trigger
t -> do
KeyPred
pr <- m KeyPred
pred
if | KeyPred
pr (Trigger
tTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event) -> Milliseconds -> m a
next (Milliseconds
ms Milliseconds -> Milliseconds -> Milliseconds
forall a. Num a => a -> a -> a
- Trigger
tTrigger
-> Getting Milliseconds Trigger Milliseconds -> Milliseconds
forall s a. s -> Getting a s a -> a
^.Getting Milliseconds Trigger Milliseconds
forall c. HasTrigger c => Lens' c Milliseconds
Lens' Trigger Milliseconds
elapsed) m a -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
| KeyPred
isPress (Trigger
tTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event) -> m ()
onTimeout m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
| Bool
otherwise -> Milliseconds -> m a
cancel (Milliseconds
ms Milliseconds -> Milliseconds -> Milliseconds
forall a. Num a => a -> a -> a
- Trigger
tTrigger
-> Getting Milliseconds Trigger Milliseconds -> Milliseconds
forall s a. s -> Getting a s a -> a
^.Getting Milliseconds Trigger Milliseconds
forall c. HasTrigger c => Lens' c Milliseconds
Lens' Trigger Milliseconds
elapsed) m a -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
let cancel :: m ()
cancel = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False
let doHold :: m ()
doHold = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Bool -> m ()
forall (m :: * -> *). MonadKIO m => Bool -> m ()
hold Bool
False
let whileReleased :: Milliseconds -> m ()
whileReleased = m KeyPred
-> m ()
-> (Milliseconds -> m ())
-> (Milliseconds -> m ())
-> Milliseconds
-> m ()
forall {m :: * -> *} {a} {a}.
MonadK m =>
m KeyPred
-> m ()
-> (Milliseconds -> m a)
-> (Milliseconds -> m a)
-> Milliseconds
-> m ()
doNext (Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Press) m ()
cancel (\Milliseconds
_ -> [(Milliseconds, Button)] -> m ()
forall (m :: * -> *). MonadK m => [(Milliseconds, Button)] -> m ()
go [(Milliseconds, Button)]
bs') (m () -> Milliseconds -> m ()
forall a b. a -> b -> a
const m ()
cancel)
let whilePressed :: Milliseconds -> m ()
whilePressed = m KeyPred
-> m ()
-> (Milliseconds -> m ())
-> (Milliseconds -> m ())
-> Milliseconds
-> m ()
forall {m :: * -> *} {a} {a}.
MonadK m =>
m KeyPred
-> m ()
-> (Milliseconds -> m a)
-> (Milliseconds -> m a)
-> Milliseconds
-> m ()
doNext (Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release) m ()
doHold Milliseconds -> m ()
whileReleased Milliseconds -> m ()
whilePressed
Milliseconds -> m ()
whilePressed Milliseconds
ms
tapMacro :: [Button] -> Button
tapMacro :: [Button] -> Button
tapMacro [Button]
bs = AnyK () -> AnyK () -> AnyK () -> Button
mkButton' (Bool -> [Button] -> m ()
forall {f :: * -> *}. MonadK f => Bool -> [Button] -> f ()
go Bool
False [Button]
bs) (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (Bool -> [Button] -> m ()
forall {f :: * -> *}. MonadK f => Bool -> [Button] -> f ()
go Bool
True [Button]
bs)
where
go :: Bool -> [Button] -> f ()
go Bool
_ [] = () -> f ()
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
go Bool
False [Button
b] = Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b
go Bool
True [Button
b] = Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b
go Bool
forceTap (Button
b:[Button]
rst) = Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b f () -> f () -> f ()
forall a b. f a -> f b -> f b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> [Button] -> f ()
go Bool
forceTap [Button]
rst
tapMacroRelease :: [Button] -> Button
tapMacroRelease :: [Button] -> Button
tapMacroRelease [Button]
bs = AnyK () -> AnyK () -> AnyK () -> Button
mkButton' (Bool -> [Button] -> m ()
forall {f :: * -> *}. MonadK f => Bool -> [Button] -> f ()
go Bool
False [Button]
bs) (() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (Bool -> [Button] -> m ()
forall {f :: * -> *}. MonadK f => Bool -> [Button] -> f ()
go Bool
True [Button]
bs)
where
go :: Bool -> [Button] -> f ()
go Bool
_ [] = () -> f ()
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
go Bool
False [Button
b] = Switch -> f Catch -> f ()
forall (m :: * -> *). MonadK m => Switch -> m Catch -> m ()
awaitMy Switch
Release (f Catch -> f ()) -> f Catch -> f ()
forall a b. (a -> b) -> a -> b
$ Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b f () -> f Catch -> f Catch
forall a b. f a -> f b -> f b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Catch -> f Catch
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Catch
Catch
go Bool
True [Button
b] = Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b
go Bool
forceTap (Button
b:[Button]
rst) = Button -> f ()
forall (m :: * -> *). MonadK m => Button -> m ()
tap Button
b f () -> f () -> f ()
forall a b. f a -> f b -> f b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> [Button] -> f ()
go Bool
forceTap [Button]
rst
layerDelay :: Milliseconds -> LayerTag -> Button
layerDelay :: Milliseconds -> LayerTag -> Button
layerDelay Milliseconds
d LayerTag
t = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerTag -> LayerOp
PushLayer LayerTag
t)
Milliseconds -> m () -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> m () -> m ()
after Milliseconds
d (LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PopLayer LayerTag
t)
layerNext :: LayerTag -> Button
layerNext :: LayerTag -> Button
layerNext LayerTag
t = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ do
LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerTag -> LayerOp
PushLayer LayerTag
t)
KeyPred -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
KeyPred -> (KeyEvent -> m Catch) -> m ()
await KeyPred
isPress (\KeyEvent
_ -> m () -> m ()
forall (m :: * -> *). MonadK m => m () -> m ()
whenDone (LayerOp -> m ()
forall (m :: * -> *). MonadKIO m => LayerOp -> m ()
layerOp (LayerOp -> m ()) -> LayerOp -> m ()
forall a b. (a -> b) -> a -> b
$ LayerTag -> LayerOp
PopLayer LayerTag
t) m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch)
stickyKey :: Milliseconds -> Button -> Button
stickyKey :: Milliseconds -> Button -> Button
stickyKey Milliseconds
ms Button
b = AnyK () -> Button
onPress m ()
AnyK ()
go
where
go :: MonadK m => m ()
go :: AnyK ()
go = HookLocation -> (KeyEvent -> m Catch) -> m ()
forall (m :: * -> *).
MonadKIO m =>
HookLocation -> (KeyEvent -> m Catch) -> m ()
hookF HookLocation
InputHook ((KeyEvent -> m Catch) -> m ()) -> (KeyEvent -> m Catch) -> m ()
forall a b. (a -> b) -> a -> b
$ \KeyEvent
e -> do
KeyPred
p <- Switch -> m KeyPred
forall (m :: * -> *). MonadK m => Switch -> m KeyPred
matchMy Switch
Release
if | KeyPred
p KeyEvent
e -> m ()
AnyK ()
doTap m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
| Bool -> Bool
not (KeyPred
isRelease KeyEvent
e) -> KeyEvent -> m ()
forall (m :: * -> *). MonadK m => KeyEvent -> m ()
doHold KeyEvent
e m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch
| Bool
otherwise -> m ()
AnyK ()
go m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
NoCatch
doHold :: MonadK m => KeyEvent -> m ()
doHold :: forall (m :: * -> *). MonadK m => KeyEvent -> m ()
doHold KeyEvent
e = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject KeyEvent
e
doTap :: MonadK m => m ()
doTap :: AnyK ()
doTap =
Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
forall (m :: * -> *).
MonadK m =>
Milliseconds -> m KeyPred -> m () -> (Trigger -> m Catch) -> m ()
within Milliseconds
ms
(KeyPred -> m KeyPred
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KeyPred
isPress)
(() -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
(\Trigger
t -> Action -> AnyK ()
runAction (Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
pressAction)
m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> KeyEvent -> m ()
forall (m :: * -> *). MonadKIO m => KeyEvent -> m ()
inject (Trigger
tTrigger -> Getting KeyEvent Trigger KeyEvent -> KeyEvent
forall s a. s -> Getting a s a -> a
^.Getting KeyEvent Trigger KeyEvent
forall c. HasTrigger c => Lens' c KeyEvent
Lens' Trigger KeyEvent
event)
m () -> m () -> m ()
forall a b. m a -> m b -> m b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Milliseconds -> m () -> m ()
forall (m :: * -> *). MonadK m => Milliseconds -> m () -> m ()
after Milliseconds
3 (Action -> AnyK ()
runAction (Action -> AnyK ()) -> Action -> AnyK ()
forall a b. (a -> b) -> a -> b
$ Button
bButton -> Getting Action Button Action -> Action
forall s a. s -> Getting a s a -> a
^.Getting Action Button Action
forall c. HasButton c => Lens' c Action
Lens' Button Action
releaseAction)
m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch)
steppedButton :: [Button] -> Button
steppedButton :: [Button] -> Button
steppedButton [Button]
bs = AnyK () -> Button
onPress (AnyK () -> Button) -> AnyK () -> Button
forall a b. (a -> b) -> a -> b
$ [Button] -> m ()
forall {m :: * -> *}. MonadK m => [Button] -> m ()
go [Button]
bs
where
go :: [Button] -> m ()
go [] = m ()
forall a. HasCallStack => a
undefined
go [Button
b] = Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b
go (Button
b:[Button]
bs') = do
Button -> m ()
forall (m :: * -> *). MonadK m => Button -> m ()
press Button
b
Switch -> m Catch -> m ()
forall (m :: * -> *). MonadK m => Switch -> m Catch -> m ()
awaitMy Switch
Press (m Catch -> m ()) -> m Catch -> m ()
forall a b. (a -> b) -> a -> b
$ [Button] -> m ()
go [Button]
bs' m () -> Catch -> m Catch
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> Catch
Catch