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

Always allocate a new wl_resource when binding an object

Previously we would bind some resources into multiple client hash tables.
parent 419e4071
......@@ -163,20 +163,20 @@ static const struct wl_compositor_listener compositor_listener = {
};
static void
display_handle_global(struct wl_display *display, uint32_t id,
display_handle_global(struct wl_display *display, uint32_t name,
const char *interface, uint32_t version, void *data)
{
struct display *d = data;
if (strcmp(interface, "wl_compositor") == 0) {
d->compositor =
wl_display_bind(display, id, &wl_compositor_interface);
d->compositor = wl_display_bind(display, name,
&wl_compositor_interface);
wl_compositor_add_listener(d->compositor,
&compositor_listener, d);
} else if (strcmp(interface, "wl_shell") == 0) {
d->shell = wl_display_bind(display, id, &wl_shell_interface);
d->shell = wl_display_bind(display, name, &wl_shell_interface);
} else if (strcmp(interface, "wl_shm") == 0) {
d->shm = wl_display_bind(display, id, &wl_shm_interface);
d->shm = wl_display_bind(display, name, &wl_shm_interface);
}
}
......@@ -198,6 +198,7 @@ create_display(void)
display = malloc(sizeof *display);
display->display = wl_display_connect(NULL);
display->xrgb_visual = NULL;
assert(display->display);
wl_display_add_global_listener(display->display,
......@@ -206,7 +207,7 @@ create_display(void)
wl_display_get_fd(display->display, event_mask_update, display);
while (display->xrgb_visual)
while (!display->xrgb_visual)
wl_display_roundtrip(display->display);
return display;
......
......@@ -1625,18 +1625,22 @@ const static struct wl_input_device_interface input_device_interface = {
input_device_attach,
};
static void
bind_input_device(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
wl_client_add_object(client, &wl_input_device_interface,
&input_device_interface, id, data);
}
WL_EXPORT void
wlsc_input_device_init(struct wlsc_input_device *device,
struct wlsc_compositor *ec)
{
wl_input_device_init(&device->input_device, &ec->compositor);
device->input_device.resource.object.interface = &wl_input_device_interface;
device->input_device.resource.object.implementation =
(void (**)(void)) &input_device_interface;
device->input_device.resource.data = device;
wl_display_add_global(ec->wl_display,
&device->input_device.resource.object, NULL);
wl_display_add_global(ec->wl_display, &wl_input_device_interface,
device, bind_input_device);
device->sprite = wlsc_surface_create(ec,
device->input_device.x,
......@@ -1655,16 +1659,17 @@ wlsc_input_device_init(struct wlsc_input_device *device,
}
static void
wlsc_output_post_geometry(struct wl_client *client, struct wl_object *global,
uint32_t version, uint32_t id)
bind_output(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
struct wlsc_output *output =
container_of(global, struct wlsc_output, resource.object);
struct wlsc_output *output = data;
struct wlsc_mode *mode;
struct wl_resource *resource;
resource = wl_client_add_object(client, &wl_output_interface,
NULL, id, output);
output->resource.client = client;
output->resource.object.id = id;
wl_resource_post_event(&output->resource,
wl_resource_post_event(resource,
WL_OUTPUT_GEOMETRY,
output->x,
output->y,
......@@ -1674,7 +1679,7 @@ wlsc_output_post_geometry(struct wl_client *client, struct wl_object *global,
output->make, output->model);
wl_list_for_each (mode, &output->mode_list, link) {
wl_resource_post_event(&output->resource,
wl_resource_post_event(resource,
WL_OUTPUT_MODE,
mode->flags,
mode->width,
......@@ -1859,9 +1864,8 @@ wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
wl_list_init(&output->scanout_buffer_destroy_listener.link);
wl_list_init(&output->frame_callback_list);
output->resource.object.interface = &wl_output_interface;
wl_display_add_global(c->wl_display, &output->resource.object,
wlsc_output_post_geometry);
wl_display_add_global(c->wl_display, &wl_output_interface,
output, bind_output);
}
static void
......
......@@ -622,20 +622,17 @@ meego_tablet_shell_set_selection_focus(struct wlsc_shell *shell,
}
static void
bind_shell(struct wl_client *client,
struct wl_object *global, uint32_t version, uint32_t id)
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct meego_tablet_shell *shell =
container_of(global,
struct meego_tablet_shell, resource.object);
struct meego_tablet_shell *shell = data;
if (shell->client != client)
/* Throw an error or just let the client fail when it
* tries to access the object?. */
return;
shell->resource.client = client;
shell->resource.object.id = id;
wl_client_add_object(client, &meego_tablet_shell_interface,
&tablet_shell_interface, id, shell);
}
void
......@@ -654,13 +651,10 @@ shell_init(struct wlsc_compositor *compositor)
memset(shell, 0, sizeof *shell);
shell->compositor = compositor;
shell->resource.object.interface = &meego_tablet_shell_interface;
shell->resource.object.implementation =
(void (**)(void)) &tablet_shell_interface;
/* FIXME: This will make the object available to all clients. */
wl_display_add_global(compositor->wl_display,
&shell->resource.object, bind_shell);
&meego_tablet_shell_interface,
shell, bind_shell);
loop = wl_display_get_event_loop(compositor->wl_display);
shell->long_press_source =
......
......@@ -50,6 +50,14 @@ struct screenshooter_interface screenshooter_implementation = {
screenshooter_shoot
};
static void
bind_shooter(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
wl_client_add_object(client, &screenshooter_interface,
&screenshooter_implementation, id, data);
}
void
screenshooter_create(struct wlsc_compositor *ec)
{
......@@ -59,10 +67,8 @@ screenshooter_create(struct wlsc_compositor *ec)
if (shooter == NULL)
return;
shooter->base.interface = &screenshooter_interface;
shooter->base.implementation =
(void(**)(void)) &screenshooter_implementation;
shooter->ec = ec;
wl_display_add_global(ec->wl_display, &shooter->base, NULL);
wl_display_add_global(ec->wl_display, &screenshooter_interface,
shooter, bind_shooter);
};
......@@ -29,7 +29,7 @@
#include "compositor.h"
struct wl_shell {
struct wl_object object;
struct wl_resource resource;
struct wlsc_shell shell;
};
......@@ -345,8 +345,6 @@ wl_drag_set_pointer_focus(struct wl_drag *drag,
if (surface &&
(!drag->drag_focus ||
drag->drag_focus->resource.client != surface->resource.client)) {
wl_client_post_global(surface->resource.client,
&drag->drag_offer.resource.object);
drag->drag_offer.resource.client = surface->resource.client;
end = drag->types.data + drag->types.size;
......@@ -487,6 +485,14 @@ static const struct wl_grab_interface drag_grab_interface = {
drag_grab_end
};
static void
bind_drag_offer(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
wl_client_add_object(client, &wl_drag_offer_interface,
&drag_offer_interface, id, data);
}
static void
drag_activate(struct wl_client *client,
struct wl_resource *resource,
......@@ -506,12 +512,8 @@ drag_activate(struct wl_client *client,
drag->source = surface;
drag->drag_offer.resource.object.interface = &wl_drag_offer_interface;
drag->drag_offer.resource.object.implementation =
(void (**)(void)) &drag_offer_interface;
wl_display_add_global(display,
&drag->drag_offer.resource.object, NULL);
wl_display_add_global(display, &wl_drag_offer_interface,
drag, bind_drag_offer);
target = pick_surface(device, &sx, &sy);
wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
......@@ -585,8 +587,6 @@ wlsc_selection_set_focus(struct wlsc_shell *shell,
NULL);
if (surface) {
wl_client_post_global(surface->resource.client,
&selection->selection_offer.resource.object);
selection->selection_offer.resource.client = surface->resource.client;
end = selection->types.data + selection->types.size;
......@@ -643,6 +643,14 @@ selection_offer(struct wl_client *client,
wl_client_post_no_memory(client);
}
static void
bind_selection_offer(struct wl_client *client,
void *data, uint32_t version, uint32_t id)
{
wl_client_add_object(client, &wl_selection_offer_interface,
&selection_offer_interface, id, data);
}
static void
selection_activate(struct wl_client *client,
struct wl_resource *resource,
......@@ -656,14 +664,8 @@ selection_activate(struct wl_client *client,
selection->input_device = device;
selection->selection_offer.resource.object.interface =
&wl_selection_offer_interface;
selection->selection_offer.resource.object.implementation =
(void (**)(void)) &selection_offer_interface;
wl_display_add_global(display,
&selection->selection_offer.resource.object,
NULL);
wl_display_add_global(display, &wl_selection_offer_interface,
selection, bind_selection_offer);
if (wd->selection) {
wl_resource_post_event(&wd->selection->resource,
......@@ -812,6 +814,13 @@ attach(struct wlsc_shell *shell, struct wlsc_surface *es)
}
}
static void
bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
wl_client_add_object(client, &wl_shell_interface,
&shell_interface, id, data);
}
int
shell_init(struct wlsc_compositor *ec);
......@@ -828,9 +837,8 @@ shell_init(struct wlsc_compositor *ec)
shell->shell.attach = attach;
shell->shell.set_selection_focus = wlsc_selection_set_focus;
shell->object.interface = &wl_shell_interface;
shell->object.implementation = (void (**)(void)) &shell_interface;
if (wl_display_add_global(ec->wl_display, &shell->object, NULL))
if (!wl_display_add_global(ec->wl_display,
&wl_shell_interface, shell, bind_shell))
return -1;
wlsc_compositor_add_binding(ec, 0, BTN_LEFT, MODIFIER_SUPER,
......
......@@ -48,10 +48,6 @@
* - Send take focus, hook into wlsc_surface_activate.
*/
struct xserver {
struct wl_resource resource;
};
struct wlsc_xserver {
struct wl_display *wl_display;
struct wl_event_loop *loop;
......@@ -63,7 +59,8 @@ struct wlsc_xserver {
int display;
struct wlsc_process process;
struct xserver xserver;
struct wl_resource *resource;
struct wl_client *client;
struct wlsc_wm *wm;
};
......@@ -407,8 +404,8 @@ wlsc_wm_create(struct wlsc_xserver *wxs)
return NULL;
}
wl_resource_post_event(&wxs->xserver.resource, XSERVER_CLIENT, sv[1]);
wl_client_flush(wxs->xserver.resource.client);
wl_resource_post_event(wxs->resource, XSERVER_CLIENT, sv[1]);
wl_client_flush(wxs->resource->client);
close(sv[1]);
/* xcb_connect_to_fd takes ownership of the fd. */
......@@ -460,27 +457,28 @@ wlsc_wm_destroy(struct wlsc_wm *wm)
static void
wlsc_xserver_bind(struct wl_client *client,
struct wl_object *global, uint32_t version, uint32_t id)
void *data, uint32_t version, uint32_t id)
{
struct wlsc_xserver *wxs =
container_of(global, struct wlsc_xserver,
xserver.resource.object);
struct wlsc_xserver *wxs = data;
/* If it's a different client than the xserver we launched,
* don't start the wm. */
if (client != wxs->xserver.resource.client)
if (client != wxs->client)
return;
wxs->xserver.resource.object.id = id;
wxs->wm = wlsc_wm_create(wxs);
if (wxs == NULL) {
fprintf(stderr, "failed to create wm\n");
}
wl_resource_post_event(&wxs->xserver.resource,
wxs->resource =
wl_client_add_object(client, &xserver_interface,
&xserver_interface, id, wxs);
wl_resource_post_event(wxs->resource,
XSERVER_LISTEN_SOCKET, wxs->abstract_fd);
wl_resource_post_event(&wxs->xserver.resource,
wl_resource_post_event(wxs->resource,
XSERVER_LISTEN_SOCKET, wxs->unix_fd);
}
......@@ -529,8 +527,7 @@ wlsc_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
fprintf(stderr, "forked X server, pid %d\n", mxs->process.pid);
close(sv[1]);
mxs->xserver.resource.client =
wl_client_create(mxs->wl_display, sv[0]);
mxs->client = wl_client_create(mxs->wl_display, sv[0]);
wlsc_watch_process(&mxs->process);
......@@ -569,7 +566,7 @@ wlsc_xserver_cleanup(struct wlsc_process *process, int status)
container_of(process, struct wlsc_xserver, process);
mxs->process.pid = 0;
mxs->xserver.resource.client = NULL;
mxs->resource = NULL;
mxs->abstract_source =
wl_event_loop_add_fd(mxs->loop, mxs->abstract_fd,
......@@ -602,7 +599,7 @@ xserver_set_window_id(struct wl_client *client, struct wl_resource *resource,
struct wlsc_wm *wm = wxs->wm;
struct wlsc_wm_window *window;
if (client != wxs->xserver.resource.client)
if (client != wxs->client)
return;
window = wl_hash_table_lookup(wm->window_hash, id);
......@@ -795,11 +792,8 @@ wlsc_xserver_init(struct wlsc_compositor *compositor)
WL_EVENT_READABLE,
wlsc_xserver_handle_event, mxs);
mxs->xserver.resource.object.interface = &xserver_interface;
mxs->xserver.resource.object.implementation =
(void (**)(void)) &xserver_implementation;
wl_display_add_global(display, &mxs->xserver.resource.object,
wlsc_xserver_bind);
wl_display_add_global(display, &xserver_interface,
mxs, wlsc_xserver_bind);
compositor->wxs = mxs;
......
Supports Markdown
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