Use wl_resource_create() for creating resources

This commit sets the version numbers for all added/created objects.  The
wl_compositor.create_surface implementation was altered to create a surface
with the same version as the underlying wl_compositor.  Since no other
"child interfaces" have version greater than 1, they were all hard-coded to
version 1.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
dev
Jason Ekstrand 12 years ago committed by Kristian Høgsberg
parent d27cb096ad
commit a85118c1b8
  1. 57
      src/compositor.c
  2. 2
      src/compositor.h
  3. 36
      src/data-device.c
  4. 25
      src/input.c
  5. 7
      src/screenshooter.c
  6. 62
      src/shell.c
  7. 17
      src/tablet-shell.c
  8. 43
      src/text-backend.c
  9. 6
      src/xwayland/launcher.c
  10. 10
      src/zoom.c
  11. 6
      tests/weston-test.c

@ -1489,9 +1489,11 @@ surface_frame(struct wl_client *client,
return; return;
} }
cb->resource = wl_client_add_object(client, &wl_callback_interface, cb->resource = wl_resource_create(client,
NULL, callback, cb); &wl_callback_interface,
wl_resource_set_destructor(cb->resource, destroy_frame_callback); 1, callback);
wl_resource_set_implementation(cb->resource, NULL, cb,
destroy_frame_callback);
wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link);
} }
@ -1688,10 +1690,11 @@ compositor_create_surface(struct wl_client *client,
return; return;
} }
surface->resource = wl_client_add_object(client, &wl_surface_interface, surface->resource =
&surface_interface, wl_resource_create(client, &wl_surface_interface,
id, surface); wl_resource_get_version(resource), id);
wl_resource_set_destructor(surface->resource, destroy_surface); wl_resource_set_implementation(surface->resource, &surface_interface,
surface, destroy_surface);
} }
static void static void
@ -1751,9 +1754,10 @@ compositor_create_region(struct wl_client *client,
pixman_region32_init(&region->region); pixman_region32_init(&region->region);
region->resource = wl_client_add_object(client, &wl_region_interface, region->resource =
&region_interface, id, region); wl_resource_create(client, &wl_region_interface, 1, id);
wl_resource_set_destructor(region->resource, destroy_region); wl_resource_set_implementation(region->resource, &region_interface,
region, destroy_region);
} }
static const struct wl_compositor_interface compositor_interface = { static const struct wl_compositor_interface compositor_interface = {
@ -2288,16 +2292,16 @@ weston_subsurface_create(uint32_t id, struct weston_surface *surface,
if (!sub) if (!sub)
return NULL; return NULL;
sub->resource = wl_client_add_object(client, sub->resource =
&wl_subsurface_interface, wl_resource_create(client, &wl_subsurface_interface, 1, id);
&subsurface_implementation,
id, sub);
if (!sub->resource) { if (!sub->resource) {
free(sub); free(sub);
return NULL; return NULL;
} }
wl_resource_set_destructor(sub->resource, subsurface_resource_destroy); wl_resource_set_implementation(sub->resource,
&subsurface_implementation,
sub, subsurface_resource_destroy);
weston_subsurface_link_surface(sub, surface); weston_subsurface_link_surface(sub, surface);
weston_subsurface_link_parent(sub, parent); weston_subsurface_link_parent(sub, parent);
weston_subsurface_cache_init(sub); weston_subsurface_cache_init(sub);
@ -2408,9 +2412,14 @@ bind_subcompositor(struct wl_client *client,
void *data, uint32_t version, uint32_t id) void *data, uint32_t version, uint32_t id)
{ {
struct weston_compositor *compositor = data; struct weston_compositor *compositor = data;
struct wl_resource *resource;
wl_client_add_object(client, &wl_subcompositor_interface, resource =
&subcompositor_interface, id, compositor); wl_resource_create(client, &wl_subcompositor_interface, 1, id);
if (resource)
wl_resource_set_implementation(resource,
&subcompositor_interface,
compositor, NULL);
} }
static void static void
@ -2522,11 +2531,11 @@ bind_output(struct wl_client *client,
struct weston_mode *mode; struct weston_mode *mode;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, resource = wl_resource_create(client, &wl_output_interface,
&wl_output_interface, NULL, id, data); MIN(version, 2), id);
wl_list_insert(&output->resource_list, wl_resource_get_link(resource)); wl_list_insert(&output->resource_list, wl_resource_get_link(resource));
wl_resource_set_destructor(resource, unbind_resource); wl_resource_set_implementation(resource, NULL, data, unbind_resource);
wl_output_send_geometry(resource, wl_output_send_geometry(resource,
output->x, output->x,
@ -2742,9 +2751,13 @@ compositor_bind(struct wl_client *client,
void *data, uint32_t version, uint32_t id) void *data, uint32_t version, uint32_t id)
{ {
struct weston_compositor *compositor = data; struct weston_compositor *compositor = data;
struct wl_resource *resource;
wl_client_add_object(client, &wl_compositor_interface, resource = wl_resource_create(client, &wl_compositor_interface,
&compositor_interface, id, compositor); MIN(version, 3), id);
if (resource)
wl_resource_set_implementation(resource, &compositor_interface,
compositor, NULL);
} }
static void static void

@ -594,7 +594,7 @@ struct weston_buffer {
union { union {
struct wl_shm_buffer *shm_buffer; struct wl_shm_buffer *shm_buffer;
struct wl_buffer *legacy_buffer; void *legacy_buffer;
}; };
int32_t width, height; int32_t width, height;
uint32_t busy_count; uint32_t busy_count;

@ -117,10 +117,11 @@ wl_data_source_send_offer(struct wl_data_source *source,
if (offer == NULL) if (offer == NULL)
return NULL; return NULL;
offer->resource = wl_client_new_object(wl_resource_get_client(target), offer->resource =
&wl_data_offer_interface, wl_resource_create(wl_resource_get_client(target),
&data_offer_interface, offer); &wl_data_offer_interface, 1, 0);
wl_resource_set_destructor(offer->resource, destroy_data_offer); wl_resource_set_implementation(offer->resource, &data_offer_interface,
offer, destroy_data_offer);
offer->source = source; offer->source = source;
offer->source_destroy_listener.notify = destroy_offer_data_source; offer->source_destroy_listener.notify = destroy_offer_data_source;
@ -545,11 +546,10 @@ create_data_source(struct wl_client *client,
wl_array_init(&source->mime_types); wl_array_init(&source->mime_types);
source->resource = wl_client_add_object(client, source->resource =
&wl_data_source_interface, wl_resource_create(client, &wl_data_source_interface, 1, id);
&data_source_interface, wl_resource_set_implementation(source->resource, &data_source_interface,
id, source); source, destroy_data_source);
wl_resource_set_destructor(source->resource, destroy_data_source);
} }
static void unbind_data_device(struct wl_resource *resource) static void unbind_data_device(struct wl_resource *resource)
@ -565,12 +565,12 @@ get_data_device(struct wl_client *client,
struct weston_seat *seat = wl_resource_get_user_data(seat_resource); struct weston_seat *seat = wl_resource_get_user_data(seat_resource);
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &wl_data_device_interface, resource = wl_resource_create(client,
&data_device_interface, id, &wl_data_device_interface, 1, id);
seat);
wl_list_insert(&seat->drag_resource_list, wl_resource_get_link(resource)); wl_list_insert(&seat->drag_resource_list, wl_resource_get_link(resource));
wl_resource_set_destructor(resource, unbind_data_device); wl_resource_set_implementation(resource, &data_device_interface,
seat, unbind_data_device);
} }
static const struct wl_data_device_manager_interface manager_interface = { static const struct wl_data_device_manager_interface manager_interface = {
@ -582,8 +582,14 @@ static void
bind_manager(struct wl_client *client, bind_manager(struct wl_client *client,
void *data, uint32_t version, uint32_t id) void *data, uint32_t version, uint32_t id)
{ {
wl_client_add_object(client, &wl_data_device_manager_interface, struct wl_resource *resource;
&manager_interface, id, NULL);
resource =
wl_resource_create(client,
&wl_data_device_manager_interface, 1, id);
if (resource)
wl_resource_set_implementation(resource, &manager_interface,
NULL, NULL);
} }
WL_EXPORT void WL_EXPORT void

@ -1186,10 +1186,11 @@ seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
if (!seat->pointer) if (!seat->pointer)
return; return;
cr = wl_client_add_object(client, &wl_pointer_interface, cr = wl_resource_create(client, &wl_pointer_interface,
&pointer_interface, id, seat->pointer); wl_resource_get_version(resource), id);
wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr)); wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr));
wl_resource_set_destructor(cr, unbind_resource); wl_resource_set_implementation(cr, &pointer_interface, seat->pointer,
unbind_resource);
if (seat->pointer->focus && if (seat->pointer->focus &&
wl_resource_get_client(seat->pointer->focus->resource) == client) { wl_resource_get_client(seat->pointer->focus->resource) == client) {
@ -1219,10 +1220,10 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
if (!seat->keyboard) if (!seat->keyboard)
return; return;
cr = wl_client_add_object(client, &wl_keyboard_interface, NULL, id, cr = wl_resource_create(client, &wl_keyboard_interface,
seat); wl_resource_get_version(resource), id);
wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr)); wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr));
wl_resource_set_destructor(cr, unbind_resource); wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
if (seat->compositor->use_xkbcommon) { if (seat->compositor->use_xkbcommon) {
wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
@ -1254,9 +1255,10 @@ seat_get_touch(struct wl_client *client, struct wl_resource *resource,
if (!seat->touch) if (!seat->touch)
return; return;
cr = wl_client_add_object(client, &wl_touch_interface, NULL, id, seat); cr = wl_resource_create(client, &wl_touch_interface,
wl_resource_get_version(resource), id);
wl_list_insert(&seat->touch->resource_list, wl_resource_get_link(cr)); wl_list_insert(&seat->touch->resource_list, wl_resource_get_link(cr));
wl_resource_set_destructor(cr, unbind_resource); wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
} }
static const struct wl_seat_interface seat_interface = { static const struct wl_seat_interface seat_interface = {
@ -1272,10 +1274,11 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct wl_resource *resource; struct wl_resource *resource;
enum wl_seat_capability caps = 0; enum wl_seat_capability caps = 0;
resource = wl_client_add_object(client, &wl_seat_interface, resource = wl_resource_create(client,
&seat_interface, id, data); &wl_seat_interface, MIN(version, 2), id);
wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource)); wl_list_insert(&seat->base_resource_list, wl_resource_get_link(resource));
wl_resource_set_destructor(resource, unbind_resource); wl_resource_set_implementation(resource, &seat_interface, data,
unbind_resource);
if (seat->pointer) if (seat->pointer)
caps |= WL_SEAT_CAPABILITY_POINTER; caps |= WL_SEAT_CAPABILITY_POINTER;

@ -217,14 +217,17 @@ bind_shooter(struct wl_client *client,
struct screenshooter *shooter = data; struct screenshooter *shooter = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &screenshooter_interface, resource = wl_resource_create(client,
&screenshooter_implementation, id, data); &screenshooter_interface, 1, id);
if (client != shooter->client) { if (client != shooter->client) {
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
"screenshooter failed: permission denied"); "screenshooter failed: permission denied");
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
wl_resource_set_implementation(resource, &screenshooter_implementation,
data, NULL);
} }
static void static void

@ -1015,16 +1015,17 @@ bind_workspace_manager(struct wl_client *client,
struct desktop_shell *shell = data; struct desktop_shell *shell = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &workspace_manager_interface, resource = wl_resource_create(client,
&workspace_manager_implementation, &workspace_manager_interface, 1, id);
id, shell);
if (resource == NULL) { if (resource == NULL) {
weston_log("couldn't add workspace manager object"); weston_log("couldn't add workspace manager object");
return; return;
} }
wl_resource_set_destructor(resource, unbind_resource); wl_resource_set_implementation(resource,
&workspace_manager_implementation,
shell, unbind_resource);
wl_list_insert(&shell->workspaces.client_list, wl_list_insert(&shell->workspaces.client_list,
wl_resource_get_link(resource)); wl_resource_get_link(resource));
@ -2332,12 +2333,12 @@ shell_get_shell_surface(struct wl_client *client,
return; return;
} }
shsurf->resource = wl_client_add_object(client, shsurf->resource =
&wl_shell_surface_interface, wl_resource_create(client,
&wl_shell_surface_interface, 1, id);
wl_resource_set_implementation(shsurf->resource,
&shell_surface_implementation, &shell_surface_implementation,
id, shsurf); shsurf, shell_destroy_shell_surface);
wl_resource_set_destructor(shsurf->resource,
shell_destroy_shell_surface);
} }
static const struct wl_shell_interface shell_implementation = { static const struct wl_shell_interface shell_implementation = {
@ -3598,9 +3599,12 @@ static void
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{ {
struct desktop_shell *shell = data; struct desktop_shell *shell = data;
struct wl_resource *resource;
wl_client_add_object(client, &wl_shell_interface, resource = wl_resource_create(client, &wl_shell_interface, 1, id);
&shell_implementation, id, shell); if (resource)
wl_resource_set_implementation(resource, &shell_implementation,
shell, NULL);
} }
static void static void
@ -3622,12 +3626,13 @@ bind_desktop_shell(struct wl_client *client,
struct desktop_shell *shell = data; struct desktop_shell *shell = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &desktop_shell_interface, resource = wl_resource_create(client, &desktop_shell_interface,
&desktop_shell_implementation, MIN(version, 2), id);
id, shell);
if (client == shell->child.client) { if (client == shell->child.client) {
wl_resource_set_destructor(resource, unbind_desktop_shell); wl_resource_set_implementation(resource,
&desktop_shell_implementation,
shell, unbind_desktop_shell);
shell->child.desktop_shell = resource; shell->child.desktop_shell = resource;
if (version < 2) if (version < 2)
@ -3700,12 +3705,12 @@ bind_screensaver(struct wl_client *client,
struct desktop_shell *shell = data; struct desktop_shell *shell = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &screensaver_interface, resource = wl_resource_create(client, &screensaver_interface, 1, id);
&screensaver_implementation,
id, shell);
if (shell->screensaver.binding == NULL) { if (shell->screensaver.binding == NULL) {
wl_resource_set_destructor(resource, unbind_screensaver); wl_resource_set_implementation(resource,
&screensaver_implementation,
shell, unbind_screensaver);
shell->screensaver.binding = resource; shell->screensaver.binding = resource;
return; return;
} }
@ -3894,12 +3899,12 @@ input_panel_get_input_panel_surface(struct wl_client *client,
return; return;
} }
ipsurf->resource = wl_client_add_object(client, ipsurf->resource =
&wl_input_panel_surface_interface, wl_resource_create(client,
&wl_input_panel_surface_interface, 1, id);
wl_resource_set_implementation(ipsurf->resource,
&input_panel_surface_implementation, &input_panel_surface_implementation,
id, ipsurf); ipsurf,
wl_resource_set_destructor(ipsurf->resource,
destroy_input_panel_surface_resource); destroy_input_panel_surface_resource);
} }
@ -3922,12 +3927,13 @@ bind_input_panel(struct wl_client *client,
struct desktop_shell *shell = data; struct desktop_shell *shell = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &wl_input_panel_interface, resource = wl_resource_create(client,
&input_panel_implementation, &wl_input_panel_interface, 1, id);
id, shell);
if (shell->input_panel.binding == NULL) { if (shell->input_panel.binding == NULL) {
wl_resource_set_destructor(resource, unbind_input_panel); wl_resource_set_implementation(resource,
&input_panel_implementation,
shell, unbind_input_panel);
shell->input_panel.binding = resource; shell->input_panel.binding = resource;
return; return;
} }

@ -350,12 +350,11 @@ tablet_shell_create_client(struct wl_client *client,
tablet_client->shell = shell; tablet_client->shell = shell;
tablet_client->name = strdup(name); tablet_client->name = strdup(name);
tablet_client->resource = wl_client_add_object(client, tablet_client->resource =
&tablet_client_interface, wl_resource_create(client, &tablet_client_interface, 1, id);
wl_resource_set_implementation(tablet_client->resource,
&tablet_client_implementation, &tablet_client_implementation,
id, tablet_client); tablet_client, destroy_tablet_client);
wl_resource_set_destructor(tablet_client->resource,
destroy_tablet_client);
tablet_client->surface = NULL; tablet_client->surface = NULL;
shell->current_client = tablet_client; shell->current_client = tablet_client;
@ -498,11 +497,11 @@ bind_tablet_shell(struct wl_client *client, void *data, uint32_t version,
* tries to access the object?. */ * tries to access the object?. */
return; return;
shell->resource = wl_client_add_object(client, shell->resource =
&tablet_shell_interface, wl_resource_create(client, &tablet_shell_interface, 1, id);
wl_resource_set_implementation(shell->resource,
&tablet_shell_implementation, &tablet_shell_implementation,
id, shell); shell, destroy_tablet_shell);
wl_resource_set_destructor(shell->resource, destroy_tablet_shell);
} }
static void static void

@ -358,11 +358,11 @@ static void text_input_manager_create_text_input(struct wl_client *client,
text_input = calloc(1, sizeof *text_input); text_input = calloc(1, sizeof *text_input);
text_input->resource = wl_client_add_object(client, text_input->resource =
&wl_text_input_interface, wl_resource_create(client, &wl_text_input_interface, 1, id);
wl_resource_set_implementation(text_input->resource,
&text_input_implementation, &text_input_implementation,
id, text_input); text_input, destroy_text_input);
wl_resource_set_destructor(text_input->resource, destroy_text_input);
text_input->ec = text_input_manager->ec; text_input->ec = text_input_manager->ec;
@ -380,12 +380,16 @@ bind_text_input_manager(struct wl_client *client,
uint32_t id) uint32_t id)
{ {
struct text_input_manager *text_input_manager = data; struct text_input_manager *text_input_manager = data;
struct wl_resource *resource;
/* No checking for duplicate binding necessary. /* No checking for duplicate binding necessary. */
* No events have to be sent, so we don't need the return value. */ resource =
wl_client_add_object(client, &wl_text_input_manager_interface, wl_resource_create(client,
&wl_text_input_manager_interface, 1, id);
if (resource)
wl_resource_set_implementation(resource,
&text_input_manager_implementation, &text_input_manager_implementation,
id, text_input_manager); text_input_manager, NULL);
} }
static void static void
@ -582,9 +586,8 @@ input_method_context_grab_keyboard(struct wl_client *client,
struct weston_seat *seat = context->input_method->seat; struct weston_seat *seat = context->input_method->seat;
struct weston_keyboard *keyboard = seat->keyboard; struct weston_keyboard *keyboard = seat->keyboard;
cr = wl_client_add_object(client, &wl_keyboard_interface, cr = wl_resource_create(client, &wl_keyboard_interface, 1, id);
NULL, id, context); wl_resource_set_implementation(cr, NULL, context, unbind_keyboard);
wl_resource_set_destructor(cr, unbind_keyboard);
context->keyboard = cr; context->keyboard = cr;
@ -703,12 +706,12 @@ input_method_context_create(struct text_input *model,
return; return;
binding = input_method->input_method_binding; binding = input_method->input_method_binding;
context->resource = wl_client_new_object(wl_resource_get_client(binding), context->resource =
&wl_input_method_context_interface, wl_resource_create(wl_resource_get_client(binding),
&wl_input_method_context_interface, 1, 0);
wl_resource_set_implementation(context->resource,
&input_method_context_implementation, &input_method_context_implementation,
context); context, destroy_input_method_context);
wl_resource_set_destructor(context->resource,
destroy_input_method_context);
context->model = model; context->model = model;
context->input_method = input_method; context->input_method = input_method;
@ -756,9 +759,8 @@ bind_input_method(struct wl_client *client,
struct text_backend *text_backend = input_method->text_backend; struct text_backend *text_backend = input_method->text_backend;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &wl_input_method_interface, resource =
NULL, wl_resource_create(client, &wl_input_method_interface, 1, id);
id, input_method);
if (input_method->input_method_binding != NULL) { if (input_method->input_method_binding != NULL) {
wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT,
@ -774,7 +776,8 @@ bind_input_method(struct wl_client *client,
return; return;
} }
wl_resource_set_destructor(resource, unbind_input_method); wl_resource_set_implementation(resource, NULL, input_method,
unbind_input_method);
input_method->input_method_binding = resource; input_method->input_method_binding = resource;
text_backend->input_method.binding = resource; text_backend->input_method.binding = resource;

@ -159,8 +159,10 @@ bind_xserver(struct wl_client *client,
return; return;
wxs->resource = wxs->resource =
wl_client_add_object(client, &xserver_interface, wl_resource_create(client, &xserver_interface,
&xserver_implementation, id, wxs); 1, id);
wl_resource_set_implementation(wxs->resource, &xserver_implementation,
wxs, NULL);
wxs->wm = weston_wm_create(wxs); wxs->wm = weston_wm_create(wxs);
if (wxs->wm == NULL) { if (wxs->wm == NULL) {

@ -53,8 +53,14 @@ static void
bind_text_cursor_position(struct wl_client *client, bind_text_cursor_position(struct wl_client *client,
void *data, uint32_t version, uint32_t id) void *data, uint32_t version, uint32_t id)
{ {
wl_client_add_object(client, &text_cursor_position_interface, struct wl_resource *resource;
&text_cursor_position_implementation, id, data);
resource = wl_resource_create(client,
&text_cursor_position_interface, 1, id);
if (resource)
wl_resource_set_implementation(resource,
&text_cursor_position_implementation,
data, NULL);
} }
static void static void

@ -191,8 +191,10 @@ bind_test(struct wl_client *client, void *data, uint32_t version, uint32_t id)
struct weston_test *test = data; struct weston_test *test = data;
struct wl_resource *resource; struct wl_resource *resource;
resource = wl_client_add_object(client, &wl_test_interface, resource = wl_client_add_versioned_object(client, &wl_test_interface,
&test_implementation, id, test); 1, id);
wl_resource_set_implementation(resource, &test_implementation,
test, NULL);
notify_pointer_position(test, resource); notify_pointer_position(test, resource);
} }

Loading…
Cancel
Save