Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seperate discrete (mouse wheel) and continuous (touchpad) scroll events on wayland #4699

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions glfw/wl_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ static void pointerHandleButton(void* data UNUSED,
#undef x
#undef y

// counters for ignoring axis events following axis_discrete events in the
// same frame along the same axis
static unsigned int discreteXCount = 0;
static unsigned int discreteYCount = 0;

static void pointerHandleAxis(void* data UNUSED,
struct wl_pointer* pointer UNUSED,
uint32_t time UNUSED,
Expand All @@ -331,20 +336,80 @@ static void pointerHandleAxis(void* data UNUSED,
assert(axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL ||
axis == WL_POINTER_AXIS_VERTICAL_SCROLL);

if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL)
if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
if (discreteXCount) {
--discreteXCount;
return;
}
x = -wl_fixed_to_double(value);
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
}
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
if (discreteYCount) {
--discreteYCount;
return;
}
y = -wl_fixed_to_double(value);
}

_glfwInputScroll(window, x, y, 1, _glfw.wl.xkb.states.modifiers);
}

static void pointerHandleFrame(void* data UNUSED,
struct wl_pointer* pointer UNUSED)
{
discreteXCount = 0;
discreteYCount = 0;
}

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;
++discreteXCount;
}
else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
y = -discrete;
++discreteYCount;
}

_glfwInputScroll(window, x, y, 0, _glfw.wl.xkb.states.modifiers);
}

static const struct wl_pointer_listener pointerListener = {
pointerHandleEnter,
pointerHandleLeave,
pointerHandleMotion,
pointerHandleButton,
pointerHandleAxis,
pointerHandleFrame,
pointerHandleAxisSource,
pointerHandleAxisStop,
pointerHandleAxisDiscrete,
};

static void keyboardHandleKeymap(void* data UNUSED,
Expand Down Expand Up @@ -571,7 +636,7 @@ static void registryHandleGlobal(void* data UNUSED,
{
if (!_glfw.wl.seat)
{
_glfw.wl.seatVersion = min(4, version);
_glfw.wl.seatVersion = min(5, version);
_glfw.wl.seat =
wl_registry_bind(registry, name, &wl_seat_interface,
_glfw.wl.seatVersion);
Expand Down