aboutsummaryrefslogtreecommitdiff
path: root/plug/src/Config.hs
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2026-01-04 21:41:39 -0700
committerJosh Rahm <joshuarahm@gmail.com>2026-01-04 21:41:39 -0700
commit9637f06dd40418bd01cde0fe9f33d4fe979555ab (patch)
treec41c136ed52aee4a4b74818531b05c55b938deb8 /plug/src/Config.hs
parent5e86dbfa1bb30c8b1f36582e1a5229a208c5bff4 (diff)
downloadmontis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.tar.gz
montis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.tar.bz2
montis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.zip
[refactor] Change dragging behavior to use the motion event.
Diffstat (limited to 'plug/src/Config.hs')
-rw-r--r--plug/src/Config.hs24
1 files changed, 12 insertions, 12 deletions
diff --git a/plug/src/Config.hs b/plug/src/Config.hs
index e80f360..5cf616f 100644
--- a/plug/src/Config.hs
+++ b/plug/src/Config.hs
@@ -50,6 +50,14 @@ instance StateExtension Dragging where
marshalExtension _ = Nothing
demarshalExtension _ = Nothing
+newtype CursorPosition = CursorPosition (Double, Double)
+ deriving (Typeable)
+
+instance StateExtension CursorPosition where
+ initialValue = CursorPosition (0, 0)
+ marshalExtension _ = Nothing
+ demarshalExtension _ = Nothing
+
leftButton :: Word32
leftButton = 272 -- BTN_LEFT
@@ -58,8 +66,8 @@ onButton ev
| buttonEvent_button ev /= leftButton = return ()
| buttonEvent_state ev == ButtonPressed = do
self <- getSelfPtr
+ CursorPosition (x, y) <- fromMaybe (CursorPosition (0, 0)) <$> xStateGet
newDrag <- liftIO $ do
- (x, y) <- getCursorPosition self
tl <- foreign_toplevelAt (unwrapSelf self) (realToFrac x) (realToFrac y)
if tl == nullPtr
then return (Dragging Nothing)
@@ -74,13 +82,13 @@ onButton ev
| otherwise = return ()
onMotion :: MotionEvent -> Montis ()
-onMotion _ev = do
+onMotion ev = do
+ let (x, y) = motionEvent_absolute ev
+ xStatePut (CursorPosition (x, y))
Dragging mdrag <- fromMaybe (Dragging Nothing) <$> xStateGet
case mdrag of
Nothing -> return ()
Just (DragState tl dx dy) -> do
- self <- getSelfPtr
- (x, y) <- liftIO $ getCursorPosition self
liftIO $
foreign_setToplevelPosition
tl
@@ -90,14 +98,6 @@ onMotion _ev = do
unwrapSelf :: SelfPtr -> Ptr Void
unwrapSelf (SelfPtr p) = p
-getCursorPosition :: SelfPtr -> IO (Double, Double)
-getCursorPosition self =
- alloca $ \xPtr -> alloca $ \yPtr -> do
- foreign_getCursorPosition (unwrapSelf self) xPtr yPtr
- x <- peek xPtr
- y <- peek yPtr
- return (realToFrac (x :: CDouble), realToFrac (y :: CDouble))
-
getToplevelPosition :: Ptr ForeignMontisToplevel -> IO (Double, Double)
getToplevelPosition tl =
alloca $ \xPtr -> alloca $ \yPtr -> do