#include "config.h"
+#include <assert.h>
#define _POSIX_C_SOURCE 200809L
#include <stdint.h>
#include <stdlib.h>
#define SEAT_VERSION 7
+static const struct wl_seat_interface seat_impl;
+
static void seat_handle_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id);
static void seat_handle_display_destroy(struct wl_listener *listener,
void *data);
+static void seat_handle_selection_source_destroy(struct wl_listener *listener,
+ void *data);
static void seat_destroy(struct ds_seat *seat);
static struct ds_seat_client *seat_client_create(struct ds_seat *seat,
struct wl_client *wl_client);
wl_signal_init(&seat->events.keyboard_grab_end);
wl_signal_init(&seat->events.touch_grab_begin);
wl_signal_init(&seat->events.touch_grab_end);
+ wl_signal_init(&seat->events.set_selection);
seat->display_destroy.notify = seat_handle_display_destroy;
wl_display_add_destroy_listener(display, &seat->display_destroy);
return seat_client_for_wl_client(seat, wl_client);
}
+WL_EXPORT struct ds_seat_client *
+ds_seat_client_from_resource(struct wl_resource *resource)
+{
+ assert(wl_resource_instance_of(resource, &wl_seat_interface, &seat_impl));
+ return wl_resource_get_user_data(resource);
+}
+
WL_EXPORT void
ds_seat_client_add_destroy_listener(struct ds_seat_client *seat_client,
struct wl_listener *listener)
wl_signal_add(&seat_client->events.destroy, listener);
}
+WL_EXPORT void
+ds_seat_set_selection(struct ds_seat *seat, struct ds_data_source *source,
+ uint32_t serial)
+{
+ if (seat->selection_source &&
+ seat->selection_serial - serial < UINT32_MAX / 2) {
+ ds_dbg("Rejecting set selection selection_serial(%d) serial(%d)",
+ seat->selection_serial, serial);
+ return;
+ }
+
+ seat->selection_serial = serial;
+
+ if (seat->selection_source == source)
+ return;
+
+ if (seat->selection_source) {
+ /* TODO
+ wl_list_remove(&seat->selection_source_destroy.link);
+ ds_data_source_destroy(seat->selection_source);
+ */
+ seat->selection_source = NULL;
+
+ }
+
+ if (source) {
+ /* TODO
+ seat->selection_source_destroy.notify =
+ seat_handle_selection_source_destroy;
+ wl_signal_add(&source->events.destroy,
+ &seat->selection_source_destroy);
+ */
+
+ seat->selection_source = source;
+ }
+
+ wl_signal_emit(&seat->events.set_selection, seat);
+}
+
+struct ds_data_source *
+ds_seat_get_selection(struct ds_seat *seat)
+{
+ return seat->selection_source;
+}
+
+struct ds_seat *
+ds_seat_client_get_seat(struct ds_seat_client *seat_client)
+{
+ return seat_client->seat;
+}
+
+void
+ds_seat_add_set_selection_listener(struct ds_seat *seat,
+ struct wl_listener *listener)
+{
+ wl_signal_add(&seat->events.set_selection, listener);
+}
+
struct ds_seat_client *
seat_client_for_wl_client(struct ds_seat *seat, struct wl_client *wl_client)
{
}
static void
+seat_handle_selection_source_destroy(struct wl_listener *listener,
+ void *data)
+{
+ struct ds_seat *seat;
+
+ seat = wl_container_of(listener, seat, selection_source_destroy);
+
+ wl_list_remove(&seat->selection_source_destroy.link);
+ seat->selection_source = NULL;
+
+ wl_signal_emit(&seat->events.set_selection, seat);
+}
+
+static void
seat_destroy(struct ds_seat *seat)
{
struct ds_seat_client *seat_client, *tmp;
struct wl_display *display;
struct wl_global *global;
+ struct ds_data_source *selection_source;
+ uint32_t selection_serial;
+
struct wl_list clients; // ds_seat_client::link
struct ds_seat_pointer pointer;
struct ds_seat_touch touch;
struct wl_listener display_destroy;
+ struct wl_listener selection_source_destroy;
struct {
struct wl_signal destroy;
struct wl_signal touch_grab_begin;
struct wl_signal touch_grab_end;
+
+ struct wl_signal set_selection;
+ struct wl_signal start_drag;
} events;
};