Check for discrete mouse events on wayland

This commit is contained in:
Rui Ming (Max) Xiong 2022-02-12 02:12:59 -05:00
parent 263d121f3e
commit 40bf12af7a

71
glfw/wl_init.c vendored
View File

@ -317,6 +317,11 @@ static void pointerHandleButton(void* data UNUSED,
#undef x #undef x
#undef y #undef y
// flags for ignoring axis events following axis_discrete events in the
// same frame along the same axis
static bool ignoreNextX = false;
static bool ignoreNextY = false;
static void pointerHandleAxis(void* data UNUSED, static void pointerHandleAxis(void* data UNUSED,
struct wl_pointer* pointer UNUSED, struct wl_pointer* pointer UNUSED,
uint32_t time UNUSED, uint32_t time UNUSED,
@ -331,20 +336,80 @@ static void pointerHandleAxis(void* data UNUSED,
assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL || assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL ||
axis == WL_POINTER_AXIS_VERTICAL_SCROLL); axis == WL_POINTER_AXIS_VERTICAL_SCROLL);
if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if (ignoreNextX) {
ignoreNextX = false;
return;
}
x = -wl_fixed_to_double(value); x = -wl_fixed_to_double(value);
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) }
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
if (ignoreNextY) {
ignoreNextY = false;
return;
}
y = -wl_fixed_to_double(value); y = -wl_fixed_to_double(value);
}
_glfwInputScroll(window, x, y, 1, _glfw.wl.xkb.states.modifiers); _glfwInputScroll(window, x, y, 1, _glfw.wl.xkb.states.modifiers);
} }
static void pointerHandleFrame(void* data UNUSED,
struct wl_pointer* pointer UNUSED)
{
ignoreNextX = false;
ignoreNextY = false;
}
static void pointerHandleAxisSource(void* data UNUSED,
struct wl_pointer* pointer UNUSED,
uint32_t source UNUSED)
{
}
static void pointerHandleAxisStop(void *data UNUSED,
struct wl_pointer *wl_pointer UNUSED,
uint32_t time UNUSED,
uint32_t axis UNUSED)
{
}
static void pointerHandleAxisDiscrete(void *data UNUSED,
struct wl_pointer *wl_pointer UNUSED,
uint32_t axis UNUSED,
int32_t discrete UNUSED)
{
_GLFWwindow* window = _glfw.wl.pointerFocus;
double x = 0.0, y = 0.0;
if (!window)
return;
assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL ||
axis == WL_POINTER_AXIS_VERTICAL_SCROLL);
if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
x = -discrete;
ignoreNextX = true;
}
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
y = -discrete;
ignoreNextY = true;
}
_glfwInputScroll(window, x, y, 0, _glfw.wl.xkb.states.modifiers);
}
static const struct wl_pointer_listener pointerListener = { static const struct wl_pointer_listener pointerListener = {
pointerHandleEnter, pointerHandleEnter,
pointerHandleLeave, pointerHandleLeave,
pointerHandleMotion, pointerHandleMotion,
pointerHandleButton, pointerHandleButton,
pointerHandleAxis, pointerHandleAxis,
pointerHandleFrame,
pointerHandleAxisSource,
pointerHandleAxisStop,
pointerHandleAxisDiscrete,
}; };
static void keyboardHandleKeymap(void* data UNUSED, static void keyboardHandleKeymap(void* data UNUSED,
@ -571,7 +636,7 @@ static void registryHandleGlobal(void* data UNUSED,
{ {
if (!_glfw.wl.seat) if (!_glfw.wl.seat)
{ {
_glfw.wl.seatVersion = min(4, version); _glfw.wl.seatVersion = min(5, version);
_glfw.wl.seat = _glfw.wl.seat =
wl_registry_bind(registry, name, &wl_seat_interface, wl_registry_bind(registry, name, &wl_seat_interface,
_glfw.wl.seatVersion); _glfw.wl.seatVersion);