mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 08:32:30 +00:00
Implement absolute motion events for wayland
This commit is contained in:
parent
0813c1dd39
commit
272030652a
@ -63,7 +63,7 @@ static bool wlr_wl_backend_init(struct wlr_backend_state* state) {
|
||||
state->remote_display_src = wl_event_loop_add_fd(loop, fd, events,
|
||||
dispatch_events, state);
|
||||
wl_event_source_check(state->remote_display_src);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -102,6 +102,17 @@ bool wlr_backend_is_wl(struct wlr_backend *b) {
|
||||
return b->impl == &backend_impl;
|
||||
}
|
||||
|
||||
struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend,
|
||||
struct wl_surface *surface) {
|
||||
for (size_t i = 0; i < backend->outputs->length; ++i) {
|
||||
struct wlr_output *output = backend->outputs->items[i];
|
||||
if(output->state->surface == surface)
|
||||
return output;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
|
||||
wlr_log(L_INFO, "Creating wayland backend");
|
||||
|
||||
|
@ -17,9 +17,15 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
|
||||
wl_fixed_t surface_y) {
|
||||
struct wlr_input_device *dev = data;
|
||||
assert(dev && dev->pointer && dev->pointer->state);
|
||||
struct wlr_pointer_state *state = dev->pointer->state;
|
||||
state->surface_x = wl_fixed_to_double(surface_x);
|
||||
state->surface_y = wl_fixed_to_double(surface_y);
|
||||
struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend,
|
||||
surface);
|
||||
|
||||
if (!output) {
|
||||
wlr_log(L_ERROR, "pointer entered invalid surface");
|
||||
return;
|
||||
}
|
||||
|
||||
dev->pointer->state->current_output = output;
|
||||
}
|
||||
|
||||
static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer,
|
||||
@ -32,22 +38,20 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
|
||||
struct wlr_input_device *dev = data;
|
||||
assert(dev && dev->pointer && dev->pointer->state);
|
||||
struct wlr_pointer_state *state = dev->pointer->state;
|
||||
assert(state->current_output);
|
||||
|
||||
double x = wl_fixed_to_double(surface_x);
|
||||
double y = wl_fixed_to_double(surface_y);
|
||||
int width, height;
|
||||
wl_egl_window_get_attached_size(state->current_output->state->egl_window,
|
||||
&width, &height);
|
||||
|
||||
if (x == state->surface_x && y == state->surface_y)
|
||||
return;
|
||||
|
||||
struct wlr_event_pointer_motion wlr_event;
|
||||
struct wlr_event_pointer_motion_absolute wlr_event;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
wlr_event.time_usec = time * 1000;
|
||||
wlr_event.delta_x = x - state->surface_x;
|
||||
wlr_event.delta_y = y - state->surface_y;
|
||||
wl_signal_emit(&dev->pointer->events.motion, &wlr_event);
|
||||
|
||||
state->surface_x = x;
|
||||
state->surface_y = y;
|
||||
wlr_event.width_mm = width;
|
||||
wlr_event.height_mm = height;
|
||||
wlr_event.x_mm = wl_fixed_to_double(surface_x);
|
||||
wlr_event.y_mm = wl_fixed_to_double(surface_y);
|
||||
wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
|
||||
}
|
||||
|
||||
static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
||||
@ -73,7 +77,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
|
||||
wlr_event.orientation = axis;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
wlr_event.time_usec = time * 1000;
|
||||
wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS; // TODO
|
||||
wlr_event.source = WLR_AXIS_SOURCE_CONTINUOUS;
|
||||
wl_signal_emit(&dev->pointer->events.axis, &wlr_event);
|
||||
}
|
||||
|
||||
@ -182,7 +186,8 @@ static struct wlr_input_device *allocate_device(struct wlr_backend_state *state,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: any way to retrieve those information?
|
||||
devstate->backend = state;
|
||||
|
||||
int vendor = 0;
|
||||
int product = 0;
|
||||
const char *name = "wayland";
|
||||
|
@ -39,16 +39,17 @@ struct wlr_output_state {
|
||||
};
|
||||
|
||||
struct wlr_input_device_state {
|
||||
enum wlr_input_device_type type;
|
||||
struct wlr_backend_state* backend;
|
||||
void *resource;
|
||||
};
|
||||
|
||||
struct wlr_pointer_state {
|
||||
double surface_x;
|
||||
double surface_y;
|
||||
struct wlr_output *current_output;
|
||||
};
|
||||
|
||||
void wlr_wl_registry_poll(struct wlr_backend_state *backend);
|
||||
struct wlr_output *wlr_wl_output_for_surface(struct wlr_backend_state *backend,
|
||||
struct wl_surface *surface);
|
||||
|
||||
extern const struct wl_seat_listener seat_listener;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user