mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 03:45:58 +01:00
Implement absolute motion events for wayland
This commit is contained in:
parent
0813c1dd39
commit
272030652a
3 changed files with 38 additions and 21 deletions
|
@ -102,6 +102,17 @@ bool wlr_backend_is_wl(struct wlr_backend *b) {
|
||||||
return b->impl == &backend_impl;
|
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) {
|
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
|
||||||
wlr_log(L_INFO, "Creating wayland backend");
|
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) {
|
wl_fixed_t surface_y) {
|
||||||
struct wlr_input_device *dev = data;
|
struct wlr_input_device *dev = data;
|
||||||
assert(dev && dev->pointer && dev->pointer->state);
|
assert(dev && dev->pointer && dev->pointer->state);
|
||||||
struct wlr_pointer_state *state = dev->pointer->state;
|
struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend,
|
||||||
state->surface_x = wl_fixed_to_double(surface_x);
|
surface);
|
||||||
state->surface_y = wl_fixed_to_double(surface_y);
|
|
||||||
|
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,
|
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;
|
struct wlr_input_device *dev = data;
|
||||||
assert(dev && dev->pointer && dev->pointer->state);
|
assert(dev && dev->pointer && dev->pointer->state);
|
||||||
struct wlr_pointer_state *state = dev->pointer->state;
|
struct wlr_pointer_state *state = dev->pointer->state;
|
||||||
|
assert(state->current_output);
|
||||||
|
|
||||||
double x = wl_fixed_to_double(surface_x);
|
int width, height;
|
||||||
double y = wl_fixed_to_double(surface_y);
|
wl_egl_window_get_attached_size(state->current_output->state->egl_window,
|
||||||
|
&width, &height);
|
||||||
|
|
||||||
if (x == state->surface_x && y == state->surface_y)
|
struct wlr_event_pointer_motion_absolute wlr_event;
|
||||||
return;
|
|
||||||
|
|
||||||
struct wlr_event_pointer_motion wlr_event;
|
|
||||||
wlr_event.time_sec = time / 1000;
|
wlr_event.time_sec = time / 1000;
|
||||||
wlr_event.time_usec = time * 1000;
|
wlr_event.time_usec = time * 1000;
|
||||||
wlr_event.delta_x = x - state->surface_x;
|
wlr_event.width_mm = width;
|
||||||
wlr_event.delta_y = y - state->surface_y;
|
wlr_event.height_mm = height;
|
||||||
wl_signal_emit(&dev->pointer->events.motion, &wlr_event);
|
wlr_event.x_mm = wl_fixed_to_double(surface_x);
|
||||||
|
wlr_event.y_mm = wl_fixed_to_double(surface_y);
|
||||||
state->surface_x = x;
|
wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
|
||||||
state->surface_y = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
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.orientation = axis;
|
||||||
wlr_event.time_sec = time / 1000;
|
wlr_event.time_sec = time / 1000;
|
||||||
wlr_event.time_usec = 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);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: any way to retrieve those information?
|
devstate->backend = state;
|
||||||
|
|
||||||
int vendor = 0;
|
int vendor = 0;
|
||||||
int product = 0;
|
int product = 0;
|
||||||
const char *name = "wayland";
|
const char *name = "wayland";
|
||||||
|
|
|
@ -39,16 +39,17 @@ struct wlr_output_state {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_input_device_state {
|
struct wlr_input_device_state {
|
||||||
enum wlr_input_device_type type;
|
struct wlr_backend_state* backend;
|
||||||
void *resource;
|
void *resource;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_pointer_state {
|
struct wlr_pointer_state {
|
||||||
double surface_x;
|
struct wlr_output *current_output;
|
||||||
double surface_y;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_wl_registry_poll(struct wlr_backend_state *backend);
|
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;
|
extern const struct wl_seat_listener seat_listener;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue