Move basic grab handling to core libraries

dev
Kristian Høgsberg 14 years ago
parent 0d8805ea18
commit 5753188e16
  1. 69
      compositor/compositor.c
  2. 70
      wayland/wayland-server.c
  3. 11
      wayland/wayland-server.h

@ -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)

@ -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)

@ -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,

Loading…
Cancel
Save