Commit 5ffe9f47 authored by Kristian Høgsberg's avatar Kristian Høgsberg
Browse files

New grab API

This commit changes the way struct wl_grab works in a couple of ways:

 - The grab itself now decides when it ends instead of hardcoding button
   up as the terminating event.  We remove the end vfunc since a grab now
   always know when it ends and can just clean up at that point.

 - We add a new focus vfunc that is invoked every time the pointer enters
   a new surface, regardless of any grabs.  The callback receives the
   surface and the surface-relative pointer coordinates.  The callback lets
   a grab send enter/leave events and change the grab focus.

 - The grab has a focus surface, wich determines the coordinate space
   for the motion callback coordinates.

 - The input device always tracks the current surface, ie the surface that
   currently contains the pointer, and coordinates relative to that surface.

With these changes, we will be able to pull the core input event delivery
and the drag and drop grab into the core wayland-server library.
parent 44b529f2
......@@ -488,6 +488,7 @@ wl_input_device_set_pointer_focus(struct wl_input_device *device,
device->pointer_focus_resource = resource;
device->pointer_focus = surface;
device->pointer_focus_time = time;
device->default_grab.focus = surface;
}
WL_EXPORT void
......@@ -524,62 +525,29 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device,
}
WL_EXPORT void
wl_input_device_end_grab(struct wl_input_device *device, uint32_t time)
wl_input_device_start_grab(struct wl_input_device *device,
struct wl_grab *grab, uint32_t time)
{
const struct wl_grab_interface *interface;
device->grab = grab;
interface = device->grab->interface;
interface->end(device->grab, time);
device->grab = NULL;
wl_list_remove(&device->grab_listener.link);
}
static void
lose_grab_surface(struct wl_listener *listener,
struct wl_resource *resource, uint32_t time)
{
struct wl_input_device *device =
container_of(listener,
struct wl_input_device, grab_listener);
grab->input_device = device;
wl_input_device_end_grab(device, time);
if (device->current)
interface->focus(device->grab, time, device->current,
device->current_x, device->current_y);
}
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->resource.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)
wl_input_device_end_grab(struct wl_input_device *device, uint32_t time)
{
if (device->grab != &device->implicit_grab ||
device->grab_time != time ||
device->pointer_focus != surface)
return -1;
device->grab = grab;
grab->input_device = device;
const struct wl_grab_interface *interface;
return 0;
device->grab = &device->default_grab;
interface = device->grab->interface;
interface->focus(device->grab, time, device->current,
device->current_x, device->current_y);
}
static void
......
......@@ -147,16 +147,19 @@ struct wl_surface {
struct wl_grab;
struct wl_grab_interface {
void (*focus)(struct wl_grab *grab, uint32_t time,
struct wl_surface *surface, int32_t x, int32_t y);
void (*motion)(struct wl_grab *grab,
uint32_t time, int32_t x, int32_t y);
void (*button)(struct wl_grab *grab,
uint32_t time, int32_t button, int32_t state);
void (*end)(struct wl_grab *grab, uint32_t time);
};
struct wl_grab {
const struct wl_grab_interface *interface;
struct wl_input_device *input_device;
struct wl_surface *focus;
int32_t x, y;
};
struct wl_input_device {
......@@ -172,8 +175,12 @@ struct wl_input_device {
struct wl_listener keyboard_focus_listener;
int32_t x, y;
struct wl_surface *current;
int32_t current_x, current_y;
struct wl_grab *grab;
struct wl_grab implicit_grab;
struct wl_grab default_grab;
uint32_t button_count;
uint32_t grab_time;
int32_t grab_x, grab_y;
uint32_t grab_button;
......@@ -241,12 +248,7 @@ 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);
struct wl_grab *grab, uint32_t time);
struct wl_shm;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment