Commit aa0fb0f4 authored by Daniel Stone's avatar Daniel Stone Committed by Kristian Høgsberg
Browse files

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's avatarDaniel Stone <daniel@fooishbar.org>
parent 6d1902b8
......@@ -41,16 +41,6 @@ Core wayland protocol
keys down on pointer_focus and subsequent key events... or just key
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 (?)
- The output protocol needs to send all the ugly timing details for the modes.
......
......@@ -383,7 +383,7 @@
<request name="get_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>
</interface>
......@@ -412,7 +412,7 @@
</request>
<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"/>
</request>
......@@ -429,7 +429,7 @@
</enum>
<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="edges" type="uint"/>
</request>
......@@ -525,7 +525,7 @@
inside or outside the surface?
</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="parent" type="object" interface="wl_shell_surface"/>
<arg name="x" type="int"/>
......@@ -697,15 +697,60 @@
</event>
</interface>
<interface name="wl_input_device" version="1">
<description summary="input device group">
A group of keyboards and pointer devices (mice, for
example). This object is published as a global during start up,
or when such a device is hot plugged. A input_device group
typically has a pointer and maintains a keyboard_focus and a
pointer_focus.
<interface name="wl_seat" version="1">
<description summary="seat">
A group of keyboards, pointer (mice, for example) and touch
devices . This object is published as a global during start up,
or when such a device is hot plugged. A seat typically has a
pointer and maintains a keyboard_focus and a pointer_focus.
</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">
<description summary="set the pointer image">
Set the pointer's image. This request only takes effect if
......@@ -719,6 +764,27 @@
<arg name="hotspot_y" type="int"/>
</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">
<description summary="pointer motion event">
Notification of pointer location change. The arguments surface_[xy]
......@@ -757,51 +823,40 @@
<arg name="axis" type="uint"/>
<arg name="value" type="int"/>
</event>
</interface>
<event name="key">
<description summary="key event">
A key was pressed or released.
</description>
<interface name="wl_keyboard" version="1">
<description summary="keyboard input device">
</description>
<event name="enter">
<arg name="serial" type="uint"/>
<arg name="time" type="uint"/>
<arg name="key" type="uint"/>
<arg name="state" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="keys" type="array"/>
</event>
<event name="pointer_enter">
<description summary="pointer enter event">
Notification that this input device's pointer is focused on
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>
<event name="leave">
<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="pointer_leave">
<description summary="pointer leave event">
<event name="key">
<description summary="key event">
A key was pressed or released.
</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"/>
<arg name="time" type="uint"/>
<arg name="key" type="uint"/>
<arg name="state" type="uint"/>
</event>
</interface>
<event name="keyboard_leave">
<arg name="serial" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
</event>
<interface name="wl_touch" version="1">
<description summary="touch screen input device">
</description>
<event name="touch_down">
<event name="down">
<arg name="serial" type="uint"/>
<arg name="time" type="uint"/>
<arg name="surface" type="object" interface="wl_surface"/>
......@@ -810,26 +865,26 @@
<arg name="y" type="fixed" />
</event>
<event name="touch_up">
<event name="up">
<arg name="serial" type="uint"/>
<arg name="time" type="uint"/>
<arg name="id" type="int" />
</event>
<event name="touch_motion">
<event name="motion">
<arg name="time" type="uint"/>
<arg name="id" type="int" />
<arg name="x" type="fixed" />
<arg name="y" type="fixed" />
</event>
<event name="touch_frame">
<event name="frame">
<description summary="end of touch frame event">
Indicates the end of a contact point list.
</description>
</event>
<event name="touch_cancel">
<event name="cancel">
<description summary="touch session cancelled">
Sent if the compositor decides the touch stream is a global
gesture. No further events are sent to the clients from that
......
......@@ -169,48 +169,46 @@ find_resource(struct wl_list *list, struct wl_client *client)
static void
destroy_drag_focus(struct wl_listener *listener, void *data)
{
struct wl_input_device *device =
container_of(listener, struct wl_input_device,
drag_focus_listener);
struct wl_seat *seat =
container_of(listener, struct wl_seat, drag_focus_listener);
device->drag_focus_resource = NULL;
seat->drag_focus_resource = NULL;
}
static void
drag_grab_focus(struct wl_pointer_grab *grab,
struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
{
struct wl_input_device *device =
container_of(grab, struct wl_input_device, drag_grab);
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
struct wl_resource *resource, *offer;
struct wl_display *display;
uint32_t serial;
if (device->drag_focus_resource) {
wl_data_device_send_leave(device->drag_focus_resource);
wl_list_remove(&device->drag_focus_listener.link);
device->drag_focus_resource = NULL;
device->drag_focus = NULL;
if (seat->drag_focus_resource) {
wl_data_device_send_leave(seat->drag_focus_resource);
wl_list_remove(&seat->drag_focus_listener.link);
seat->drag_focus_resource = NULL;
seat->drag_focus = NULL;
}
if (surface)
resource = find_resource(&device->drag_resource_list,
resource = find_resource(&seat->drag_resource_list,
surface->resource.client);
if (surface && resource) {
display = wl_client_get_display(resource->client);
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);
wl_data_device_send_enter(resource, serial, &surface->resource,
x, y, offer);
device->drag_focus = surface;
device->drag_focus_listener.notify = destroy_drag_focus;
seat->drag_focus = surface;
seat->drag_focus_listener.notify = destroy_drag_focus;
wl_signal_add(&resource->destroy_signal,
&device->drag_focus_listener);
device->drag_focus_resource = resource;
&seat->drag_focus_listener);
seat->drag_focus_resource = resource;
grab->focus = surface;
}
}
......@@ -219,53 +217,51 @@ static void
drag_grab_motion(struct wl_pointer_grab *grab,
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{
struct wl_input_device *device =
container_of(grab, struct wl_input_device, drag_grab);
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
if (device->drag_focus_resource)
wl_data_device_send_motion(device->drag_focus_resource,
if (seat->drag_focus_resource)
wl_data_device_send_motion(seat->drag_focus_resource,
time, x, y);
}
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_surface_interface *implementation;
if (device->drag_surface) {
surface_resource = &device->drag_surface->resource;
if (seat->drag_surface) {
surface_resource = &seat->drag_surface->resource;
implementation = (struct wl_surface_interface *)
surface_resource->object.implementation;
implementation->attach(surface_resource->client,
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_input_device_end_pointer_grab(device);
wl_pointer_end_grab(seat->pointer);
device->drag_data_source = NULL;
device->drag_surface = NULL;
seat->drag_data_source = NULL;
seat->drag_surface = NULL;
}
static void
drag_grab_button(struct wl_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state)
{
struct wl_input_device *device =
container_of(grab, struct wl_input_device, drag_grab);
struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab);
if (device->drag_focus_resource &&
device->grab_button == button && state == 0)
wl_data_device_send_drop(device->drag_focus_resource);
if (seat->drag_focus_resource &&
seat->pointer->grab_button == button && state == 0)
wl_data_device_send_drop(seat->drag_focus_resource);
if (device->button_count == 0 && state == 0) {
data_device_end_drag_grab(device);
wl_list_remove(&device->drag_data_source_listener.link);
if (seat->pointer->button_count == 0 && state == 0) {
data_device_end_drag_grab(seat);
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
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,
drag_data_source_listener);
data_device_end_drag_grab(device);
data_device_end_drag_grab(seat);
}
static void
destroy_data_device_icon(struct wl_listener *listener, void *data)
{
struct wl_input_device *device;
device = container_of(listener, struct wl_input_device,
drag_icon_listener);
struct wl_seat *seat = container_of(listener, struct wl_seat,
drag_data_source_listener);
device->drag_surface = NULL;
seat->drag_surface = NULL;
}
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 *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
* surface that matches the given time. */
/* 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;
device->drag_data_source_listener.notify = destroy_data_device_source;
seat->drag_data_source = source_resource->data;
seat->drag_data_source_listener.notify = destroy_data_device_source;
wl_signal_add(&source_resource->destroy_signal,
&device->drag_data_source_listener);
&seat->drag_data_source_listener);
if (icon_resource) {
device->drag_surface = icon_resource->data;
device->drag_icon_listener.notify = destroy_data_device_icon;
seat->drag_surface = icon_resource->data;
seat->drag_icon_listener.notify = destroy_data_device_icon;
wl_signal_add(&icon_resource->destroy_signal,
&device->drag_icon_listener);
wl_signal_emit(&device->drag_icon_signal, icon_resource);
&seat->drag_icon_listener);
wl_signal_emit(&seat->drag_icon_signal, icon_resource);
}
wl_input_device_set_pointer_focus(device, NULL,
wl_fixed_from_int(0),
wl_fixed_from_int(0));
wl_input_device_start_pointer_grab(device, &device->drag_grab);
wl_pointer_set_focus(seat->pointer, NULL,
wl_fixed_from_int(0), wl_fixed_from_int(0));
wl_pointer_start_grab(seat->pointer, &seat->drag_grab);
}
static void
destroy_selection_data_source(struct wl_listener *listener, void *data)
{
struct wl_input_device *device =
container_of(listener, struct wl_input_device,
selection_data_source_listener);
struct wl_resource *data_device, *focus;
struct wl_seat *seat = container_of(listener, struct wl_seat,
selection_data_source_listener);
struct wl_resource *data_device;
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) {
data_device = find_resource(&device->drag_resource_list,
data_device = find_resource(&seat->drag_resource_list,
focus->client);
wl_data_device_send_selection(data_device, NULL);
}
}
WL_EXPORT void
wl_input_device_set_selection(struct wl_input_device *device,
struct wl_data_source *source, uint32_t serial)
wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source,
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 &&
device->selection_serial - serial < UINT32_MAX / 2)
if (seat->selection_data_source &&
seat->selection_serial - serial < UINT32_MAX / 2)
return;
if (device->selection_data_source) {
device->selection_data_source->cancel(device->selection_data_source);
wl_list_remove(&device->selection_data_source_listener.link);
device->selection_data_source = NULL;
if (seat->selection_data_source) {
seat->selection_data_source->cancel(seat->selection_data_source);
wl_list_remove(&seat->selection_data_source_listener.link);
seat->selection_data_source = NULL;
}
device->selection_data_source = source;
device->selection_serial = serial;
seat->selection_data_source = source;
seat->selection_serial = serial;
focus = device->keyboard_focus_resource;
if (seat->keyboard)
focus = seat->keyboard->focus_resource;
if (focus) {
data_device = find_resource(&device->drag_resource_list,
data_device = find_resource(&seat->drag_resource_list,
focus->client);
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);
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;
wl_signal_add(&source->resource.destroy_signal,
&device->selection_data_source_listener);
&seat->selection_data_source_listener);
}
static void
......@@ -397,8 +390,8 @@ data_device_set_selection(struct wl_client *client,
return;
/* FIXME: Store serial and check against incoming serial here. */
wl_input_device_set_selection(resource->data, source_resource->data,
serial);
wl_seat_set_selection(resource->data, source_resource->data,
serial);
}
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
get_data_device(struct wl_client *client,
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;
resource =
wl_client_add_object(client, &wl_data_device_interface,
&data_device_interface, id, device);
wl_list_insert(&device->drag_resource_list, &resource->link);
resource = wl_client_add_object(client, &wl_data_device_interface,
&data_device_interface, id,
seat);
wl_list_insert(&seat->drag_resource_list, &resource->link);
resource->destroy = unbind_data_device;
}
......@@ -484,21 +477,24 @@ bind_manager(struct wl_client *client,
}
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_data_source *source;
focus = device->keyboard_focus_resource;
if (!seat->keyboard)
return;
focus = seat->keyboard->focus_resource;
if (!focus)
return;
data_device = find_resource(&device->drag_resource_list,
data_device = find_resource(&seat->drag_resource_list,
focus->client);
if (!data_device)
return;
source = device->selection_data_source;
source = seat->selection_data_source;
if (source) {
offer = wl_data_source_send_offer(source, data_device);
wl_data_device_send_selection(data_device, offer);
......
......@@ -453,33 +453,31 @@ wl_client_destroy(struct wl_client *client)
static void
lose_pointer_focus(struct wl_listener *listener, void *data)
{
struct wl_input_device *device =
container_of(listener, struct wl_input_device,
pointer_focus_listener);
struct wl_pointer *pointer =
container_of(listener, struct wl_pointer, focus_listener);
device->pointer_focus_resource = NULL;
pointer->focus_resource = NULL;
}
static void
lose_keyboard_focus(struct wl_listener *listener, void *data)