From 5753188e1663241338c0b31428b0dd7a6641044b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 5 Jan 2011 17:34:54 -0500 Subject: [PATCH] Move basic grab handling to core libraries --- compositor/compositor.c | 69 --------------------------------------- wayland/wayland-server.c | 70 ++++++++++++++++++++++++++++++++++++++++ wayland/wayland-server.h | 11 +++++++ 3 files changed, 81 insertions(+), 69 deletions(-) diff --git a/compositor/compositor.c b/compositor/compositor.c index d9b81d87..4290e758 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -499,56 +499,6 @@ wlsc_input_device_set_pointer_image(struct wlsc_input_device *device, pointer_images[type].hotspot_y); } -static void -wl_input_device_end_grab(struct wl_input_device *device, uint32_t time); - -static void -lose_grab_surface(struct wl_listener *listener, - struct wl_surface *surface, uint32_t time) -{ - struct wl_input_device *device = - container_of(listener, - struct wl_input_device, grab_listener); - - wl_input_device_end_grab(device, time); -} - -static void -wl_input_device_start_grab(struct wl_input_device *device, - struct wl_grab *grab, - uint32_t button, uint32_t time) -{ - struct wl_surface *focus = device->pointer_focus; - - device->grab = grab; - device->grab_button = button; - device->grab_time = time; - device->grab_x = device->x; - device->grab_y = device->y; - - device->grab_listener.func = lose_grab_surface; - wl_list_insert(focus->destroy_listener_list.prev, - &device->grab_listener.link); - - grab->input_device = device; -} - -static int -wl_input_device_update_grab(struct wl_input_device *device, - struct wl_grab *grab, - struct wl_surface *surface, uint32_t time) -{ - if (device->grab != &device->motion_grab || - device->grab_time != time || - device->pointer_focus != surface) - return -1; - - device->grab = grab; - grab->input_device = device; - - return 0; -} - struct wlsc_move_grab { struct wl_grab grab; int32_t dx, dy; @@ -933,25 +883,6 @@ notify_motion(struct wl_input_device *device, uint32_t time, int x, int y) wlsc_compositor_schedule_repaint(ec); } -static void -wl_input_device_end_grab(struct wl_input_device *device, uint32_t time) -{ - struct wlsc_surface *es; - const struct wl_grab_interface *interface; - int32_t sx, sy; - - interface = device->grab->interface; - interface->end(device->grab, time); - device->grab->input_device = NULL; - device->grab = NULL; - - wl_list_remove(&device->grab_listener.link); - es = pick_surface(device, &sx, &sy); - wl_input_device_set_pointer_focus(device, - &es->surface, time, - device->x, device->y, sx, sy); -} - void notify_button(struct wl_input_device *device, uint32_t time, int32_t button, int32_t state) diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c index 677d85ab..e60f2ae6 100644 --- a/wayland/wayland-server.c +++ b/wayland/wayland-server.c @@ -401,6 +401,76 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device, &device->keyboard_focus_listener.link); } +WL_EXPORT void +wl_input_device_end_grab(struct wl_input_device *device, uint32_t time) +{ + const struct wl_grab_interface *interface; + + interface = device->grab->interface; + interface->end(device->grab, time); + device->grab->input_device = NULL; + device->grab = NULL; + + wl_list_remove(&device->grab_listener.link); + +#if 0 + struct wlsc_surface *es; + int32_t sx, sy; + + es = pick_surface(device, &sx, &sy); + wl_input_device_set_pointer_focus(device, + &es->surface, time, + device->x, device->y, sx, sy); +#endif +} + +static void +lose_grab_surface(struct wl_listener *listener, + struct wl_surface *surface, uint32_t time) +{ + struct wl_input_device *device = + container_of(listener, + struct wl_input_device, grab_listener); + + wl_input_device_end_grab(device, time); +} + +WL_EXPORT void +wl_input_device_start_grab(struct wl_input_device *device, + struct wl_grab *grab, + uint32_t button, uint32_t time) +{ + struct wl_surface *focus = device->pointer_focus; + + device->grab = grab; + device->grab_button = button; + device->grab_time = time; + device->grab_x = device->x; + device->grab_y = device->y; + + device->grab_listener.func = lose_grab_surface; + wl_list_insert(focus->destroy_listener_list.prev, + &device->grab_listener.link); + + grab->input_device = device; +} + +WL_EXPORT int +wl_input_device_update_grab(struct wl_input_device *device, + struct wl_grab *grab, + struct wl_surface *surface, uint32_t time) +{ + if (device->grab != &device->motion_grab || + device->grab_time != time || + device->pointer_focus != surface) + return -1; + + device->grab = grab; + grab->input_device = device; + + return 0; +} + static void display_sync(struct wl_client *client, struct wl_display *display, uint32_t key) diff --git a/wayland/wayland-server.h b/wayland/wayland-server.h index f0f321bc..96661585 100644 --- a/wayland/wayland-server.h +++ b/wayland/wayland-server.h @@ -227,6 +227,17 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device, struct wl_surface *surface, uint32_t time); +void +wl_input_device_end_grab(struct wl_input_device *device, uint32_t time); +void +wl_input_device_start_grab(struct wl_input_device *device, + struct wl_grab *grab, + uint32_t button, uint32_t time); +int +wl_input_device_update_grab(struct wl_input_device *device, + struct wl_grab *grab, + struct wl_surface *surface, uint32_t time); + int wl_compositor_init(struct wl_compositor *compositor, const struct wl_compositor_interface *interface,