Add wl_display_remove_global.

Change 4453ba084a 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.
This commit is contained in:
Laszlo Agocs 2011-06-14 10:35:46 +02:00 committed by Kristian Høgsberg
parent 9c36ea776b
commit aae9f214e5
4 changed files with 54 additions and 0 deletions

View file

@ -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

View file

@ -258,6 +258,20 @@ display_handle_global(void *data,
id, interface, version, listener->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
};

View file

@ -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)

View file

@ -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,