wl_list_remove(wl_resource_get_link(resource));
}
-static void
-pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial,
- struct wl_resource *surface_resource, int32_t x, int32_t y)
+void
+pepper_input_init(pepper_input_t *input, pepper_seat_t *seat)
{
- /* TODO */
-}
+ input->seat = seat;
+ input->focus = NULL;
-static void
-pointer_release(struct wl_client *client, struct wl_resource *resource)
-{
- wl_resource_destroy(resource);
+ wl_list_init(&input->resource_list);
+ wl_list_init(&input->focus_resource_list);
}
-static const struct wl_pointer_interface pointer_interface =
+void
+pepper_input_fini(pepper_input_t *input)
{
- pointer_set_cursor,
- pointer_release,
-};
+ wl_list_remove(&input->focus_destroy_listener.link);
+}
-static void
-seat_get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+void
+pepper_input_bind_resource(pepper_input_t *input,
+ struct wl_client *client, int version, uint32_t id,
+ const struct wl_interface *interface, const void *impl, void *data)
{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- struct wl_resource *r;
+ struct wl_resource *resource = wl_resource_create(client, interface, version, id);
- if (!seat->pointer.active)
- return;
-
- r = wl_resource_create(client, &wl_pointer_interface, wl_resource_get_version(resource), id);
- if (!r)
+ if (!resource)
{
wl_client_post_no_memory(client);
return;
}
- wl_list_insert(&seat->pointer.resource_list, wl_resource_get_link(r));
- wl_resource_set_implementation(r, &pointer_interface, &seat->pointer, unbind_resource);
-
- /* TODO */
-
-}
-
-static void
-keyboard_release(struct wl_client *client, struct wl_resource *resource)
-{
- wl_resource_destroy(resource);
+ wl_list_insert(&input->resource_list, wl_resource_get_link(resource));
+ wl_resource_set_implementation(resource, impl, data, unbind_resource);
}
-static const struct wl_keyboard_interface keyboard_interface =
+void
+pepper_input_set_focus(pepper_input_t *input, pepper_view_t *focus)
{
- keyboard_release,
-};
-
-static void
-seat_get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id)
-{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- struct wl_resource *r;
-
- if (!seat->keyboard.active)
+ if (input->focus == focus)
return;
- r = wl_resource_create(client, &wl_keyboard_interface, wl_resource_get_version(resource), id);
- if (!r)
+ PEPPER_ASSERT(!focus || focus->surface != NULL);
+
+ if (input->focus)
{
- wl_client_post_no_memory(client);
- return;
+ wl_list_insert_list(&input->resource_list, &input->focus_resource_list);
+ wl_list_init(&input->focus_resource_list);
+ wl_list_remove(&input->focus_destroy_listener.link);
}
- wl_list_insert(&seat->keyboard.resource_list, wl_resource_get_link(r));
- wl_resource_set_implementation(r, &keyboard_interface, &seat->keyboard, unbind_resource);
-
- /* TODO */
+ input->focus = focus;
-}
-
-static void
-touch_release(struct wl_client *client, struct wl_resource *resource)
-{
- wl_resource_destroy(resource);
-}
-
-static const struct wl_touch_interface touch_interface =
-{
- touch_release,
-};
-
-static void
-seat_get_touch(struct wl_client *client, struct wl_resource *resource, uint32_t id)
-{
- pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
- struct wl_resource *r;
-
- if (!seat->touch.active)
- return;
-
- r = wl_resource_create(client, &wl_touch_interface, wl_resource_get_version(resource), id);
- if (!r)
+ if (focus)
{
- wl_client_post_no_memory(client);
- return;
- }
+ struct wl_resource *resource, *tmp;
+ struct wl_client *client = wl_resource_get_client(focus->surface->resource);
- wl_list_insert(&seat->touch.resource_list, wl_resource_get_link(r));
- wl_resource_set_implementation(r, &touch_interface, &seat->touch, unbind_resource);
-
- /* TODO */
+ wl_resource_for_each_safe(resource, tmp, &input->resource_list)
+ {
+ if (wl_resource_get_client(resource) == client)
+ {
+ wl_list_remove(wl_resource_get_link(resource));
+ wl_list_insert(&input->focus_resource_list, wl_resource_get_link(resource));
+ }
+ }
+ wl_resource_add_destroy_listener(focus->surface->resource, &input->focus_destroy_listener);
+ }
}
static const struct wl_seat_interface seat_interface = {
- seat_get_pointer,
- seat_get_keyboard,
- seat_get_touch,
+ pepper_pointer_bind_resource,
+ pepper_keyboard_bind_resource,
+ pepper_touch_bind_resource,
};
static void
if (seat->name)
free(seat->name);
- if (seat->pointer.active)
- {
- wl_resource_for_each_safe(resource, tmp, &seat->pointer.resource_list)
- wl_resource_destroy(resource);
- pepper_object_fini(&seat->pointer.base);
- }
+ if (seat->pointer)
+ pepper_pointer_destroy(seat->pointer);
- if (seat->keyboard.active)
- {
- wl_resource_for_each_safe(resource, tmp, &seat->keyboard.resource_list)
- wl_resource_destroy(resource);
- pepper_object_fini(&seat->keyboard.base);
- }
+ if (seat->keyboard)
+ pepper_keyboard_destroy(seat->keyboard);
- if (seat->touch.active)
- {
- wl_resource_for_each_safe(resource, tmp, &seat->touch.resource_list)
- wl_resource_destroy(resource);
- pepper_object_fini(&seat->touch.base);
- }
+ if (seat->touch)
+ pepper_touch_destroy(seat->touch);
if (seat->global)
wl_global_destroy(seat->global);
PEPPER_API pepper_pointer_t *
pepper_seat_get_pointer(pepper_seat_t *seat)
{
- if (seat->pointer.active)
- return &seat->pointer;
-
- return NULL;
+ return seat->pointer;
}
PEPPER_API pepper_keyboard_t *
pepper_seat_get_keyboard(pepper_seat_t *seat)
{
- if (seat->keyboard.active)
- return &seat->keyboard;
-
- return NULL;
+ return seat->keyboard;
}
PEPPER_API pepper_touch_t *
pepper_seat_get_touch(pepper_seat_t *seat)
{
- if (seat->touch.active)
- return &seat->touch;
-
- return NULL;
+ return seat->touch;
}
PEPPER_API const char *
return seat->name;
}
-PEPPER_API void
-pepper_pointer_set_position(pepper_pointer_t *pointer, int32_t x, int32_t y)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_get_position(pepper_pointer_t *pointer, int32_t *x, int32_t *y)
-{
- /* TODO */
-}
-
-PEPPER_API pepper_view_t *
-pepper_pointer_get_focus_view(pepper_pointer_t *pointer)
-{
- /* TODO */
- return NULL;
-}
-
-PEPPER_API void
-pepper_pointer_set_focus_view(pepper_pointer_t *pointer, pepper_view_t *view)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_send_leave(pepper_pointer_t *pointer, pepper_view_t *target_view)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *target_view)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_send_motion(pepper_pointer_t *pointer,
- pepper_view_t *target_view,
- uint32_t time,
- int32_t x,
- int32_t y)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_send_button(pepper_pointer_t *pointer,
- pepper_view_t *target_view,
- uint32_t time,
- uint32_t button,
- uint32_t state)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_pointer_send_axis(pepper_pointer_t *pointer,
- pepper_view_t *target_view,
- uint32_t time,
- uint32_t axis,
- uint32_t amount)
-{
- /* TODO */
-}
-
-PEPPER_API pepper_view_t *
-pepper_keyboard_get_focus_view(pepper_keyboard_t *keyboard)
-{
- /* TODO */
- return NULL;
-}
-
-PEPPER_API void
-pepper_keyboard_set_focus_view(pepper_keyboard_t *keyboard, pepper_view_t *view)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_keyboard_send_leave(pepper_keyboard_t *keyboard, pepper_view_t *target_view)
-{
- /* TODO */
-}
-
-PEPPER_API void
-pepper_keyboard_send_enter(pepper_keyboard_t *keyboard, pepper_view_t *target_view)
-{
- /* TODO */
-}
-
static void
seat_update_pointer_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_POINTER) && !seat->pointer.active)
+ if ((seat->caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer)
{
- seat->pointer.active = PEPPER_TRUE;
- pepper_object_init(&seat->pointer.base, PEPPER_OBJECT_POINTER);
- wl_list_init(&seat->pointer.resource_list);
+ seat->pointer = pepper_pointer_create(seat);
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_ADD, &seat->pointer);
}
- else if (!(seat->caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer.active)
+ else if (!(seat->caps & WL_SEAT_CAPABILITY_POINTER) && seat->pointer)
{
- seat->pointer.active = PEPPER_FALSE;
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_POINTER_REMOVE, &seat->pointer);
- pepper_object_fini(&seat->pointer.base);
+ pepper_pointer_destroy(seat->pointer);
}
}
static void
seat_update_keyboard_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->keyboard.active)
+ if ((seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && !seat->keyboard)
{
- seat->keyboard.active = PEPPER_TRUE;
- pepper_object_init(&seat->keyboard.base, PEPPER_OBJECT_KEYBOARD);
- wl_list_init(&seat->keyboard.resource_list);
+ seat->keyboard = pepper_keyboard_create(seat);
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_ADD, &seat->keyboard);
}
- else if (!(seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard.active)
+ else if (!(seat->caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard)
{
- seat->keyboard.active = PEPPER_FALSE;
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_KEYBOARD_REMOVE, &seat->keyboard);
- pepper_object_fini(&seat->keyboard.base);
+ pepper_keyboard_destroy(seat->keyboard);
}
}
static void
seat_update_touch_cap(pepper_seat_t *seat)
{
- if ((seat->caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->touch.active)
+ if ((seat->caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->touch)
{
- seat->touch.active = PEPPER_TRUE;
- pepper_object_init(&seat->touch.base, PEPPER_OBJECT_TOUCH);
- wl_list_init(&seat->touch.resource_list);
+ seat->touch = pepper_touch_create(seat);
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_ADD, &seat->touch);
}
- else if (!(seat->caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch.active)
+ else if (!(seat->caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch)
{
- seat->touch.active = PEPPER_FALSE;
pepper_object_emit_event(&seat->base, PEPPER_EVENT_SEAT_TOUCH_REMOVE, &seat->touch);
- pepper_object_fini(&seat->touch.base);
+ pepper_touch_destroy(seat->touch);
}
}
typedef struct pepper_data_source pepper_data_source_t;
typedef struct pepper_data_device pepper_data_device_t;
typedef struct pepper_data_offer pepper_data_offer_t;
+typedef struct pepper_input pepper_input_t;
struct pepper_object
{
pepper_transform_pixman_region(pixman_region32_t *region, const pepper_mat4_t *matrix);
/* Input */
+struct pepper_input
+{
+ pepper_seat_t *seat;
+ struct wl_list resource_list;
+ pepper_view_t *focus;
+ struct wl_listener focus_destroy_listener;
+ struct wl_list focus_resource_list;
+};
+
+void
+pepper_input_init(pepper_input_t *input, pepper_seat_t *seat);
+
+void
+pepper_input_fini(pepper_input_t *input);
+
+void
+pepper_input_bind_resource(pepper_input_t *input,
+ struct wl_client *client, int version, uint32_t id,
+ const struct wl_interface *interface, const void *impl, void *data);
+
+void
+pepper_input_set_focus(pepper_input_t *input, pepper_view_t *view);
+
struct pepper_pointer
{
pepper_object_t base;
- pepper_seat_t *seat;
- pepper_bool_t active;
- struct wl_list resource_list;
+ pepper_input_t input;
};
+pepper_pointer_t *
+pepper_pointer_create(pepper_seat_t *seat);
+
+void
+pepper_pointer_destroy(pepper_pointer_t *pointer);
+
+void
+pepper_pointer_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+
struct pepper_keyboard
{
pepper_object_t base;
- pepper_seat_t *seat;
- pepper_bool_t active;
- struct wl_list resource_list;
+ pepper_input_t input;
};
+pepper_keyboard_t *
+pepper_keyboard_create(pepper_seat_t *seat);
+
+void
+pepper_keyboard_destroy(pepper_keyboard_t *keyboard);
+
+void
+pepper_keyboard_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+
struct pepper_touch
{
pepper_object_t base;
- pepper_seat_t *seat;
- pepper_bool_t active;
- struct wl_list resource_list;
+ pepper_input_t input;
};
+pepper_touch_t *
+pepper_touch_create(pepper_seat_t *seat);
+
+void
+pepper_touch_destroy(pepper_touch_t *touch);
+
+void
+pepper_touch_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id);
+
struct pepper_seat
{
pepper_object_t base;
enum wl_seat_capability caps;
uint32_t modifier;
- pepper_pointer_t pointer;
- pepper_keyboard_t keyboard;
- pepper_touch_t touch;
+ pepper_pointer_t *pointer;
+ pepper_keyboard_t *keyboard;
+ pepper_touch_t *touch;
pepper_list_t input_device_list;
};
PEPPER_API pepper_output_t *
pepper_compositor_find_output(pepper_compositor_t *compositor, const char *name);
-/* Input. */
+/* Seat & Input Device. */
PEPPER_API pepper_seat_t *
pepper_compositor_add_seat(pepper_compositor_t *compositor, const char *seat_name);
PEPPER_API void
pepper_seat_remove_input_device(pepper_seat_t *seat, pepper_input_device_t *device);
+PEPPER_API const char *
+pepper_input_device_get_property(pepper_input_device_t *device, const char *key);
+
+/* Pointer. */
PEPPER_API void
pepper_pointer_set_position(pepper_pointer_t *pointer, int32_t x, int32_t y);
PEPPER_API void
pepper_pointer_get_position(pepper_pointer_t *pointer, int32_t *x, int32_t *y);
-PEPPER_API pepper_view_t *
-pepper_pointer_get_focus_view(pepper_pointer_t *pointer);
-
PEPPER_API void
-pepper_pointer_set_focus_view(pepper_pointer_t *pointer, pepper_view_t *view);
+pepper_pointer_set_focus(pepper_pointer_t *pointer, pepper_view_t *focus);
+
+PEPPER_API pepper_view_t *
+pepper_pointer_get_focus(pepper_pointer_t *pointer);
PEPPER_API void
pepper_pointer_send_leave(pepper_pointer_t *pointer, pepper_view_t *target_view);
pepper_pointer_send_axis(pepper_pointer_t *pointer, pepper_view_t *target_view,
uint32_t time, uint32_t axis, uint32_t amount);
-PEPPER_API pepper_view_t *
-pepper_keyboard_get_focus_view(pepper_keyboard_t *keyboard);
-
+/* Keyboard. */
PEPPER_API void
-pepper_keyboard_set_focus_view(pepper_keyboard_t *keyboard, pepper_view_t *view);
+pepper_keyboard_set_focus(pepper_keyboard_t *keyboard, pepper_view_t *focus);
+
+PEPPER_API pepper_view_t *
+pepper_keyboard_get_focus(pepper_keyboard_t *keyboard);
PEPPER_API void
pepper_keyboard_send_leave(pepper_keyboard_t *keyboard, pepper_view_t *target_view);
PEPPER_API void
pepper_keyboard_send_enter(pepper_keyboard_t *keyboard, pepper_view_t *target_view);
-PEPPER_API const char *
-pepper_input_device_get_property(pepper_input_device_t *device, const char *key);
+/* Touch. */
+PEPPER_API void
+pepper_touch_set_focus(pepper_touch_t *touch, pepper_view_t *focus);
+
+PEPPER_API pepper_view_t *
+pepper_touch_get_focus(pepper_touch_t *touch);
/* Surface. */
PEPPER_API const char *
--- /dev/null
+#include "pepper-internal.h"
+
+static void
+pointer_set_cursor(struct wl_client *client, struct wl_resource *resource, uint32_t serial,
+ struct wl_resource *surface_resource, int32_t x, int32_t y)
+{
+ /* TODO: */
+}
+
+static void
+pointer_release(struct wl_client *client, struct wl_resource *resource)
+{
+ wl_resource_destroy(resource);
+}
+
+static const struct wl_pointer_interface pointer_impl =
+{
+ pointer_set_cursor,
+ pointer_release,
+};
+
+pepper_pointer_t *
+pepper_pointer_create(pepper_seat_t *seat)
+{
+ pepper_pointer_t *pointer =
+ (pepper_pointer_t *)pepper_object_alloc(PEPPER_OBJECT_TOUCH, sizeof(pepper_pointer_t));
+
+ PEPPER_CHECK(pointer, return NULL, "pepper_object_alloc() failed.\n");
+
+ pepper_input_init(&pointer->input, seat);
+ return pointer;
+}
+
+void
+pepper_pointer_destroy(pepper_pointer_t *pointer)
+{
+ pepper_input_fini(&pointer->input);
+ free(pointer);
+}
+
+void
+pepper_pointer_bind_resource(struct wl_client *client, struct wl_resource *resource, uint32_t id)
+{
+ pepper_seat_t *seat = (pepper_seat_t *)wl_resource_get_user_data(resource);
+
+ if (!seat->pointer)
+ return;
+
+ pepper_input_bind_resource(&seat->pointer->input, client, wl_resource_get_version(resource),
+ id, &wl_pointer_interface, &pointer_impl, seat->pointer);
+}
+
+PEPPER_API void
+pepper_pointer_set_position(pepper_pointer_t *pointer, int32_t x, int32_t y)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_get_position(pepper_pointer_t *pointer, int32_t *x, int32_t *y)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_set_focus(pepper_pointer_t *pointer, pepper_view_t *focus)
+{
+ /* TODO: */
+}
+
+PEPPER_API pepper_view_t *
+pepper_pointer_get_focus(pepper_pointer_t *pointer)
+{
+ /* TODO: */
+ return NULL;
+}
+
+PEPPER_API void
+pepper_pointer_send_leave(pepper_pointer_t *pointer, pepper_view_t *target_view)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_send_enter(pepper_pointer_t *pointer, pepper_view_t *target_view)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_send_motion(pepper_pointer_t *pointer, pepper_view_t *target_view,
+ uint32_t time, int32_t x, int32_t y)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_send_button(pepper_pointer_t *pointer, pepper_view_t *target_view,
+ uint32_t time, uint32_t button, uint32_t state)
+{
+ /* TODO: */
+}
+
+PEPPER_API void
+pepper_pointer_send_axis(pepper_pointer_t *pointer, pepper_view_t *target_view,
+ uint32_t time, uint32_t axis, uint32_t amount)
+{
+ /* TODO: */
+}