[client] tests: cover Wayland motion ordering

This commit is contained in:
Geoffrey McRae
2026-08-06 12:33:15 +10:00
parent e9a16ef523
commit dbf44d9df2
5 changed files with 107 additions and 13 deletions

View File

@@ -64,11 +64,11 @@ static uint32_t proxyId(void * proxy)
static void pointerMotionHandler(void * data, struct wl_pointer * pointer, static void pointerMotionHandler(void * data, struct wl_pointer * pointer,
uint32_t time, wl_fixed_t sxW, wl_fixed_t syW) uint32_t time, wl_fixed_t sxW, wl_fixed_t syW)
{ {
wlWm.cursorX = wl_fixed_to_double(sxW); wlMotionAbs(&wlWm.motion, wl_fixed_to_double(sxW),
wlWm.cursorY = wl_fixed_to_double(syW); wl_fixed_to_double(syW));
MTRACE("abs time=%u pos=%.3f,%.3f", time, wlWm.cursorX, MTRACE("abs time=%u pos=%.3f,%.3f", time, wlWm.motion.x,
wlWm.cursorY); wlWm.motion.y);
app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
if (!wlWm.warpSupport && !wlWm.relativePointer) if (!wlWm.warpSupport && !wlWm.relativePointer)
app_handleMouseBasic(); 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); wl_pointer_set_cursor(pointer, serial, wlWm.cursor, wlWm.cursorHotX, wlWm.cursorHotY);
wlWm.pointerEnterSerial = serial; wlWm.pointerEnterSerial = serial;
wlWm.cursorX = wl_fixed_to_double(sxW); wlMotionAbs(&wlWm.motion, wl_fixed_to_double(sxW),
wlWm.cursorY = wl_fixed_to_double(syW); wl_fixed_to_double(syW));
app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
if (wlWm.warpSupport) if (wlWm.warpSupport)
{ {
@@ -248,13 +248,12 @@ static void relativePointerMotionHandler(void * data,
{ {
const double dx = wl_fixed_to_double(dxW); const double dx = wl_fixed_to_double(dxW);
const double dy = wl_fixed_to_double(dyW); const double dy = wl_fixed_to_double(dyW);
wlWm.cursorX += dx; wlMotionRel(&wlWm.motion, dx, dy);
wlWm.cursorY += dy;
MTRACE("rel time=%u:%u delta=%.3f,%.3f raw=%.3f,%.3f " MTRACE("rel time=%u:%u delta=%.3f,%.3f raw=%.3f,%.3f "
"pos=%.3f,%.3f", timeHi, timeLo, dx, dy, "pos=%.3f,%.3f", timeHi, timeLo, dx, dy,
wl_fixed_to_double(dxUnaccelW), wl_fixed_to_double(dyUnaccelW), wl_fixed_to_double(dxUnaccelW), wl_fixed_to_double(dyUnaccelW),
wlWm.cursorX, wlWm.cursorY); wlWm.motion.x, wlWm.motion.y);
app_updateCursorPos(wlWm.cursorX, wlWm.cursorY); app_updateCursorPos(wlWm.motion.x, wlWm.motion.y);
app_handleMouseRelative( app_handleMouseRelative(
dx, dx,

View File

@@ -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

View File

@@ -55,6 +55,7 @@
#include "wayland-xdg-toplevel-icon-v1-client-protocol.h" #include "wayland-xdg-toplevel-icon-v1-client-protocol.h"
#include "scale.h" #include "scale.h"
#include "motion.h"
typedef void (*WaylandPollCallback)(uint32_t events, void * opaque); typedef void (*WaylandPollCallback)(uint32_t events, void * opaque);
@@ -142,7 +143,7 @@ struct WaylandDSState
bool needsResize; bool needsResize;
bool configured; bool configured;
bool warpSupport; bool warpSupport;
double cursorX, cursorY; struct WlMotion motion;
double scrollState; double scrollState;
#if defined(ENABLE_EGL) || defined(ENABLE_OPENGL) #if defined(ENABLE_EGL) || defined(ENABLE_OPENGL)

View File

@@ -33,6 +33,19 @@ set_tests_properties(lgmp-transport-tests PROPERTIES
TIMEOUT 10 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_package(GTest REQUIRED)
find_program(WESTON_EXECUTABLE NAMES weston) find_program(WESTON_EXECUTABLE NAMES weston)
if(NOT WESTON_EXECUTABLE) if(NOT WESTON_EXECUTABLE)

View File

@@ -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;
}