[PATCH weston] Convert resources to use wl_resource_init or wl_client_add_object
Jason Ekstrand
jason at jlekstrand.net
Fri Mar 8 20:26:53 PST 2013
This commit converts all of the wl_resource instances in weston to be
initialized using wl_resource_init. It also cleans up the use of wl_resource
in shell_surface and input_panel_surface. Specifically, shell_surface and
input_panel_surface now contain only a pointer to their corresponding
wl_resource which may be null in the case that the object was created by
xwayland.
Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
src/compositor.c | 18 ++++++-----------
src/shell.c | 57 +++++++++++++++++++++++-------------------------------
src/tablet-shell.c | 16 ++++++---------
src/text-backend.c | 15 +++++---------
4 files changed, 41 insertions(+), 65 deletions(-)
diff --git a/src/compositor.c b/src/compositor.c
index 5ff68d7..ca92e1f 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1488,13 +1488,10 @@ compositor_create_surface(struct wl_client *client,
return;
}
- surface->surface.resource.destroy = destroy_surface;
+ wl_resource_init(&surface->surface.resource, &wl_surface_interface,
+ &surface_interface, id, surface);
- surface->surface.resource.object.id = id;
- surface->surface.resource.object.interface = &wl_surface_interface;
- surface->surface.resource.object.implementation =
- (void (**)(void)) &surface_interface;
- surface->surface.resource.data = surface;
+ surface->surface.resource.destroy = destroy_surface;
wl_client_add_resource(client, &surface->surface.resource);
}
@@ -1555,13 +1552,10 @@ compositor_create_region(struct wl_client *client,
return;
}
- region->resource.destroy = destroy_region;
+ wl_resource_init(®ion->resource, &wl_region_interface,
+ ®ion_interface, id, region);
- region->resource.object.id = id;
- region->resource.object.interface = &wl_region_interface;
- region->resource.object.implementation =
- (void (**)(void)) ®ion_interface;
- region->resource.data = region;
+ region->resource.destroy = destroy_region;
pixman_region32_init(®ion->region);
diff --git a/src/shell.c b/src/shell.c
index 6573038..8729efb 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -71,7 +71,7 @@ struct workspace {
};
struct input_panel_surface {
- struct wl_resource resource;
+ struct wl_resource *resource;
struct desktop_shell *shell;
@@ -168,7 +168,7 @@ struct ping_timer {
};
struct shell_surface {
- struct wl_resource resource;
+ struct wl_resource *resource;
struct weston_surface *surface;
struct wl_listener surface_destroy_listener;
@@ -301,7 +301,7 @@ shell_grab_start(struct shell_grab *grab,
grab->grab.interface = interface;
grab->shsurf = shsurf;
grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
- wl_signal_add(&shsurf->resource.destroy_signal,
+ wl_signal_add(&shsurf->resource->destroy_signal,
&grab->shsurf_destroy_listener);
grab->pointer = pointer;
@@ -1140,7 +1140,7 @@ send_configure(struct weston_surface *surface,
{
struct shell_surface *shsurf = get_shell_surface(surface);
- wl_shell_surface_send_configure(&shsurf->resource,
+ wl_shell_surface_send_configure(shsurf->resource,
edges, width, height);
}
@@ -1323,7 +1323,7 @@ ping_handler(struct weston_surface *surface, uint32_t serial)
if (!shsurf)
return;
- if (!shsurf->resource.client)
+ if (!shsurf->resource)
return;
if (shsurf->surface == shsurf->shell->grab_surface)
@@ -1340,7 +1340,7 @@ ping_handler(struct weston_surface *surface, uint32_t serial)
wl_event_loop_add_timer(loop, ping_timeout_handler, shsurf);
wl_event_source_timer_update(shsurf->ping_timer->source, ping_timeout);
- wl_shell_surface_send_ping(&shsurf->resource, serial);
+ wl_shell_surface_send_ping(shsurf->resource, serial);
}
}
@@ -1896,7 +1896,7 @@ popup_grab_end(struct wl_pointer *pointer)
container_of(grab, struct shell_surface, popup.grab);
if (pointer->grab->interface == &popup_grab_interface) {
- wl_shell_surface_send_popup_done(&shsurf->resource);
+ wl_shell_surface_send_popup_done(shsurf->resource);
wl_pointer_end_grab(grab->pointer);
shsurf->popup.grab.pointer = NULL;
}
@@ -1946,7 +1946,7 @@ shell_map_popup(struct shell_surface *shsurf)
if (seat->pointer->grab_serial == shsurf->popup.serial) {
wl_pointer_start_grab(seat->pointer, &shsurf->popup.grab);
} else {
- wl_shell_surface_send_popup_done(&shsurf->resource);
+ wl_shell_surface_send_popup_done(shsurf->resource);
}
}
@@ -2004,6 +2004,7 @@ destroy_shell_surface(struct shell_surface *shsurf)
ping_timer_destroy(shsurf);
wl_list_remove(&shsurf->link);
+ free(shsurf->resource);
free(shsurf);
}
@@ -2022,11 +2023,9 @@ shell_handle_surface_destroy(struct wl_listener *listener, void *data)
struct shell_surface,
surface_destroy_listener);
- if (shsurf->resource.client) {
- wl_resource_destroy(&shsurf->resource);
+ if (shsurf->resource) {
+ wl_resource_destroy(shsurf->resource);
} else {
- wl_signal_emit(&shsurf->resource.destroy_signal,
- &shsurf->resource);
destroy_shell_surface(shsurf);
}
}
@@ -2074,7 +2073,6 @@ create_shell_surface(void *shell, struct weston_surface *surface,
shsurf->ping_timer = NULL;
wl_list_init(&shsurf->fullscreen.transform.link);
- wl_signal_init(&shsurf->resource.destroy_signal);
shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
wl_signal_add(&surface->surface.resource.destroy_signal,
&shsurf->surface_destroy_listener);
@@ -2121,15 +2119,13 @@ shell_get_shell_surface(struct wl_client *client,
"surface->configure already set");
return;
}
+
+ shsurf->resource = wl_client_add_object(client,
+ &wl_shell_surface_interface,
+ &shell_surface_implementation,
+ id, shsurf);
- shsurf->resource.destroy = shell_destroy_shell_surface;
- shsurf->resource.object.id = id;
- shsurf->resource.object.interface = &wl_shell_surface_interface;
- shsurf->resource.object.implementation =
- (void (**)(void)) &shell_surface_implementation;
- shsurf->resource.data = shsurf;
-
- wl_client_add_resource(client, &shsurf->resource);
+ shsurf->resource->destroy = shell_destroy_shell_surface;
}
static const struct wl_shell_interface shell_implementation = {
@@ -3400,6 +3396,7 @@ destroy_input_panel_surface(struct input_panel_surface *input_panel_surface)
input_panel_surface->surface->configure = NULL;
+ free(input_panel_surface->resource);
free(input_panel_surface);
}
@@ -3420,11 +3417,9 @@ input_panel_handle_surface_destroy(struct wl_listener *listener, void *data)
struct input_panel_surface,
surface_destroy_listener);
- if (ipsurface->resource.client) {
- wl_resource_destroy(&ipsurface->resource);
+ if (ipsurface->resource) {
+ wl_resource_destroy(ipsurface->resource);
} else {
- wl_signal_emit(&ipsurface->resource.destroy_signal,
- &ipsurface->resource);
destroy_input_panel_surface(ipsurface);
}
}
@@ -3445,7 +3440,6 @@ create_input_panel_surface(struct desktop_shell *shell,
input_panel_surface->surface = surface;
- wl_signal_init(&input_panel_surface->resource.destroy_signal);
input_panel_surface->surface_destroy_listener.notify = input_panel_handle_surface_destroy;
wl_signal_add(&surface->surface.resource.destroy_signal,
&input_panel_surface->surface_destroy_listener);
@@ -3504,14 +3498,11 @@ input_panel_get_input_panel_surface(struct wl_client *client,
return;
}
- ipsurf->resource.destroy = destroy_input_panel_surface_resource;
- ipsurf->resource.object.id = id;
- ipsurf->resource.object.interface = &input_panel_surface_interface;
- ipsurf->resource.object.implementation =
- (void (**)(void)) &input_panel_surface_implementation;
- ipsurf->resource.data = ipsurf;
+ wl_client_add_object(client, &input_panel_surface_interface,
+ &input_panel_surface_implementation,
+ id, ipsurf);
- wl_client_add_resource(client, &ipsurf->resource);
+ ipsurf->resource->destroy = destroy_input_panel_surface_resource;
}
static const struct input_panel_interface input_panel_implementation = {
diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index 9006b19..afeff6b 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -350,16 +350,14 @@ tablet_shell_create_client(struct wl_client *client,
return;
}
+ wl_resource_init(&tablet_client->resource, &tablet_client_interface,
+ &tablet_client_implementation, id, NULL);
+
tablet_client->client = wl_client_create(compositor->wl_display, fd);
tablet_client->shell = shell;
tablet_client->name = strdup(name);
tablet_client->resource.destroy = destroy_tablet_client;
- tablet_client->resource.object.id = id;
- tablet_client->resource.object.interface =
- &tablet_client_interface;
- tablet_client->resource.object.implementation =
- (void (**)(void)) &tablet_client_implementation;
wl_client_add_resource(client, &tablet_client->resource);
tablet_client->surface = NULL;
@@ -502,13 +500,11 @@ bind_tablet_shell(struct wl_client *client, void *data, uint32_t version,
/* Throw an error or just let the client fail when it
* tries to access the object?. */
return;
+
+ wl_resource_init(&shell->resource, &tablet_shell_interface,
+ &tablet_shell_implementation, id, shell);
- shell->resource.object.id = id;
- shell->resource.object.interface = &tablet_shell_interface;
- shell->resource.object.implementation =
- (void (**)(void)) &tablet_shell_implementation;
shell->resource.client = client;
- shell->resource.data = shell;
shell->resource.destroy = destroy_tablet_shell;
wl_client_add_resource(client, &shell->resource);
diff --git a/src/text-backend.c b/src/text-backend.c
index a92aebe..e219121 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -322,12 +322,9 @@ static void text_model_factory_create_text_model(struct wl_client *client,
text_model = calloc(1, sizeof *text_model);
- text_model->resource.object.id = id;
- text_model->resource.object.interface = &text_model_interface;
- text_model->resource.object.implementation =
- (void (**)(void)) &text_model_implementation;
+ wl_resource_init(&text_model->resource, &text_model_interface,
+ &text_model_implementation, id, text_model);
- text_model->resource.data = text_model;
text_model->resource.destroy = destroy_text_model;
text_model->ec = text_model_factory->ec;
@@ -642,13 +639,11 @@ input_method_context_create(struct text_model *model,
if (context == NULL)
return;
+ wl_resource_init(&context->resource, &input_method_context_interface,
+ &input_method_context_implementation, 0, context);
+
context->resource.destroy = destroy_input_method_context;
- context->resource.object.id = 0;
- context->resource.object.interface = &input_method_context_interface;
- context->resource.object.implementation =
- (void (**)(void)) &input_method_context_implementation;
context->resource.data = context;
- wl_signal_init(&context->resource.destroy_signal);
context->model = model;
context->input_method = input_method;
--
1.8.1.4
More information about the wayland-devel
mailing list