diff --git a/client/displayservers/Wayland/input.c b/client/displayservers/Wayland/input.c index 2d3248ac..a8dc91f2 100644 --- a/client/displayservers/Wayland/input.c +++ b/client/displayservers/Wayland/input.c @@ -64,11 +64,11 @@ static uint32_t proxyId(void * proxy) static void pointerMotionHandler(void * data, struct wl_pointer * pointer, uint32_t time, wl_fixed_t sxW, wl_fixed_t syW) { - wlWm.cursorX = wl_fixed_to_double(sxW); - wlWm.cursorY = wl_fixed_to_double(syW); - MTRACE("abs time=%u pos=%.3f,%.3f", time, wlWm.cursorX, - wlWm.cursorY); - app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); + wlMotionAbs(&wlWm.motion, wl_fixed_to_double(sxW), + wl_fixed_to_double(syW)); + MTRACE("abs time=%u pos=%.3f,%.3f", time, wlWm.motion.x, + wlWm.motion.y); + app_updateCursorPos(wlWm.motion.x, wlWm.motion.y); if (!wlWm.warpSupport && !wlWm.relativePointer) app_handleMouseBasic(); @@ -91,9 +91,9 @@ static void pointerEnterHandler(void * data, struct wl_pointer * pointer, wl_pointer_set_cursor(pointer, serial, wlWm.cursor, wlWm.cursorHotX, wlWm.cursorHotY); wlWm.pointerEnterSerial = serial; - wlWm.cursorX = wl_fixed_to_double(sxW); - wlWm.cursorY = wl_fixed_to_double(syW); - app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); + wlMotionAbs(&wlWm.motion, wl_fixed_to_double(sxW), + wl_fixed_to_double(syW)); + app_updateCursorPos(wlWm.motion.x, wlWm.motion.y); if (wlWm.warpSupport) { @@ -248,13 +248,12 @@ static void relativePointerMotionHandler(void * data, { const double dx = wl_fixed_to_double(dxW); const double dy = wl_fixed_to_double(dyW); - wlWm.cursorX += dx; - wlWm.cursorY += dy; + wlMotionRel(&wlWm.motion, dx, dy); MTRACE("rel time=%u:%u delta=%.3f,%.3f raw=%.3f,%.3f " "pos=%.3f,%.3f", timeHi, timeLo, dx, dy, wl_fixed_to_double(dxUnaccelW), wl_fixed_to_double(dyUnaccelW), - wlWm.cursorX, wlWm.cursorY); - app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); + wlWm.motion.x, wlWm.motion.y); + app_updateCursorPos(wlWm.motion.x, wlWm.motion.y); app_handleMouseRelative( dx, diff --git a/client/displayservers/Wayland/motion.h b/client/displayservers/Wayland/motion.h new file mode 100644 index 00000000..11478a29 --- /dev/null +++ b/client/displayservers/Wayland/motion.h @@ -0,0 +1,42 @@ +/** + * Looking Glass + * Copyright © 2017-2026 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef LG_WAYLAND_MOTION_H +#define LG_WAYLAND_MOTION_H + +struct WlMotion +{ + double x; + double y; +}; + +static inline void wlMotionAbs(struct WlMotion * pos, double x, double y) +{ + pos->x = x; + pos->y = y; +} + +static inline void wlMotionRel(struct WlMotion * pos, double x, double y) +{ + pos->x += x; + pos->y += y; +} + +#endif diff --git a/client/displayservers/Wayland/wayland.h b/client/displayservers/Wayland/wayland.h index 6b52ceb9..35fae875 100644 --- a/client/displayservers/Wayland/wayland.h +++ b/client/displayservers/Wayland/wayland.h @@ -55,6 +55,7 @@ #include "wayland-xdg-toplevel-icon-v1-client-protocol.h" #include "scale.h" +#include "motion.h" typedef void (*WaylandPollCallback)(uint32_t events, void * opaque); @@ -142,7 +143,7 @@ struct WaylandDSState bool needsResize; bool configured; bool warpSupport; - double cursorX, cursorY; + struct WlMotion motion; double scrollState; #if defined(ENABLE_EGL) || defined(ENABLE_OPENGL) diff --git a/client/tests/CMakeLists.txt b/client/tests/CMakeLists.txt index e80c9be4..0978037f 100644 --- a/client/tests/CMakeLists.txt +++ b/client/tests/CMakeLists.txt @@ -33,6 +33,19 @@ set_tests_properties(lgmp-transport-tests PROPERTIES TIMEOUT 10 ) +add_executable(wayland-motion-tests + motion_test.c +) +target_include_directories(wayland-motion-tests PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/../displayservers/Wayland" +) +add_test(NAME wayland-motion-tests + COMMAND wayland-motion-tests +) +set_tests_properties(wayland-motion-tests PROPERTIES + TIMEOUT 10 +) + find_package(GTest REQUIRED) find_program(WESTON_EXECUTABLE NAMES weston) if(NOT WESTON_EXECUTABLE) diff --git a/client/tests/motion_test.c b/client/tests/motion_test.c new file mode 100644 index 00000000..bc308af5 --- /dev/null +++ b/client/tests/motion_test.c @@ -0,0 +1,39 @@ +/** + * Looking Glass + * Copyright © 2017-2026 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "motion.h" +#include "test.h" + +int main(void) +{ + struct WlMotion absFirst = { 0 }; + struct WlMotion relFirst = { 0 }; + + wlMotionAbs(&absFirst, 100, 50); + wlMotionRel(&absFirst, 5, -2); + wlMotionRel(&relFirst, 5, -2); + wlMotionAbs(&relFirst, 100, 50); + + CHECK(absFirst.x == 105); + CHECK(absFirst.y == 48); + CHECK(relFirst.x == 100); + CHECK(relFirst.y == 50); + return 0; +}