diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-08-19 13:44:01 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-08-27 12:06:11 -0400 |
commit | e908893080a391b731591720e52f4c38c4c644e4 (patch) | |
tree | 74440c756a9515ecbdbe2b19d9ab584746f05de5 /src | |
parent | a7c682432893d2e5e534953ef64193f1dd4bcef4 (diff) |
Bind globals to client provided object IDs
Diffstat (limited to 'src')
-rw-r--r-- | src/scanner.c | 13 | ||||
-rw-r--r-- | src/wayland-client.c | 32 | ||||
-rw-r--r-- | src/wayland-client.h | 5 | ||||
-rw-r--r-- | src/wayland-server.c | 18 | ||||
-rw-r--r-- | src/wayland-server.h | 2 |
5 files changed, 28 insertions, 42 deletions
diff --git a/src/scanner.c b/src/scanner.c index b114fbf..d6e8969 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -347,19 +347,6 @@ emit_stubs(struct wl_list *message_list, struct interface *interface) if (strcmp(interface->name, "wl_display") == 0) return; - printf("static inline struct %s *\n" - "%s_create(struct wl_display *display, uint32_t id, uint32_t version)\n" - "{\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" - "}\n\n", - interface->name, - interface->name, - interface->name, - interface->name, - interface->name); - printf("static inline void\n" "%s_set_user_data(struct %s *%s, void *user_data)\n" "{\n" diff --git a/src/wayland-client.c b/src/wayland-client.c index ec62885..f4920d7 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -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->object.id = id; + proxy->object.id = wl_display_allocate_id(display); proxy->display = display; wl_hash_table_insert(display->objects, proxy->object.id, 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_display_allocate_id(factory->display)); -} - WL_EXPORT void 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_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_proxy_marshal(&display->proxy, - 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 * diff --git a/src/wayland-client.h b/src/wayland-client.h index dc5aa5f..53b323d 100644 --- a/src/wayland-client.h +++ b/src/wayland-client.h @@ -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" diff --git a/src/wayland-server.c b/src/wayland-server.c index 275e6de..337ac0b 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -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) break; if (&global->link == &display->global_list) wl_client_post_error(client, &client->display->resource.object, WL_DISPLAY_ERROR_INVALID_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); - wl_hash_table_insert(client->objects, - 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->resource.object.id = id; + wl_resource_post_event(&compositor->resource, WL_COMPOSITOR_TOKEN_VISUAL, &compositor->argb_visual.object, diff --git a/src/wayland-server.h b/src/wayland-server.h index 2077a1c..2ef4899 100644 --- a/src/wayland-server.h +++ b/src/wayland-server.h @@ -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, |