Commit e9088930 authored by Kristian Høgsberg's avatar Kristian Høgsberg
Browse files

Bind globals to client provided object IDs

parent a7c68243
......@@ -31,9 +31,10 @@
It is used for internal wayland protocol features. -->
<interface name="wl_display" version="1">
<request name="bind">
<arg name="id" type="uint"/>
<arg name="name" type="uint"/>
<arg name="interface" type="string"/>
<arg name="version" type="uint"/>
<arg name="id" type="new_id" interface="wl_object"/>
<!-- sync is an just an echo, which will reply with a key event.
......@@ -347,19 +347,6 @@ emit_stubs(struct wl_list *message_list, struct interface *interface)
if (strcmp(interface->name, "wl_display") == 0)
printf("static inline struct %s *\n"
"%s_create(struct wl_display *display, uint32_t id, uint32_t version)\n"
"\twl_display_bind(display, id, \"%s\", version);\n\n"
"\treturn (struct %s *)\n"
"\t\twl_proxy_create_for_id(display, &%s_interface, id);\n"
printf("static inline void\n"
"%s_set_user_data(struct %s *%s, void *user_data)\n"
......@@ -122,10 +122,10 @@ wl_display_remove_global_listener(struct wl_display *display,
WL_EXPORT struct wl_proxy *
wl_proxy_create_for_id(struct wl_display *display,
const struct wl_interface *interface, uint32_t id)
wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
struct wl_proxy *proxy;
struct wl_display *display = factory->display;
proxy = malloc(sizeof *proxy);
if (proxy == NULL)
......@@ -133,21 +133,13 @@ wl_proxy_create_for_id(struct wl_display *display,
proxy->object.interface = interface;
proxy->object.implementation = NULL;
proxy-> = id;
proxy-> = wl_display_allocate_id(display);
proxy->display = display;
wl_hash_table_insert(display->objects, proxy->, proxy);
return proxy;
WL_EXPORT struct wl_proxy *
wl_proxy_create(struct wl_proxy *factory,
const struct wl_interface *interface)
return wl_proxy_create_for_id(factory->display, interface,
wl_proxy_destroy(struct wl_proxy *proxy)
......@@ -367,8 +359,6 @@ wl_display_connect(const char *name)
return NULL;
wl_display_bind(display, 1, "wl_display", 1);
return display;
......@@ -524,12 +514,20 @@ wl_display_allocate_id(struct wl_display *display)
return display->id++;
WL_EXPORT void *
wl_display_bind(struct wl_display *display,
uint32_t id, const char *interface, uint32_t version)
uint32_t name, const struct wl_interface *interface)
WL_DISPLAY_BIND, id, interface, version);
struct wl_proxy *proxy;
proxy = wl_proxy_create(&display->proxy, interface);
if (proxy == NULL)
return NULL;
wl_proxy_marshal(&display->proxy, WL_DISPLAY_BIND,
name, interface->name, interface->version, proxy);
return proxy;
WL_EXPORT struct wl_callback *
......@@ -44,8 +44,9 @@ int wl_proxy_add_listener(struct wl_proxy *proxy,
void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data);
void *wl_proxy_get_user_data(struct wl_proxy *proxy);
void wl_display_bind(struct wl_display *display,
uint32_t id, const char *interface, uint32_t version);
void *wl_display_bind(struct wl_display *display,
uint32_t name, const struct wl_interface *interface);
struct wl_callback *wl_display_sync(struct wl_display *display);
#include "wayland-client-protocol.h"
......@@ -544,26 +544,24 @@ wl_input_device_update_grab(struct wl_input_device *device,
static void
display_bind(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
const char *interface, uint32_t version)
struct wl_resource *resource, uint32_t name,
const char *interface, uint32_t version, uint32_t id)
struct wl_global *global;
struct wl_display *display = resource->data;
wl_list_for_each(global, &display->global_list, link)
if (global->object->id == id)
if (global->object->id == name)
if (&global->link == &display->global_list)
wl_client_post_error(client, &client->display->resource.object,
"invalid object %d", id);
"invalid global %d", name);
else if (global->bind)
global->bind(client, global->object, version);
global->bind(client, global->object, version, id);
global->object->id, global->object);
wl_hash_table_insert(client->objects, id, global->object);
static void
......@@ -849,12 +847,14 @@ wl_display_add_socket(struct wl_display *display, const char *name)
static void
compositor_bind(struct wl_client *client,
struct wl_object *global, uint32_t version)
struct wl_object *global, uint32_t version, uint32_t id)
struct wl_compositor *compositor =
container_of(global, struct wl_compositor, resource.object);
compositor->resource.client = client;
compositor-> = id;
......@@ -87,7 +87,7 @@ void wl_display_add_object(struct wl_display *display,
typedef void (*wl_global_bind_func_t)(struct wl_client *client,
struct wl_object *global,
uint32_t version);
uint32_t version, uint32_t id);
int wl_display_add_global(struct wl_display *display,
struct wl_object *object,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment