cage: add relative-pointer-unstable-v1 support

This commit is contained in:
Jonathan GUILLOT 2023-11-09 17:14:37 +01:00 committed by Simon Ser
parent efbf7c035b
commit 2ab480910e
4 changed files with 36 additions and 12 deletions

8
cage.c
View file

@ -30,6 +30,7 @@
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h> #include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_presentation_time.h> #include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h> #include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_server_decoration.h>
@ -517,6 +518,13 @@ main(int argc, char *argv[])
} }
wl_signal_add(&virtual_pointer->events.new_virtual_pointer, &server.new_virtual_pointer); wl_signal_add(&virtual_pointer->events.new_virtual_pointer, &server.new_virtual_pointer);
server.relative_pointer_manager = wlr_relative_pointer_manager_v1_create(server.wl_display);
if (!server.relative_pointer_manager) {
wlr_log(WLR_ERROR, "Unable to create the relative pointer manager");
ret = 1;
goto end;
}
#if CAGE_HAS_XWAYLAND #if CAGE_HAS_XWAYLAND
xwayland = wlr_xwayland_create(server.wl_display, compositor, true); xwayland = wlr_xwayland_create(server.wl_display, compositor, true);
if (!xwayland) { if (!xwayland) {

35
seat.c
View file

@ -22,6 +22,7 @@
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_keyboard_group.h> #include <wlr/types/wlr_keyboard_group.h>
#include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_scene.h> #include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_touch.h> #include <wlr/types/wlr_touch.h>
@ -607,20 +608,25 @@ handle_cursor_button(struct wl_listener *listener, void *data)
} }
static void static void
process_cursor_motion(struct cg_seat *seat, uint32_t time) process_cursor_motion(struct cg_seat *seat, uint32_t time_msec, double dx, double dy, double dx_unaccel,
double dy_unaccel)
{ {
double sx, sy; double sx, sy;
struct wlr_seat *wlr_seat = seat->seat; struct wlr_seat *wlr_seat = seat->seat;
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
struct cg_view *view = desktop_view_at(seat->server, seat->cursor->x, seat->cursor->y, &surface, &sx, &sy); struct cg_view *view = desktop_view_at(seat->server, seat->cursor->x, seat->cursor->y, &surface, &sx, &sy);
if (!view) { if (!view) {
wlr_seat_pointer_clear_focus(wlr_seat); wlr_seat_pointer_clear_focus(wlr_seat);
} else { } else {
wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy); wlr_seat_pointer_notify_enter(wlr_seat, surface, sx, sy);
wlr_seat_pointer_notify_motion(wlr_seat, time_msec, sx, sy);
}
wlr_seat_pointer_notify_motion(wlr_seat, time, sx, sy); if (dx != 0 || dy != 0) {
wlr_relative_pointer_manager_v1_send_relative_motion(seat->server->relative_pointer_manager, wlr_seat,
(uint64_t) time_msec * 1000, dx, dy, dx_unaccel,
dy_unaccel);
} }
struct cg_drag_icon *drag_icon; struct cg_drag_icon *drag_icon;
@ -637,19 +643,26 @@ handle_cursor_motion_absolute(struct wl_listener *listener, void *data)
struct cg_seat *seat = wl_container_of(listener, seat, cursor_motion_absolute); struct cg_seat *seat = wl_container_of(listener, seat, cursor_motion_absolute);
struct wlr_pointer_motion_absolute_event *event = data; struct wlr_pointer_motion_absolute_event *event = data;
double lx, ly;
wlr_cursor_absolute_to_layout_coords(seat->cursor, &event->pointer->base, event->x, event->y, &lx, &ly);
double dx = lx - seat->cursor->x;
double dy = ly - seat->cursor->y;
wlr_cursor_warp_absolute(seat->cursor, &event->pointer->base, event->x, event->y); wlr_cursor_warp_absolute(seat->cursor, &event->pointer->base, event->x, event->y);
process_cursor_motion(seat, event->time_msec); process_cursor_motion(seat, event->time_msec, dx, dy, dx, dy);
wlr_idle_notify_activity(seat->server->idle, seat->seat); wlr_idle_notify_activity(seat->server->idle, seat->seat);
} }
static void static void
handle_cursor_motion(struct wl_listener *listener, void *data) handle_cursor_motion_relative(struct wl_listener *listener, void *data)
{ {
struct cg_seat *seat = wl_container_of(listener, seat, cursor_motion); struct cg_seat *seat = wl_container_of(listener, seat, cursor_motion_relative);
struct wlr_pointer_motion_event *event = data; struct wlr_pointer_motion_event *event = data;
wlr_cursor_move(seat->cursor, &event->pointer->base, event->delta_x, event->delta_y); wlr_cursor_move(seat->cursor, &event->pointer->base, event->delta_x, event->delta_y);
process_cursor_motion(seat, event->time_msec); process_cursor_motion(seat, event->time_msec, event->delta_x, event->delta_y, event->unaccel_dx,
event->unaccel_dy);
wlr_idle_notify_activity(seat->server->idle, seat->seat); wlr_idle_notify_activity(seat->server->idle, seat->seat);
} }
@ -749,7 +762,7 @@ handle_destroy(struct wl_listener *listener, void *data)
{ {
struct cg_seat *seat = wl_container_of(listener, seat, destroy); struct cg_seat *seat = wl_container_of(listener, seat, destroy);
wl_list_remove(&seat->destroy.link); wl_list_remove(&seat->destroy.link);
wl_list_remove(&seat->cursor_motion.link); wl_list_remove(&seat->cursor_motion_relative.link);
wl_list_remove(&seat->cursor_motion_absolute.link); wl_list_remove(&seat->cursor_motion_absolute.link);
wl_list_remove(&seat->cursor_button.link); wl_list_remove(&seat->cursor_button.link);
wl_list_remove(&seat->cursor_axis.link); wl_list_remove(&seat->cursor_axis.link);
@ -823,8 +836,8 @@ seat_create(struct cg_server *server, struct wlr_backend *backend)
} }
} }
seat->cursor_motion.notify = handle_cursor_motion; seat->cursor_motion_relative.notify = handle_cursor_motion_relative;
wl_signal_add(&seat->cursor->events.motion, &seat->cursor_motion); wl_signal_add(&seat->cursor->events.motion, &seat->cursor_motion_relative);
seat->cursor_motion_absolute.notify = handle_cursor_motion_absolute; seat->cursor_motion_absolute.notify = handle_cursor_motion_absolute;
wl_signal_add(&seat->cursor->events.motion_absolute, &seat->cursor_motion_absolute); wl_signal_add(&seat->cursor->events.motion_absolute, &seat->cursor_motion_absolute);
seat->cursor_button.notify = handle_cursor_button; seat->cursor_button.notify = handle_cursor_button;
@ -942,7 +955,7 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view)
wlr_seat_keyboard_notify_enter(wlr_seat, view->wlr_surface, NULL, 0, NULL); wlr_seat_keyboard_notify_enter(wlr_seat, view->wlr_surface, NULL, 0, NULL);
} }
process_cursor_motion(seat, -1); process_cursor_motion(seat, -1, 0, 0, 0, 0);
} }
void void

2
seat.h
View file

@ -27,7 +27,7 @@ struct cg_seat {
struct wlr_cursor *cursor; struct wlr_cursor *cursor;
struct wlr_xcursor_manager *xcursor_manager; struct wlr_xcursor_manager *xcursor_manager;
struct wl_listener cursor_motion; struct wl_listener cursor_motion_relative;
struct wl_listener cursor_motion_absolute; struct wl_listener cursor_motion_absolute;
struct wl_listener cursor_button; struct wl_listener cursor_button;
struct wl_listener cursor_axis; struct wl_listener cursor_axis;

View file

@ -7,6 +7,7 @@
#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_idle.h>
#include <wlr/types/wlr_idle_inhibit_v1.h> #include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_xdg_decoration_v1.h> #include <wlr/types/wlr_xdg_decoration_v1.h>
#if CAGE_HAS_XWAYLAND #if CAGE_HAS_XWAYLAND
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
@ -51,6 +52,8 @@ struct cg_server {
struct wl_listener output_manager_apply; struct wl_listener output_manager_apply;
struct wl_listener output_manager_test; struct wl_listener output_manager_test;
struct wlr_relative_pointer_manager_v1 *relative_pointer_manager;
bool xdg_decoration; bool xdg_decoration;
bool allow_vt_switch; bool allow_vt_switch;
bool return_app_code; bool return_app_code;