struct wl_connection *connection;
struct wl_event_source *source;
struct wl_display *display;
+ struct wl_resource display_resource;
struct wl_list resource_list;
uint32_t id_count;
uint32_t mask;
};
struct wl_display {
- struct wl_object object;
+ struct wl_resource resource;
struct wl_event_loop *loop;
struct wl_hash_table *objects;
int run;
static int wl_debug = 0;
WL_EXPORT void
-wl_client_post_event(struct wl_client *client, struct wl_object *sender,
- uint32_t opcode, ...)
+wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
{
struct wl_closure *closure;
+ struct wl_object *object = &resource->object;
va_list ap;
va_start(ap, opcode);
- closure = wl_connection_vmarshal(client->connection,
- sender, opcode, ap,
- &sender->interface->events[opcode]);
+ closure = wl_connection_vmarshal(resource->client->connection,
+ object, opcode, ap,
+ &object->interface->events[opcode]);
va_end(ap);
- wl_closure_send(closure, client->connection);
+ wl_closure_send(closure, resource->client->connection);
if (wl_debug)
- wl_closure_print(closure, sender, true);
+ wl_closure_print(closure, object, true);
wl_closure_destroy(closure);
}
vsnprintf(buffer, sizeof buffer, msg, ap);
va_end(ap);
- wl_client_post_event(client, &client->display->object,
- WL_DISPLAY_ERROR, object, code, buffer);
+ wl_resource_post_event(&client->display_resource,
+ WL_DISPLAY_ERROR, object, code, buffer);
}
static int
{
struct wl_client *client = data;
struct wl_connection *connection = client->connection;
+ struct wl_resource *resource;
struct wl_object *object;
struct wl_closure *closure;
const struct wl_message *message;
if (len < size)
break;
- object = wl_hash_table_lookup(client->display->objects, p[0]);
- if (object == NULL) {
- wl_client_post_error(client, &client->display->object,
+ resource = wl_hash_table_lookup(client->display->objects, p[0]);
+ if (resource == NULL) {
+ wl_client_post_error(client,
+ &client->display->resource.object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", p[0]);
wl_connection_consume(connection, size);
continue;
}
+ object = &resource->object;
if (opcode >= object->interface->method_count) {
- wl_client_post_error(client, &client->display->object,
+ wl_client_post_error(client,
+ &client->display->resource.object,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid method %d, object %s@%d",
object->interface->name,
len -= size;
if (closure == NULL && errno == EINVAL) {
- wl_client_post_error(client, &client->display->object,
+ wl_client_post_error(client,
+ &client->display->resource.object,
WL_DISPLAY_ERROR_INVALID_METHOD,
"invalid arguments for %s@%d.%s",
object->interface->name,
- object->id, message->name);
+ object->id,
+ message->name);
continue;
} else if (closure == NULL && errno == ENOMEM) {
wl_client_post_no_memory(client);
if (wl_debug)
- wl_closure_print(closure, object, false);
+ wl_closure_print(closure, object, false);
wl_closure_invoke(closure, object,
object->implementation[opcode], client);
static void
wl_display_post_range(struct wl_display *display, struct wl_client *client)
{
- wl_client_post_event(client, &client->display->object,
- WL_DISPLAY_RANGE, display->client_id_range);
+ wl_resource_post_event(&client->display_resource,
+ WL_DISPLAY_RANGE, display->client_id_range);
display->client_id_range += 256;
client->id_count += 256;
}
return NULL;
}
+ client->display_resource.object = display->resource.object;
+ client->display_resource.client = client;
+
wl_list_insert(display->client_list.prev, &client->link);
wl_list_init(&client->resource_list);
if (client->id_count-- < 64)
wl_display_post_range(display, client);
+ resource->client = client;
wl_list_init(&resource->destroy_listener_list);
wl_hash_table_insert(client->display->objects,
WL_EXPORT void
wl_client_post_no_memory(struct wl_client *client)
{
- wl_client_post_error(client, &client->display->object,
+ wl_client_post_error(client, &client->display->resource.object,
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
}
WL_EXPORT void
wl_client_post_global(struct wl_client *client, struct wl_object *object)
{
- wl_client_post_event(client,
- &client->display->object,
- WL_DISPLAY_GLOBAL,
- object->id,
- object->interface->name,
- object->interface->version);
+ wl_resource_post_event(&client->display_resource,
+ WL_DISPLAY_GLOBAL,
+ object->id,
+ object->interface->name,
+ object->interface->version);
}
WL_EXPORT void
-wl_resource_destroy(struct wl_resource *resource,
- struct wl_client *client, uint32_t time)
+wl_resource_destroy(struct wl_resource *resource, uint32_t time)
{
- struct wl_display *display = client->display;
+ struct wl_display *display = resource->client->display;
struct wl_listener *l, *next;
- wl_list_for_each_safe(l, next,
- &resource->destroy_listener_list, link)
+ wl_list_for_each_safe(l, next, &resource->destroy_listener_list, link)
l->func(l, resource, time);
wl_list_remove(&resource->link);
if (resource->object.id > 0)
wl_hash_table_remove(display->objects, resource->object.id);
- resource->destroy(resource, client);
+ resource->destroy(resource);
}
WL_EXPORT void
printf("disconnect from client %p\n", client);
wl_list_for_each_safe(resource, tmp, &client->resource_list, link)
- wl_resource_destroy(resource, client, 0);
+ wl_resource_destroy(resource, 0);
wl_event_source_remove(client->source);
wl_connection_destroy(client->connection);
wl_input_device_init(struct wl_input_device *device,
struct wl_compositor *compositor)
{
- wl_list_init(&device->pointer_focus_listener.link);
+ memset(device, 0, sizeof *device);
+ wl_list_init(&device->resource_list);
device->pointer_focus_listener.func = lose_pointer_focus;
- wl_list_init(&device->keyboard_focus_listener.link);
device->keyboard_focus_listener.func = lose_keyboard_focus;
device->x = 100;
device->compositor = compositor;
}
+static struct wl_resource *
+find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
+{
+ struct wl_resource *r;
+
+ if (!surface)
+ return NULL;
+
+ wl_list_for_each(r, list, link) {
+ if (r->client == surface->resource.client)
+ return r;
+ }
+
+ return NULL;
+}
+
WL_EXPORT void
wl_input_device_set_pointer_focus(struct wl_input_device *device,
struct wl_surface *surface,
int32_t x, int32_t y,
int32_t sx, int32_t sy)
{
+ struct wl_resource *resource;
+
if (device->pointer_focus == surface)
return;
- if (device->pointer_focus &&
- (!surface || device->pointer_focus->client != surface->client))
- wl_client_post_event(device->pointer_focus->client,
- &device->object,
- WL_INPUT_DEVICE_POINTER_FOCUS,
- time, NULL, 0, 0, 0, 0);
- if (device->pointer_focus)
+ if (device->pointer_focus_resource &&
+ (!surface ||
+ device->pointer_focus->resource.client != surface->resource.client))
+ wl_resource_post_event(device->pointer_focus_resource,
+ WL_INPUT_DEVICE_POINTER_FOCUS,
+ time, NULL, 0, 0, 0, 0);
+ if (device->pointer_focus_resource)
wl_list_remove(&device->pointer_focus_listener.link);
- if (surface) {
- wl_client_post_event(surface->client,
- &device->object,
- WL_INPUT_DEVICE_POINTER_FOCUS,
- time, surface, x, y, sx, sy);
+ resource = find_resource_for_surface(&device->resource_list, surface);
+ if (resource) {
+ wl_resource_post_event(resource,
+ WL_INPUT_DEVICE_POINTER_FOCUS,
+ time, surface, x, y, sx, sy);
wl_list_insert(surface->resource.destroy_listener_list.prev,
&device->pointer_focus_listener.link);
}
+ device->pointer_focus_resource = resource;
device->pointer_focus = surface;
device->pointer_focus_time = time;
-
}
WL_EXPORT void
struct wl_surface *surface,
uint32_t time)
{
+ struct wl_resource *resource;
+
if (device->keyboard_focus == surface)
return;
- if (device->keyboard_focus &&
- (!surface || device->keyboard_focus->client != surface->client))
- wl_client_post_event(device->keyboard_focus->client,
- &device->object,
- WL_INPUT_DEVICE_KEYBOARD_FOCUS,
- time, NULL, &device->keys);
- if (device->keyboard_focus)
+ if (device->keyboard_focus_resource &&
+ (!surface ||
+ device->keyboard_focus->resource.client != surface->resource.client))
+ wl_resource_post_event(device->keyboard_focus_resource,
+ WL_INPUT_DEVICE_KEYBOARD_FOCUS,
+ time, NULL, &device->keys);
+ if (device->keyboard_focus_resource)
wl_list_remove(&device->keyboard_focus_listener.link);
- if (surface) {
- wl_client_post_event(surface->client,
- &device->object,
- WL_INPUT_DEVICE_KEYBOARD_FOCUS,
- time, surface, &device->keys);
+ resource = find_resource_for_surface(&device->resource_list, surface);
+ if (resource) {
+ wl_resource_post_event(resource,
+ WL_INPUT_DEVICE_KEYBOARD_FOCUS,
+ time, surface, &device->keys);
wl_list_insert(surface->resource.destroy_listener_list.prev,
&device->keyboard_focus_listener.link);
}
+ device->keyboard_focus_resource = resource;
device->keyboard_focus = surface;
device->keyboard_focus_time = time;
}
static void
display_bind(struct wl_client *client,
- struct wl_display *display, uint32_t id,
+ struct wl_resource *resource, uint32_t id,
const char *interface, uint32_t version)
{
struct wl_global *global;
+ struct wl_display *display = resource->data;
wl_list_for_each(global, &display->global_list, link)
if (global->object->id == id)
break;
if (&global->link == &display->global_list)
- wl_client_post_error(client, &client->display->object,
+ wl_client_post_error(client, &client->display->resource.object,
WL_DISPLAY_ERROR_INVALID_OBJECT,
"invalid object %d", id);
else if (global->func)
static void
display_sync(struct wl_client *client,
- struct wl_display *display, uint32_t id)
+ struct wl_resource *resource, uint32_t id)
{
- struct wl_object object;
+ struct wl_resource callback;
- object.interface = &wl_callback_interface;
- object.id = id;
+ callback.object.interface = &wl_callback_interface;
+ callback.object.id = id;
+ callback.client = client;
- wl_client_post_event(client, &object, WL_CALLBACK_DONE, 0);
+ wl_resource_post_event(&callback, WL_CALLBACK_DONE, 0);
}
struct wl_display_interface display_interface = {
display->client_id_range = 256; /* Gah, arbitrary... */
display->id = 1;
- display->object.interface = &wl_display_interface;
- display->object.implementation = (void (**)(void)) &display_interface;
- wl_display_add_object(display, &display->object);
- if (wl_display_add_global(display, &display->object, NULL)) {
+ display->resource.object.interface = &wl_display_interface;
+ display->resource.object.implementation =
+ (void (**)(void)) &display_interface;
+ display->resource.data = display;
+
+ wl_display_add_object(display, &display->resource.object);
+ if (wl_display_add_global(display, &display->resource.object, NULL)) {
wl_hash_table_destroy(display->objects);
wl_event_loop_destroy(display->loop);
free(display);
return -1;
wl_list_for_each(client, &display->client_list, link)
- wl_client_post_event(client,
- &client->display->object,
- WL_DISPLAY_GLOBAL_REMOVE,
- global->object->id);
+ wl_resource_post_event(&client->display_resource,
+ WL_DISPLAY_GLOBAL_REMOVE,
+ global->object->id);
wl_list_remove(&global->link);
free(global);
struct wl_object *global, uint32_t version)
{
struct wl_compositor *compositor =
- container_of(global, struct wl_compositor, object);
+ container_of(global, struct wl_compositor, resource.object);
- wl_client_post_event(client, global,
- WL_COMPOSITOR_TOKEN_VISUAL,
- &compositor->argb_visual.object,
- WL_COMPOSITOR_VISUAL_ARGB32);
+ compositor->resource.client = client;
+ wl_resource_post_event(&compositor->resource,
+ WL_COMPOSITOR_TOKEN_VISUAL,
+ &compositor->argb_visual.object,
+ WL_COMPOSITOR_VISUAL_ARGB32);
- wl_client_post_event(client, global,
- WL_COMPOSITOR_TOKEN_VISUAL,
- &compositor->premultiplied_argb_visual.object,
- WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32);
+ wl_resource_post_event(&compositor->resource,
+ WL_COMPOSITOR_TOKEN_VISUAL,
+ &compositor->premultiplied_argb_visual.object,
+ WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32);
- wl_client_post_event(client, global,
- WL_COMPOSITOR_TOKEN_VISUAL,
- &compositor->rgb_visual.object,
- WL_COMPOSITOR_VISUAL_XRGB32);
+ wl_resource_post_event(&compositor->resource,
+ WL_COMPOSITOR_TOKEN_VISUAL,
+ &compositor->rgb_visual.object,
+ WL_COMPOSITOR_VISUAL_XRGB32);
}
WL_EXPORT int
const struct wl_compositor_interface *interface,
struct wl_display *display)
{
- compositor->object.interface = &wl_compositor_interface;
- compositor->object.implementation = (void (**)(void)) interface;
- wl_display_add_object(display, &compositor->object);
- if (wl_display_add_global(display,
- &compositor->object, compositor_bind))
+ compositor->resource.object.interface = &wl_compositor_interface;
+ compositor->resource.object.implementation =
+ (void (**)(void)) interface;
+ compositor->resource.data = compositor;
+ wl_display_add_object(display, &compositor->resource.object);
+ if (wl_display_add_global(display, &compositor->resource.object,
+ compositor_bind))
return -1;
compositor->argb_visual.object.interface = &wl_visual_interface;
#include "wayland-server.h"
struct wl_shm {
- struct wl_object object;
+ struct wl_resource resource;
const struct wl_shm_callbacks *callbacks;
};
};
static void
-destroy_buffer(struct wl_resource *resource, struct wl_client *client)
+destroy_buffer(struct wl_resource *resource)
{
struct wl_shm_buffer *buffer =
container_of(resource, struct wl_shm_buffer, buffer.resource);
}
static void
-shm_buffer_damage(struct wl_client *client, struct wl_buffer *buffer_base,
+shm_buffer_damage(struct wl_client *client, struct wl_resource *resource,
int32_t x, int32_t y, int32_t width, int32_t height)
{
- struct wl_shm_buffer *buffer = (struct wl_shm_buffer *) buffer_base;
+ struct wl_shm_buffer *buffer = resource->data;
- buffer->shm->callbacks->buffer_damaged(buffer_base, x, y,
+ buffer->shm->callbacks->buffer_damaged(&buffer->buffer, x, y,
width, height);
}
static void
-shm_buffer_destroy(struct wl_client *client, struct wl_buffer *buffer)
+shm_buffer_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(&buffer->resource, client, 0);
+ wl_resource_destroy(resource, 0);
}
const static struct wl_buffer_interface shm_buffer_interface = {
buffer->buffer.width = width;
buffer->buffer.height = height;
buffer->buffer.visual = visual;
- buffer->buffer.client = client;
buffer->stride = stride;
buffer->data = data;
buffer->buffer.resource.object.implementation = (void (**)(void))
&shm_buffer_interface;
+ buffer->buffer.resource.data = buffer;
+ buffer->buffer.resource.client = client;
buffer->buffer.resource.destroy = destroy_buffer;
buffer->shm = shm;
}
static void
-shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
+shm_create_buffer(struct wl_client *client, struct wl_resource *resource,
uint32_t id, int fd, int32_t width, int32_t height,
uint32_t stride, struct wl_visual *visual)
{
+ struct wl_shm *shm = resource->data;
struct wl_shm_buffer *buffer;
void *data;
if (!visual || visual->object.interface != &wl_visual_interface) {
- wl_client_post_error(client, &shm->object,
+ wl_client_post_error(client, &shm->resource.object,
WL_SHM_ERROR_INVALID_VISUAL,
"invalid visual");
close(fd);
}
if (width < 0 || height < 0 || stride < width) {
- wl_client_post_error(client, &shm->object,
+ wl_client_post_error(client, &shm->resource.object,
WL_SHM_ERROR_INVALID_STRIDE,
"invalid width, height or stride (%dx%d, %u)",
width, height, stride);
close(fd);
if (data == MAP_FAILED) {
- wl_client_post_error(client, &shm->object,
+ wl_client_post_error(client, &shm->resource.object,
WL_SHM_ERROR_INVALID_FD,
"failed mmap fd %d", fd);
return;
if (!shm)
return NULL;
- shm->object.interface = &wl_shm_interface;
- shm->object.implementation = (void (**)(void)) &shm_interface;
- wl_display_add_object(display, &shm->object);
- wl_display_add_global(display, &shm->object, NULL);
+ shm->resource.object.interface = &wl_shm_interface;
+ shm->resource.object.implementation = (void (**)(void)) &shm_interface;
+ shm->resource.data = shm;
+ wl_display_add_object(display, &shm->resource.object);
+ wl_display_add_global(display, &shm->resource.object, NULL);
shm->callbacks = callbacks;