diff options
Diffstat (limited to 'src/Chelleport')
| -rw-r--r-- | src/Chelleport/AppShell.hs | 4 | ||||
| -rw-r--r-- | src/Chelleport/Control.hs | 27 | ||||
| -rw-r--r-- | src/Chelleport/Types.hs | 14 |
3 files changed, 27 insertions, 18 deletions
diff --git a/src/Chelleport/AppShell.hs b/src/Chelleport/AppShell.hs index b31c964..382f61e 100644 --- a/src/Chelleport/AppShell.hs +++ b/src/Chelleport/AppShell.hs @@ -1,6 +1,6 @@ module Chelleport.AppShell (setupAppShell, MonadAppShell (..)) where -import Chelleport.Control (MonadControl (mouseButtonUp)) +import Chelleport.Control (MonadControl (releaseMouseButton)) import Chelleport.Draw (colorBackground) import Chelleport.Types import Control.Monad (foldM) @@ -23,7 +23,7 @@ instance (MonadIO m) => MonadAppShell (AppM m) where ctx <- ask SDL.destroyRenderer $ ctxRenderer ctx SDL.destroyWindow $ ctxWindow ctx - mouseButtonUp + releaseMouseButton liftIO $ do X11.closeDisplay $ ctxX11Display ctx exitSuccess diff --git a/src/Chelleport/Control.hs b/src/Chelleport/Control.hs index 2dcb565..fa25681 100644 --- a/src/Chelleport/Control.hs +++ b/src/Chelleport/Control.hs @@ -12,25 +12,25 @@ import qualified Graphics.X11 as X11 import qualified SDL class (Monad m) => MonadControl m where - pressMouseButton :: MouseButtonType -> m () + clickMouseButton :: MouseButtonType -> m () moveMousePointer :: CInt -> CInt -> m () - mouseButtonDown :: m () - mouseButtonUp :: m () + pressMouseButton :: m () + releaseMouseButton :: m () getMousePointerPosition :: m (CInt, CInt) foreign import ccall unsafe "X11/extensions/XTest.h XTestFakeButtonEvent" xSimulateButtonEvent :: X11.Display -> X11.Button -> Bool -> X11.Time -> IO X11.Status -- Wrap with delay to prevent async window close issues -withDelay :: (MonadIO m) => m () -> m () -withDelay act = delay >> act >> delay +withInteractionDelay :: (MonadIO m) => m () -> m () +withInteractionDelay act = delay >> act >> delay where delay = liftIO (threadDelay 20_000) instance (MonadIO m) => MonadControl (AppM m) where - pressMouseButton btn = do + clickMouseButton btn = do (DrawContext {ctxX11Display = display}) <- ask - withDelay . liftIO $ do + withInteractionDelay . liftIO $ do xSimulateButtonEvent display x11Button True 0 xSimulateButtonEvent display x11Button False 0 X11.sync display False @@ -51,15 +51,15 @@ instance (MonadIO m) => MonadControl (AppM m) where Debug.traceM "ERROR: Cant query pointer" pure (x, y) - mouseButtonDown = do + pressMouseButton = do (DrawContext {ctxX11Display = display}) <- ask - withDelay . liftIO $ do + withInteractionDelay . liftIO $ do xSimulateButtonEvent display X11.button1 True 0 X11.sync display False - mouseButtonUp = do + releaseMouseButton = do (DrawContext {ctxX11Display = display}) <- ask - withDelay . liftIO $ do + withInteractionDelay . liftIO $ do xSimulateButtonEvent display X11.button1 False 0 X11.sync display False @@ -85,6 +85,11 @@ withShift event = SDL.keyModifierLeftShift modifier || SDL.keyModifierRightShift where modifier = SDL.keysymModifier . SDL.keyboardEventKeysym $ event +withCtrl :: SDL.KeyboardEventData -> Bool +withCtrl event = SDL.keyModifierLeftCtrl modifier || SDL.keyModifierRightCtrl modifier + where + modifier = SDL.keysymModifier . SDL.keyboardEventKeysym $ event + directionalIncrement :: (CInt, CInt) -> Char -> (Int, Int) directionalIncrement (incX, incY) = \case 'H' -> (-cIntToInt incX, 0) diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs index e648618..b114189 100644 --- a/src/Chelleport/Types.hs +++ b/src/Chelleport/Types.hs @@ -18,18 +18,22 @@ data State = State { stateGrid :: KeyGrid, stateKeySequence :: KeySequence, stateIsMatched :: Bool, - stateIsShiftPressed :: Bool + stateIsShiftPressed :: Bool, + stateIsDragging :: Bool } deriving (Show, Eq) data AppAction - = HandleKeyInput SDL.Keycode + = ChainMouseClick MouseButtonType + | HandleKeyInput SDL.Keycode + | IncrementMouseCursor (Int, Int) + | MouseDragStart + | MouseDragEnd + | MouseDragToggle | MoveMousePosition (Int, Int) | ResetKeys - | TriggerMouseClick MouseButtonType - | ChainMouseClick MouseButtonType - | IncrementMouseCursor (Int, Int) | ShutdownApp + | TriggerMouseClick MouseButtonType | UpdateShiftState Bool deriving (Show, Eq) |
