aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport')
-rw-r--r--src/Chelleport/AppState.hs11
-rw-r--r--src/Chelleport/Control.hs19
-rw-r--r--src/Chelleport/Types.hs4
3 files changed, 24 insertions, 10 deletions
diff --git a/src/Chelleport/AppState.hs b/src/Chelleport/AppState.hs
index 25575f1..7687257 100644
--- a/src/Chelleport/AppState.hs
+++ b/src/Chelleport/AppState.hs
@@ -1,7 +1,7 @@
module Chelleport.AppState (initialState, update) where
import Chelleport.AppShell (MonadAppShell (hideWindow, showWindow, shutdownApp))
-import Chelleport.Control (MonadControl (..), directionalIncrement)
+import Chelleport.Control (MonadControl (..), directionalIncrement, hjklDirection)
import Chelleport.Draw (MonadDraw (windowPosition, windowSize), pointerPositionIncrement, screenPositionFromCellPosition, wordPosition)
import Chelleport.KeySequence (findMatchPosition, generateGrid, nextChars, toKeyChar)
import Chelleport.OCR (MonadOCR (captureScreenshot), getWordsInImage)
@@ -36,9 +36,7 @@ update state@(State {stateMode = ModeHints}) (HandleKeyInput keycode) = do
case (toKeyChar keycode, validNextKeys) of
(Just keyChar, Just validChars')
| stateIsMatched state && keyChar `elem` ("HJKL" :: String) -> do
- incr <- pointerPositionIncrement state
- let action = IncrementMouseCursor $ directionalIncrement incr keyChar
- pure (state, Just action)
+ pure (state, Just $ MoveMouseInDirection $ hjklDirection keyChar)
| keyChar `elem` validChars' -> do
let newKeySequence = stateKeySequence state ++ [keyChar]
let matchPosition = findMatchPosition newKeySequence $ stateGrid state
@@ -115,6 +113,11 @@ update state MouseDragToggle
| stateIsDragging state = pure (state {stateIsDragging = False}, Just MouseDragEnd)
| otherwise = do pure (state {stateIsDragging = True}, Just MouseDragStart)
+-- Apply movement in given direction
+update state (MoveMouseInDirection direction) = do
+ incr <- pointerPositionIncrement state
+ pure (state, Just $ IncrementMouseCursor $ directionalIncrement incr direction)
+
-- Move mouse to given position
update state (MoveMousePosition (x, y)) = do
moveMousePointer (intToCInt x) (intToCInt y)
diff --git a/src/Chelleport/Control.hs b/src/Chelleport/Control.hs
index 48bdcb2..e7bd418 100644
--- a/src/Chelleport/Control.hs
+++ b/src/Chelleport/Control.hs
@@ -94,10 +94,17 @@ anyDigit = isKeycodeDigit . eventToKeycode
anyAlphanumeric :: SDL.KeyboardEventData -> Bool
anyAlphanumeric = isValidKey . eventToKeycode
-directionalIncrement :: (CInt, CInt) -> Char -> (Int, Int)
+hjklDirection :: Char -> Direction
+hjklDirection = \case
+ 'H' -> DirLeft
+ 'L' -> DirRight
+ 'K' -> DirUp
+ 'J' -> DirDown
+ _ -> DirUp
+
+directionalIncrement :: (CInt, CInt) -> Direction -> (Int, Int)
directionalIncrement (incX, incY) = \case
- 'H' -> (-cIntToInt incX, 0)
- 'L' -> (cIntToInt incX, 0)
- 'K' -> (0, -cIntToInt incY)
- 'J' -> (0, cIntToInt incY)
- _ -> undefined
+ DirLeft -> (-cIntToInt incX, 0)
+ DirRight -> (cIntToInt incX, 0)
+ DirUp -> (0, -cIntToInt incY)
+ DirDown -> (0, cIntToInt incY)
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs
index f526fe8..89b2e3d 100644
--- a/src/Chelleport/Types.hs
+++ b/src/Chelleport/Types.hs
@@ -62,6 +62,9 @@ defaultAppState =
stateMode = ModeHints
}
+data Direction = DirUp | DirDown | DirLeft | DirRight
+ deriving (Show, Eq)
+
data AppAction
= ChainMouseClick MouseButtonType
| HandleKeyInput SDL.Keycode
@@ -70,6 +73,7 @@ data AppAction
| MouseDragEnd
| MouseDragStart
| MouseDragToggle
+ | MoveMouseInDirection Direction
| MoveMousePosition (Int, Int)
| ResetKeys
| SetMode Mode