summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>2011-06-14 10:35:46 +0200
committerKristian Høgsberg <krh@bitplanet.net>2011-06-20 11:56:22 -0400
commitaae9f214e5f0d8d1deac4816fe40f76b2cf84f55 (patch)
tree295ce80b1dc89887f4b1b778454b46fd9f435892
parent9c36ea776b48decd84828d0b51842c91e2c9124a (diff)
Add wl_display_remove_global.
Change 4453ba084aae5a00318b9dfdeda95e8eaa17494c disallows using post_global with objects not on the global list. Therefore selection and drag offers have to be added to the global list from now on. However these may often get replaced by a newer object and thus need a way to remove a global from the global list.
-rw-r--r--protocol/wayland.xml5
-rw-r--r--wayland/wayland-client.c15
-rw-r--r--wayland/wayland-server.c31
-rw-r--r--wayland/wayland-server.h3
4 files changed, 54 insertions, 0 deletions
diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index ad35072..bf21425 100644
--- a/protocol/wayland.xml
+++ b/protocol/wayland.xml
@@ -53,6 +53,11 @@
<arg name="version" type="uint"/>
</event>
+ <!-- Notify the client of removed global objects. -->
+ <event name="global_remove">
+ <arg name="id" type="uint" />
+ </event>
+
<!-- Internal, deprecated, and will be changed. This is an object
IDs range that is used by the client to allocate object IDs
in "new_id" type arguments. The server sends range
diff --git a/wayland/wayland-client.c b/wayland/wayland-client.c
index 6a27514..e8266e1 100644
--- a/wayland/wayland-client.c
+++ b/wayland/wayland-client.c
@@ -259,6 +259,20 @@ display_handle_global(void *data,
}
static void
+display_handle_global_remove(void *data,
+ struct wl_display *display, uint32_t id)
+{
+ struct wl_global *global;
+
+ wl_list_for_each(global, &display->global_list, link)
+ if (global->id == id) {
+ wl_list_remove(&global->link);
+ free(global);
+ break;
+ }
+}
+
+static void
display_handle_range(void *data,
struct wl_display *display, uint32_t range)
{
@@ -298,6 +312,7 @@ display_handle_key(void *data,
static const struct wl_display_listener display_listener = {
display_handle_error,
display_handle_global,
+ display_handle_global_remove,
display_handle_range,
display_handle_key
};
diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index 017db08..5875656 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -58,6 +58,7 @@ struct wl_client {
struct wl_display *display;
struct wl_list resource_list;
uint32_t id_count;
+ struct wl_list link;
};
struct wl_display {
@@ -72,6 +73,7 @@ struct wl_display {
struct wl_list global_list;
struct wl_list socket_list;
+ struct wl_list client_list;
};
struct wl_frame_listener {
@@ -262,6 +264,8 @@ wl_client_create(struct wl_display *display, int fd)
return NULL;
}
+ wl_list_insert(display->client_list.prev, &client->link);
+
wl_list_init(&client->resource_list);
wl_display_post_range(display, client);
@@ -335,6 +339,7 @@ wl_client_destroy(struct wl_client *client)
wl_event_source_remove(client->source);
wl_connection_destroy(client->connection);
+ wl_list_remove(&client->link);
free(client);
}
@@ -596,6 +601,7 @@ wl_display_create(void)
wl_list_init(&display->frame_list);
wl_list_init(&display->global_list);
wl_list_init(&display->socket_list);
+ wl_list_init(&display->client_list);
display->client_id_range = 256; /* Gah, arbitrary... */
@@ -659,6 +665,31 @@ wl_display_add_global(struct wl_display *display,
return 0;
}
+WL_EXPORT int
+wl_display_remove_global(struct wl_display *display,
+ struct wl_object *object)
+{
+ struct wl_global *global;
+ struct wl_client *client;
+
+ wl_list_for_each(global, &display->global_list, link)
+ if (global->object == object)
+ break;
+
+ if (&global->link == &display->global_list)
+ return -1;
+
+ wl_list_for_each(client, &display->client_list, link)
+ wl_client_post_event(client,
+ &client->display->object,
+ WL_DISPLAY_GLOBAL_REMOVE,
+ global->object->id);
+ wl_list_remove(&global->link);
+ free(global);
+
+ return 0;
+}
+
WL_EXPORT void
wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
uint32_t time)
diff --git a/wayland/wayland-server.h b/wayland/wayland-server.h
index 6a042cd..d1c655a 100644
--- a/wayland/wayland-server.h
+++ b/wayland/wayland-server.h
@@ -93,6 +93,9 @@ int wl_display_add_global(struct wl_display *display,
struct wl_object *object,
wl_global_bind_func_t func);
+int wl_display_remove_global(struct wl_display *display,
+ struct wl_object *object);
+
struct wl_client *wl_client_create(struct wl_display *display, int fd);
void wl_client_destroy(struct wl_client *client);
void wl_client_post_error(struct wl_client *client, struct wl_object *object,