aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-20 19:51:08 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-20 19:54:25 +0530
commit496c7d048df6a9a3650c0a0b996888decb4ea9d1 (patch)
treebdd74d3678dff626249a14f9682e8d3b798d4d05 /src
parentf96b1395518b2941b2746398094c06d3d40d18f1 (diff)
downloadchelleport-496c7d048df6a9a3650c0a0b996888decb4ea9d1.tar.gz
chelleport-496c7d048df6a9a3650c0a0b996888decb4ea9d1.zip
Add shift+click to chain clicks in sequence
Diffstat (limited to 'src')
-rw-r--r--src/Chelleport.hs22
-rw-r--r--src/Chelleport/Control.hs11
-rw-r--r--src/Chelleport/KeySequence.hs1
-rw-r--r--src/Chelleport/Types.hs1
4 files changed, 25 insertions, 10 deletions
diff --git a/src/Chelleport.hs b/src/Chelleport.hs
index 98d1aa6..6c06af4 100644
--- a/src/Chelleport.hs
+++ b/src/Chelleport.hs
@@ -2,9 +2,9 @@
module Chelleport where
-import Chelleport.AppShell (MonadAppShell (hideWindow, shutdownApp), setupAppShell)
+import Chelleport.AppShell (MonadAppShell (hideWindow, showWindow, shutdownApp), setupAppShell)
import Chelleport.Context (initializeContext)
-import Chelleport.Control (MonadControl (getMousePointerPosition, moveMousePointer, pressMouseButton), directionalIncrement, eventToKeycode, isKeyPress, isKeyPressWith, isKeyReleaseWith)
+import Chelleport.Control (MonadControl (getMousePointerPosition, moveMousePointer, pressMouseButton), directionalIncrement, eventToKeycode, isKeyPressWith, isKeyPressed, isKeyReleaseWith, withShift)
import Chelleport.Draw (MonadDraw, cellSize)
import Chelleport.KeySequence (findMatchPosition, generateGrid, isValidKey, nextChars, toKeyChar)
import Chelleport.Types
@@ -12,7 +12,6 @@ import Chelleport.Utils (intToCInt)
import qualified Chelleport.View
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Reader (ReaderT (runReaderT))
-import Data.List ((\\))
import Data.Maybe (fromMaybe, isJust)
import qualified SDL
@@ -46,18 +45,20 @@ initialState = do
where
rows = 9
columns = 16
- hintKeys = ['A' .. 'Z'] \\ "Q"
+ hintKeys = ['A' .. 'Z']
eventHandler :: SDL.Event -> Maybe AppAction
eventHandler event =
case SDL.eventPayload event of
SDL.QuitEvent -> Just ShutdownApp
SDL.KeyboardEvent ev
- | isKeyPressWith ev SDL.KeycodeQ -> Just ShutdownApp
| isKeyPressWith ev SDL.KeycodeEscape -> Just ShutdownApp
- | isKeyPressWith ev SDL.KeycodeSpace -> Just TriggerLeftClick
+ | isKeyPressWith ev SDL.KeycodeSpace ->
+ if withShift ev
+ then Just ChainLeftClick
+ else Just TriggerLeftClick
| isKeyPressWith ev SDL.KeycodeTab -> Just ResetKeys
- | isKeyPress ev && isValidKey (eventToKeycode ev) ->
+ | isKeyPressed ev && isValidKey (eventToKeycode ev) ->
Just $ HandleKeyInput $ eventToKeycode ev
| isKeyPressWith ev SDL.KeycodeLShift || isKeyPressWith ev SDL.KeycodeRShift ->
Just $ UpdateShiftState True
@@ -120,6 +121,13 @@ update state TriggerLeftClick = do
pressMouseButton LeftClick
pure (state, Just ShutdownApp)
+-- Chain clicks
+update state ChainLeftClick = do
+ hideWindow
+ pressMouseButton LeftClick
+ showWindow
+ pure (state, Just ResetKeys)
+
-- Cleanup everything and exit
update state ShutdownApp = do
shutdownApp
diff --git a/src/Chelleport/Control.hs b/src/Chelleport/Control.hs
index 2ad2a34..38b6c53 100644
--- a/src/Chelleport/Control.hs
+++ b/src/Chelleport/Control.hs
@@ -36,8 +36,8 @@ instance (MonadIO m) => MonadControl (AppM m) where
(SDL.P (SDL.V2 x y)) <- SDL.getAbsoluteMouseLocation
pure (x, y)
-isKeyPress :: SDL.KeyboardEventData -> Bool
-isKeyPress = (== SDL.Pressed) . SDL.keyboardEventKeyMotion
+isKeyPressed :: SDL.KeyboardEventData -> Bool
+isKeyPressed = (== SDL.Pressed) . SDL.keyboardEventKeyMotion
isKeyRelease :: SDL.KeyboardEventData -> Bool
isKeyRelease = (== SDL.Released) . SDL.keyboardEventKeyMotion
@@ -47,12 +47,17 @@ eventToKeycode = SDL.keysymKeycode . SDL.keyboardEventKeysym
isKeyPressWith :: SDL.KeyboardEventData -> SDL.Keycode -> Bool
isKeyPressWith keyboardEvent keyCode =
- isKeyPress keyboardEvent && eventToKeycode keyboardEvent == keyCode
+ isKeyPressed keyboardEvent && eventToKeycode keyboardEvent == keyCode
isKeyReleaseWith :: SDL.KeyboardEventData -> SDL.Keycode -> Bool
isKeyReleaseWith keyboardEvent keyCode =
isKeyRelease keyboardEvent && eventToKeycode keyboardEvent == keyCode
+withShift :: SDL.KeyboardEventData -> Bool
+withShift event = SDL.keyModifierLeftShift modifier || SDL.keyModifierRightShift 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/KeySequence.hs b/src/Chelleport/KeySequence.hs
index d92fe0e..dc5f603 100644
--- a/src/Chelleport/KeySequence.hs
+++ b/src/Chelleport/KeySequence.hs
@@ -72,6 +72,7 @@ keycodeMapping =
(SDL.KeycodeN, 'N'),
(SDL.KeycodeO, 'O'),
(SDL.KeycodeP, 'P'),
+ (SDL.KeycodeQ, 'Q'),
(SDL.KeycodeR, 'R'),
(SDL.KeycodeS, 'S'),
(SDL.KeycodeT, 'T'),
diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs
index a6aa7cc..ca17c23 100644
--- a/src/Chelleport/Types.hs
+++ b/src/Chelleport/Types.hs
@@ -27,6 +27,7 @@ data AppAction
| MoveMousePosition (Int, Int)
| ResetKeys
| TriggerLeftClick
+ | ChainLeftClick
| IncrementMouseCursor (Int, Int)
| ShutdownApp
| UpdateShiftState Bool