Add discrete pointer scroll

qemu-extended-key-event
Andri Yngvason 2020-07-19 20:39:18 +00:00
parent e7a1460cb8
commit e55a845920
3 changed files with 56 additions and 3 deletions

View File

@ -30,6 +30,10 @@ enum pointer_button_mask {
POINTER_BUTTON_MIDDLE = 1 << 1, POINTER_BUTTON_MIDDLE = 1 << 1,
POINTER_BUTTON_RIGHT = 1 << 2, POINTER_BUTTON_RIGHT = 1 << 2,
// TODO: More buttons // TODO: More buttons
POINTER_SCROLL_UP = 1 << 3,
POINTER_SCROLL_DOWN = 1 << 4,
POINTER_SCROLL_LEFT = 1 << 5,
POINTER_SCROLL_RIGHT = 1 << 6,
}; };
struct pointer { struct pointer {
@ -40,6 +44,9 @@ struct pointer {
enum pointer_button_mask pressed; enum pointer_button_mask pressed;
wl_fixed_t x, y; wl_fixed_t x, y;
int vertical_scroll_steps;
int horizontal_scroll_steps;
struct wl_cursor_theme* cursor_theme; struct wl_cursor_theme* cursor_theme;
struct wl_surface* cursor_surface; struct wl_surface* cursor_surface;

View File

@ -365,7 +365,39 @@ void on_pointer_event(struct pointer_collection* collection,
int x = wl_fixed_to_int(pointer->x); int x = wl_fixed_to_int(pointer->x);
int y = wl_fixed_to_int(pointer->y); int y = wl_fixed_to_int(pointer->y);
vnc_client_send_pointer_event(client, x, y, pointer->pressed); enum pointer_button_mask pressed = pointer->pressed;
int vertical_steps = pointer->vertical_scroll_steps;
int horizontal_steps = pointer->horizontal_scroll_steps;
if (!vertical_steps && !horizontal_steps) {
vnc_client_send_pointer_event(client, x, y, pressed);
return;
}
enum pointer_button_mask scroll_mask = 0;
if (vertical_steps < 0) {
vertical_steps *= -1;
scroll_mask |= POINTER_SCROLL_UP;
} else {
scroll_mask |= POINTER_SCROLL_DOWN;
}
if (horizontal_steps < 0) {
horizontal_steps *= -1;
scroll_mask |= POINTER_SCROLL_LEFT;
} else {
scroll_mask |= POINTER_SCROLL_RIGHT;
}
while (horizontal_steps > 0 || vertical_steps > 0) {
vnc_client_send_pointer_event(client, x, y, pressed | scroll_mask);
vnc_client_send_pointer_event(client, x, y, pressed);
if (--vertical_steps <= 0)
scroll_mask &= ~(POINTER_SCROLL_UP | POINTER_SCROLL_DOWN);
if (--horizontal_steps <= 0)
scroll_mask &= ~(POINTER_SCROLL_LEFT | POINTER_SCROLL_RIGHT);
}
} }
void on_keyboard_event(struct keyboard_collection* collection, void on_keyboard_event(struct keyboard_collection* collection,

View File

@ -221,7 +221,6 @@ static void pointer_button(void* data, struct wl_pointer* wl_pointer,
case BTN_MIDDLE: case BTN_MIDDLE:
pointer_set_button_state(pointer, POINTER_BUTTON_MIDDLE, state); pointer_set_button_state(pointer, POINTER_BUTTON_MIDDLE, state);
break; break;
// TODO: More buttons // TODO: More buttons
} }
} }
@ -247,7 +246,19 @@ static void pointer_axis_stop(void* data, struct wl_pointer* wl_pointer,
static void pointer_axis_discrete(void* data, struct wl_pointer* wl_pointer, static void pointer_axis_discrete(void* data, struct wl_pointer* wl_pointer,
enum wl_pointer_axis axis, int steps) enum wl_pointer_axis axis, int steps)
{ {
// TODO struct pointer_collection* self = data;
struct pointer* pointer =
pointer_collection_find_wl_pointer(self, wl_pointer);
switch (axis) {
case WL_POINTER_AXIS_VERTICAL_SCROLL:
pointer->vertical_scroll_steps += steps;
break;
case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
pointer->horizontal_scroll_steps += steps;
break;
default:;
}
} }
static void pointer_frame(void* data, struct wl_pointer* wl_pointer) static void pointer_frame(void* data, struct wl_pointer* wl_pointer)
@ -257,6 +268,9 @@ static void pointer_frame(void* data, struct wl_pointer* wl_pointer)
pointer_collection_find_wl_pointer(self, wl_pointer); pointer_collection_find_wl_pointer(self, wl_pointer);
self->on_frame(self, pointer); self->on_frame(self, pointer);
pointer->vertical_scroll_steps = 0;
pointer->horizontal_scroll_steps = 0;
} }
static struct wl_pointer_listener pointer_listener = { static struct wl_pointer_listener pointer_listener = {