Fix scrolling on Wayland, apparently you cannot use Linux kernel keycodes

This commit is contained in:
speedie 2023-07-22 03:25:35 +02:00
parent ea48ea69ed
commit 5129856857
2 changed files with 23 additions and 6 deletions

View file

@ -208,7 +208,6 @@ void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, uint32_t forma
}
void buttonpress_wl(uint32_t button, double ex, double ey) {
struct item *item;
int x = 0;
int y = 0;
int w;
@ -217,6 +216,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
int item_num = 0;
int yp = 0;
unsigned int i, click;
struct item *item;
if (ex == 0 && ey == 0) {
return; // While it is possible to click at this position, usually it means we're outside the window area.
@ -346,6 +346,21 @@ void pointer_motion_handler(void *data, struct wl_pointer *pointer, uint32_t tim
mouse_y = wl_fixed_to_int(y);
}
void pointer_axis_handler(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) {
mouse_scroll = 1;
if (value > 0) {
mouse_scroll_direction = 0;
} else {
mouse_scroll_direction = 1;
}
buttonpress_wl(mouse_scroll_direction, mouse_x, mouse_y);
mouse_scroll = 0;
mouse_scroll_direction = -1;
}
void pointer_button_handler(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state) {
if (state != WL_POINTER_BUTTON_STATE_PRESSED) {
return; // We don't want a release event to count as a click, only the initial press.

View file

@ -65,8 +65,8 @@ static WlMouse wl_cbuttons[256];
#define WL_Forward 0x115
#define WL_Back 0x116
#define WL_Task 0x117
#define WL_Up 0x151
#define WL_Down 0x150
#define WL_Up 1
#define WL_Down 0
static WlKey wlhkeys[1] = { { -1, WL_CtrlAlt, XKB_KEY_Delete, quit, {0} } };
@ -111,9 +111,10 @@ static int output_physical_width = 0;
static int output_physical_height = 0;
static int output_width = 0;
static int output_height = 0;
static int mouse_x = 0;
static int mouse_y = 0;
static int mouse_scroll = 0;
static int mouse_scroll_direction = 0;
static void zero();
static void resizeclient_wl(struct state *state);
@ -134,6 +135,7 @@ static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, in
static void keypress_wl(struct state *state, enum wl_keyboard_key_state key_state, xkb_keysym_t sym);
static void pointer_button_handler(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
static void pointer_motion_handler(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y);
static void pointer_axis_handler(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value);
static void buttonpress_wl(uint32_t button, double ex, double ey);
static int is_correct_modifier(struct state *state, char *modifier);
static int roundtrip(struct state *state);
@ -188,7 +190,7 @@ static const struct wl_pointer_listener pointer_listener = {
.leave = zero,
.motion = pointer_motion_handler,
.button = pointer_button_handler,
.axis = zero,
.axis = pointer_axis_handler,
};
struct wl_output_listener output_listener = {