mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-03 09:01:42 -05:00
server: Make everything in the object hash a wl_resource
This commit is contained in:
parent
936cd607a7
commit
2df5d2f114
4 changed files with 170 additions and 132 deletions
|
|
@ -527,9 +527,8 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
|
||||||
n = strlen(m->name) + 17;
|
n = strlen(m->name) + 17;
|
||||||
if (is_interface) {
|
if (is_interface) {
|
||||||
printf("struct wl_client *client,\n"
|
printf("struct wl_client *client,\n"
|
||||||
"%sstruct %s *%s",
|
"%sstruct wl_resource *resource",
|
||||||
indent(n),
|
indent(n));
|
||||||
interface->name, interface->name);
|
|
||||||
} else {
|
} else {
|
||||||
printf("void *data,\n"),
|
printf("void *data,\n"),
|
||||||
printf("%sstruct %s *%s",
|
printf("%sstruct %s *%s",
|
||||||
|
|
@ -606,7 +605,8 @@ emit_header(struct protocol *protocol, int server)
|
||||||
"#include <stdint.h>\n"
|
"#include <stdint.h>\n"
|
||||||
"#include <stddef.h>\n"
|
"#include <stddef.h>\n"
|
||||||
"#include \"wayland-util.h\"\n\n"
|
"#include \"wayland-util.h\"\n\n"
|
||||||
"struct wl_client;\n\n",
|
"struct wl_client;\n"
|
||||||
|
"struct wl_resource;\n\n",
|
||||||
protocol->uppercase_name, s,
|
protocol->uppercase_name, s,
|
||||||
protocol->uppercase_name, s);
|
protocol->uppercase_name, s);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ struct wl_client {
|
||||||
struct wl_connection *connection;
|
struct wl_connection *connection;
|
||||||
struct wl_event_source *source;
|
struct wl_event_source *source;
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
|
struct wl_resource display_resource;
|
||||||
struct wl_list resource_list;
|
struct wl_list resource_list;
|
||||||
uint32_t id_count;
|
uint32_t id_count;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
|
|
@ -64,7 +65,7 @@ struct wl_client {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_display {
|
struct wl_display {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
struct wl_event_loop *loop;
|
struct wl_event_loop *loop;
|
||||||
struct wl_hash_table *objects;
|
struct wl_hash_table *objects;
|
||||||
int run;
|
int run;
|
||||||
|
|
@ -87,22 +88,22 @@ struct wl_global {
|
||||||
static int wl_debug = 0;
|
static int wl_debug = 0;
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_client_post_event(struct wl_client *client, struct wl_object *sender,
|
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
|
||||||
uint32_t opcode, ...)
|
|
||||||
{
|
{
|
||||||
struct wl_closure *closure;
|
struct wl_closure *closure;
|
||||||
|
struct wl_object *object = &resource->object;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, opcode);
|
va_start(ap, opcode);
|
||||||
closure = wl_connection_vmarshal(client->connection,
|
closure = wl_connection_vmarshal(resource->client->connection,
|
||||||
sender, opcode, ap,
|
object, opcode, ap,
|
||||||
&sender->interface->events[opcode]);
|
&object->interface->events[opcode]);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
wl_closure_send(closure, client->connection);
|
wl_closure_send(closure, resource->client->connection);
|
||||||
|
|
||||||
if (wl_debug)
|
if (wl_debug)
|
||||||
wl_closure_print(closure, sender, true);
|
wl_closure_print(closure, object, true);
|
||||||
|
|
||||||
wl_closure_destroy(closure);
|
wl_closure_destroy(closure);
|
||||||
}
|
}
|
||||||
|
|
@ -118,8 +119,8 @@ wl_client_post_error(struct wl_client *client, struct wl_object *object,
|
||||||
vsnprintf(buffer, sizeof buffer, msg, ap);
|
vsnprintf(buffer, sizeof buffer, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
wl_client_post_event(client, &client->display->object,
|
wl_resource_post_event(&client->display_resource,
|
||||||
WL_DISPLAY_ERROR, object, code, buffer);
|
WL_DISPLAY_ERROR, object, code, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -127,6 +128,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
{
|
{
|
||||||
struct wl_client *client = data;
|
struct wl_client *client = data;
|
||||||
struct wl_connection *connection = client->connection;
|
struct wl_connection *connection = client->connection;
|
||||||
|
struct wl_resource *resource;
|
||||||
struct wl_object *object;
|
struct wl_object *object;
|
||||||
struct wl_closure *closure;
|
struct wl_closure *closure;
|
||||||
const struct wl_message *message;
|
const struct wl_message *message;
|
||||||
|
|
@ -152,9 +154,10 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
if (len < size)
|
if (len < size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
object = wl_hash_table_lookup(client->display->objects, p[0]);
|
resource = wl_hash_table_lookup(client->display->objects, p[0]);
|
||||||
if (object == NULL) {
|
if (resource == NULL) {
|
||||||
wl_client_post_error(client, &client->display->object,
|
wl_client_post_error(client,
|
||||||
|
&client->display->resource.object,
|
||||||
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
||||||
"invalid object %d", p[0]);
|
"invalid object %d", p[0]);
|
||||||
wl_connection_consume(connection, size);
|
wl_connection_consume(connection, size);
|
||||||
|
|
@ -162,8 +165,10 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object = &resource->object;
|
||||||
if (opcode >= object->interface->method_count) {
|
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,
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
||||||
"invalid method %d, object %s@%d",
|
"invalid method %d, object %s@%d",
|
||||||
object->interface->name,
|
object->interface->name,
|
||||||
|
|
@ -180,11 +185,13 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
len -= size;
|
len -= size;
|
||||||
|
|
||||||
if (closure == NULL && errno == EINVAL) {
|
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,
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
||||||
"invalid arguments for %s@%d.%s",
|
"invalid arguments for %s@%d.%s",
|
||||||
object->interface->name,
|
object->interface->name,
|
||||||
object->id, message->name);
|
object->id,
|
||||||
|
message->name);
|
||||||
continue;
|
continue;
|
||||||
} else if (closure == NULL && errno == ENOMEM) {
|
} else if (closure == NULL && errno == ENOMEM) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
|
|
@ -193,7 +200,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
|
||||||
|
|
||||||
|
|
||||||
if (wl_debug)
|
if (wl_debug)
|
||||||
wl_closure_print(closure, object, false);
|
wl_closure_print(closure, object, false);
|
||||||
|
|
||||||
wl_closure_invoke(closure, object,
|
wl_closure_invoke(closure, object,
|
||||||
object->implementation[opcode], client);
|
object->implementation[opcode], client);
|
||||||
|
|
@ -236,8 +243,8 @@ wl_client_get_display(struct wl_client *client)
|
||||||
static void
|
static void
|
||||||
wl_display_post_range(struct wl_display *display, struct wl_client *client)
|
wl_display_post_range(struct wl_display *display, struct wl_client *client)
|
||||||
{
|
{
|
||||||
wl_client_post_event(client, &client->display->object,
|
wl_resource_post_event(&client->display_resource,
|
||||||
WL_DISPLAY_RANGE, display->client_id_range);
|
WL_DISPLAY_RANGE, display->client_id_range);
|
||||||
display->client_id_range += 256;
|
display->client_id_range += 256;
|
||||||
client->id_count += 256;
|
client->id_count += 256;
|
||||||
}
|
}
|
||||||
|
|
@ -264,6 +271,9 @@ wl_client_create(struct wl_display *display, int fd)
|
||||||
return NULL;
|
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_insert(display->client_list.prev, &client->link);
|
||||||
|
|
||||||
wl_list_init(&client->resource_list);
|
wl_list_init(&client->resource_list);
|
||||||
|
|
@ -285,6 +295,7 @@ wl_client_add_resource(struct wl_client *client,
|
||||||
if (client->id_count-- < 64)
|
if (client->id_count-- < 64)
|
||||||
wl_display_post_range(display, client);
|
wl_display_post_range(display, client);
|
||||||
|
|
||||||
|
resource->client = client;
|
||||||
wl_list_init(&resource->destroy_listener_list);
|
wl_list_init(&resource->destroy_listener_list);
|
||||||
|
|
||||||
wl_hash_table_insert(client->display->objects,
|
wl_hash_table_insert(client->display->objects,
|
||||||
|
|
@ -295,36 +306,33 @@ wl_client_add_resource(struct wl_client *client,
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_client_post_no_memory(struct wl_client *client)
|
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_DISPLAY_ERROR_NO_MEMORY, "no memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_client_post_global(struct wl_client *client, struct wl_object *object)
|
wl_client_post_global(struct wl_client *client, struct wl_object *object)
|
||||||
{
|
{
|
||||||
wl_client_post_event(client,
|
wl_resource_post_event(&client->display_resource,
|
||||||
&client->display->object,
|
WL_DISPLAY_GLOBAL,
|
||||||
WL_DISPLAY_GLOBAL,
|
object->id,
|
||||||
object->id,
|
object->interface->name,
|
||||||
object->interface->name,
|
object->interface->version);
|
||||||
object->interface->version);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
wl_resource_destroy(struct wl_resource *resource,
|
wl_resource_destroy(struct wl_resource *resource, uint32_t time)
|
||||||
struct wl_client *client, uint32_t time)
|
|
||||||
{
|
{
|
||||||
struct wl_display *display = client->display;
|
struct wl_display *display = resource->client->display;
|
||||||
struct wl_listener *l, *next;
|
struct wl_listener *l, *next;
|
||||||
|
|
||||||
wl_list_for_each_safe(l, next,
|
wl_list_for_each_safe(l, next, &resource->destroy_listener_list, link)
|
||||||
&resource->destroy_listener_list, link)
|
|
||||||
l->func(l, resource, time);
|
l->func(l, resource, time);
|
||||||
|
|
||||||
wl_list_remove(&resource->link);
|
wl_list_remove(&resource->link);
|
||||||
if (resource->object.id > 0)
|
if (resource->object.id > 0)
|
||||||
wl_hash_table_remove(display->objects, resource->object.id);
|
wl_hash_table_remove(display->objects, resource->object.id);
|
||||||
resource->destroy(resource, client);
|
resource->destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
|
|
@ -335,7 +343,7 @@ wl_client_destroy(struct wl_client *client)
|
||||||
printf("disconnect from client %p\n", client);
|
printf("disconnect from client %p\n", client);
|
||||||
|
|
||||||
wl_list_for_each_safe(resource, tmp, &client->resource_list, link)
|
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_event_source_remove(client->source);
|
||||||
wl_connection_destroy(client->connection);
|
wl_connection_destroy(client->connection);
|
||||||
|
|
@ -369,9 +377,9 @@ WL_EXPORT void
|
||||||
wl_input_device_init(struct wl_input_device *device,
|
wl_input_device_init(struct wl_input_device *device,
|
||||||
struct wl_compositor *compositor)
|
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;
|
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->keyboard_focus_listener.func = lose_keyboard_focus;
|
||||||
|
|
||||||
device->x = 100;
|
device->x = 100;
|
||||||
|
|
@ -379,6 +387,22 @@ wl_input_device_init(struct wl_input_device *device,
|
||||||
device->compositor = compositor;
|
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_EXPORT void
|
||||||
wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
||||||
struct wl_surface *surface,
|
struct wl_surface *surface,
|
||||||
|
|
@ -386,30 +410,32 @@ wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
||||||
int32_t x, int32_t y,
|
int32_t x, int32_t y,
|
||||||
int32_t sx, int32_t sy)
|
int32_t sx, int32_t sy)
|
||||||
{
|
{
|
||||||
|
struct wl_resource *resource;
|
||||||
|
|
||||||
if (device->pointer_focus == surface)
|
if (device->pointer_focus == surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (device->pointer_focus &&
|
if (device->pointer_focus_resource &&
|
||||||
(!surface || device->pointer_focus->client != surface->client))
|
(!surface ||
|
||||||
wl_client_post_event(device->pointer_focus->client,
|
device->pointer_focus->resource.client != surface->resource.client))
|
||||||
&device->object,
|
wl_resource_post_event(device->pointer_focus_resource,
|
||||||
WL_INPUT_DEVICE_POINTER_FOCUS,
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
||||||
time, NULL, 0, 0, 0, 0);
|
time, NULL, 0, 0, 0, 0);
|
||||||
if (device->pointer_focus)
|
if (device->pointer_focus_resource)
|
||||||
wl_list_remove(&device->pointer_focus_listener.link);
|
wl_list_remove(&device->pointer_focus_listener.link);
|
||||||
|
|
||||||
if (surface) {
|
resource = find_resource_for_surface(&device->resource_list, surface);
|
||||||
wl_client_post_event(surface->client,
|
if (resource) {
|
||||||
&device->object,
|
wl_resource_post_event(resource,
|
||||||
WL_INPUT_DEVICE_POINTER_FOCUS,
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
||||||
time, surface, x, y, sx, sy);
|
time, surface, x, y, sx, sy);
|
||||||
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||||
&device->pointer_focus_listener.link);
|
&device->pointer_focus_listener.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device->pointer_focus_resource = resource;
|
||||||
device->pointer_focus = surface;
|
device->pointer_focus = surface;
|
||||||
device->pointer_focus_time = time;
|
device->pointer_focus_time = time;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT void
|
WL_EXPORT void
|
||||||
|
|
@ -417,27 +443,30 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device,
|
||||||
struct wl_surface *surface,
|
struct wl_surface *surface,
|
||||||
uint32_t time)
|
uint32_t time)
|
||||||
{
|
{
|
||||||
|
struct wl_resource *resource;
|
||||||
|
|
||||||
if (device->keyboard_focus == surface)
|
if (device->keyboard_focus == surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (device->keyboard_focus &&
|
if (device->keyboard_focus_resource &&
|
||||||
(!surface || device->keyboard_focus->client != surface->client))
|
(!surface ||
|
||||||
wl_client_post_event(device->keyboard_focus->client,
|
device->keyboard_focus->resource.client != surface->resource.client))
|
||||||
&device->object,
|
wl_resource_post_event(device->keyboard_focus_resource,
|
||||||
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
||||||
time, NULL, &device->keys);
|
time, NULL, &device->keys);
|
||||||
if (device->keyboard_focus)
|
if (device->keyboard_focus_resource)
|
||||||
wl_list_remove(&device->keyboard_focus_listener.link);
|
wl_list_remove(&device->keyboard_focus_listener.link);
|
||||||
|
|
||||||
if (surface) {
|
resource = find_resource_for_surface(&device->resource_list, surface);
|
||||||
wl_client_post_event(surface->client,
|
if (resource) {
|
||||||
&device->object,
|
wl_resource_post_event(resource,
|
||||||
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
||||||
time, surface, &device->keys);
|
time, surface, &device->keys);
|
||||||
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||||
&device->keyboard_focus_listener.link);
|
&device->keyboard_focus_listener.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
device->keyboard_focus_resource = resource;
|
||||||
device->keyboard_focus = surface;
|
device->keyboard_focus = surface;
|
||||||
device->keyboard_focus_time = time;
|
device->keyboard_focus_time = time;
|
||||||
}
|
}
|
||||||
|
|
@ -504,17 +533,18 @@ wl_input_device_update_grab(struct wl_input_device *device,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
display_bind(struct wl_client *client,
|
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)
|
const char *interface, uint32_t version)
|
||||||
{
|
{
|
||||||
struct wl_global *global;
|
struct wl_global *global;
|
||||||
|
struct wl_display *display = resource->data;
|
||||||
|
|
||||||
wl_list_for_each(global, &display->global_list, link)
|
wl_list_for_each(global, &display->global_list, link)
|
||||||
if (global->object->id == id)
|
if (global->object->id == id)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (&global->link == &display->global_list)
|
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,
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
||||||
"invalid object %d", id);
|
"invalid object %d", id);
|
||||||
else if (global->func)
|
else if (global->func)
|
||||||
|
|
@ -523,14 +553,15 @@ display_bind(struct wl_client *client,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
display_sync(struct wl_client *client,
|
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;
|
callback.object.interface = &wl_callback_interface;
|
||||||
object.id = id;
|
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 = {
|
struct wl_display_interface display_interface = {
|
||||||
|
|
@ -574,10 +605,13 @@ wl_display_create(void)
|
||||||
display->client_id_range = 256; /* Gah, arbitrary... */
|
display->client_id_range = 256; /* Gah, arbitrary... */
|
||||||
|
|
||||||
display->id = 1;
|
display->id = 1;
|
||||||
display->object.interface = &wl_display_interface;
|
display->resource.object.interface = &wl_display_interface;
|
||||||
display->object.implementation = (void (**)(void)) &display_interface;
|
display->resource.object.implementation =
|
||||||
wl_display_add_object(display, &display->object);
|
(void (**)(void)) &display_interface;
|
||||||
if (wl_display_add_global(display, &display->object, NULL)) {
|
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_hash_table_destroy(display->objects);
|
||||||
wl_event_loop_destroy(display->loop);
|
wl_event_loop_destroy(display->loop);
|
||||||
free(display);
|
free(display);
|
||||||
|
|
@ -648,10 +682,9 @@ wl_display_remove_global(struct wl_display *display,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
wl_list_for_each(client, &display->client_list, link)
|
wl_list_for_each(client, &display->client_list, link)
|
||||||
wl_client_post_event(client,
|
wl_resource_post_event(&client->display_resource,
|
||||||
&client->display->object,
|
WL_DISPLAY_GLOBAL_REMOVE,
|
||||||
WL_DISPLAY_GLOBAL_REMOVE,
|
global->object->id);
|
||||||
global->object->id);
|
|
||||||
wl_list_remove(&global->link);
|
wl_list_remove(&global->link);
|
||||||
free(global);
|
free(global);
|
||||||
|
|
||||||
|
|
@ -820,22 +853,23 @@ compositor_bind(struct wl_client *client,
|
||||||
struct wl_object *global, uint32_t version)
|
struct wl_object *global, uint32_t version)
|
||||||
{
|
{
|
||||||
struct wl_compositor *compositor =
|
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,
|
compositor->resource.client = client;
|
||||||
WL_COMPOSITOR_TOKEN_VISUAL,
|
wl_resource_post_event(&compositor->resource,
|
||||||
&compositor->argb_visual.object,
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
||||||
WL_COMPOSITOR_VISUAL_ARGB32);
|
&compositor->argb_visual.object,
|
||||||
|
WL_COMPOSITOR_VISUAL_ARGB32);
|
||||||
|
|
||||||
wl_client_post_event(client, global,
|
wl_resource_post_event(&compositor->resource,
|
||||||
WL_COMPOSITOR_TOKEN_VISUAL,
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
||||||
&compositor->premultiplied_argb_visual.object,
|
&compositor->premultiplied_argb_visual.object,
|
||||||
WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32);
|
WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32);
|
||||||
|
|
||||||
wl_client_post_event(client, global,
|
wl_resource_post_event(&compositor->resource,
|
||||||
WL_COMPOSITOR_TOKEN_VISUAL,
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
||||||
&compositor->rgb_visual.object,
|
&compositor->rgb_visual.object,
|
||||||
WL_COMPOSITOR_VISUAL_XRGB32);
|
WL_COMPOSITOR_VISUAL_XRGB32);
|
||||||
}
|
}
|
||||||
|
|
||||||
WL_EXPORT int
|
WL_EXPORT int
|
||||||
|
|
@ -843,11 +877,13 @@ wl_compositor_init(struct wl_compositor *compositor,
|
||||||
const struct wl_compositor_interface *interface,
|
const struct wl_compositor_interface *interface,
|
||||||
struct wl_display *display)
|
struct wl_display *display)
|
||||||
{
|
{
|
||||||
compositor->object.interface = &wl_compositor_interface;
|
compositor->resource.object.interface = &wl_compositor_interface;
|
||||||
compositor->object.implementation = (void (**)(void)) interface;
|
compositor->resource.object.implementation =
|
||||||
wl_display_add_object(display, &compositor->object);
|
(void (**)(void)) interface;
|
||||||
if (wl_display_add_global(display,
|
compositor->resource.data = compositor;
|
||||||
&compositor->object, compositor_bind))
|
wl_display_add_object(display, &compositor->resource.object);
|
||||||
|
if (wl_display_add_global(display, &compositor->resource.object,
|
||||||
|
compositor_bind))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
compositor->argb_visual.object.interface = &wl_visual_interface;
|
compositor->argb_visual.object.interface = &wl_visual_interface;
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,15 @@ void wl_client_post_no_memory(struct wl_client *client);
|
||||||
void wl_client_post_global(struct wl_client *client, struct wl_object *object);
|
void wl_client_post_global(struct wl_client *client, struct wl_object *object);
|
||||||
void wl_client_flush(struct wl_client *client);
|
void wl_client_flush(struct wl_client *client);
|
||||||
|
|
||||||
|
struct wl_resource {
|
||||||
|
struct wl_object object;
|
||||||
|
void (*destroy)(struct wl_resource *resource);
|
||||||
|
struct wl_list link;
|
||||||
|
struct wl_list destroy_listener_list;
|
||||||
|
struct wl_client *client;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
struct wl_visual {
|
struct wl_visual {
|
||||||
struct wl_object object;
|
struct wl_object object;
|
||||||
};
|
};
|
||||||
|
|
@ -119,23 +128,14 @@ struct wl_shm_callbacks {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_compositor {
|
struct wl_compositor {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
struct wl_visual argb_visual;
|
struct wl_visual argb_visual;
|
||||||
struct wl_visual premultiplied_argb_visual;
|
struct wl_visual premultiplied_argb_visual;
|
||||||
struct wl_visual rgb_visual;
|
struct wl_visual rgb_visual;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_resource {
|
|
||||||
struct wl_object object;
|
|
||||||
void (*destroy)(struct wl_resource *resource,
|
|
||||||
struct wl_client *client);
|
|
||||||
struct wl_list link;
|
|
||||||
struct wl_list destroy_listener_list;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct wl_buffer {
|
struct wl_buffer {
|
||||||
struct wl_resource resource;
|
struct wl_resource resource;
|
||||||
struct wl_client *client;
|
|
||||||
struct wl_visual *visual;
|
struct wl_visual *visual;
|
||||||
int32_t width, height;
|
int32_t width, height;
|
||||||
uint32_t busy_count;
|
uint32_t busy_count;
|
||||||
|
|
@ -150,7 +150,6 @@ struct wl_listener {
|
||||||
|
|
||||||
struct wl_surface {
|
struct wl_surface {
|
||||||
struct wl_resource resource;
|
struct wl_resource resource;
|
||||||
struct wl_client *client;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_grab;
|
struct wl_grab;
|
||||||
|
|
@ -168,9 +167,12 @@ struct wl_grab {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_input_device {
|
struct wl_input_device {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
|
struct wl_list resource_list;
|
||||||
struct wl_compositor *compositor;
|
struct wl_compositor *compositor;
|
||||||
|
struct wl_resource *pointer_focus_resource;
|
||||||
struct wl_surface *pointer_focus;
|
struct wl_surface *pointer_focus;
|
||||||
|
struct wl_resource *keyboard_focus_resource;
|
||||||
struct wl_surface *keyboard_focus;
|
struct wl_surface *keyboard_focus;
|
||||||
struct wl_array keys;
|
struct wl_array keys;
|
||||||
uint32_t pointer_focus_time;
|
uint32_t pointer_focus_time;
|
||||||
|
|
@ -188,7 +190,7 @@ struct wl_input_device {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_drag_offer {
|
struct wl_drag_offer {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_drag {
|
struct wl_drag {
|
||||||
|
|
@ -206,7 +208,7 @@ struct wl_drag {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_selection_offer {
|
struct wl_selection_offer {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wl_selection {
|
struct wl_selection {
|
||||||
|
|
@ -221,9 +223,7 @@ struct wl_selection {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
wl_client_post_event(struct wl_client *client,
|
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...);
|
||||||
struct wl_object *sender,
|
|
||||||
uint32_t event, ...);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
wl_display_set_compositor(struct wl_display *display,
|
wl_display_set_compositor(struct wl_display *display,
|
||||||
|
|
@ -242,8 +242,7 @@ struct wl_display *
|
||||||
wl_client_get_display(struct wl_client *client);
|
wl_client_get_display(struct wl_client *client);
|
||||||
|
|
||||||
void
|
void
|
||||||
wl_resource_destroy(struct wl_resource *resource,
|
wl_resource_destroy(struct wl_resource *resource, uint32_t time);
|
||||||
struct wl_client *client, uint32_t time);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wl_input_device_init(struct wl_input_device *device,
|
wl_input_device_init(struct wl_input_device *device,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
#include "wayland-server.h"
|
#include "wayland-server.h"
|
||||||
|
|
||||||
struct wl_shm {
|
struct wl_shm {
|
||||||
struct wl_object object;
|
struct wl_resource resource;
|
||||||
const struct wl_shm_callbacks *callbacks;
|
const struct wl_shm_callbacks *callbacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ struct wl_shm_buffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_buffer(struct wl_resource *resource, struct wl_client *client)
|
destroy_buffer(struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
struct wl_shm_buffer *buffer =
|
struct wl_shm_buffer *buffer =
|
||||||
container_of(resource, struct wl_shm_buffer, buffer.resource);
|
container_of(resource, struct wl_shm_buffer, buffer.resource);
|
||||||
|
|
@ -59,19 +59,19 @@ destroy_buffer(struct wl_resource *resource, struct wl_client *client)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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)
|
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);
|
width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 = {
|
const static struct wl_buffer_interface shm_buffer_interface = {
|
||||||
|
|
@ -94,7 +94,6 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
|
||||||
buffer->buffer.width = width;
|
buffer->buffer.width = width;
|
||||||
buffer->buffer.height = height;
|
buffer->buffer.height = height;
|
||||||
buffer->buffer.visual = visual;
|
buffer->buffer.visual = visual;
|
||||||
buffer->buffer.client = client;
|
|
||||||
buffer->stride = stride;
|
buffer->stride = stride;
|
||||||
buffer->data = data;
|
buffer->data = data;
|
||||||
|
|
||||||
|
|
@ -103,6 +102,8 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
|
||||||
buffer->buffer.resource.object.implementation = (void (**)(void))
|
buffer->buffer.resource.object.implementation = (void (**)(void))
|
||||||
&shm_buffer_interface;
|
&shm_buffer_interface;
|
||||||
|
|
||||||
|
buffer->buffer.resource.data = buffer;
|
||||||
|
buffer->buffer.resource.client = client;
|
||||||
buffer->buffer.resource.destroy = destroy_buffer;
|
buffer->buffer.resource.destroy = destroy_buffer;
|
||||||
|
|
||||||
buffer->shm = shm;
|
buffer->shm = shm;
|
||||||
|
|
@ -113,15 +114,16 @@ wl_shm_buffer_init(struct wl_shm *shm, struct wl_client *client, uint32_t id,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 id, int fd, int32_t width, int32_t height,
|
||||||
uint32_t stride, struct wl_visual *visual)
|
uint32_t stride, struct wl_visual *visual)
|
||||||
{
|
{
|
||||||
|
struct wl_shm *shm = resource->data;
|
||||||
struct wl_shm_buffer *buffer;
|
struct wl_shm_buffer *buffer;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
if (!visual || visual->object.interface != &wl_visual_interface) {
|
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,
|
WL_SHM_ERROR_INVALID_VISUAL,
|
||||||
"invalid visual");
|
"invalid visual");
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
@ -129,7 +131,7 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width < 0 || height < 0 || stride < width) {
|
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,
|
WL_SHM_ERROR_INVALID_STRIDE,
|
||||||
"invalid width, height or stride (%dx%d, %u)",
|
"invalid width, height or stride (%dx%d, %u)",
|
||||||
width, height, stride);
|
width, height, stride);
|
||||||
|
|
@ -142,7 +144,7 @@ shm_create_buffer(struct wl_client *client, struct wl_shm *shm,
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
if (data == MAP_FAILED) {
|
if (data == MAP_FAILED) {
|
||||||
wl_client_post_error(client, &shm->object,
|
wl_client_post_error(client, &shm->resource.object,
|
||||||
WL_SHM_ERROR_INVALID_FD,
|
WL_SHM_ERROR_INVALID_FD,
|
||||||
"failed mmap fd %d", fd);
|
"failed mmap fd %d", fd);
|
||||||
return;
|
return;
|
||||||
|
|
@ -175,10 +177,11 @@ wl_shm_init(struct wl_display *display,
|
||||||
if (!shm)
|
if (!shm)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
shm->object.interface = &wl_shm_interface;
|
shm->resource.object.interface = &wl_shm_interface;
|
||||||
shm->object.implementation = (void (**)(void)) &shm_interface;
|
shm->resource.object.implementation = (void (**)(void)) &shm_interface;
|
||||||
wl_display_add_object(display, &shm->object);
|
shm->resource.data = shm;
|
||||||
wl_display_add_global(display, &shm->object, NULL);
|
wl_display_add_object(display, &shm->resource.object);
|
||||||
|
wl_display_add_global(display, &shm->resource.object, NULL);
|
||||||
|
|
||||||
shm->callbacks = callbacks;
|
shm->callbacks = callbacks;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue