2008-12-02 15:15:01 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
|
*
|
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-04-11 09:24:11 -04:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
2008-09-30 09:46:10 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdio.h>
|
2008-11-28 19:12:45 -05:00
|
|
|
#include <stdarg.h>
|
2011-07-14 18:56:40 +03:00
|
|
|
#include <stdbool.h>
|
2008-09-30 09:46:10 -04:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/un.h>
|
2008-11-06 10:38:17 -05:00
|
|
|
#include <dlfcn.h>
|
2008-11-28 19:12:45 -05:00
|
|
|
#include <assert.h>
|
2010-12-06 16:56:28 -05:00
|
|
|
#include <sys/time.h>
|
2011-04-11 09:24:11 -04:00
|
|
|
#include <fcntl.h>
|
2011-04-13 09:38:29 +02:00
|
|
|
#include <sys/file.h>
|
|
|
|
|
#include <sys/stat.h>
|
2008-09-30 09:46:10 -04:00
|
|
|
#include <ffi.h>
|
2008-10-08 12:48:46 -04:00
|
|
|
|
2011-11-18 13:46:56 -05:00
|
|
|
#include "wayland-private.h"
|
2010-08-10 14:12:05 -04:00
|
|
|
#include "wayland-server.h"
|
2010-08-03 09:26:44 -04:00
|
|
|
#include "wayland-server-protocol.h"
|
2012-03-21 11:11:26 +02:00
|
|
|
#include "wayland-os.h"
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2012-06-15 21:09:00 +00:00
|
|
|
/* This is the size of the char array in struct sock_addr_un.
|
|
|
|
|
No Wayland socket can be created with a path longer than this,
|
|
|
|
|
including the null terminator. */
|
|
|
|
|
#ifndef UNIX_PATH_MAX
|
|
|
|
|
#define UNIX_PATH_MAX 108
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define LOCK_SUFFIX ".lock"
|
|
|
|
|
#define LOCK_SUFFIXLEN 5
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
struct wl_socket {
|
|
|
|
|
int fd;
|
2011-04-13 09:38:29 +02:00
|
|
|
int fd_lock;
|
2010-12-01 15:36:20 -05:00
|
|
|
struct sockaddr_un addr;
|
2012-06-15 21:09:00 +00:00
|
|
|
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
2010-12-01 15:36:20 -05:00
|
|
|
struct wl_list link;
|
2011-12-22 16:52:37 +02:00
|
|
|
struct wl_event_source *source;
|
2010-12-01 15:36:20 -05:00
|
|
|
};
|
|
|
|
|
|
2008-09-30 09:46:10 -04:00
|
|
|
struct wl_client {
|
2008-10-08 12:48:46 -04:00
|
|
|
struct wl_connection *connection;
|
2008-09-30 09:46:10 -04:00
|
|
|
struct wl_event_source *source;
|
|
|
|
|
struct wl_display *display;
|
2011-08-19 16:57:48 -04:00
|
|
|
struct wl_resource *display_resource;
|
2008-12-21 22:45:33 -05:00
|
|
|
uint32_t id_count;
|
2011-06-29 11:43:11 -04:00
|
|
|
uint32_t mask;
|
2011-06-14 10:35:46 +02:00
|
|
|
struct wl_list link;
|
2011-08-19 22:50:53 -04:00
|
|
|
struct wl_map objects;
|
2012-04-13 09:53:15 -04:00
|
|
|
struct wl_signal destroy_signal;
|
2012-02-18 00:29:25 -05:00
|
|
|
struct ucred ucred;
|
2011-08-29 15:01:41 -04:00
|
|
|
int error;
|
2008-09-30 09:46:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct wl_display {
|
|
|
|
|
struct wl_event_loop *loop;
|
2010-12-01 15:36:20 -05:00
|
|
|
int run;
|
2008-10-07 10:10:36 -04:00
|
|
|
|
2008-11-23 23:41:08 -05:00
|
|
|
uint32_t id;
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
uint32_t serial;
|
2008-11-02 10:12:29 -05:00
|
|
|
|
2012-10-08 13:53:47 -04:00
|
|
|
struct wl_list registry_resource_list;
|
2008-11-23 19:10:23 -05:00
|
|
|
struct wl_list global_list;
|
2010-12-01 15:36:20 -05:00
|
|
|
struct wl_list socket_list;
|
2011-06-14 10:35:46 +02:00
|
|
|
struct wl_list client_list;
|
2013-01-11 14:29:32 -06:00
|
|
|
|
|
|
|
|
struct wl_signal destroy_signal;
|
2013-08-06 20:05:53 +02:00
|
|
|
|
|
|
|
|
struct wl_array additional_shm_formats;
|
2008-09-30 09:46:10 -04:00
|
|
|
};
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_global {
|
2013-07-08 18:45:41 -04:00
|
|
|
struct wl_display *display;
|
2011-08-19 16:57:48 -04:00
|
|
|
const struct wl_interface *interface;
|
|
|
|
|
uint32_t name;
|
2013-07-08 18:45:41 -04:00
|
|
|
uint32_t version;
|
2011-08-19 16:57:48 -04:00
|
|
|
void *data;
|
2011-08-19 11:05:01 -04:00
|
|
|
wl_global_bind_func_t bind;
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_list link;
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-27 20:09:18 -05:00
|
|
|
struct wl_resource {
|
|
|
|
|
struct wl_object object;
|
|
|
|
|
wl_resource_destroy_func_t destroy;
|
|
|
|
|
struct wl_list link;
|
|
|
|
|
struct wl_signal destroy_signal;
|
|
|
|
|
struct wl_client *client;
|
|
|
|
|
void *data;
|
2013-06-27 20:09:20 -05:00
|
|
|
int version;
|
2013-06-27 20:09:18 -05:00
|
|
|
};
|
|
|
|
|
|
2010-09-07 10:58:19 -04:00
|
|
|
static int wl_debug = 0;
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
WL_EXPORT void
|
2011-08-18 17:53:50 -04:00
|
|
|
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
|
2008-12-21 23:37:12 -05:00
|
|
|
{
|
2012-06-12 17:45:25 -04:00
|
|
|
struct wl_closure *closure;
|
2011-08-18 17:53:50 -04:00
|
|
|
struct wl_object *object = &resource->object;
|
2008-12-21 23:37:12 -05:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, opcode);
|
2012-06-12 17:45:25 -04:00
|
|
|
closure = wl_closure_vmarshal(object, opcode, ap,
|
|
|
|
|
&object->interface->events[opcode]);
|
2008-12-21 23:37:12 -05:00
|
|
|
va_end(ap);
|
2010-09-07 21:34:45 -04:00
|
|
|
|
2013-08-06 09:50:14 -07:00
|
|
|
if (closure == NULL) {
|
2013-08-06 10:15:35 -07:00
|
|
|
resource->client->error = 1;
|
2011-12-16 10:29:36 +02:00
|
|
|
return;
|
2013-08-06 09:50:14 -07:00
|
|
|
}
|
2011-12-16 10:29:36 +02:00
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (wl_closure_send(closure, resource->client->connection))
|
2013-08-06 10:15:35 -07:00
|
|
|
resource->client->error = 1;
|
2010-09-07 21:40:31 -04:00
|
|
|
|
2011-07-14 18:56:40 +03:00
|
|
|
if (wl_debug)
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_print(closure, object, true);
|
2010-09-07 21:40:31 -04:00
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_destroy(closure);
|
2008-12-21 23:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
2011-11-17 16:46:36 -05:00
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
|
|
|
|
|
{
|
2012-06-12 17:45:25 -04:00
|
|
|
struct wl_closure *closure;
|
2011-11-17 16:46:36 -05:00
|
|
|
struct wl_object *object = &resource->object;
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, opcode);
|
2012-06-12 17:45:25 -04:00
|
|
|
closure = wl_closure_vmarshal(object, opcode, ap,
|
|
|
|
|
&object->interface->events[opcode]);
|
2011-11-17 16:46:36 -05:00
|
|
|
va_end(ap);
|
|
|
|
|
|
2013-08-06 09:50:14 -07:00
|
|
|
if (closure == NULL) {
|
2013-08-06 10:15:35 -07:00
|
|
|
resource->client->error = 1;
|
2011-12-16 10:29:36 +02:00
|
|
|
return;
|
2013-08-06 09:50:14 -07:00
|
|
|
}
|
2011-12-16 10:29:36 +02:00
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (wl_closure_queue(closure, resource->client->connection))
|
2013-08-06 10:15:35 -07:00
|
|
|
resource->client->error = 1;
|
2011-11-17 16:46:36 -05:00
|
|
|
|
|
|
|
|
if (wl_debug)
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_print(closure, object, true);
|
2011-11-17 16:46:36 -05:00
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_destroy(closure);
|
2011-11-17 16:46:36 -05:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 10:57:06 -04:00
|
|
|
WL_EXPORT void
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_error(struct wl_resource *resource,
|
|
|
|
|
uint32_t code, const char *msg, ...)
|
2011-05-11 10:57:06 -04:00
|
|
|
{
|
2011-09-01 09:53:33 -04:00
|
|
|
struct wl_client *client = resource->client;
|
2011-05-11 10:57:06 -04:00
|
|
|
char buffer[128];
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
vsnprintf(buffer, sizeof buffer, msg, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2011-08-29 15:01:41 -04:00
|
|
|
client->error = 1;
|
2011-11-28 09:47:15 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When a client aborts, its resources are destroyed in id order,
|
|
|
|
|
* which means the display resource is destroyed first. If destruction
|
|
|
|
|
* of any later resources results in a protocol error, we end up here
|
|
|
|
|
* with a NULL display_resource. Do not try to send errors to an
|
|
|
|
|
* already dead client.
|
|
|
|
|
*/
|
|
|
|
|
if (!client->display_resource)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
wl_resource_post_event(client->display_resource,
|
2011-09-01 09:53:33 -04:00
|
|
|
WL_DISPLAY_ERROR, resource, code, buffer);
|
2011-05-11 10:57:06 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-22 12:06:34 -04:00
|
|
|
static int
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_client_connection_data(int fd, uint32_t mask, void *data)
|
2008-10-07 10:10:36 -04:00
|
|
|
{
|
2008-10-08 12:48:46 -04:00
|
|
|
struct wl_client *client = data;
|
|
|
|
|
struct wl_connection *connection = client->connection;
|
2011-08-18 17:53:50 -04:00
|
|
|
struct wl_resource *resource;
|
2008-10-07 10:10:36 -04:00
|
|
|
struct wl_object *object;
|
2012-06-12 17:45:25 -04:00
|
|
|
struct wl_closure *closure;
|
2010-08-30 09:47:36 -04:00
|
|
|
const struct wl_message *message;
|
2012-03-22 17:21:58 +02:00
|
|
|
uint32_t p[2];
|
2013-07-02 14:57:10 -04:00
|
|
|
uint32_t resource_flags;
|
2012-03-22 17:21:58 +02:00
|
|
|
int opcode, size;
|
2012-06-12 17:45:25 -04:00
|
|
|
int len;
|
2008-10-08 12:48:46 -04:00
|
|
|
|
2012-10-04 16:54:22 -04:00
|
|
|
if (mask & (WL_EVENT_ERROR | WL_EVENT_HANGUP)) {
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_client_destroy(client);
|
2011-04-22 12:06:34 -04:00
|
|
|
return 1;
|
2008-10-08 12:48:46 -04:00
|
|
|
}
|
2008-10-08 10:47:59 -04:00
|
|
|
|
2012-10-04 16:54:22 -04:00
|
|
|
if (mask & WL_EVENT_WRITABLE) {
|
|
|
|
|
len = wl_connection_flush(connection);
|
|
|
|
|
if (len < 0 && errno != EAGAIN) {
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
return 1;
|
|
|
|
|
} else if (len >= 0) {
|
|
|
|
|
wl_event_source_fd_update(client->source,
|
|
|
|
|
WL_EVENT_READABLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = 0;
|
|
|
|
|
if (mask & WL_EVENT_READABLE) {
|
|
|
|
|
len = wl_connection_read(connection);
|
|
|
|
|
if (len < 0 && errno != EAGAIN) {
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-30 11:27:02 -04:00
|
|
|
while ((size_t) len >= sizeof p) {
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_connection_copy(connection, p, sizeof p);
|
2008-10-07 10:10:36 -04:00
|
|
|
opcode = p[1] & 0xffff;
|
|
|
|
|
size = p[1] >> 16;
|
2008-10-08 12:48:46 -04:00
|
|
|
if (len < size)
|
2008-10-07 10:10:36 -04:00
|
|
|
break;
|
|
|
|
|
|
2011-08-19 22:50:53 -04:00
|
|
|
resource = wl_map_lookup(&client->objects, p[0]);
|
2013-07-02 14:57:10 -04:00
|
|
|
resource_flags = wl_map_lookup_flags(&client->objects, p[0]);
|
2011-08-18 17:53:50 -04:00
|
|
|
if (resource == NULL) {
|
2011-10-11 13:58:18 -04:00
|
|
|
wl_resource_post_error(client->display_resource,
|
2011-09-01 09:53:33 -04:00
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
2012-07-23 19:54:42 +01:00
|
|
|
"invalid object %u", p[0]);
|
2011-08-29 15:01:41 -04:00
|
|
|
break;
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2011-08-18 17:53:50 -04:00
|
|
|
object = &resource->object;
|
2008-10-07 10:10:36 -04:00
|
|
|
if (opcode >= object->interface->method_count) {
|
2011-10-11 14:36:49 -04:00
|
|
|
wl_resource_post_error(client->display_resource,
|
2011-09-01 09:53:33 -04:00
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
2012-07-23 19:54:42 +01:00
|
|
|
"invalid method %d, object %s@%u",
|
2012-03-27 16:36:25 -04:00
|
|
|
opcode,
|
2011-09-01 09:53:33 -04:00
|
|
|
object->interface->name,
|
2012-03-27 16:36:25 -04:00
|
|
|
object->id);
|
2011-08-29 15:01:41 -04:00
|
|
|
break;
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2010-08-30 09:47:36 -04:00
|
|
|
message = &object->interface->methods[opcode];
|
2013-07-02 14:57:10 -04:00
|
|
|
if (!(resource_flags & WL_MAP_ENTRY_LEGACY) &&
|
|
|
|
|
resource->version > 0 &&
|
|
|
|
|
resource->version < wl_message_get_since(message)) {
|
|
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
|
|
|
|
"invalid method %d, object %s@%u",
|
|
|
|
|
opcode,
|
|
|
|
|
object->interface->name,
|
|
|
|
|
object->id);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
closure = wl_connection_demarshal(client->connection, size,
|
|
|
|
|
&client->objects, message);
|
2010-08-30 09:47:36 -04:00
|
|
|
len -= size;
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2013-03-28 18:48:09 +00:00
|
|
|
if (closure == NULL && errno == ENOMEM) {
|
|
|
|
|
wl_resource_post_no_memory(resource);
|
|
|
|
|
break;
|
|
|
|
|
} else if ((closure == NULL && errno == EINVAL) ||
|
|
|
|
|
wl_closure_lookup_objects(closure, &client->objects) < 0) {
|
2011-10-11 14:36:49 -04:00
|
|
|
wl_resource_post_error(client->display_resource,
|
2011-09-01 09:53:33 -04:00
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
2012-07-23 19:54:42 +01:00
|
|
|
"invalid arguments for %s@%u.%s",
|
2011-09-01 09:53:33 -04:00
|
|
|
object->interface->name,
|
|
|
|
|
object->id,
|
|
|
|
|
message->name);
|
2011-08-29 15:01:41 -04:00
|
|
|
break;
|
2010-08-30 09:47:36 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 12:14:34 -04:00
|
|
|
if (wl_debug)
|
|
|
|
|
wl_closure_print(closure, object, false);
|
|
|
|
|
|
2013-03-08 18:44:16 +01:00
|
|
|
wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, object,
|
2013-03-08 22:26:12 -06:00
|
|
|
opcode, client);
|
2010-08-30 09:47:36 -04:00
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_destroy(closure);
|
2011-08-29 15:01:41 -04:00
|
|
|
|
|
|
|
|
if (client->error)
|
|
|
|
|
break;
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
2011-04-22 12:06:34 -04:00
|
|
|
|
2011-08-29 15:01:41 -04:00
|
|
|
if (client->error)
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
|
2011-04-22 12:06:34 -04:00
|
|
|
return 1;
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
|
|
|
|
|
2011-06-29 11:43:11 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_flush(struct wl_client *client)
|
|
|
|
|
{
|
2012-10-04 16:54:22 -04:00
|
|
|
wl_connection_flush(client->connection);
|
2011-06-29 11:43:11 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-17 21:23:10 -04:00
|
|
|
WL_EXPORT struct wl_display *
|
|
|
|
|
wl_client_get_display(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->display;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
static void
|
|
|
|
|
bind_display(struct wl_client *client,
|
|
|
|
|
void *data, uint32_t version, uint32_t id);
|
|
|
|
|
|
2011-04-11 09:15:09 -04:00
|
|
|
WL_EXPORT struct wl_client *
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_client_create(struct wl_display *display, int fd)
|
|
|
|
|
{
|
|
|
|
|
struct wl_client *client;
|
2012-02-18 00:29:25 -05:00
|
|
|
socklen_t len;
|
2008-10-08 12:48:46 -04:00
|
|
|
|
|
|
|
|
client = malloc(sizeof *client);
|
|
|
|
|
if (client == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memset(client, 0, sizeof *client);
|
|
|
|
|
client->display = display;
|
|
|
|
|
client->source = wl_event_loop_add_fd(display->loop, fd,
|
|
|
|
|
WL_EVENT_READABLE,
|
|
|
|
|
wl_client_connection_data, client);
|
2012-02-18 00:29:25 -05:00
|
|
|
|
2012-10-16 20:32:19 +02:00
|
|
|
if (!client->source)
|
|
|
|
|
goto err_client;
|
|
|
|
|
|
2012-02-18 00:29:25 -05:00
|
|
|
len = sizeof client->ucred;
|
|
|
|
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
|
2012-10-16 20:32:19 +02:00
|
|
|
&client->ucred, &len) < 0)
|
|
|
|
|
goto err_source;
|
2012-02-18 00:29:25 -05:00
|
|
|
|
2012-10-04 16:54:22 -04:00
|
|
|
client->connection = wl_connection_create(fd);
|
2012-10-16 20:32:19 +02:00
|
|
|
if (client->connection == NULL)
|
|
|
|
|
goto err_source;
|
2008-12-21 22:45:33 -05:00
|
|
|
|
2013-06-01 17:40:52 -05:00
|
|
|
wl_map_init(&client->objects, WL_MAP_SERVER_SIDE);
|
2011-08-19 22:50:53 -04:00
|
|
|
|
2013-06-01 17:40:53 -05:00
|
|
|
if (wl_map_insert_at(&client->objects, 0, 0, NULL) < 0)
|
2012-10-16 20:32:19 +02:00
|
|
|
goto err_map;
|
2011-08-19 11:06:37 -04:00
|
|
|
|
2012-04-13 09:53:15 -04:00
|
|
|
wl_signal_init(&client->destroy_signal);
|
2011-08-19 16:57:48 -04:00
|
|
|
bind_display(client, display, 1, 1);
|
2011-08-18 17:53:50 -04:00
|
|
|
|
2012-10-16 20:32:19 +02:00
|
|
|
if (!client->display_resource)
|
|
|
|
|
goto err_map;
|
|
|
|
|
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_insert(display->client_list.prev, &client->link);
|
|
|
|
|
|
2008-10-08 12:48:46 -04:00
|
|
|
return client;
|
2012-10-16 20:32:19 +02:00
|
|
|
|
|
|
|
|
err_map:
|
|
|
|
|
wl_map_release(&client->objects);
|
|
|
|
|
wl_connection_destroy(client->connection);
|
|
|
|
|
err_source:
|
|
|
|
|
wl_event_source_remove(client->source);
|
|
|
|
|
err_client:
|
|
|
|
|
free(client);
|
|
|
|
|
return NULL;
|
2008-10-08 12:48:46 -04:00
|
|
|
}
|
|
|
|
|
|
2012-02-18 00:29:25 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_get_credentials(struct wl_client *client,
|
|
|
|
|
pid_t *pid, uid_t *uid, gid_t *gid)
|
|
|
|
|
{
|
|
|
|
|
if (pid)
|
|
|
|
|
*pid = client->ucred.pid;
|
|
|
|
|
if (uid)
|
|
|
|
|
*uid = client->ucred.uid;
|
|
|
|
|
if (gid)
|
|
|
|
|
*gid = client->ucred.gid;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-27 11:28:06 -04:00
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_client_get_object(struct wl_client *client, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
return wl_map_lookup(&client->objects, id);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-02 15:39:03 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_post_no_memory(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 20:55:16 -04:00
|
|
|
WL_EXPORT void
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_no_memory(struct wl_resource *resource)
|
2010-09-02 20:55:16 -04:00
|
|
|
{
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_error(resource->client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
|
2010-09-02 20:55:16 -04:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 17:07:14 -04:00
|
|
|
static void
|
|
|
|
|
destroy_resource(void *element, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource = element;
|
2013-07-02 16:59:44 -04:00
|
|
|
struct wl_client *client = resource->client;
|
|
|
|
|
uint32_t flags;
|
2011-08-19 17:07:14 -04:00
|
|
|
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_emit(&resource->destroy_signal, resource);
|
2011-08-19 17:07:14 -04:00
|
|
|
|
2013-07-02 16:59:44 -04:00
|
|
|
flags = wl_map_lookup_flags(&client->objects, resource->object.id);
|
2011-08-19 17:07:14 -04:00
|
|
|
if (resource->destroy)
|
|
|
|
|
resource->destroy(resource);
|
2013-07-02 16:59:44 -04:00
|
|
|
|
|
|
|
|
if (!(flags & WL_MAP_ENTRY_LEGACY))
|
|
|
|
|
free(resource);
|
2011-08-19 17:07:14 -04:00
|
|
|
}
|
|
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
WL_EXPORT void
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
wl_resource_destroy(struct wl_resource *resource)
|
2008-12-15 20:35:24 -05:00
|
|
|
{
|
2011-08-19 11:06:37 -04:00
|
|
|
struct wl_client *client = resource->client;
|
2012-03-01 22:46:07 -05:00
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
|
|
id = resource->object.id;
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
destroy_resource(resource, NULL);
|
2011-05-06 17:09:51 +02:00
|
|
|
|
2012-03-01 22:46:07 -05:00
|
|
|
if (id < WL_SERVER_ID_START) {
|
2011-11-29 14:32:32 +02:00
|
|
|
if (client->display_resource) {
|
|
|
|
|
wl_resource_queue_event(client->display_resource,
|
2012-03-01 22:46:07 -05:00
|
|
|
WL_DISPLAY_DELETE_ID, id);
|
2011-11-29 14:32:32 +02:00
|
|
|
}
|
2013-06-01 17:40:53 -05:00
|
|
|
wl_map_insert_at(&client->objects, 0, id, NULL);
|
2011-11-18 21:59:36 -05:00
|
|
|
} else {
|
2012-03-01 22:46:07 -05:00
|
|
|
wl_map_remove(&client->objects, id);
|
2011-11-18 21:59:36 -05:00
|
|
|
}
|
2008-12-15 20:35:24 -05:00
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:00:30 -04:00
|
|
|
WL_EXPORT uint32_t
|
|
|
|
|
wl_resource_get_id(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return resource->object.id;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 17:40:54 -05:00
|
|
|
WL_EXPORT struct wl_list *
|
|
|
|
|
wl_resource_get_link(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return &resource->link;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 10:07:52 -05:00
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_resource_from_link(struct wl_list *link)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
return wl_container_of(link, resource, link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_resource_find_for_client(struct wl_list *list, struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
if (client == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(resource, list, link) {
|
|
|
|
|
if (resource->client == client)
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 17:40:54 -05:00
|
|
|
WL_EXPORT struct wl_client *
|
|
|
|
|
wl_resource_get_client(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return resource->client;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 10:07:52 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_set_user_data(struct wl_resource *resource, void *data)
|
|
|
|
|
{
|
|
|
|
|
resource->data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 17:40:54 -05:00
|
|
|
WL_EXPORT void *
|
|
|
|
|
wl_resource_get_user_data(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return resource->data;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_resource_get_version(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return resource->version;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 17:40:54 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_set_destructor(struct wl_resource *resource,
|
|
|
|
|
wl_resource_destroy_func_t destroy)
|
|
|
|
|
{
|
|
|
|
|
resource->destroy = destroy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-20 20:36:47 -05:00
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_resource_instance_of(struct wl_resource *resource,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation)
|
|
|
|
|
{
|
|
|
|
|
return wl_interface_equal(resource->object.interface, interface) &&
|
|
|
|
|
resource->object.implementation == implementation;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-01 17:40:54 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_add_destroy_listener(struct wl_resource *resource,
|
|
|
|
|
struct wl_listener * listener)
|
|
|
|
|
{
|
|
|
|
|
wl_signal_add(&resource->destroy_signal, listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_listener *
|
|
|
|
|
wl_resource_get_destroy_listener(struct wl_resource *resource,
|
|
|
|
|
wl_notify_func_t notify)
|
|
|
|
|
{
|
|
|
|
|
return wl_signal_get(&resource->destroy_signal, notify);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-13 09:53:15 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_add_destroy_listener(struct wl_client *client,
|
|
|
|
|
struct wl_listener *listener)
|
|
|
|
|
{
|
|
|
|
|
wl_signal_add(&client->destroy_signal, listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_listener *
|
|
|
|
|
wl_client_get_destroy_listener(struct wl_client *client,
|
|
|
|
|
wl_notify_func_t notify)
|
|
|
|
|
{
|
|
|
|
|
return wl_signal_get(&client->destroy_signal, notify);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 17:44:31 -04:00
|
|
|
WL_EXPORT void
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_client_destroy(struct wl_client *client)
|
|
|
|
|
{
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
uint32_t serial = 0;
|
2011-08-19 22:50:53 -04:00
|
|
|
|
2012-05-29 17:38:51 +02:00
|
|
|
wl_log("disconnect from client %p\n", client);
|
2008-10-11 21:37:55 -04:00
|
|
|
|
2012-04-13 09:53:15 -04:00
|
|
|
wl_signal_emit(&client->destroy_signal, client);
|
|
|
|
|
|
2011-08-29 15:01:41 -04:00
|
|
|
wl_client_flush(client);
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
wl_map_for_each(&client->objects, destroy_resource, &serial);
|
2011-08-19 22:50:53 -04:00
|
|
|
wl_map_release(&client->objects);
|
2008-11-28 18:35:25 -05:00
|
|
|
wl_event_source_remove(client->source);
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_connection_destroy(client->connection);
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_remove(&client->link);
|
2008-10-08 12:48:46 -04:00
|
|
|
free(client);
|
2008-09-30 09:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:38:44 -04:00
|
|
|
static void
|
2012-10-08 13:53:47 -04:00
|
|
|
registry_bind(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource, uint32_t name,
|
|
|
|
|
const char *interface, uint32_t version, uint32_t id)
|
2011-04-14 10:38:44 -04:00
|
|
|
{
|
|
|
|
|
struct wl_global *global;
|
2011-08-18 17:53:50 -04:00
|
|
|
struct wl_display *display = resource->data;
|
2011-04-14 10:38:44 -04:00
|
|
|
|
|
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
2011-08-19 16:57:48 -04:00
|
|
|
if (global->name == name)
|
2011-05-12 21:27:57 -04:00
|
|
|
break;
|
|
|
|
|
|
2013-07-08 18:45:41 -04:00
|
|
|
if (&global->link == &display->global_list ||
|
|
|
|
|
global->version < version)
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_error(resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid global %d", name);
|
2011-08-19 16:57:48 -04:00
|
|
|
else
|
|
|
|
|
global->bind(client, global->data, version, id);
|
2011-04-14 10:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 13:53:47 -04:00
|
|
|
static const struct wl_registry_interface registry_interface = {
|
|
|
|
|
registry_bind
|
|
|
|
|
};
|
|
|
|
|
|
2010-09-03 14:46:38 -04:00
|
|
|
static void
|
|
|
|
|
display_sync(struct wl_client *client,
|
2011-08-18 17:53:50 -04:00
|
|
|
struct wl_resource *resource, uint32_t id)
|
2010-09-03 14:46:38 -04:00
|
|
|
{
|
2011-08-19 22:50:53 -04:00
|
|
|
struct wl_resource *callback;
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
uint32_t serial;
|
2010-09-03 14:46:38 -04:00
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
callback = wl_resource_create(client, &wl_callback_interface, 1, id);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (callback == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
serial = wl_display_get_serial(client->display);
|
|
|
|
|
wl_callback_send_done(callback, serial);
|
|
|
|
|
wl_resource_destroy(callback);
|
2010-09-03 14:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 13:53:47 -04:00
|
|
|
static void
|
|
|
|
|
unbind_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
wl_list_remove(&resource->link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
display_get_registry(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct wl_display *display = resource->data;
|
|
|
|
|
struct wl_resource *registry_resource;
|
|
|
|
|
struct wl_global *global;
|
|
|
|
|
|
|
|
|
|
registry_resource =
|
2013-06-27 20:09:20 -05:00
|
|
|
wl_resource_create(client, &wl_registry_interface, 1, id);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (registry_resource == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
wl_resource_set_implementation(registry_resource,
|
|
|
|
|
®istry_interface,
|
|
|
|
|
display, unbind_resource);
|
2012-10-08 13:53:47 -04:00
|
|
|
|
|
|
|
|
wl_list_insert(&display->registry_resource_list,
|
|
|
|
|
®istry_resource->link);
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
|
|
|
|
wl_resource_post_event(registry_resource,
|
|
|
|
|
WL_REGISTRY_GLOBAL,
|
|
|
|
|
global->name,
|
|
|
|
|
global->interface->name,
|
2013-07-08 18:45:41 -04:00
|
|
|
global->version);
|
2012-10-08 13:53:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct wl_display_interface display_interface = {
|
2010-09-03 14:46:38 -04:00
|
|
|
display_sync,
|
2012-10-08 13:53:47 -04:00
|
|
|
display_get_registry
|
2010-09-03 14:46:38 -04:00
|
|
|
};
|
|
|
|
|
|
2011-11-28 09:47:15 +02:00
|
|
|
static void
|
|
|
|
|
destroy_client_display_resource(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
resource->client->display_resource = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
static void
|
|
|
|
|
bind_display(struct wl_client *client,
|
|
|
|
|
void *data, uint32_t version, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
struct wl_display *display = data;
|
|
|
|
|
|
|
|
|
|
client->display_resource =
|
2013-06-27 20:09:20 -05:00
|
|
|
wl_resource_create(client, &wl_display_interface, 1, id);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (client->display_resource == NULL) {
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
wl_resource_set_implementation(client->display_resource,
|
|
|
|
|
&display_interface, display,
|
|
|
|
|
destroy_client_display_resource);
|
2011-08-19 16:57:48 -04:00
|
|
|
}
|
2010-09-03 14:46:38 -04:00
|
|
|
|
2008-12-05 11:13:50 -05:00
|
|
|
WL_EXPORT struct wl_display *
|
2008-09-30 09:46:10 -04:00
|
|
|
wl_display_create(void)
|
|
|
|
|
{
|
|
|
|
|
struct wl_display *display;
|
2010-09-07 10:58:19 -04:00
|
|
|
const char *debug;
|
|
|
|
|
|
|
|
|
|
debug = getenv("WAYLAND_DEBUG");
|
2012-11-21 17:14:55 -05:00
|
|
|
if (debug && (strstr(debug, "server") || strstr(debug, "1")))
|
2010-09-07 10:58:19 -04:00
|
|
|
wl_debug = 1;
|
2008-09-30 09:46:10 -04:00
|
|
|
|
|
|
|
|
display = malloc(sizeof *display);
|
|
|
|
|
if (display == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
display->loop = wl_event_loop_create();
|
|
|
|
|
if (display->loop == NULL) {
|
|
|
|
|
free(display);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-23 19:10:23 -05:00
|
|
|
wl_list_init(&display->global_list);
|
2010-12-01 15:36:20 -05:00
|
|
|
wl_list_init(&display->socket_list);
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_init(&display->client_list);
|
2012-10-08 13:53:47 -04:00
|
|
|
wl_list_init(&display->registry_resource_list);
|
2008-11-02 10:12:29 -05:00
|
|
|
|
2013-01-11 14:29:32 -06:00
|
|
|
wl_signal_init(&display->destroy_signal);
|
|
|
|
|
|
2008-11-23 23:41:08 -05:00
|
|
|
display->id = 1;
|
2012-05-22 18:48:13 +01:00
|
|
|
display->serial = 0;
|
2011-08-18 17:53:50 -04:00
|
|
|
|
2013-08-06 20:05:53 +02:00
|
|
|
wl_array_init(&display->additional_shm_formats);
|
|
|
|
|
|
2013-07-08 18:45:41 -04:00
|
|
|
if (!wl_global_create(display, &wl_display_interface, 1,
|
|
|
|
|
display, bind_display)) {
|
2011-03-11 14:58:06 +02:00
|
|
|
wl_event_loop_destroy(display->loop);
|
2008-11-23 19:10:23 -05:00
|
|
|
free(display);
|
|
|
|
|
return NULL;
|
2010-09-03 14:46:38 -04:00
|
|
|
}
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2010-09-03 14:46:38 -04:00
|
|
|
return display;
|
2008-09-30 09:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_destroy(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
struct wl_socket *s, *next;
|
2011-06-14 11:41:54 +02:00
|
|
|
struct wl_global *global, *gnext;
|
2010-12-01 15:36:20 -05:00
|
|
|
|
2013-01-11 14:29:32 -06:00
|
|
|
wl_signal_emit(&display->destroy_signal, display);
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
wl_list_for_each_safe(s, next, &display->socket_list, link) {
|
2011-12-22 16:52:37 +02:00
|
|
|
wl_event_source_remove(s->source);
|
2010-12-01 15:36:20 -05:00
|
|
|
unlink(s->addr.sun_path);
|
2012-06-30 19:50:09 +00:00
|
|
|
close(s->fd);
|
2011-04-13 09:38:29 +02:00
|
|
|
unlink(s->lock_addr);
|
2012-06-30 19:50:09 +00:00
|
|
|
close(s->fd_lock);
|
2010-12-01 15:36:20 -05:00
|
|
|
free(s);
|
|
|
|
|
}
|
2011-12-22 16:52:37 +02:00
|
|
|
wl_event_loop_destroy(display->loop);
|
2010-12-01 15:36:20 -05:00
|
|
|
|
2011-06-14 11:41:54 +02:00
|
|
|
wl_list_for_each_safe(global, gnext, &display->global_list, link)
|
|
|
|
|
free(global);
|
|
|
|
|
|
2013-08-08 10:31:56 +02:00
|
|
|
wl_array_release(&display->additional_shm_formats);
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
free(display);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
WL_EXPORT struct wl_global *
|
2013-07-08 18:45:41 -04:00
|
|
|
wl_global_create(struct wl_display *display,
|
|
|
|
|
const struct wl_interface *interface, int version,
|
|
|
|
|
void *data, wl_global_bind_func_t bind)
|
2008-11-23 19:10:23 -05:00
|
|
|
{
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_global *global;
|
2012-10-08 13:53:47 -04:00
|
|
|
struct wl_resource *resource;
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2013-07-08 18:45:41 -04:00
|
|
|
if (interface->version < version) {
|
|
|
|
|
wl_log("wl_global_create: implemented version higher "
|
|
|
|
|
"than interface version%m\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
global = malloc(sizeof *global);
|
|
|
|
|
if (global == NULL)
|
2011-08-19 16:57:48 -04:00
|
|
|
return NULL;
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2013-07-08 18:45:41 -04:00
|
|
|
global->display = display;
|
2011-08-19 16:57:48 -04:00
|
|
|
global->name = display->id++;
|
|
|
|
|
global->interface = interface;
|
2013-07-08 18:45:41 -04:00
|
|
|
global->version = version;
|
2011-08-19 16:57:48 -04:00
|
|
|
global->data = data;
|
2011-08-19 11:05:01 -04:00
|
|
|
global->bind = bind;
|
2008-12-21 23:37:12 -05:00
|
|
|
wl_list_insert(display->global_list.prev, &global->link);
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2012-10-08 13:53:47 -04:00
|
|
|
wl_list_for_each(resource, &display->registry_resource_list, link)
|
|
|
|
|
wl_resource_post_event(resource,
|
|
|
|
|
WL_REGISTRY_GLOBAL,
|
2012-05-02 08:46:47 +02:00
|
|
|
global->name,
|
|
|
|
|
global->interface->name,
|
2013-07-08 18:45:41 -04:00
|
|
|
global->version);
|
2012-05-02 08:46:47 +02:00
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
return global;
|
2008-11-23 19:10:23 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
WL_EXPORT void
|
2013-07-08 18:45:41 -04:00
|
|
|
wl_global_destroy(struct wl_global *global)
|
2011-06-14 10:35:46 +02:00
|
|
|
{
|
2013-07-08 18:45:41 -04:00
|
|
|
struct wl_display *display = global->display;
|
2012-10-08 13:53:47 -04:00
|
|
|
struct wl_resource *resource;
|
2011-06-14 10:35:46 +02:00
|
|
|
|
2012-10-08 13:53:47 -04:00
|
|
|
wl_list_for_each(resource, &display->registry_resource_list, link)
|
|
|
|
|
wl_resource_post_event(resource, WL_REGISTRY_GLOBAL_REMOVE,
|
|
|
|
|
global->name);
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_remove(&global->link);
|
|
|
|
|
free(global);
|
|
|
|
|
}
|
|
|
|
|
|
Switch protocol to using serial numbers for ordering events and requests
The wayland protocol, as X, uses timestamps to match up certain
requests with input events. The problem is that sometimes we need to
send out an event that doesn't have a corresponding timestamped input
event. For example, the pointer focus surface goes away and new
surface needs to receive a pointer enter event. These events are
normally timestamped with the evdev event timestamp, but in this case,
we don't have a evdev timestamp. So we have to go to gettimeofday (or
clock_gettime()) and then we don't know if it's coming from the same
time source etc.
However for all these cases we don't need a real time timestamp, we
just need a serial number that encodes the order of events inside the
server. So we introduce a serial number mechanism that we can use to
order events. We still need real-time timestamps for actual input
device events (motion, buttons, keys, touch), to be able to reason
about double-click speed and movement speed so events that correspond to user input carry both a serial number and a timestamp.
The serial number also give us a mechanism to key together events that
are "logically the same" such as a unicode event and a keycode event,
or a motion event and a relative event from a raw device.
2012-04-11 22:25:51 -04:00
|
|
|
WL_EXPORT uint32_t
|
|
|
|
|
wl_display_get_serial(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
return display->serial;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT uint32_t
|
|
|
|
|
wl_display_next_serial(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
display->serial++;
|
|
|
|
|
|
|
|
|
|
return display->serial;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-08 15:39:41 -05:00
|
|
|
WL_EXPORT struct wl_event_loop *
|
2008-10-11 19:21:35 -04:00
|
|
|
wl_display_get_event_loop(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
return display->loop;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_terminate(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
display->run = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-05 11:13:50 -05:00
|
|
|
WL_EXPORT void
|
2008-09-30 09:46:10 -04:00
|
|
|
wl_display_run(struct wl_display *display)
|
|
|
|
|
{
|
2010-12-01 15:36:20 -05:00
|
|
|
display->run = 1;
|
|
|
|
|
|
2012-10-04 16:54:22 -04:00
|
|
|
while (display->run) {
|
|
|
|
|
wl_display_flush_clients(display);
|
2010-11-19 10:47:28 -05:00
|
|
|
wl_event_loop_dispatch(display->loop, -1);
|
2012-10-04 16:54:22 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_flush_clients(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
struct wl_client *client, *next;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each_safe(client, next, &display->client_list, link) {
|
|
|
|
|
ret = wl_connection_flush(client->connection);
|
|
|
|
|
if (ret < 0 && errno == EAGAIN) {
|
|
|
|
|
wl_event_source_fd_update(client->source,
|
|
|
|
|
WL_EVENT_WRITABLE |
|
|
|
|
|
WL_EVENT_READABLE);
|
|
|
|
|
} else if (ret < 0) {
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-30 09:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-22 12:06:34 -04:00
|
|
|
static int
|
2008-09-30 09:46:10 -04:00
|
|
|
socket_data(int fd, uint32_t mask, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wl_display *display = data;
|
|
|
|
|
struct sockaddr_un name;
|
|
|
|
|
socklen_t length;
|
|
|
|
|
int client_fd;
|
|
|
|
|
|
|
|
|
|
length = sizeof name;
|
2012-03-22 14:16:10 +02:00
|
|
|
client_fd = wl_os_accept_cloexec(fd, (struct sockaddr *) &name,
|
|
|
|
|
&length);
|
2008-09-30 09:46:10 -04:00
|
|
|
if (client_fd < 0)
|
2012-06-15 22:01:06 +00:00
|
|
|
wl_log("failed to accept: %m\n");
|
2012-03-22 14:24:18 +02:00
|
|
|
else
|
2012-10-16 20:32:19 +02:00
|
|
|
if (!wl_client_create(display, client_fd))
|
|
|
|
|
close(client_fd);
|
2011-04-22 12:06:34 -04:00
|
|
|
|
|
|
|
|
return 1;
|
2008-09-30 09:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
2011-04-13 09:38:29 +02:00
|
|
|
static int
|
2012-06-15 21:09:00 +00:00
|
|
|
get_socket_lock(struct wl_socket *socket)
|
2011-04-13 09:38:29 +02:00
|
|
|
{
|
|
|
|
|
struct stat socket_stat;
|
2012-06-16 22:47:42 +00:00
|
|
|
int fd_lock;
|
2011-04-13 09:38:29 +02:00
|
|
|
|
2012-06-15 21:09:00 +00:00
|
|
|
snprintf(socket->lock_addr, sizeof socket->lock_addr,
|
|
|
|
|
"%s%s", socket->addr.sun_path, LOCK_SUFFIX);
|
2011-04-13 09:38:29 +02:00
|
|
|
|
2012-06-16 22:47:42 +00:00
|
|
|
fd_lock = open(socket->lock_addr, O_CREAT | O_CLOEXEC,
|
|
|
|
|
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
|
2011-04-13 09:38:29 +02:00
|
|
|
|
2012-06-16 22:47:42 +00:00
|
|
|
if (fd_lock < 0) {
|
2012-05-29 17:38:51 +02:00
|
|
|
wl_log("unable to open lockfile %s check permissions\n",
|
2011-04-13 09:38:29 +02:00
|
|
|
socket->lock_addr);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-16 22:47:42 +00:00
|
|
|
if (flock(fd_lock, LOCK_EX | LOCK_NB) < 0) {
|
2012-05-29 17:38:51 +02:00
|
|
|
wl_log("unable to lock lockfile %s, maybe another compositor is running\n",
|
2011-04-13 09:38:29 +02:00
|
|
|
socket->lock_addr);
|
2012-06-16 22:47:42 +00:00
|
|
|
close(fd_lock);
|
2011-04-13 09:38:29 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stat(socket->addr.sun_path, &socket_stat) < 0 ) {
|
|
|
|
|
if (errno != ENOENT) {
|
2012-05-29 17:38:51 +02:00
|
|
|
wl_log("did not manage to stat file %s\n",
|
2011-04-13 09:38:29 +02:00
|
|
|
socket->addr.sun_path);
|
2012-06-16 22:47:42 +00:00
|
|
|
close(fd_lock);
|
2011-04-13 09:38:29 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
} else if (socket_stat.st_mode & S_IWUSR ||
|
|
|
|
|
socket_stat.st_mode & S_IWGRP) {
|
|
|
|
|
unlink(socket->addr.sun_path);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-16 22:47:42 +00:00
|
|
|
return fd_lock;
|
2011-04-13 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-05 11:13:50 -05:00
|
|
|
WL_EXPORT int
|
2010-12-01 15:36:20 -05:00
|
|
|
wl_display_add_socket(struct wl_display *display, const char *name)
|
2008-09-30 09:46:10 -04:00
|
|
|
{
|
2010-12-01 15:36:20 -05:00
|
|
|
struct wl_socket *s;
|
2012-06-15 21:32:19 +00:00
|
|
|
socklen_t size;
|
|
|
|
|
int name_size;
|
2010-12-01 15:36:20 -05:00
|
|
|
const char *runtime_dir;
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2012-06-06 14:30:19 +03:00
|
|
|
runtime_dir = getenv("XDG_RUNTIME_DIR");
|
|
|
|
|
if (!runtime_dir) {
|
|
|
|
|
wl_log("error: XDG_RUNTIME_DIR not set in the environment\n");
|
|
|
|
|
|
|
|
|
|
/* to prevent programs reporting
|
|
|
|
|
* "failed to add socket: Success" */
|
|
|
|
|
errno = ENOENT;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
s = malloc(sizeof *s);
|
2011-01-25 15:11:53 -05:00
|
|
|
if (s == NULL)
|
2008-09-30 09:46:10 -04:00
|
|
|
return -1;
|
|
|
|
|
|
2012-03-21 11:11:26 +02:00
|
|
|
s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
|
2011-03-11 16:59:53 +02:00
|
|
|
if (s->fd < 0) {
|
|
|
|
|
free(s);
|
2010-12-01 15:36:20 -05:00
|
|
|
return -1;
|
2011-03-11 16:59:53 +02:00
|
|
|
}
|
2010-12-01 15:36:20 -05:00
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = getenv("WAYLAND_DISPLAY");
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = "wayland-0";
|
|
|
|
|
|
|
|
|
|
memset(&s->addr, 0, sizeof s->addr);
|
|
|
|
|
s->addr.sun_family = AF_LOCAL;
|
|
|
|
|
name_size = snprintf(s->addr.sun_path, sizeof s->addr.sun_path,
|
|
|
|
|
"%s/%s", runtime_dir, name) + 1;
|
2012-06-15 21:32:19 +00:00
|
|
|
|
|
|
|
|
assert(name_size > 0);
|
|
|
|
|
if (name_size > (int)sizeof s->addr.sun_path) {
|
|
|
|
|
wl_log("error: socket path \"%s/%s\" plus null terminator"
|
|
|
|
|
" exceeds 108 bytes\n", runtime_dir, name);
|
|
|
|
|
close(s->fd);
|
|
|
|
|
free(s);
|
|
|
|
|
/* to prevent programs reporting
|
|
|
|
|
* "failed to add socket: Success" */
|
|
|
|
|
errno = ENAMETOOLONG;
|
|
|
|
|
return -1;
|
|
|
|
|
};
|
|
|
|
|
|
2012-05-29 17:38:51 +02:00
|
|
|
wl_log("using socket %s\n", s->addr.sun_path);
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2012-06-16 22:47:42 +00:00
|
|
|
s->fd_lock = get_socket_lock(s);
|
|
|
|
|
if (s->fd_lock < 0) {
|
2011-04-13 09:38:29 +02:00
|
|
|
close(s->fd);
|
|
|
|
|
free(s);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-07 15:22:22 -05:00
|
|
|
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
2011-03-11 16:59:53 +02:00
|
|
|
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
|
2012-06-16 22:51:35 +00:00
|
|
|
wl_log("bind() failed with error: %m\n");
|
2011-03-11 16:59:53 +02:00
|
|
|
close(s->fd);
|
2012-06-30 19:50:09 +00:00
|
|
|
unlink(s->lock_addr);
|
|
|
|
|
close(s->fd_lock);
|
2011-03-11 16:59:53 +02:00
|
|
|
free(s);
|
2008-09-30 09:46:10 -04:00
|
|
|
return -1;
|
2011-03-11 16:59:53 +02:00
|
|
|
}
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2011-03-11 16:59:53 +02:00
|
|
|
if (listen(s->fd, 1) < 0) {
|
2012-06-16 22:51:35 +00:00
|
|
|
wl_log("listen() failed with error: %m\n");
|
2011-03-11 16:59:53 +02:00
|
|
|
unlink(s->addr.sun_path);
|
2012-06-30 19:50:09 +00:00
|
|
|
close(s->fd);
|
|
|
|
|
unlink(s->lock_addr);
|
|
|
|
|
close(s->fd_lock);
|
2011-03-11 16:59:53 +02:00
|
|
|
free(s);
|
2008-09-30 09:46:10 -04:00
|
|
|
return -1;
|
2011-03-11 16:59:53 +02:00
|
|
|
}
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2011-12-22 16:52:37 +02:00
|
|
|
s->source = wl_event_loop_add_fd(display->loop, s->fd,
|
|
|
|
|
WL_EVENT_READABLE,
|
|
|
|
|
socket_data, display);
|
|
|
|
|
if (s->source == NULL) {
|
2011-03-11 16:59:53 +02:00
|
|
|
unlink(s->addr.sun_path);
|
2012-06-30 19:50:09 +00:00
|
|
|
close(s->fd);
|
|
|
|
|
unlink(s->lock_addr);
|
|
|
|
|
close(s->fd_lock);
|
2011-03-11 16:59:53 +02:00
|
|
|
free(s);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-12-01 15:36:20 -05:00
|
|
|
wl_list_insert(display->socket_list.prev, &s->link);
|
2008-09-30 09:46:10 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-12-08 15:12:58 -05:00
|
|
|
|
2013-01-11 14:29:32 -06:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_add_destroy_listener(struct wl_display *display,
|
|
|
|
|
struct wl_listener *listener)
|
|
|
|
|
{
|
|
|
|
|
wl_signal_add(&display->destroy_signal, listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_listener *
|
|
|
|
|
wl_display_get_destroy_listener(struct wl_display *display,
|
|
|
|
|
wl_notify_func_t notify)
|
|
|
|
|
{
|
|
|
|
|
return wl_signal_get(&display->destroy_signal, notify);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_set_implementation(struct wl_resource *resource,
|
|
|
|
|
const void *implementation,
|
|
|
|
|
void *data, wl_resource_destroy_func_t destroy)
|
|
|
|
|
{
|
|
|
|
|
resource->object.implementation = implementation;
|
|
|
|
|
resource->data = data;
|
|
|
|
|
resource->destroy = destroy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_resource_create(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
int version, uint32_t id)
|
2011-08-19 16:57:48 -04:00
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = malloc(sizeof *resource);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (resource == NULL)
|
2011-08-19 16:57:48 -04:00
|
|
|
return NULL;
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
if (id == 0)
|
|
|
|
|
id = wl_map_insert_new(&client->objects, 0, NULL);
|
|
|
|
|
|
2013-06-27 20:09:18 -05:00
|
|
|
resource->object.id = id;
|
|
|
|
|
resource->object.interface = interface;
|
2013-06-27 20:09:20 -05:00
|
|
|
resource->object.implementation = NULL;
|
2013-06-27 20:09:18 -05:00
|
|
|
|
|
|
|
|
wl_signal_init(&resource->destroy_signal);
|
|
|
|
|
|
2013-06-18 12:42:40 -05:00
|
|
|
resource->destroy = NULL;
|
2013-06-27 20:09:18 -05:00
|
|
|
resource->client = client;
|
2013-06-27 20:09:20 -05:00
|
|
|
resource->data = NULL;
|
|
|
|
|
resource->version = version;
|
2011-08-19 16:57:48 -04:00
|
|
|
|
2013-06-01 17:40:53 -05:00
|
|
|
if (wl_map_insert_at(&client->objects, 0, resource->object.id, resource) < 0) {
|
2012-07-18 15:51:45 +02:00
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid new id %d",
|
|
|
|
|
resource->object.id);
|
2011-08-19 22:50:53 -04:00
|
|
|
free(resource);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-08-19 16:57:48 -04:00
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
2011-11-15 08:58:34 -05:00
|
|
|
|
2013-07-02 14:34:42 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_log_set_handler_server(wl_log_func_t handler)
|
|
|
|
|
{
|
|
|
|
|
wl_log_handler = handler;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Deprecated functions below. */
|
|
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
|
wl_client_add_resource(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource) WL_DEPRECATED;
|
|
|
|
|
|
|
|
|
|
WL_EXPORT uint32_t
|
|
|
|
|
wl_client_add_resource(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
if (resource->object.id == 0) {
|
|
|
|
|
resource->object.id =
|
|
|
|
|
wl_map_insert_new(&client->objects,
|
|
|
|
|
WL_MAP_ENTRY_LEGACY, resource);
|
|
|
|
|
} else if (wl_map_insert_at(&client->objects, WL_MAP_ENTRY_LEGACY,
|
|
|
|
|
resource->object.id, resource) < 0) {
|
|
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid new id %d",
|
|
|
|
|
resource->object.id);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource->client = client;
|
|
|
|
|
wl_signal_init(&resource->destroy_signal);
|
|
|
|
|
|
|
|
|
|
return resource->object.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_resource *
|
|
|
|
|
wl_client_add_object(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation,
|
|
|
|
|
uint32_t id, void *data) WL_DEPRECATED;
|
|
|
|
|
|
2011-11-15 08:58:34 -05:00
|
|
|
WL_EXPORT struct wl_resource *
|
2013-07-02 14:34:42 -04:00
|
|
|
wl_client_add_object(struct wl_client *client,
|
2011-11-15 08:58:34 -05:00
|
|
|
const struct wl_interface *interface,
|
2013-07-02 14:34:42 -04:00
|
|
|
const void *implementation, uint32_t id, void *data)
|
2011-11-15 08:58:34 -05:00
|
|
|
{
|
2013-06-27 20:09:20 -05:00
|
|
|
struct wl_resource *resource;
|
2011-11-15 08:58:34 -05:00
|
|
|
|
2013-07-02 14:34:42 -04:00
|
|
|
resource = wl_resource_create(client, interface, -1, id);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (resource == NULL)
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
else
|
|
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
|
implementation, data, NULL);
|
2011-11-15 08:58:34 -05:00
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
return resource;
|
2011-11-15 08:58:34 -05:00
|
|
|
}
|
2012-05-29 17:37:02 +02:00
|
|
|
|
2013-07-02 14:34:42 -04:00
|
|
|
struct wl_resource *
|
|
|
|
|
wl_client_new_object(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation, void *data) WL_DEPRECATED;
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_client_new_object(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation, void *data)
|
2012-05-29 17:37:02 +02:00
|
|
|
{
|
2013-07-02 14:34:42 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = wl_resource_create(client, interface, -1, 0);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (resource == NULL)
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
else
|
|
|
|
|
wl_resource_set_implementation(resource,
|
|
|
|
|
implementation, data, NULL);
|
2013-07-02 14:34:42 -04:00
|
|
|
|
|
|
|
|
return resource;
|
2012-05-29 17:37:02 +02:00
|
|
|
}
|
2013-07-08 18:45:41 -04:00
|
|
|
|
|
|
|
|
struct wl_global *
|
|
|
|
|
wl_display_add_global(struct wl_display *display,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
void *data, wl_global_bind_func_t bind) WL_DEPRECATED;
|
|
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_global *
|
|
|
|
|
wl_display_add_global(struct wl_display *display,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
void *data, wl_global_bind_func_t bind)
|
|
|
|
|
{
|
|
|
|
|
return wl_global_create(display, interface, interface->version, data, bind);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
wl_display_remove_global(struct wl_display *display,
|
|
|
|
|
struct wl_global *global) WL_DEPRECATED;
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_remove_global(struct wl_display *display, struct wl_global *global)
|
|
|
|
|
{
|
|
|
|
|
wl_global_destroy(global);
|
|
|
|
|
}
|
2013-08-06 20:05:53 +02:00
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_add_shm_format(struct wl_display *display, uint32_t format)
|
|
|
|
|
{
|
|
|
|
|
uint32_t *p;
|
|
|
|
|
|
|
|
|
|
p = wl_array_add(&display->additional_shm_formats, sizeof *p);
|
|
|
|
|
*p = format;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_array *
|
|
|
|
|
wl_display_get_additional_shm_formats(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
return &display->additional_shm_formats;
|
|
|
|
|
}
|