[PATCH wayland] Convert wl_input_device to wl_seat (and friends)
Daniel Stone
daniel at fooishbar.org
Wed May 16 10:44:40 PDT 2012
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 at fooishbar.org>
---
TODO | 10 --
protocol/wayland.xml | 145 +++++++++++++++--------
src/data-device.c | 192 +++++++++++++++----------------
src/wayland-server.c | 310 +++++++++++++++++++++++++++++++++-----------------
src/wayland-server.h | 143 +++++++++++++++--------
5 files changed, 494 insertions(+), 306 deletions(-)
diff --git a/TODO b/TODO
index 870a6e1..c8dcbac 100644
--- a/TODO
+++ b/TODO
@@ -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.
diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index 6b1562b..f14d1d2 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -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
diff --git a/src/data-device.c b/src/data-device.c
index 25b8743..8472da4 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -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);
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 62ab503..c1be56a 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -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)
{
- struct wl_input_device *device =
- container_of(listener, struct wl_input_device,
- keyboard_focus_listener);
+ struct wl_keyboard *keyboard =
+ container_of(listener, struct wl_keyboard, focus_listener);
- device->keyboard_focus_resource = NULL;
+ keyboard->focus_resource = NULL;
}
static void
default_grab_focus(struct wl_pointer_grab *grab,
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;
- wl_input_device_set_pointer_focus(device, surface, x, y);
+ wl_pointer_set_focus(pointer, surface, x, y);
}
static void
@@ -488,31 +486,28 @@ default_grab_motion(struct wl_pointer_grab *grab,
{
struct wl_resource *resource;
- resource = grab->input_device->pointer_focus_resource;
+ resource = grab->pointer->focus_resource;
if (resource)
- wl_input_device_send_motion(resource, time, x, y);
+ wl_pointer_send_motion(resource, time, x, y);
}
static void
default_grab_button(struct wl_pointer_grab *grab,
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;
uint32_t serial;
- resource = device->pointer_focus_resource;
+ resource = pointer->focus_resource;
if (resource) {
serial = wl_display_next_serial(resource->client->display);
- wl_input_device_send_button(resource, serial, time,
- button, state);
+ wl_pointer_send_button(resource, serial, time, button, state);
}
- if (device->button_count == 0 && state == 0)
- wl_input_device_set_pointer_focus(device,
- device->current,
- device->current_x,
- device->current_y);
+ if (pointer->button_count == 0 && state == 0)
+ wl_pointer_set_focus(pointer, pointer->current,
+ pointer->current_x, pointer->current_y);
}
static const struct wl_pointer_grab_interface
@@ -526,14 +521,14 @@ static void
default_grab_key(struct wl_keyboard_grab *grab,
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;
uint32_t serial;
- resource = device->keyboard_focus_resource;
+ resource = keyboard->focus_resource;
if (resource) {
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_input_device_init(struct wl_input_device *device)
+wl_pointer_init(struct wl_pointer *pointer)
{
- memset(device, 0, sizeof *device);
- wl_list_init(&device->resource_list);
- wl_array_init(&device->keys);
- device->pointer_focus_listener.notify = lose_pointer_focus;
- device->keyboard_focus_listener.notify = lose_keyboard_focus;
-
- device->default_pointer_grab.interface = &default_pointer_grab_interface;
- device->default_pointer_grab.input_device = device;
- device->pointer_grab = &device->default_pointer_grab;
-
- 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);
+ memset(pointer, 0, sizeof *pointer);
+ wl_list_init(&pointer->resource_list);
+ pointer->focus_listener.notify = lose_pointer_focus;
+ pointer->default_grab.interface = &default_pointer_grab_interface;
+ pointer->default_grab.pointer = pointer;
+ pointer->grab = &pointer->default_grab;
+
+ /* FIXME: Pick better co-ords. */
+ pointer->x = wl_fixed_from_int(100);
+ pointer->y = wl_fixed_from_int(100);
}
WL_EXPORT void
-wl_input_device_release(struct wl_input_device *device)
+wl_pointer_release(struct wl_pointer *pointer)
{
- if (device->keyboard_focus_resource)
- wl_list_remove(&device->keyboard_focus_listener.link);
+ /* XXX: What about pointer->resource_list? */
+ if (pointer->focus_resource)
+ wl_list_remove(&pointer->focus_listener.link);
+}
+
+WL_EXPORT void
+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;
+}
+
+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_EXPORT void
+wl_touch_init(struct wl_touch *touch)
+{
+ memset(touch, 0, sizeof *touch);
+ wl_list_init(&touch->resource_list);
+}
- if (device->pointer_focus_resource)
- wl_list_remove(&device->pointer_focus_listener.link);
+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);
+}
- /* XXX: What about device->resource_list? */
+WL_EXPORT void
+wl_seat_init(struct wl_seat *seat)
+{
+ memset(seat, 0, sizeof *seat);
- wl_array_release(&device->keys);
+ 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 *
@@ -599,113 +698,110 @@ find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
}
WL_EXPORT void
-wl_input_device_set_pointer_focus(struct wl_input_device *device,
- struct wl_surface *surface,
- wl_fixed_t sx, wl_fixed_t sy)
+wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
+ wl_fixed_t sx, wl_fixed_t sy)
{
struct wl_resource *resource;
uint32_t serial;
- if (device->pointer_focus == surface)
+ if (pointer->focus == surface)
return;
- resource = device->pointer_focus_resource;
+ resource = pointer->focus_resource;
if (resource) {
serial = wl_display_next_serial(resource->client->display);
- wl_input_device_send_pointer_leave(resource, serial,
- &device->pointer_focus->resource);
- wl_list_remove(&device->pointer_focus_listener.link);
+ wl_pointer_send_leave(resource, serial,
+ &pointer->focus->resource);
+ wl_list_remove(&pointer->focus_listener.link);
}
-
- resource = find_resource_for_surface(&device->resource_list, surface);
+ resource = find_resource_for_surface(&pointer->resource_list,
+ surface);
if (resource) {
serial = wl_display_next_serial(resource->client->display);
- wl_input_device_send_pointer_enter(resource, serial,
- &surface->resource,
- sx, sy);
+ wl_pointer_send_enter(resource, serial, &surface->resource,
+ sx, sy);
wl_signal_add(&resource->destroy_signal,
- &device->pointer_focus_listener);
- device->pointer_focus_serial = serial;
+ &pointer->focus_listener);
+ pointer->focus_serial = serial;
}
- device->pointer_focus_resource = resource;
- device->pointer_focus = surface;
- device->default_pointer_grab.focus = surface;
+ pointer->focus_resource = resource;
+ pointer->focus = surface;
+ pointer->default_grab.focus = surface;
}
WL_EXPORT void
-wl_input_device_set_keyboard_focus(struct wl_input_device *device,
- struct wl_surface *surface)
+wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface)
{
struct wl_resource *resource;
uint32_t serial;
- if (device->keyboard_focus == surface)
+ if (keyboard->focus == surface)
return;
- if (device->keyboard_focus_resource) {
- resource = device->keyboard_focus_resource;
+ if (keyboard->focus_resource) {
+ resource = keyboard->focus_resource;
serial = wl_display_next_serial(resource->client->display);
- wl_input_device_send_keyboard_leave(resource, serial,
- &device->keyboard_focus->resource);
- wl_list_remove(&device->keyboard_focus_listener.link);
+ wl_keyboard_send_leave(resource, serial,
+ &keyboard->focus->resource);
+ 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) {
serial = wl_display_next_serial(resource->client->display);
- wl_input_device_send_keyboard_enter(resource, serial,
- &surface->resource,
- &device->keys);
+ wl_keyboard_send_enter(resource, serial, &surface->resource,
+ &keyboard->keys);
wl_signal_add(&resource->destroy_signal,
- &device->keyboard_focus_listener);
- device->keyboard_focus_serial = serial;
+ &keyboard->focus_listener);
+ keyboard->focus_serial = serial;
}
- device->keyboard_focus_resource = resource;
- device->keyboard_focus = surface;
+ keyboard->focus_resource = resource;
+ keyboard->focus = surface;
}
WL_EXPORT void
-wl_input_device_start_keyboard_grab(struct wl_input_device *device,
- struct wl_keyboard_grab *grab)
+wl_keyboard_start_grab(struct wl_keyboard *keyboard,
+ struct wl_keyboard_grab *grab)
{
- device->keyboard_grab = grab;
- grab->input_device = device;
+ keyboard->grab = grab;
+ grab->keyboard = keyboard;
+ /* XXX focus? */
}
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_input_device_start_pointer_grab(struct wl_input_device *device,
- struct wl_pointer_grab *grab)
+wl_pointer_start_grab(struct wl_pointer *pointer, struct wl_pointer_grab *grab)
{
const struct wl_pointer_grab_interface *interface;
- device->pointer_grab = grab;
- interface = device->pointer_grab->interface;
- grab->input_device = device;
+ pointer->grab = grab;
+ interface = pointer->grab->interface;
+ grab->pointer = pointer;
- if (device->current)
- interface->focus(device->pointer_grab, device->current,
- device->current_x, device->current_y);
+ if (pointer->current)
+ interface->focus(pointer->grab, pointer->current,
+ pointer->current_x, pointer->current_y);
}
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;
- device->pointer_grab = &device->default_pointer_grab;
- interface = device->pointer_grab->interface;
- interface->focus(device->pointer_grab, device->current,
- device->current_x, device->current_y);
+ pointer->grab = &pointer->default_grab;
+ interface = pointer->grab->interface;
+ interface->focus(pointer->grab, pointer->current,
+ pointer->current_x, pointer->current_y);
}
static void
diff --git a/src/wayland-server.h b/src/wayland-server.h
index d426b35..31f6fe5 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -74,7 +74,10 @@ int wl_event_loop_get_fd(struct wl_event_loop *loop);
struct wl_client;
struct wl_display;
-struct wl_input_device;
+struct wl_seat;
+struct wl_pointer;
+struct wl_keyboard;
+struct wl_touch;
struct wl_listener;
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 {
const struct wl_pointer_grab_interface *interface;
- struct wl_input_device *input_device;
+ struct wl_pointer *pointer;
struct wl_surface *focus;
wl_fixed_t x, y;
};
@@ -211,7 +214,7 @@ struct wl_keyboard_grab_interface {
struct wl_keyboard_grab {
const struct wl_keyboard_grab_interface *interface;
- struct wl_input_device *input_device;
+ struct wl_keyboard *keyboard;
struct wl_surface *focus;
uint32_t key;
};
@@ -230,33 +233,68 @@ struct wl_data_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_resource *pointer_focus_resource;
- struct wl_surface *pointer_focus;
- struct wl_resource *keyboard_focus_resource;
- struct wl_surface *keyboard_focus;
- struct wl_array keys;
- uint32_t pointer_focus_serial;
- uint32_t keyboard_focus_serial;
- struct wl_listener pointer_focus_listener;
- struct wl_listener keyboard_focus_listener;
+ struct wl_surface *focus;
+ struct wl_resource *focus_resource;
+ struct wl_listener focus_listener;
+ uint32_t focus_serial;
+
+ struct wl_pointer_grab *grab;
+ struct wl_pointer_grab default_grab;
+ wl_fixed_t grab_x, grab_y;
+ uint32_t grab_button;
+ uint32_t grab_serial;
+ uint32_t grab_time;
wl_fixed_t x, y;
struct wl_surface *current;
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 grab_time;
- uint32_t grab_serial;
- wl_fixed_t grab_x, grab_y;
- uint32_t grab_button;
+};
+
+struct wl_keyboard {
+ 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;
- 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_data_source *drag_data_source;
@@ -268,12 +306,6 @@ struct wl_input_device {
struct wl_surface *drag_surface;
struct wl_listener drag_icon_listener;
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);
void
-wl_input_device_init(struct wl_input_device *device);
+wl_seat_init(struct wl_seat *seat);
void
-wl_input_device_release(struct wl_input_device *device);
+wl_seat_release(struct wl_seat *seat);
void
-wl_input_device_set_pointer_focus(struct wl_input_device *device,
- struct wl_surface *surface,
- wl_fixed_t sx, wl_fixed_t sy);
+wl_seat_set_pointer(struct wl_seat *seat, struct wl_pointer *pointer);
+void
+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
-wl_input_device_set_keyboard_focus(struct wl_input_device *device,
- struct wl_surface *surface);
+wl_pointer_init(struct wl_pointer *pointer);
void
-wl_data_device_set_keyboard_focus(struct wl_input_device *device);
-int
-wl_data_device_manager_init(struct wl_display *display);
+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_input_device_start_keyboard_grab(struct wl_input_device *device,
- struct wl_keyboard_grab *grab);
+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_input_device_end_keyboard_grab(struct wl_input_device *device);
+wl_keyboard_start_grab(struct wl_keyboard *device,
+ struct wl_keyboard_grab *grab);
+void
+wl_keyboard_end_grab(struct wl_keyboard *keyboard);
void
-wl_input_device_start_pointer_grab(struct wl_input_device *device,
- struct wl_pointer_grab *grab);
+wl_touch_init(struct wl_touch *touch);
+void
+wl_touch_release(struct wl_touch *touch);
+
void
-wl_input_device_end_pointer_grab(struct wl_input_device *device);
+wl_data_device_set_keyboard_focus(struct wl_seat *seat);
+
+int
+wl_data_device_manager_init(struct wl_display *display);
+
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);
void *
--
1.7.10
More information about the wayland-devel
mailing list