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

wl: Specify button modifier in listeners #689

Merged
merged 1 commit into from
Aug 26, 2024
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
40 changes: 31 additions & 9 deletions platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <glib-object.h>
#include <glib.h>
#include <linux/input-event-codes.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -283,6 +284,27 @@ pointer_on_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct
seat->pointer.surface = NULL;
}

static uint32_t
button_modifier(CogWlSeat *seat)
{
if (!seat->pointer.state) {
return 0;
}

switch (seat->pointer.button) {
case BTN_LEFT:
return wpe_input_pointer_modifier_button1;

case BTN_RIGHT:
return wpe_input_pointer_modifier_button2;

case BTN_MIDDLE:
return wpe_input_pointer_modifier_button3;
}

return 0;
}

static void
pointer_on_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y)
{
Expand All @@ -302,7 +324,8 @@ pointer_on_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixe
seat->pointer.x * display->current_output->scale,
seat->pointer.y * display->current_output->scale,
seat->pointer.button,
seat->pointer.state};
seat->pointer.state,
button_modifier(seat)};

g_assert(seat->pointer_target);
CogWlViewport *viewport = COG_WL_VIEWPORT(seat->pointer_target);
Expand Down Expand Up @@ -342,14 +365,13 @@ pointer_on_button(void *data,
seat->pointer.button = !!state ? button : 0;
seat->pointer.state = state;

struct wpe_input_pointer_event event = {
wpe_input_pointer_event_type_button,
time,
seat->pointer.x * display->current_output->scale,
seat->pointer.y * display->current_output->scale,
seat->pointer.button,
seat->pointer.state,
};
struct wpe_input_pointer_event event = {wpe_input_pointer_event_type_button,
time,
seat->pointer.x * display->current_output->scale,
seat->pointer.y * display->current_output->scale,
seat->pointer.button,
seat->pointer.state,
button_modifier(seat)};

CogWlPopup *popup = platform->popup;
if (popup && popup->wl_surface) {
Expand Down