Convert wl_input_device to wl_seat (and friends)

wl_input_device has been both renamed and split.  wl_seat is now a
virtual object representing a group of logically related input devices
with related focus.

It now only generates one event: to let clients know that it has new
capabilities.  It takes requests which hand back objects for the
wl_pointer, wl_keyboard and wl_touch interfaces it exposes which all
provide the old input interface, just under different names.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Daniel Stone 2012-05-16 18:44:40 +01:00 committed by Kristian Høgsberg
parent 6d1902b85c
commit aa0fb0f49c
5 changed files with 498 additions and 310 deletions

10
TODO
View file

@ -41,16 +41,6 @@ Core wayland protocol
keys down on pointer_focus and subsequent key events... or just key keys down on pointer_focus and subsequent key events... or just key
events for modifier keys... or for the non-repeating subset? events for modifier keys... or for the non-repeating subset?
- Input protocol restructuring: break up events into wl_pointer
(enter/leave/motion/button/axis events, set_pointer_surface
request), wl_keyboard (enter/leave/key events... what
else... unicode event, set_map request? pending kb work), and
wl_touch (down/up/motion/cancel events) interfaces. Rename
wl_input_device to wl_seat. wl_seat has zero or one of each, and
will announce this at bind time. Raw devices are also tied to a
wl_seat, but we may not do that for 1.0, we just need to make sure
wl_seat has a forward compatible way to announce them.
- Add timestamp to touch_cancel, add touch id to touch_cancel (?) - Add timestamp to touch_cancel, add touch id to touch_cancel (?)
- The output protocol needs to send all the ugly timing details for the modes. - The output protocol needs to send all the ugly timing details for the modes.

View file

@ -383,7 +383,7 @@
<request name="get_data_device"> <request name="get_data_device">
<arg name="id" type="new_id" interface="wl_data_device"/> <arg name="id" type="new_id" interface="wl_data_device"/>
<arg name="input_device" type="object" interface="wl_input_device"/> <arg name="seat" type="object" interface="wl_seat"/>
</request> </request>
</interface> </interface>
@ -412,7 +412,7 @@
</request> </request>
<request name="move"> <request name="move">
<arg name="input_device" type="object" interface="wl_input_device"/> <arg name="seat" type="object" interface="wl_seat"/>
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
</request> </request>
@ -429,7 +429,7 @@
</enum> </enum>
<request name="resize"> <request name="resize">
<arg name="input_device" type="object" interface="wl_input_device"/> <arg name="seat" type="object" interface="wl_seat"/>
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
<arg name="edges" type="uint"/> <arg name="edges" type="uint"/>
</request> </request>
@ -525,7 +525,7 @@
inside or outside the surface? inside or outside the surface?
</description> </description>
<arg name="input_device" type="object" interface="wl_input_device"/> <arg name="seat" type="object" interface="wl_seat"/>
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
<arg name="parent" type="object" interface="wl_shell_surface"/> <arg name="parent" type="object" interface="wl_shell_surface"/>
<arg name="x" type="int"/> <arg name="x" type="int"/>
@ -697,15 +697,60 @@
</event> </event>
</interface> </interface>
<interface name="wl_input_device" version="1"> <interface name="wl_seat" version="1">
<description summary="input device group"> <description summary="seat">
A group of keyboards and pointer devices (mice, for A group of keyboards, pointer (mice, for example) and touch
example). This object is published as a global during start up, devices . This object is published as a global during start up,
or when such a device is hot plugged. A input_device group or when such a device is hot plugged. A seat typically has a
typically has a pointer and maintains a keyboard_focus and a pointer and maintains a keyboard_focus and a pointer_focus.
pointer_focus.
</description> </description>
<enum name="capability">
<description summary="seat capability bitmask">
This is a bitmask of capabilities this seat has; if a member is
set, then it is present on the seat.
</description>
<entry name="pointer" value="1" summary="wl_pointer"/>
<entry name="keyboard" value="2" summary="wl_keyboard"/>
<entry name="touch" value="4" summary="wl_touch"/>
</enum>
<event name="capabilities">
<description summary="seat capabilities changed">
This is emitted whenever a seat gains or loses the pointer,
keyboard or touch capabilities. The argument is a wl_seat_caps_mask
enum containing the complete set of capabilities this seat has.
</description>
<arg name="capabilities" type="uint"/>
</event>
<request name="get_pointer">
<description summary="return pointer object">
The ID provided will be initialized to the wl_pointer interface
for this seat.
</description>
<arg name="id" type="new_id" interface="wl_pointer"/>
</request>
<request name="get_keyboard">
<description summary="return pointer object">
The ID provided will be initialized to the wl_keyboard interface
for this seat.
</description>
<arg name="id" type="new_id" interface="wl_keyboard"/>
</request>
<request name="get_touch">
<description summary="return pointer object">
The ID provided will be initialized to the wl_touch interface
for this seat.
</description>
<arg name="id" type="new_id" interface="wl_touch"/>
</request>
</interface>
<interface name="wl_pointer" version="1">
<request name="attach"> <request name="attach">
<description summary="set the pointer image"> <description summary="set the pointer image">
Set the pointer's image. This request only takes effect if Set the pointer's image. This request only takes effect if
@ -719,6 +764,27 @@
<arg name="hotspot_y" type="int"/> <arg name="hotspot_y" type="int"/>
</request> </request>
<event name="enter">
<description summary="enter event">
Notification that this seat's pointer is focused on a certain
surface. When an seat's focus enters a surface, the pointer image
is undefined and a client should respond to this event by setting
an appropriate pointer image.
</description>
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="surface_x" type="fixed"/>
<arg name="surface_y" type="fixed"/>
</event>
<event name="leave">
<description summary="leave event">
</description>
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<event name="motion"> <event name="motion">
<description summary="pointer motion event"> <description summary="pointer motion event">
Notification of pointer location change. The arguments surface_[xy] Notification of pointer location change. The arguments surface_[xy]
@ -757,6 +823,22 @@
<arg name="axis" type="uint"/> <arg name="axis" type="uint"/>
<arg name="value" type="int"/> <arg name="value" type="int"/>
</event> </event>
</interface>
<interface name="wl_keyboard" version="1">
<description summary="keyboard input device">
</description>
<event name="enter">
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="keys" type="array"/>
</event>
<event name="leave">
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<event name="key"> <event name="key">
<description summary="key event"> <description summary="key event">
@ -768,40 +850,13 @@
<arg name="key" type="uint"/> <arg name="key" type="uint"/>
<arg name="state" type="uint"/> <arg name="state" type="uint"/>
</event> </event>
</interface>
<event name="pointer_enter"> <interface name="wl_touch" version="1">
<description summary="pointer enter event"> <description summary="touch screen input device">
Notification that this input device's pointer is focused on </description>
certain surface. When an input_device enters a surface, the
pointer image is undefined and a client should respond to this
event by setting an appropriate pointer image.
</description>
<arg name="serial" type="uint"/> <event name="down">
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="surface_x" type="fixed"/>
<arg name="surface_y" type="fixed"/>
</event>
<event name="pointer_leave">
<description summary="pointer leave event">
</description>
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<event name="keyboard_enter">
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="keys" type="array"/>
</event>
<event name="keyboard_leave">
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<event name="touch_down">
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
<arg name="time" type="uint"/> <arg name="time" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/> <arg name="surface" type="object" interface="wl_surface"/>
@ -810,26 +865,26 @@
<arg name="y" type="fixed" /> <arg name="y" type="fixed" />
</event> </event>
<event name="touch_up"> <event name="up">
<arg name="serial" type="uint"/> <arg name="serial" type="uint"/>
<arg name="time" type="uint"/> <arg name="time" type="uint"/>
<arg name="id" type="int" /> <arg name="id" type="int" />
</event> </event>
<event name="touch_motion"> <event name="motion">
<arg name="time" type="uint"/> <arg name="time" type="uint"/>
<arg name="id" type="int" /> <arg name="id" type="int" />
<arg name="x" type="fixed" /> <arg name="x" type="fixed" />
<arg name="y" type="fixed" /> <arg name="y" type="fixed" />
</event> </event>
<event name="touch_frame"> <event name="frame">
<description summary="end of touch frame event"> <description summary="end of touch frame event">
Indicates the end of a contact point list. Indicates the end of a contact point list.
</description> </description>
</event> </event>
<event name="touch_cancel"> <event name="cancel">
<description summary="touch session cancelled"> <description summary="touch session cancelled">
Sent if the compositor decides the touch stream is a global Sent if the compositor decides the touch stream is a global
gesture. No further events are sent to the clients from that gesture. No further events are sent to the clients from that

View file

@ -169,48 +169,46 @@ find_resource(struct wl_list *list, struct wl_client *client)
static void static void
destroy_drag_focus(struct wl_listener *listener, void *data) destroy_drag_focus(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device = struct wl_seat *seat =
container_of(listener, struct wl_input_device, container_of(listener, struct wl_seat, drag_focus_listener);
drag_focus_listener);
device->drag_focus_resource = NULL; seat->drag_focus_resource = NULL;
} }
static void static void
drag_grab_focus(struct wl_pointer_grab *grab, drag_grab_focus(struct wl_pointer_grab *grab,
struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
{ {
struct wl_input_device *device = struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
container_of(grab, struct wl_input_device, drag_grab);
struct wl_resource *resource, *offer; struct wl_resource *resource, *offer;
struct wl_display *display; struct wl_display *display;
uint32_t serial; uint32_t serial;
if (device->drag_focus_resource) { if (seat->drag_focus_resource) {
wl_data_device_send_leave(device->drag_focus_resource); wl_data_device_send_leave(seat->drag_focus_resource);
wl_list_remove(&device->drag_focus_listener.link); wl_list_remove(&seat->drag_focus_listener.link);
device->drag_focus_resource = NULL; seat->drag_focus_resource = NULL;
device->drag_focus = NULL; seat->drag_focus = NULL;
} }
if (surface) if (surface)
resource = find_resource(&device->drag_resource_list, resource = find_resource(&seat->drag_resource_list,
surface->resource.client); surface->resource.client);
if (surface && resource) { if (surface && resource) {
display = wl_client_get_display(resource->client); display = wl_client_get_display(resource->client);
serial = wl_display_next_serial(display); serial = wl_display_next_serial(display);
offer = wl_data_source_send_offer(device->drag_data_source, offer = wl_data_source_send_offer(seat->drag_data_source,
resource); resource);
wl_data_device_send_enter(resource, serial, &surface->resource, wl_data_device_send_enter(resource, serial, &surface->resource,
x, y, offer); x, y, offer);
device->drag_focus = surface; seat->drag_focus = surface;
device->drag_focus_listener.notify = destroy_drag_focus; seat->drag_focus_listener.notify = destroy_drag_focus;
wl_signal_add(&resource->destroy_signal, wl_signal_add(&resource->destroy_signal,
&device->drag_focus_listener); &seat->drag_focus_listener);
device->drag_focus_resource = resource; seat->drag_focus_resource = resource;
grab->focus = surface; grab->focus = surface;
} }
} }
@ -219,53 +217,51 @@ static void
drag_grab_motion(struct wl_pointer_grab *grab, drag_grab_motion(struct wl_pointer_grab *grab,
uint32_t time, wl_fixed_t x, wl_fixed_t y) uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct wl_input_device *device = struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
container_of(grab, struct wl_input_device, drag_grab);
if (device->drag_focus_resource) if (seat->drag_focus_resource)
wl_data_device_send_motion(device->drag_focus_resource, wl_data_device_send_motion(seat->drag_focus_resource,
time, x, y); time, x, y);
} }
static void static void
data_device_end_drag_grab(struct wl_input_device *device) data_device_end_drag_grab(struct wl_seat *seat)
{ {
struct wl_resource *surface_resource; struct wl_resource *surface_resource;
struct wl_surface_interface *implementation; struct wl_surface_interface *implementation;
if (device->drag_surface) { if (seat->drag_surface) {
surface_resource = &device->drag_surface->resource; surface_resource = &seat->drag_surface->resource;
implementation = (struct wl_surface_interface *) implementation = (struct wl_surface_interface *)
surface_resource->object.implementation; surface_resource->object.implementation;
implementation->attach(surface_resource->client, implementation->attach(surface_resource->client,
surface_resource, NULL, 0, 0); surface_resource, NULL, 0, 0);
wl_list_remove(&device->drag_icon_listener.link); wl_list_remove(&seat->drag_icon_listener.link);
} }
drag_grab_focus(&device->drag_grab, NULL, drag_grab_focus(&seat->drag_grab, NULL,
wl_fixed_from_int(0), wl_fixed_from_int(0)); wl_fixed_from_int(0), wl_fixed_from_int(0));
wl_input_device_end_pointer_grab(device); wl_pointer_end_grab(seat->pointer);
device->drag_data_source = NULL; seat->drag_data_source = NULL;
device->drag_surface = NULL; seat->drag_surface = NULL;
} }
static void static void
drag_grab_button(struct wl_pointer_grab *grab, drag_grab_button(struct wl_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state) uint32_t time, uint32_t button, uint32_t state)
{ {
struct wl_input_device *device = struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
container_of(grab, struct wl_input_device, drag_grab);
if (device->drag_focus_resource && if (seat->drag_focus_resource &&
device->grab_button == button && state == 0) seat->pointer->grab_button == button && state == 0)
wl_data_device_send_drop(device->drag_focus_resource); wl_data_device_send_drop(seat->drag_focus_resource);
if (device->button_count == 0 && state == 0) { if (seat->pointer->button_count == 0 && state == 0) {
data_device_end_drag_grab(device); data_device_end_drag_grab(seat);
wl_list_remove(&device->drag_data_source_listener.link); wl_list_remove(&seat->drag_data_source_listener.link);
} }
} }
@ -278,23 +274,19 @@ static const struct wl_pointer_grab_interface drag_grab_interface = {
static void static void
destroy_data_device_source(struct wl_listener *listener, void *data) destroy_data_device_source(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device; struct wl_seat *seat = container_of(listener, struct wl_seat,
drag_data_source_listener);
device = container_of(listener, struct wl_input_device, data_device_end_drag_grab(seat);
drag_data_source_listener);
data_device_end_drag_grab(device);
} }
static void static void
destroy_data_device_icon(struct wl_listener *listener, void *data) destroy_data_device_icon(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device; struct wl_seat *seat = container_of(listener, struct wl_seat,
drag_data_source_listener);
device = container_of(listener, struct wl_input_device, seat->drag_surface = NULL;
drag_icon_listener);
device->drag_surface = NULL;
} }
static void static void
@ -303,89 +295,90 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *origin_resource, struct wl_resource *origin_resource,
struct wl_resource *icon_resource, uint32_t serial) struct wl_resource *icon_resource, uint32_t serial)
{ {
struct wl_input_device *device = resource->data; struct wl_seat *seat = resource->data;
/* FIXME: Check that client has implicit grab on the origin /* FIXME: Check that client has implicit grab on the origin
* surface that matches the given time. */ * surface that matches the given time. */
/* FIXME: Check that the data source type array isn't empty. */ /* FIXME: Check that the data source type array isn't empty. */
device->drag_grab.interface = &drag_grab_interface; seat->drag_grab.interface = &drag_grab_interface;
device->drag_data_source = source_resource->data; seat->drag_data_source = source_resource->data;
device->drag_data_source_listener.notify = destroy_data_device_source; seat->drag_data_source_listener.notify = destroy_data_device_source;
wl_signal_add(&source_resource->destroy_signal, wl_signal_add(&source_resource->destroy_signal,
&device->drag_data_source_listener); &seat->drag_data_source_listener);
if (icon_resource) { if (icon_resource) {
device->drag_surface = icon_resource->data; seat->drag_surface = icon_resource->data;
device->drag_icon_listener.notify = destroy_data_device_icon; seat->drag_icon_listener.notify = destroy_data_device_icon;
wl_signal_add(&icon_resource->destroy_signal, wl_signal_add(&icon_resource->destroy_signal,
&device->drag_icon_listener); &seat->drag_icon_listener);
wl_signal_emit(&device->drag_icon_signal, icon_resource); wl_signal_emit(&seat->drag_icon_signal, icon_resource);
} }
wl_input_device_set_pointer_focus(device, NULL, wl_pointer_set_focus(seat->pointer, NULL,
wl_fixed_from_int(0), wl_fixed_from_int(0), wl_fixed_from_int(0));
wl_fixed_from_int(0)); wl_pointer_start_grab(seat->pointer, &seat->drag_grab);
wl_input_device_start_pointer_grab(device, &device->drag_grab);
} }
static void static void
destroy_selection_data_source(struct wl_listener *listener, void *data) destroy_selection_data_source(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device = struct wl_seat *seat = container_of(listener, struct wl_seat,
container_of(listener, struct wl_input_device, selection_data_source_listener);
selection_data_source_listener); struct wl_resource *data_device;
struct wl_resource *data_device, *focus; struct wl_resource *focus = NULL;
device->selection_data_source = NULL; seat->selection_data_source = NULL;
focus = device->keyboard_focus_resource; if (seat->keyboard)
focus = seat->keyboard->focus_resource;
if (focus) { if (focus) {
data_device = find_resource(&device->drag_resource_list, data_device = find_resource(&seat->drag_resource_list,
focus->client); focus->client);
wl_data_device_send_selection(data_device, NULL); wl_data_device_send_selection(data_device, NULL);
} }
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_set_selection(struct wl_input_device *device, wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source,
struct wl_data_source *source, uint32_t serial) uint32_t serial)
{ {
struct wl_resource *data_device, *focus, *offer; struct wl_resource *data_device, *offer;
struct wl_resource *focus = NULL;
if (device->selection_data_source && if (seat->selection_data_source &&
device->selection_serial - serial < UINT32_MAX / 2) seat->selection_serial - serial < UINT32_MAX / 2)
return; return;
if (device->selection_data_source) { if (seat->selection_data_source) {
device->selection_data_source->cancel(device->selection_data_source); seat->selection_data_source->cancel(seat->selection_data_source);
wl_list_remove(&device->selection_data_source_listener.link); wl_list_remove(&seat->selection_data_source_listener.link);
device->selection_data_source = NULL; seat->selection_data_source = NULL;
} }
device->selection_data_source = source; seat->selection_data_source = source;
device->selection_serial = serial; seat->selection_serial = serial;
focus = device->keyboard_focus_resource; if (seat->keyboard)
focus = seat->keyboard->focus_resource;
if (focus) { if (focus) {
data_device = find_resource(&device->drag_resource_list, data_device = find_resource(&seat->drag_resource_list,
focus->client); focus->client);
if (data_device) { if (data_device) {
offer = wl_data_source_send_offer(device->selection_data_source, offer = wl_data_source_send_offer(seat->selection_data_source,
data_device); data_device);
wl_data_device_send_selection(data_device, offer); wl_data_device_send_selection(data_device, offer);
} }
} }
wl_signal_emit(&device->selection_signal, device); wl_signal_emit(&seat->selection_signal, seat);
device->selection_data_source_listener.notify = seat->selection_data_source_listener.notify =
destroy_selection_data_source; destroy_selection_data_source;
wl_signal_add(&source->resource.destroy_signal, wl_signal_add(&source->resource.destroy_signal,
&device->selection_data_source_listener); &seat->selection_data_source_listener);
} }
static void static void
@ -397,8 +390,8 @@ data_device_set_selection(struct wl_client *client,
return; return;
/* FIXME: Store serial and check against incoming serial here. */ /* FIXME: Store serial and check against incoming serial here. */
wl_input_device_set_selection(resource->data, source_resource->data, wl_seat_set_selection(resource->data, source_resource->data,
serial); serial);
} }
static const struct wl_data_device_interface data_device_interface = { static const struct wl_data_device_interface data_device_interface = {
@ -457,16 +450,16 @@ static void unbind_data_device(struct wl_resource *resource)
static void static void
get_data_device(struct wl_client *client, get_data_device(struct wl_client *client,
struct wl_resource *manager_resource, struct wl_resource *manager_resource,
uint32_t id, struct wl_resource *input_device) uint32_t id, struct wl_resource *seat_resource)
{ {
struct wl_input_device *device = input_device->data; struct wl_seat *seat = seat_resource->data;
struct wl_resource *resource; struct wl_resource *resource;
resource = resource = wl_client_add_object(client, &wl_data_device_interface,
wl_client_add_object(client, &wl_data_device_interface, &data_device_interface, id,
&data_device_interface, id, device); seat);
wl_list_insert(&device->drag_resource_list, &resource->link); wl_list_insert(&seat->drag_resource_list, &resource->link);
resource->destroy = unbind_data_device; resource->destroy = unbind_data_device;
} }
@ -484,21 +477,24 @@ bind_manager(struct wl_client *client,
} }
WL_EXPORT void WL_EXPORT void
wl_data_device_set_keyboard_focus(struct wl_input_device *device) wl_data_device_set_keyboard_focus(struct wl_seat *seat)
{ {
struct wl_resource *data_device, *focus, *offer; struct wl_resource *data_device, *focus, *offer;
struct wl_data_source *source; struct wl_data_source *source;
focus = device->keyboard_focus_resource; if (!seat->keyboard)
return;
focus = seat->keyboard->focus_resource;
if (!focus) if (!focus)
return; return;
data_device = find_resource(&device->drag_resource_list, data_device = find_resource(&seat->drag_resource_list,
focus->client); focus->client);
if (!data_device) if (!data_device)
return; return;
source = device->selection_data_source; source = seat->selection_data_source;
if (source) { if (source) {
offer = wl_data_source_send_offer(source, data_device); offer = wl_data_source_send_offer(source, data_device);
wl_data_device_send_selection(data_device, offer); wl_data_device_send_selection(data_device, offer);

View file

@ -453,33 +453,31 @@ wl_client_destroy(struct wl_client *client)
static void static void
lose_pointer_focus(struct wl_listener *listener, void *data) lose_pointer_focus(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device = struct wl_pointer *pointer =
container_of(listener, struct wl_input_device, container_of(listener, struct wl_pointer, focus_listener);
pointer_focus_listener);
device->pointer_focus_resource = NULL; pointer->focus_resource = NULL;
} }
static void static void
lose_keyboard_focus(struct wl_listener *listener, void *data) lose_keyboard_focus(struct wl_listener *listener, void *data)
{ {
struct wl_input_device *device = struct wl_keyboard *keyboard =
container_of(listener, struct wl_input_device, container_of(listener, struct wl_keyboard, focus_listener);
keyboard_focus_listener);
device->keyboard_focus_resource = NULL; keyboard->focus_resource = NULL;
} }
static void static void
default_grab_focus(struct wl_pointer_grab *grab, default_grab_focus(struct wl_pointer_grab *grab,
struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
{ {
struct wl_input_device *device = grab->input_device; struct wl_pointer *pointer = grab->pointer;
if (device->button_count > 0) if (pointer->button_count > 0)
return; return;
wl_input_device_set_pointer_focus(device, surface, x, y); wl_pointer_set_focus(pointer, surface, x, y);
} }
static void static void
@ -488,31 +486,28 @@ default_grab_motion(struct wl_pointer_grab *grab,
{ {
struct wl_resource *resource; struct wl_resource *resource;
resource = grab->input_device->pointer_focus_resource; resource = grab->pointer->focus_resource;
if (resource) if (resource)
wl_input_device_send_motion(resource, time, x, y); wl_pointer_send_motion(resource, time, x, y);
} }
static void static void
default_grab_button(struct wl_pointer_grab *grab, default_grab_button(struct wl_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state) uint32_t time, uint32_t button, uint32_t state)
{ {
struct wl_input_device *device = grab->input_device; struct wl_pointer *pointer = grab->pointer;
struct wl_resource *resource; struct wl_resource *resource;
uint32_t serial; uint32_t serial;
resource = device->pointer_focus_resource; resource = pointer->focus_resource;
if (resource) { if (resource) {
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_button(resource, serial, time, wl_pointer_send_button(resource, serial, time, button, state);
button, state);
} }
if (device->button_count == 0 && state == 0) if (pointer->button_count == 0 && state == 0)
wl_input_device_set_pointer_focus(device, wl_pointer_set_focus(pointer, pointer->current,
device->current, pointer->current_x, pointer->current_y);
device->current_x,
device->current_y);
} }
static const struct wl_pointer_grab_interface static const struct wl_pointer_grab_interface
@ -526,14 +521,14 @@ static void
default_grab_key(struct wl_keyboard_grab *grab, default_grab_key(struct wl_keyboard_grab *grab,
uint32_t time, uint32_t key, uint32_t state) uint32_t time, uint32_t key, uint32_t state)
{ {
struct wl_input_device *device = grab->input_device; struct wl_keyboard *keyboard = grab->keyboard;
struct wl_resource *resource; struct wl_resource *resource;
uint32_t serial; uint32_t serial;
resource = device->keyboard_focus_resource; resource = keyboard->focus_resource;
if (resource) { if (resource) {
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_key(resource, serial, time, key, state); wl_keyboard_send_key(resource, serial, time, key, state);
} }
} }
@ -543,43 +538,147 @@ static const struct wl_keyboard_grab_interface
}; };
WL_EXPORT void WL_EXPORT void
wl_input_device_init(struct wl_input_device *device) wl_pointer_init(struct wl_pointer *pointer)
{ {
memset(device, 0, sizeof *device); memset(pointer, 0, sizeof *pointer);
wl_list_init(&device->resource_list); wl_list_init(&pointer->resource_list);
wl_array_init(&device->keys); pointer->focus_listener.notify = lose_pointer_focus;
device->pointer_focus_listener.notify = lose_pointer_focus; pointer->default_grab.interface = &default_pointer_grab_interface;
device->keyboard_focus_listener.notify = lose_keyboard_focus; pointer->default_grab.pointer = pointer;
pointer->grab = &pointer->default_grab;
device->default_pointer_grab.interface = &default_pointer_grab_interface; /* FIXME: Pick better co-ords. */
device->default_pointer_grab.input_device = device; pointer->x = wl_fixed_from_int(100);
device->pointer_grab = &device->default_pointer_grab; pointer->y = wl_fixed_from_int(100);
device->default_keyboard_grab.interface = &default_keyboard_grab_interface;
device->default_keyboard_grab.input_device = device;
device->keyboard_grab = &device->default_keyboard_grab;
wl_list_init(&device->drag_resource_list);
device->selection_data_source = NULL;
wl_signal_init(&device->selection_signal);
wl_signal_init(&device->drag_icon_signal);
device->x = wl_fixed_from_int(100);
device->y = wl_fixed_from_int(100);
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_release(struct wl_input_device *device) wl_pointer_release(struct wl_pointer *pointer)
{ {
if (device->keyboard_focus_resource) /* XXX: What about pointer->resource_list? */
wl_list_remove(&device->keyboard_focus_listener.link); if (pointer->focus_resource)
wl_list_remove(&pointer->focus_listener.link);
}
if (device->pointer_focus_resource) WL_EXPORT void
wl_list_remove(&device->pointer_focus_listener.link); wl_keyboard_init(struct wl_keyboard *keyboard)
{
memset(keyboard, 0, sizeof *keyboard);
wl_list_init(&keyboard->resource_list);
wl_array_init(&keyboard->keys);
keyboard->focus_listener.notify = lose_keyboard_focus;
keyboard->default_grab.interface = &default_keyboard_grab_interface;
keyboard->default_grab.keyboard = keyboard;
keyboard->grab = &keyboard->default_grab;
}
/* XXX: What about device->resource_list? */ WL_EXPORT void
wl_keyboard_release(struct wl_keyboard *keyboard)
{
/* XXX: What about keyboard->resource_list? */
if (keyboard->focus_resource)
wl_list_remove(&keyboard->focus_listener.link);
wl_array_release(&keyboard->keys);
}
wl_array_release(&device->keys); WL_EXPORT void
wl_touch_init(struct wl_touch *touch)
{
memset(touch, 0, sizeof *touch);
wl_list_init(&touch->resource_list);
}
WL_EXPORT void
wl_touch_release(struct wl_touch *touch)
{
/* XXX: What about touch->resource_list? */
if (touch->focus_resource)
wl_list_remove(&touch->focus_listener.link);
}
WL_EXPORT void
wl_seat_init(struct wl_seat *seat)
{
memset(seat, 0, sizeof *seat);
seat->selection_data_source = NULL;
wl_list_init(&seat->base_resource_list);
wl_signal_init(&seat->selection_signal);
wl_list_init(&seat->drag_resource_list);
wl_signal_init(&seat->drag_icon_signal);
}
WL_EXPORT void
wl_seat_release(struct wl_seat *seat)
{
if (seat->pointer)
wl_pointer_release(seat->pointer);
if (seat->keyboard)
wl_keyboard_release(seat->keyboard);
if (seat->touch)
wl_touch_release(seat->touch);
}
static void
seat_send_updated_caps(struct wl_seat *seat)
{
struct wl_resource *r;
enum wl_seat_capability caps = 0;
if (seat->pointer)
caps |= WL_SEAT_CAPABILITY_POINTER;
if (seat->keyboard)
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
if (seat->touch)
caps |= WL_SEAT_CAPABILITY_TOUCH;
wl_list_for_each(r, &seat->base_resource_list, link)
wl_seat_send_capabilities(r, caps);
}
WL_EXPORT void
wl_seat_set_pointer(struct wl_seat *seat, struct wl_pointer *pointer)
{
if (pointer && (seat->pointer || pointer->seat))
return; /* XXX: error? */
if (!pointer && !seat->pointer)
return;
seat->pointer = pointer;
if (pointer)
pointer->seat = seat;
seat_send_updated_caps(seat);
}
WL_EXPORT void
wl_seat_set_keyboard(struct wl_seat *seat, struct wl_keyboard *keyboard)
{
if (keyboard && (seat->keyboard || keyboard->seat))
return; /* XXX: error? */
if (!keyboard && seat->keyboard)
return;
seat->keyboard = keyboard;
if (keyboard)
keyboard->seat = seat;
seat_send_updated_caps(seat);
}
WL_EXPORT void
wl_seat_set_touch(struct wl_seat *seat, struct wl_touch *touch)
{
if (touch && (seat->touch || touch->seat))
return; /* XXX: error? */
if (!touch && !seat->touch)
return;
seat->touch = touch;
if (!touch)
touch->seat = seat;
seat_send_updated_caps(seat);
} }
static struct wl_resource * static struct wl_resource *
@ -599,113 +698,110 @@ find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_set_pointer_focus(struct wl_input_device *device, wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy)
wl_fixed_t sx, wl_fixed_t sy)
{ {
struct wl_resource *resource; struct wl_resource *resource;
uint32_t serial; uint32_t serial;
if (device->pointer_focus == surface) if (pointer->focus == surface)
return; return;
resource = device->pointer_focus_resource; resource = pointer->focus_resource;
if (resource) { if (resource) {
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_pointer_leave(resource, serial, wl_pointer_send_leave(resource, serial,
&device->pointer_focus->resource); &pointer->focus->resource);
wl_list_remove(&device->pointer_focus_listener.link); wl_list_remove(&pointer->focus_listener.link);
} }
resource = find_resource_for_surface(&pointer->resource_list,
resource = find_resource_for_surface(&device->resource_list, surface); surface);
if (resource) { if (resource) {
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_pointer_enter(resource, serial, wl_pointer_send_enter(resource, serial, &surface->resource,
&surface->resource, sx, sy);
sx, sy);
wl_signal_add(&resource->destroy_signal, wl_signal_add(&resource->destroy_signal,
&device->pointer_focus_listener); &pointer->focus_listener);
device->pointer_focus_serial = serial; pointer->focus_serial = serial;
} }
device->pointer_focus_resource = resource; pointer->focus_resource = resource;
device->pointer_focus = surface; pointer->focus = surface;
device->default_pointer_grab.focus = surface; pointer->default_grab.focus = surface;
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_set_keyboard_focus(struct wl_input_device *device, wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface)
struct wl_surface *surface)
{ {
struct wl_resource *resource; struct wl_resource *resource;
uint32_t serial; uint32_t serial;
if (device->keyboard_focus == surface) if (keyboard->focus == surface)
return; return;
if (device->keyboard_focus_resource) { if (keyboard->focus_resource) {
resource = device->keyboard_focus_resource; resource = keyboard->focus_resource;
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_keyboard_leave(resource, serial, wl_keyboard_send_leave(resource, serial,
&device->keyboard_focus->resource); &keyboard->focus->resource);
wl_list_remove(&device->keyboard_focus_listener.link); wl_list_remove(&keyboard->focus_listener.link);
} }
resource = find_resource_for_surface(&device->resource_list, surface); resource = find_resource_for_surface(&keyboard->resource_list,
surface);
if (resource) { if (resource) {
serial = wl_display_next_serial(resource->client->display); serial = wl_display_next_serial(resource->client->display);
wl_input_device_send_keyboard_enter(resource, serial, wl_keyboard_send_enter(resource, serial, &surface->resource,
&surface->resource, &keyboard->keys);
&device->keys);
wl_signal_add(&resource->destroy_signal, wl_signal_add(&resource->destroy_signal,
&device->keyboard_focus_listener); &keyboard->focus_listener);
device->keyboard_focus_serial = serial; keyboard->focus_serial = serial;
} }
device->keyboard_focus_resource = resource; keyboard->focus_resource = resource;
device->keyboard_focus = surface; keyboard->focus = surface;
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_start_keyboard_grab(struct wl_input_device *device, wl_keyboard_start_grab(struct wl_keyboard *keyboard,
struct wl_keyboard_grab *grab) struct wl_keyboard_grab *grab)
{ {
device->keyboard_grab = grab; keyboard->grab = grab;
grab->input_device = device; grab->keyboard = keyboard;
/* XXX focus? */
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_end_keyboard_grab(struct wl_input_device *device) wl_keyboard_end_grab(struct wl_keyboard *keyboard)
{ {
device->keyboard_grab = &device->default_keyboard_grab; keyboard->grab = &keyboard->default_grab;
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_start_pointer_grab(struct wl_input_device *device, wl_pointer_start_grab(struct wl_pointer *pointer, struct wl_pointer_grab *grab)
struct wl_pointer_grab *grab)
{ {
const struct wl_pointer_grab_interface *interface; const struct wl_pointer_grab_interface *interface;
device->pointer_grab = grab; pointer->grab = grab;
interface = device->pointer_grab->interface; interface = pointer->grab->interface;
grab->input_device = device; grab->pointer = pointer;
if (device->current) if (pointer->current)
interface->focus(device->pointer_grab, device->current, interface->focus(pointer->grab, pointer->current,
device->current_x, device->current_y); pointer->current_x, pointer->current_y);
} }
WL_EXPORT void WL_EXPORT void
wl_input_device_end_pointer_grab(struct wl_input_device *device) wl_pointer_end_grab(struct wl_pointer *pointer)
{ {
const struct wl_pointer_grab_interface *interface; const struct wl_pointer_grab_interface *interface;
device->pointer_grab = &device->default_pointer_grab; pointer->grab = &pointer->default_grab;
interface = device->pointer_grab->interface; interface = pointer->grab->interface;
interface->focus(device->pointer_grab, device->current, interface->focus(pointer->grab, pointer->current,
device->current_x, device->current_y); pointer->current_x, pointer->current_y);
} }
static void static void

View file

@ -74,7 +74,10 @@ int wl_event_loop_get_fd(struct wl_event_loop *loop);
struct wl_client; struct wl_client;
struct wl_display; struct wl_display;
struct wl_input_device; struct wl_seat;
struct wl_pointer;
struct wl_keyboard;
struct wl_touch;
struct wl_listener; struct wl_listener;
typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data); typedef void (*wl_notify_func_t)(struct wl_listener *listener, void *data);
@ -198,7 +201,7 @@ struct wl_pointer_grab_interface {
struct wl_pointer_grab { struct wl_pointer_grab {
const struct wl_pointer_grab_interface *interface; const struct wl_pointer_grab_interface *interface;
struct wl_input_device *input_device; struct wl_pointer *pointer;
struct wl_surface *focus; struct wl_surface *focus;
wl_fixed_t x, y; wl_fixed_t x, y;
}; };
@ -211,7 +214,7 @@ struct wl_keyboard_grab_interface {
struct wl_keyboard_grab { struct wl_keyboard_grab {
const struct wl_keyboard_grab_interface *interface; const struct wl_keyboard_grab_interface *interface;
struct wl_input_device *input_device; struct wl_keyboard *keyboard;
struct wl_surface *focus; struct wl_surface *focus;
uint32_t key; uint32_t key;
}; };
@ -230,33 +233,68 @@ struct wl_data_source {
void (*cancel)(struct wl_data_source *source); void (*cancel)(struct wl_data_source *source);
}; };
struct wl_input_device { struct wl_pointer {
struct wl_seat *seat;
struct wl_list resource_list; struct wl_list resource_list;
struct wl_resource *pointer_focus_resource; struct wl_surface *focus;
struct wl_surface *pointer_focus; struct wl_resource *focus_resource;
struct wl_resource *keyboard_focus_resource; struct wl_listener focus_listener;
struct wl_surface *keyboard_focus; uint32_t focus_serial;
struct wl_array keys;
uint32_t pointer_focus_serial; struct wl_pointer_grab *grab;
uint32_t keyboard_focus_serial; struct wl_pointer_grab default_grab;
struct wl_listener pointer_focus_listener; wl_fixed_t grab_x, grab_y;
struct wl_listener keyboard_focus_listener; uint32_t grab_button;
uint32_t grab_serial;
uint32_t grab_time;
wl_fixed_t x, y; wl_fixed_t x, y;
struct wl_surface *current; struct wl_surface *current;
wl_fixed_t current_x, current_y; wl_fixed_t current_x, current_y;
struct wl_pointer_grab *pointer_grab;
struct wl_pointer_grab default_pointer_grab;
struct wl_keyboard_grab *keyboard_grab;
struct wl_keyboard_grab default_keyboard_grab;
uint32_t button_count; uint32_t button_count;
uint32_t grab_time; };
uint32_t grab_serial;
wl_fixed_t grab_x, grab_y; struct wl_keyboard {
uint32_t grab_button; struct wl_seat *seat;
struct wl_list resource_list;
struct wl_surface *focus;
struct wl_resource *focus_resource;
struct wl_listener focus_listener;
uint32_t focus_serial;
struct wl_keyboard_grab *grab;
struct wl_keyboard_grab default_grab;
uint32_t grab_key; uint32_t grab_key;
struct wl_listener grab_listener; uint32_t grab_serial;
uint32_t grab_time;
struct wl_array keys;
};
struct wl_touch {
struct wl_seat *seat;
struct wl_list resource_list;
struct wl_surface *focus;
struct wl_resource *focus_resource;
struct wl_listener focus_listener;
uint32_t focus_serial;
};
struct wl_seat {
struct wl_list base_resource_list;
struct wl_pointer *pointer;
struct wl_keyboard *keyboard;
struct wl_touch *touch;
uint32_t selection_serial;
struct wl_data_source *selection_data_source;
struct wl_listener selection_data_source_listener;
struct wl_signal selection_signal;
struct wl_list drag_resource_list; struct wl_list drag_resource_list;
struct wl_data_source *drag_data_source; struct wl_data_source *drag_data_source;
@ -268,12 +306,6 @@ struct wl_input_device {
struct wl_surface *drag_surface; struct wl_surface *drag_surface;
struct wl_listener drag_icon_listener; struct wl_listener drag_icon_listener;
struct wl_signal drag_icon_signal; struct wl_signal drag_icon_signal;
uint32_t selection_serial;
struct wl_data_source *selection_data_source;
struct wl_listener selection_data_source_listener;
struct wl_signal selection_signal;
}; };
/* /*
@ -316,39 +348,58 @@ void
wl_resource_destroy(struct wl_resource *resource); wl_resource_destroy(struct wl_resource *resource);
void void
wl_input_device_init(struct wl_input_device *device); wl_seat_init(struct wl_seat *seat);
void void
wl_input_device_release(struct wl_input_device *device); wl_seat_release(struct wl_seat *seat);
void void
wl_input_device_set_pointer_focus(struct wl_input_device *device, wl_seat_set_pointer(struct wl_seat *seat, struct wl_pointer *pointer);
struct wl_surface *surface, void
wl_fixed_t sx, wl_fixed_t sy); wl_seat_set_keyboard(struct wl_seat *seat, struct wl_keyboard *keyboard);
void
wl_seat_set_touch(struct wl_seat *seat, struct wl_touch *touch);
void void
wl_input_device_set_keyboard_focus(struct wl_input_device *device, wl_pointer_init(struct wl_pointer *pointer);
struct wl_surface *surface);
void void
wl_data_device_set_keyboard_focus(struct wl_input_device *device); wl_pointer_release(struct wl_pointer *pointer);
void
wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy);
void
wl_pointer_start_grab(struct wl_pointer *pointer,
struct wl_pointer_grab *grab);
void
wl_pointer_end_grab(struct wl_pointer *pointer);
void
wl_keyboard_init(struct wl_keyboard *keyboard);
void
wl_keyboard_release(struct wl_keyboard *keyboard);
void
wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface);
void
wl_keyboard_start_grab(struct wl_keyboard *device,
struct wl_keyboard_grab *grab);
void
wl_keyboard_end_grab(struct wl_keyboard *keyboard);
void
wl_touch_init(struct wl_touch *touch);
void
wl_touch_release(struct wl_touch *touch);
void
wl_data_device_set_keyboard_focus(struct wl_seat *seat);
int int
wl_data_device_manager_init(struct wl_display *display); wl_data_device_manager_init(struct wl_display *display);
void
wl_input_device_start_keyboard_grab(struct wl_input_device *device,
struct wl_keyboard_grab *grab);
void
wl_input_device_end_keyboard_grab(struct wl_input_device *device);
void void
wl_input_device_start_pointer_grab(struct wl_input_device *device, wl_seat_set_selection(struct wl_seat *seat,
struct wl_pointer_grab *grab); struct wl_data_source *source, uint32_t serial);
void
wl_input_device_end_pointer_grab(struct wl_input_device *device);
void
wl_input_device_set_selection(struct wl_input_device *device,
struct wl_data_source *source, uint32_t serial);
void * void *