summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2012-04-12 15:29:48 -0400
committerKristian Høgsberg <krh@bitplanet.net>2012-04-12 15:29:48 -0400
commit36914ef57331eadd6e5daee4aa92ed7be89c4e74 (patch)
tree71adce24d895bfc08b85592a0f7a5539216dfae4
parent5535f155d8567a07596660a18b6d38a46acfe987 (diff)
Introduce wl_signaltesting
This is mostly renaming and consolidating the listener_list pattern into something more concise and reusable.
-rw-r--r--src/data-device.c45
-rw-r--r--src/wayland-server.c25
-rw-r--r--src/wayland-server.h60
3 files changed, 75 insertions, 55 deletions
diff --git a/src/data-device.c b/src/data-device.c
index 1d22a84..563bf7f 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -111,12 +111,12 @@ wl_data_source_send_offer(struct wl_data_source *source,
offer->resource.object.implementation =
(void (**)(void)) source->offer_interface;
offer->resource.data = offer;
- wl_list_init(&offer->resource.destroy_listener_list);
+ wl_signal_init(&offer->resource.destroy_signal);
offer->source = source;
- offer->source_destroy_listener.func = destroy_offer_data_source;
- wl_list_insert(&source->resource.destroy_listener_list,
- &offer->source_destroy_listener.link);
+ offer->source_destroy_listener.notify = destroy_offer_data_source;
+ wl_signal_add(&source->resource.destroy_signal,
+ &offer->source_destroy_listener);
wl_client_add_resource(target->client, &offer->resource);
@@ -209,9 +209,9 @@ drag_grab_focus(struct wl_pointer_grab *grab,
x, y, offer);
device->drag_focus = surface;
- device->drag_focus_listener.func = destroy_drag_focus;
- wl_list_insert(resource->destroy_listener_list.prev,
- &device->drag_focus_listener.link);
+ device->drag_focus_listener.notify = destroy_drag_focus;
+ wl_signal_add(&resource->destroy_signal,
+ &device->drag_focus_listener);
device->drag_focus_resource = resource;
grab->focus = surface;
}
@@ -305,7 +305,6 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
struct wl_resource *icon_resource, uint32_t serial)
{
struct wl_input_device *device = resource->data;
- struct wl_listener *listener, *tmp;
/* FIXME: Check that client has implicit grab on the origin
* surface that matches the given time. */
@@ -315,19 +314,16 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
device->drag_grab.interface = &drag_grab_interface;
device->drag_data_source = source_resource->data;
- device->drag_data_source_listener.func = destroy_data_device_source;
- wl_list_insert(source_resource->destroy_listener_list.prev,
- &device->drag_data_source_listener.link);
+ device->drag_data_source_listener.notify = destroy_data_device_source;
+ wl_signal_add(&source_resource->destroy_signal,
+ &device->drag_data_source_listener);
if (icon_resource) {
device->drag_surface = icon_resource->data;
- device->drag_icon_listener.func = destroy_data_device_icon;
- wl_list_insert(icon_resource->destroy_listener_list.prev,
- &device->drag_icon_listener.link);
-
- wl_list_for_each_safe(listener, tmp,
- &device->drag_icon_listener_list, link)
- listener->func(listener, icon_resource);
+ device->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);
}
wl_input_device_start_pointer_grab(device, &device->drag_grab);
@@ -357,7 +353,6 @@ wl_input_device_set_selection(struct wl_input_device *device,
struct wl_data_source *source)
{
struct wl_resource *data_device, *focus, *offer;
- struct wl_selection_listener *listener, *next;
if (device->selection_data_source) {
device->selection_data_source->cancel(device->selection_data_source);
@@ -378,14 +373,12 @@ wl_input_device_set_selection(struct wl_input_device *device,
}
}
- wl_list_for_each_safe(listener, next,
- &device->selection_listener_list, link)
- listener->func(listener, device);
+ wl_signal_emit(&device->selection_signal, device);
- device->selection_data_source_listener.func =
+ device->selection_data_source_listener.notify =
destroy_selection_data_source;
- wl_list_insert(source->resource.destroy_listener_list.prev,
- &device->selection_data_source_listener.link);
+ wl_signal_add(&source->resource.destroy_signal,
+ &device->selection_data_source_listener);
}
static void
@@ -438,7 +431,7 @@ create_data_source(struct wl_client *client,
source->resource.object.implementation =
(void (**)(void)) &data_source_interface;
source->resource.data = source;
- wl_list_init(&source->resource.destroy_listener_list);
+ wl_signal_init(&source->resource.destroy_signal);
source->offer_interface = &data_offer_interface;
source->cancel = data_source_cancel;
diff --git a/src/wayland-server.c b/src/wayland-server.c
index e6eccd6..bbb65d0 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -368,7 +368,7 @@ wl_client_add_resource(struct wl_client *client,
resource->object.id, resource);
resource->client = client;
- wl_list_init(&resource->destroy_listener_list);
+ wl_signal_init(&resource->destroy_signal);
}
WL_EXPORT void
@@ -382,10 +382,8 @@ static void
destroy_resource(void *element, void *data)
{
struct wl_resource *resource = element;
- struct wl_listener *l, *next;
- wl_list_for_each_safe(l, next, &resource->destroy_listener_list, link)
- l->func(l, resource);
+ wl_signal_emit(&resource->destroy_signal, resource);
if (resource->destroy)
resource->destroy(resource);
@@ -527,8 +525,8 @@ wl_input_device_init(struct wl_input_device *device)
memset(device, 0, sizeof *device);
wl_list_init(&device->resource_list);
wl_array_init(&device->keys);
- device->pointer_focus_listener.func = lose_pointer_focus;
- device->keyboard_focus_listener.func = lose_keyboard_focus;
+ 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;
@@ -540,9 +538,8 @@ wl_input_device_init(struct wl_input_device *device)
wl_list_init(&device->drag_resource_list);
device->selection_data_source = NULL;
- wl_list_init(&device->selection_listener_list);
-
- wl_list_init(&device->drag_icon_listener_list);
+ wl_signal_init(&device->selection_signal);
+ wl_signal_init(&device->drag_icon_signal);
device->x = 100;
device->y = 100;
@@ -604,8 +601,8 @@ wl_input_device_set_pointer_focus(struct wl_input_device *device,
wl_input_device_send_pointer_enter(resource, serial,
&surface->resource,
sx, sy);
- wl_list_insert(resource->destroy_listener_list.prev,
- &device->pointer_focus_listener.link);
+ wl_signal_add(&resource->destroy_signal,
+ &device->pointer_focus_listener);
device->pointer_focus_serial = serial;
}
@@ -638,8 +635,8 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device,
wl_input_device_send_keyboard_enter(resource, serial,
&surface->resource,
&device->keys);
- wl_list_insert(resource->destroy_listener_list.prev,
- &device->keyboard_focus_listener.link);
+ wl_signal_add(&resource->destroy_signal,
+ &device->keyboard_focus_listener);
device->keyboard_focus_serial = serial;
}
@@ -1036,7 +1033,7 @@ wl_client_add_object(struct wl_client *client,
resource->client = client;
resource->data = data;
resource->destroy = (void *) free;
- wl_list_init(&resource->destroy_listener_list);
+ wl_signal_init(&resource->destroy_signal);
if (wl_map_insert_at(&client->objects, resource->object.id, resource) < 0) {
wl_resource_post_no_memory(client->display_resource);
diff --git a/src/wayland-server.h b/src/wayland-server.h
index 4b34547..3090032 100644
--- a/src/wayland-server.h
+++ b/src/wayland-server.h
@@ -114,11 +114,53 @@ wl_client_new_object(struct wl_client *client,
const struct wl_interface *interface,
const void *implementation, void *data);
+struct wl_listener {
+ struct wl_list link;
+ void (*notify)(struct wl_listener *listener, void *data);
+};
+
+struct wl_signal {
+ struct wl_list listener_list;
+};
+
+static inline void
+wl_signal_init(struct wl_signal *signal)
+{
+ wl_list_init(&signal->listener_list);
+}
+
+static inline void
+wl_signal_add(struct wl_signal *signal, struct wl_listener *listener)
+{
+ wl_list_insert(signal->listener_list.prev, &listener->link);
+}
+
+static inline struct wl_listener *
+wl_signal_get(struct wl_signal *signal, void *notify)
+{
+ struct wl_listener *l;
+
+ wl_list_for_each(l, &signal->listener_list, link)
+ if (l->notify == notify)
+ return l;
+
+ return NULL;
+}
+
+static inline void
+wl_signal_emit(struct wl_signal *signal, void *data)
+{
+ struct wl_listener *l, *next;
+
+ wl_list_for_each_safe(l, next, &signal->listener_list, link)
+ l->notify(l, data);
+}
+
struct wl_resource {
struct wl_object object;
void (*destroy)(struct wl_resource *resource);
struct wl_list link;
- struct wl_list destroy_listener_list;
+ struct wl_signal destroy_signal;
struct wl_client *client;
void *data;
};
@@ -129,12 +171,6 @@ struct wl_buffer {
uint32_t busy_count;
};
-struct wl_listener {
- struct wl_list link;
- void (*func)(struct wl_listener *listener,
- struct wl_resource *resource);
-};
-
struct wl_surface {
struct wl_resource resource;
};
@@ -183,12 +219,6 @@ struct wl_data_source {
void (*cancel)(struct wl_data_source *source);
};
-struct wl_selection_listener {
- void (*func)(struct wl_selection_listener *listener,
- struct wl_input_device *device);
- struct wl_list link;
-};
-
struct wl_input_device {
struct wl_list resource_list;
struct wl_resource *pointer_focus_resource;
@@ -226,11 +256,11 @@ struct wl_input_device {
struct wl_pointer_grab drag_grab;
struct wl_surface *drag_surface;
struct wl_listener drag_icon_listener;
- struct wl_list drag_icon_listener_list;
+ struct wl_signal drag_icon_signal;
struct wl_data_source *selection_data_source;
struct wl_listener selection_data_source_listener;
- struct wl_list selection_listener_list;
+ struct wl_signal selection_signal;
};