diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2026-01-04 21:41:39 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2026-01-04 21:41:39 -0700 |
| commit | 9637f06dd40418bd01cde0fe9f33d4fe979555ab (patch) | |
| tree | c41c136ed52aee4a4b74818531b05c55b938deb8 | |
| parent | 5e86dbfa1bb30c8b1f36582e1a5229a208c5bff4 (diff) | |
| download | montis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.tar.gz montis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.tar.bz2 montis-9637f06dd40418bd01cde0fe9f33d4fe979555ab.zip | |
[refactor] Change dragging behavior to use the motion event.
| -rw-r--r-- | plug/src/Config.hs | 24 | ||||
| -rw-r--r-- | plug/src/Montis/Base/Foreign/Runtime.hs | 3 | ||||
| -rw-r--r-- | plug/src/Montis/Core/Events.hs | 3 | ||||
| -rw-r--r-- | plug/src/Montis/Core/Internal/Foreign/Export.hs | 15 | ||||
| -rw-r--r-- | rt/include/plugin.h | 2 | ||||
| -rw-r--r-- | rt/include/util.h | 1 | ||||
| -rw-r--r-- | rt/src/util.c | 14 | ||||
| -rw-r--r-- | rt/src/wl.c | 5 |
8 files changed, 25 insertions, 42 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 diff --git a/plug/src/Montis/Base/Foreign/Runtime.hs b/plug/src/Montis/Base/Foreign/Runtime.hs index 5c131f3..5797aa5 100644 --- a/plug/src/Montis/Base/Foreign/Runtime.hs +++ b/plug/src/Montis/Base/Foreign/Runtime.hs @@ -14,9 +14,6 @@ foreign import ccall "montis_do_request_exit" foreign_doRequestExit :: Ptr Void foreign import ccall "montis_plugin_get_seat" foreign_getSeat :: Ptr Void -> IO (Ptr Void) -foreign import ccall "montis_plugin_get_cursor_position" - foreign_getCursorPosition :: Ptr Void -> Ptr CDouble -> Ptr CDouble -> IO () - foreign import ccall "montis_plugin_toplevel_at" foreign_toplevelAt :: Ptr Void -> CDouble -> CDouble -> IO (Ptr ForeignMontisToplevel) diff --git a/plug/src/Montis/Core/Events.hs b/plug/src/Montis/Core/Events.hs index cb74d6f..91b8618 100644 --- a/plug/src/Montis/Core/Events.hs +++ b/plug/src/Montis/Core/Events.hs @@ -31,7 +31,8 @@ data MotionEvent = MotionEvent { motionEvent_pointer :: WlrPointer, motionEvent_timeMs :: Word32, motionEvent_modifiers :: Word32, - motionEvent_absolute :: (Double, Double) + motionEvent_absolute :: (Double, Double), + motionEvent_raw :: (Double, Double) } deriving (Eq, Show, Ord) diff --git a/plug/src/Montis/Core/Internal/Foreign/Export.hs b/plug/src/Montis/Core/Internal/Foreign/Export.hs index 99ba58b..132273a 100644 --- a/plug/src/Montis/Core/Internal/Foreign/Export.hs +++ b/plug/src/Montis/Core/Internal/Foreign/Export.hs @@ -17,7 +17,7 @@ import Foreign mallocBytes, newStablePtr, ) -import Foreign.C (CChar, CInt (..)) +import Foreign.C (CChar, CDouble(..), CInt (..)) import Foreign.Ptr (castPtr) import Montis.Base.Foreign.WlRoots.Types ( ForeignSurface (toSurface), @@ -156,10 +156,10 @@ pluginHandleKeybinding inputDevicePtr eventPtr mods sym cp = -- Motion handler foreign export ccall "plugin_handle_motion" - pluginHandleMotion :: Ptr WlrPointerMotionAbsoluteEvent -> Word32 -> OpqStT -> IO OpqStT + pluginHandleMotion :: Ptr WlrPointerMotionAbsoluteEvent -> Word32 -> CDouble -> CDouble -> OpqStT -> IO OpqStT -pluginHandleMotion :: Ptr WlrPointerMotionAbsoluteEvent -> Word32 -> OpqStT -> IO OpqStT -pluginHandleMotion eventPtr modifiers = +pluginHandleMotion :: Ptr WlrPointerMotionAbsoluteEvent -> Word32 -> CDouble -> CDouble -> OpqStT -> IO OpqStT +pluginHandleMotion eventPtr modifiers lx ly = runForeign $ do s <- gets currentHooks event <- liftIO $ @@ -168,14 +168,15 @@ pluginHandleMotion eventPtr modifiers = pointerPtr <- demarshal :: Demarshal (Ptr ForeignWlrPointer) tMs <- demarshal _ <- demarshal :: Demarshal Word32 - x <- demarshal - y <- demarshal + rawX <- demarshal + rawY <- demarshal return $ MotionEvent (WlrPointer pointerPtr) tMs modifiers - (x, y) + (realToFrac lx, realToFrac ly) + (rawX, rawY) motionHook s event diff --git a/rt/include/plugin.h b/rt/include/plugin.h index 4146b37..d7ae18b 100644 --- a/rt/include/plugin.h +++ b/rt/include/plugin.h @@ -146,7 +146,7 @@ typedef struct PLUGIN { /* Absolute motion only for now; relative motion stays in the runtime. */ EXPORT(opqst_t (*plugin_handle_motion)( struct wlr_pointer_motion_absolute_event *event, uint32_t modifiers, - opqst_t state)); + double lx, double ly, opqst_t state)); /* * Handles a surface being mapped, unmapped or destroyed. diff --git a/rt/include/util.h b/rt/include/util.h index f7de541..b477113 100644 --- a/rt/include/util.h +++ b/rt/include/util.h @@ -6,7 +6,6 @@ * are intended for direct FFI use from the Haskell plugin. */ -void montis_plugin_get_cursor_position(void *ctx, double *x, double *y); void *montis_plugin_toplevel_at(void *ctx, double lx, double ly); void montis_plugin_get_toplevel_position(void *toplevel, double *x, double *y); void montis_plugin_set_toplevel_position(void *toplevel, double x, double y); diff --git a/rt/src/util.c b/rt/src/util.c index d02c07c..6576770 100644 --- a/rt/src/util.c +++ b/rt/src/util.c @@ -12,7 +12,6 @@ static struct montis_server *server_from_ctx(void *ctx) static struct montis_toplevel *toplevel_at(struct montis_server *server, double lx, double ly) { - struct wlr_surface *surface = NULL; double sx = 0.0; double sy = 0.0; @@ -28,9 +27,6 @@ static struct montis_toplevel *toplevel_at(struct montis_server *server, return NULL; } - surface = scene_surface->surface; - (void)surface; - struct wlr_scene_tree *tree = node->parent; while (tree != NULL && tree->node.data == NULL) { tree = tree->node.parent; @@ -38,16 +34,6 @@ static struct montis_toplevel *toplevel_at(struct montis_server *server, return tree ? tree->node.data : NULL; } -void montis_plugin_get_cursor_position(void *ctx, double *x, double *y) -{ - if (!ctx || !x || !y) { - return; - } - struct montis_server *server = server_from_ctx(ctx); - *x = server->cursor->x; - *y = server->cursor->y; -} - void *montis_plugin_toplevel_at(void *ctx, double lx, double ly) { if (!ctx) { diff --git a/rt/src/wl.c b/rt/src/wl.c index af348f3..f528c22 100644 --- a/rt/src/wl.c +++ b/rt/src/wl.c @@ -452,16 +452,15 @@ static void server_cursor_motion_absolute(struct wl_listener *listener, wl_container_of(listener, server, cursor_motion_absolute); struct wlr_pointer_motion_absolute_event *event = data; - printf("[CQD] - %lf %lf\n", event->x, event->y); struct wlr_seat *seat = server->seat; struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); uint32_t modifiers = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; - plugin_call_update_state(server->plugin, plugin_handle_motion, event, - modifiers); wlr_cursor_warp_absolute(server->cursor, &event->pointer->base, event->x, event->y); process_cursor_motion(server, event->time_msec); + plugin_call_update_state(server->plugin, plugin_handle_motion, event, + modifiers, server->cursor->x, server->cursor->y); } static void server_cursor_button(struct wl_listener *listener, void *data) |