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.

This commit tracks these changes in weston and the clients, as well as
similar renames (e.g. weston_input_device -> weston_seat).  Some other
changes were necessary, e.g. renaming the name for the visible mouse
sprite from 'pointer' to 'cursor' so as to not conflict.

For simplicity, every seat is always exposed with all three interfaces,
although this will change as time goes on.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
This commit is contained in:
Daniel Stone
2012-05-16 18:45:18 +01:00
committed by Kristian Høgsberg
parent dc549932b7
commit 37816df646
18 changed files with 1030 additions and 1061 deletions
+3 -3
View File
@@ -37,7 +37,7 @@ handle_surface(struct test_client *client)
struct wl_resource *resource;
struct weston_surface *surface;
struct weston_layer *layer = client->data;
struct wl_input_device *device;
struct wl_seat *seat;
assert(sscanf(client->buf, "surface %u", &id) == 1);
fprintf(stderr, "got surface id %u\n", id);
@@ -53,10 +53,10 @@ handle_surface(struct test_client *client)
wl_list_insert(&layer->surface_list, &surface->layer_link);
weston_surface_damage(surface);
device = client->compositor->input_device;
seat = &client->compositor->seat->seat;
client->compositor->focus = 1; /* Make it work even if pointer is
* outside X window. */
notify_motion(device, 100,
notify_motion(seat, 100,
wl_fixed_from_int(150), wl_fixed_from_int(150));
test_client_send(client, "bye\n");
+81 -94
View File
@@ -37,7 +37,9 @@ struct display {
};
struct input {
struct wl_input_device *input_device;
struct wl_seat *seat;
struct wl_pointer *pointer;
struct wl_keyboard *keyboard;
GLfloat x, y;
uint32_t button_mask;
struct surface *pointer_focus;
@@ -56,8 +58,29 @@ struct surface {
};
static void
input_handle_motion(void *data, struct wl_input_device *input_device,
uint32_t time, wl_fixed_t x, wl_fixed_t y)
pointer_handle_enter(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface,
wl_fixed_t x, wl_fixed_t y)
{
struct input *input = data;
input->pointer_focus = wl_surface_get_user_data(surface);
input->x = wl_fixed_to_double(x);
input->y = wl_fixed_to_double(y);
}
static void
pointer_handle_leave(void *data, struct wl_pointer *pointer,
uint32_t serial, struct wl_surface *surface)
{
struct input *input = data;
input->pointer_focus = NULL;
}
static void
pointer_handle_motion(void *data, struct wl_pointer *pointer,
uint32_t time, wl_fixed_t x, wl_fixed_t y)
{
struct input *input = data;
@@ -66,9 +89,9 @@ input_handle_motion(void *data, struct wl_input_device *input_device,
}
static void
input_handle_button(void *data,
struct wl_input_device *input_device, uint32_t serial,
uint32_t time, uint32_t button, uint32_t state)
pointer_handle_button(void *data, struct wl_pointer *pointer,
uint32_t serial, uint32_t time, uint32_t button,
uint32_t state)
{
struct input *input = data;
uint32_t bit;
@@ -81,47 +104,15 @@ input_handle_button(void *data,
}
static void
input_handle_axis(void *data,
struct wl_input_device *input_device,
pointer_handle_axis(void *data, struct wl_pointer *pointer,
uint32_t time, uint32_t axis, int32_t value)
{
}
static void
input_handle_key(void *data, struct wl_input_device *input_device,
uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
{
}
static void
input_handle_pointer_enter(void *data,
struct wl_input_device *input_device,
uint32_t serial, struct wl_surface *surface,
wl_fixed_t x, wl_fixed_t y)
{
struct input *input = data;
input->pointer_focus = wl_surface_get_user_data(surface);
input->x = wl_fixed_to_double(x);
input->y = wl_fixed_to_double(y);
}
static void
input_handle_pointer_leave(void *data,
struct wl_input_device *input_device,
uint32_t serial, struct wl_surface *surface)
{
struct input *input = data;
input->pointer_focus = NULL;
}
static void
input_handle_keyboard_enter(void *data,
struct wl_input_device *input_device,
uint32_t serial,
struct wl_surface *surface,
struct wl_array *keys)
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface,
struct wl_array *keys)
{
struct input *input = data;
@@ -129,10 +120,8 @@ input_handle_keyboard_enter(void *data,
}
static void
input_handle_keyboard_leave(void *data,
struct wl_input_device *input_device,
uint32_t serial,
struct wl_surface *surface)
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
uint32_t serial, struct wl_surface *surface)
{
struct input *input = data;
@@ -140,55 +129,55 @@ input_handle_keyboard_leave(void *data,
}
static void
input_handle_touch_down(void *data,
struct wl_input_device *wl_input_device,
uint32_t serial, uint32_t time,
struct wl_surface *surface,
int32_t id, wl_fixed_t x, wl_fixed_t y)
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
uint32_t serial, uint32_t time, uint32_t key,
uint32_t state)
{
}
static const struct wl_pointer_listener pointer_listener = {
pointer_handle_enter,
pointer_handle_leave,
pointer_handle_motion,
pointer_handle_button,
pointer_handle_axis,
};
static const struct wl_keyboard_listener keyboard_listener = {
keyboard_handle_enter,
keyboard_handle_leave,
keyboard_handle_key,
};
static void
input_handle_touch_up(void *data,
struct wl_input_device *wl_input_device,
uint32_t serial, uint32_t time, int32_t id)
seat_handle_capabilities(void *data, struct wl_seat *seat,
enum wl_seat_caps_mask caps)
{
struct input *input = data;
if ((caps & WL_SEAT_CAPS_MASK_POINTER) && !input->pointer) {
input->pointer = wl_seat_get_pointer(seat);
wl_pointer_set_user_data(input->pointer, input);
wl_pointer_add_listener(input->pointer, &pointer_listener,
input);
} else if (!(caps & WL_SEAT_CAPS_MASK_POINTER) && input->pointer) {
wl_pointer_destroy(input->pointer);
input->pointer = NULL;
}
if ((caps & WL_SEAT_CAPS_MASK_KEYBOARD) && !input->keyboard) {
input->keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_set_user_data(input->keyboard, input);
wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
input);
} else if (!(caps & WL_SEAT_CAPS_MASK_KEYBOARD) && input->keyboard) {
wl_keyboard_destroy(input->keyboard);
input->keyboard = NULL;
}
}
static void
input_handle_touch_motion(void *data,
struct wl_input_device *wl_input_device,
uint32_t time, int32_t id,
wl_fixed_t x, wl_fixed_t y)
{
}
static void
input_handle_touch_frame(void *data,
struct wl_input_device *wl_input_device)
{
}
static void
input_handle_touch_cancel(void *data,
struct wl_input_device *wl_input_device)
{
}
static const struct wl_input_device_listener input_device_listener = {
input_handle_motion,
input_handle_button,
input_handle_axis,
input_handle_key,
input_handle_pointer_enter,
input_handle_pointer_leave,
input_handle_keyboard_enter,
input_handle_keyboard_leave,
input_handle_touch_down,
input_handle_touch_up,
input_handle_touch_motion,
input_handle_touch_frame,
input_handle_touch_cancel,
static const struct wl_seat_listener seat_listener = {
seat_handle_capabilities,
};
static void
@@ -240,16 +229,14 @@ handle_global(struct wl_display *_display, uint32_t id,
display->compositor =
wl_display_bind(display->display,
id, &wl_compositor_interface);
} else if (strcmp(interface, "wl_input_device") == 0) {
} else if (strcmp(interface, "wl_seat") == 0) {
input = malloc(sizeof *input);
input->input_device =
wl_display_bind(display->display, id,
&wl_input_device_interface);
input->seat = wl_display_bind(display->display, id,
&wl_seat_interface);
input->pointer_focus = NULL;
input->keyboard_focus = NULL;
wl_input_device_add_listener(input->input_device,
&input_device_listener, input);
wl_seat_add_listener(input->seat, &seat_listener, input);
display->input = input;
} else if (strcmp(interface, "wl_output") == 0) {
output = malloc(sizeof *output);