diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 1801f3e06..39ecc10f7 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,38 @@ struct wlr_wl_backend_output *wlr_wl_output_for_surface( return NULL; } +void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend, + struct wlr_box *box) { + int min_x = INT_MAX, min_y = INT_MAX; + int max_x = INT_MIN, max_y = INT_MIN; + + struct wlr_wl_backend_output *output; + wl_list_for_each(output, &backend->outputs, link) { + struct wlr_output *wlr_output = &output->wlr_output; + + int width, height; + wlr_output_effective_resolution(wlr_output, &width, &height); + + if (wlr_output->lx < min_x) { + min_x = wlr_output->lx; + } + if (wlr_output->ly < min_y) { + min_y = wlr_output->ly; + } + if (wlr_output->lx + width > max_x) { + max_x = wlr_output->lx + width; + } + if (wlr_output->ly + height > max_y) { + max_y = wlr_output->ly + height; + } + } + + box->x = min_x; + box->y = min_y; + box->width = max_x - min_x; + box->height = max_y - min_y; +} + struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) { wlr_log(L_INFO, "Creating wayland backend"); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 3c20e6caa..7bfbf3026 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -52,23 +52,28 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, return; } + struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output; + struct wlr_box box; wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window, &box.width, &box.height); box.x = wl_fixed_to_int(surface_x); box.y = wl_fixed_to_int(surface_y); struct wlr_box transformed; - wlr_output_transform_apply_to_box( - wlr_wl_pointer->current_output->wlr_output.transform, &box, - &transformed); + wlr_output_transform_apply_to_box(wlr_output->transform, &box, &transformed); + box.x /= wlr_output->scale; + box.y /= wlr_output->scale; + + struct wlr_box layout_box; + wlr_wl_output_layout_get_box(wlr_wl_pointer->current_output->backend, &layout_box); struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.device = dev; wlr_event.time_msec = time; - wlr_event.width_mm = transformed.width; - wlr_event.height_mm = transformed.height; - wlr_event.x_mm = transformed.x; - wlr_event.y_mm = transformed.y; + wlr_event.width_mm = layout_box.width; + wlr_event.height_mm = layout_box.height; + wlr_event.x_mm = transformed.x + wlr_output->lx + layout_box.x; + wlr_event.y_mm = transformed.y + wlr_output->ly + layout_box.y; wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); } diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 1e8a55d2f..7e2ec0d6b 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,8 @@ void wlr_wl_registry_poll(struct wlr_wl_backend *backend); void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output); struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend *backend, struct wl_surface *surface); +void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend, + struct wlr_box *box); extern const struct wl_seat_listener seat_listener;