[PATCH] Add wl_display_remove_global.

Laszlo Agocs laszlo.p.agocs at nokia.com
Tue Jun 14 01:35:46 PDT 2011


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.
---
 protocol/wayland.xml     |    5 +++++
 wayland/wayland-client.c |   15 +++++++++++++++
 wayland/wayland-server.c |   30 ++++++++++++++++++++++++++++++
 wayland/wayland-server.h |    3 +++
 4 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/protocol/wayland.xml b/protocol/wayland.xml
index 9d0a539..6391c90 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 932f8b4..b17e790 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 886ec69..e5006e1 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... */
 
@@ -656,6 +662,30 @@ 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 = NULL, *p;
+	wl_list_for_each(p, &display->global_list, link)
+		if (p->object == object) {
+			global = p;
+			break;
+		}
+	if (global) {
+		struct wl_client *client;
+		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;
+	}
+	return -1;
+}
+
 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,
-- 
1.7.1


--------------060608020603020609000301--


More information about the wayland-devel mailing list