xwayland: Refactor cursor management into xwl_cursor
This struct takes away the cursor info in xwl_seat, and has an update function so we can share the frame handling code across several xwl_cursors. Signed-off-by: Carlos Garnacho <carlosg@gnome.org> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Acked-by: Ping Cheng <ping.cheng@wacom.com>
This commit is contained in:
parent
773b04748d
commit
6d1ad39fe6
|
@ -96,11 +96,11 @@ xwl_unrealize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor)
|
|||
}
|
||||
|
||||
static void
|
||||
clear_cursor_frame_callback(struct xwl_seat *xwl_seat)
|
||||
clear_cursor_frame_callback(struct xwl_cursor *xwl_cursor)
|
||||
{
|
||||
if (xwl_seat->cursor_frame_cb) {
|
||||
wl_callback_destroy (xwl_seat->cursor_frame_cb);
|
||||
xwl_seat->cursor_frame_cb = NULL;
|
||||
if (xwl_cursor->frame_cb) {
|
||||
wl_callback_destroy (xwl_cursor->frame_cb);
|
||||
xwl_cursor->frame_cb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,12 +109,12 @@ frame_callback(void *data,
|
|||
struct wl_callback *callback,
|
||||
uint32_t time)
|
||||
{
|
||||
struct xwl_seat *xwl_seat = data;
|
||||
struct xwl_cursor *xwl_cursor = data;
|
||||
|
||||
clear_cursor_frame_callback(xwl_seat);
|
||||
if (xwl_seat->cursor_needs_update) {
|
||||
xwl_seat->cursor_needs_update = FALSE;
|
||||
xwl_seat_set_cursor(xwl_seat);
|
||||
clear_cursor_frame_callback(xwl_cursor);
|
||||
if (xwl_cursor->needs_update) {
|
||||
xwl_cursor->needs_update = FALSE;
|
||||
xwl_cursor->update_proc(xwl_cursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,7 @@ static const struct wl_callback_listener frame_listener = {
|
|||
void
|
||||
xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
|
||||
{
|
||||
struct xwl_cursor *xwl_cursor = &xwl_seat->cursor;
|
||||
PixmapPtr pixmap;
|
||||
CursorPtr cursor;
|
||||
int stride;
|
||||
|
@ -135,13 +136,13 @@ xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
|
|||
if (!xwl_seat->x_cursor) {
|
||||
wl_pointer_set_cursor(xwl_seat->wl_pointer,
|
||||
xwl_seat->pointer_enter_serial, NULL, 0, 0);
|
||||
clear_cursor_frame_callback(xwl_seat);
|
||||
xwl_seat->cursor_needs_update = FALSE;
|
||||
clear_cursor_frame_callback(xwl_cursor);
|
||||
xwl_cursor->needs_update = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (xwl_seat->cursor_frame_cb) {
|
||||
xwl_seat->cursor_needs_update = TRUE;
|
||||
if (xwl_cursor->frame_cb) {
|
||||
xwl_cursor->needs_update = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -159,19 +160,19 @@ xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
|
|||
|
||||
wl_pointer_set_cursor(xwl_seat->wl_pointer,
|
||||
xwl_seat->pointer_enter_serial,
|
||||
xwl_seat->cursor,
|
||||
xwl_cursor->surface,
|
||||
xwl_seat->x_cursor->bits->xhot,
|
||||
xwl_seat->x_cursor->bits->yhot);
|
||||
wl_surface_attach(xwl_seat->cursor,
|
||||
wl_surface_attach(xwl_cursor->surface,
|
||||
xwl_shm_pixmap_get_wl_buffer(pixmap), 0, 0);
|
||||
wl_surface_damage(xwl_seat->cursor, 0, 0,
|
||||
wl_surface_damage(xwl_cursor->surface, 0, 0,
|
||||
xwl_seat->x_cursor->bits->width,
|
||||
xwl_seat->x_cursor->bits->height);
|
||||
|
||||
xwl_seat->cursor_frame_cb = wl_surface_frame(xwl_seat->cursor);
|
||||
wl_callback_add_listener(xwl_seat->cursor_frame_cb, &frame_listener, xwl_seat);
|
||||
xwl_cursor->frame_cb = wl_surface_frame(xwl_cursor->surface);
|
||||
wl_callback_add_listener(xwl_cursor->frame_cb, &frame_listener, xwl_cursor);
|
||||
|
||||
wl_surface_commit(xwl_seat->cursor);
|
||||
wl_surface_commit(xwl_cursor->surface);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -418,9 +418,9 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
|
|||
* of our surfaces might not have been shown. In that case we'll
|
||||
* have a cursor surface frame callback pending which we need to
|
||||
* clear so that we can continue submitting new cursor frames. */
|
||||
if (xwl_seat->cursor_frame_cb) {
|
||||
wl_callback_destroy(xwl_seat->cursor_frame_cb);
|
||||
xwl_seat->cursor_frame_cb = NULL;
|
||||
if (xwl_seat->cursor.frame_cb) {
|
||||
wl_callback_destroy(xwl_seat->cursor.frame_cb);
|
||||
xwl_seat->cursor.frame_cb = NULL;
|
||||
xwl_seat_set_cursor(xwl_seat);
|
||||
}
|
||||
|
||||
|
@ -1196,6 +1196,31 @@ static const struct wl_seat_listener seat_listener = {
|
|||
seat_handle_name
|
||||
};
|
||||
|
||||
static void
|
||||
xwl_cursor_init(struct xwl_cursor *xwl_cursor, struct xwl_screen *xwl_screen,
|
||||
void (* update_proc)(struct xwl_cursor *))
|
||||
{
|
||||
xwl_cursor->surface = wl_compositor_create_surface(xwl_screen->compositor);
|
||||
xwl_cursor->update_proc = update_proc;
|
||||
xwl_cursor->frame_cb = NULL;
|
||||
xwl_cursor->needs_update = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
xwl_cursor_release(struct xwl_cursor *xwl_cursor)
|
||||
{
|
||||
wl_surface_destroy(xwl_cursor->surface);
|
||||
if (xwl_cursor->frame_cb)
|
||||
wl_callback_destroy(xwl_cursor->frame_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
xwl_seat_update_cursor(struct xwl_cursor *xwl_cursor)
|
||||
{
|
||||
struct xwl_seat *xwl_seat = wl_container_of(xwl_cursor, xwl_seat, cursor);
|
||||
xwl_seat_set_cursor(xwl_seat);
|
||||
}
|
||||
|
||||
static void
|
||||
create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version)
|
||||
{
|
||||
|
@ -1215,7 +1240,8 @@ create_input_device(struct xwl_screen *xwl_screen, uint32_t id, uint32_t version
|
|||
&wl_seat_interface, min(version, 5));
|
||||
xwl_seat->id = id;
|
||||
|
||||
xwl_seat->cursor = wl_compositor_create_surface(xwl_screen->compositor);
|
||||
xwl_cursor_init(&xwl_seat->cursor, xwl_seat->xwl_screen,
|
||||
xwl_seat_update_cursor);
|
||||
wl_seat_add_listener(xwl_seat->seat, &seat_listener, xwl_seat);
|
||||
|
||||
init_tablet_manager_seat(xwl_screen, xwl_seat);
|
||||
|
@ -1246,9 +1272,7 @@ xwl_seat_destroy(struct xwl_seat *xwl_seat)
|
|||
release_tablet_manager_seat(xwl_seat);
|
||||
|
||||
wl_seat_destroy(xwl_seat->seat);
|
||||
wl_surface_destroy(xwl_seat->cursor);
|
||||
if (xwl_seat->cursor_frame_cb)
|
||||
wl_callback_destroy(xwl_seat->cursor_frame_cb);
|
||||
xwl_cursor_release(&xwl_seat->cursor);
|
||||
wl_array_release(&xwl_seat->keys);
|
||||
free(xwl_seat);
|
||||
}
|
||||
|
|
|
@ -130,6 +130,13 @@ struct xwl_pointer_warp_emulator {
|
|||
struct zwp_locked_pointer_v1 *locked_pointer;
|
||||
};
|
||||
|
||||
struct xwl_cursor {
|
||||
void (* update_proc) (struct xwl_cursor *);
|
||||
struct wl_surface *surface;
|
||||
struct wl_callback *frame_cb;
|
||||
Bool needs_update;
|
||||
};
|
||||
|
||||
struct xwl_seat {
|
||||
DeviceIntPtr pointer;
|
||||
DeviceIntPtr relative_pointer;
|
||||
|
@ -151,9 +158,7 @@ struct xwl_seat {
|
|||
uint32_t pointer_enter_serial;
|
||||
struct xorg_list link;
|
||||
CursorPtr x_cursor;
|
||||
struct wl_surface *cursor;
|
||||
struct wl_callback *cursor_frame_cb;
|
||||
Bool cursor_needs_update;
|
||||
struct xwl_cursor cursor;
|
||||
WindowPtr last_xwindow;
|
||||
|
||||
struct xorg_list touches;
|
||||
|
|
Loading…
Reference in New Issue
Block a user