2008-12-02 15:15:01 -05:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
|
*
|
2015-06-10 10:54:15 -07:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
2008-12-02 15:15:01 -05:00
|
|
|
*
|
2015-06-10 10:54:15 -07:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
|
* portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2008-12-02 15:15:01 -05:00
|
|
|
*/
|
|
|
|
|
|
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-10-08 12:48:46 -04:00
|
|
|
|
2016-05-17 21:02:01 -06:00
|
|
|
#include "wayland-util.h"
|
2011-11-18 13:46:56 -05:00
|
|
|
#include "wayland-private.h"
|
2010-08-10 14:12:05 -04:00
|
|
|
#include "wayland-server.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.
|
2015-06-10 11:26:29 -07:00
|
|
|
* No Wayland socket can be created with a path longer than this,
|
|
|
|
|
* including the null terminator.
|
|
|
|
|
*/
|
2012-06-15 21:09:00 +00:00
|
|
|
#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;
|
2014-05-08 11:25:34 -04:00
|
|
|
char *display_name;
|
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;
|
2016-08-11 17:23:09 +02:00
|
|
|
struct wl_signal resource_created_signal;
|
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;
|
2016-08-09 12:46:51 +02:00
|
|
|
struct wl_signal create_client_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-07-17 21:58:46 -05:00
|
|
|
wl_dispatcher_func_t dispatcher;
|
2013-06-27 20:09:18 -05:00
|
|
|
};
|
|
|
|
|
|
2013-12-18 20:56:18 -06:00
|
|
|
static int debug_server = 0;
|
2010-09-07 10:58:19 -04:00
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
WL_EXPORT void
|
2013-07-17 21:58:46 -05:00
|
|
|
wl_resource_post_event_array(struct wl_resource *resource, uint32_t opcode,
|
|
|
|
|
union wl_argument *args)
|
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
|
|
|
|
2013-07-17 21:58:46 -05:00
|
|
|
closure = wl_closure_marshal(object, opcode, args,
|
|
|
|
|
&object->interface->events[opcode]);
|
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
|
|
|
|
2013-12-18 20:56:18 -06:00
|
|
|
if (debug_server)
|
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
|
2013-07-17 21:58:46 -05:00
|
|
|
wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...)
|
2011-11-17 16:46:36 -05:00
|
|
|
{
|
2013-07-17 21:58:46 -05:00
|
|
|
union wl_argument args[WL_CLOSURE_MAX_ARGS];
|
2011-11-17 16:46:36 -05:00
|
|
|
struct wl_object *object = &resource->object;
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, opcode);
|
2013-07-17 21:58:46 -05:00
|
|
|
wl_argument_from_va_list(object->interface->events[opcode].signature,
|
|
|
|
|
args, WL_CLOSURE_MAX_ARGS, ap);
|
2011-11-17 16:46:36 -05:00
|
|
|
va_end(ap);
|
|
|
|
|
|
2013-07-17 21:58:46 -05:00
|
|
|
wl_resource_post_event_array(resource, opcode, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_queue_event_array(struct wl_resource *resource, uint32_t opcode,
|
|
|
|
|
union wl_argument *args)
|
|
|
|
|
{
|
|
|
|
|
struct wl_closure *closure;
|
|
|
|
|
struct wl_object *object = &resource->object;
|
|
|
|
|
|
|
|
|
|
closure = wl_closure_marshal(object, opcode, args,
|
|
|
|
|
&object->interface->events[opcode]);
|
|
|
|
|
|
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
|
|
|
|
2013-12-18 20:56:18 -06:00
|
|
|
if (debug_server)
|
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
|
|
|
}
|
|
|
|
|
|
2013-07-17 21:58:46 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...)
|
|
|
|
|
{
|
|
|
|
|
union wl_argument args[WL_CLOSURE_MAX_ARGS];
|
|
|
|
|
struct wl_object *object = &resource->object;
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, opcode);
|
|
|
|
|
wl_argument_from_va_list(object->interface->events[opcode].signature,
|
|
|
|
|
args, WL_CLOSURE_MAX_ARGS, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
wl_resource_queue_event_array(resource, opcode, args);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2015-03-19 03:42:27 -04:00
|
|
|
int opcode, size, since;
|
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);
|
2014-11-01 17:06:29 +00:00
|
|
|
if (len == 0 || (len < 0 && errno != EAGAIN)) {
|
2012-10-04 16:54:22 -04:00
|
|
|
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];
|
2015-03-19 03:42:27 -04:00
|
|
|
since = wl_message_get_since(message);
|
2013-07-02 14:57:10 -04:00
|
|
|
if (!(resource_flags & WL_MAP_ENTRY_LEGACY) &&
|
2015-03-19 03:42:27 -04:00
|
|
|
resource->version > 0 && resource->version < since) {
|
2013-07-02 14:57:10 -04:00
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
2015-03-19 03:42:27 -04:00
|
|
|
"invalid method %d (since %d < %d)"
|
|
|
|
|
", object %s@%u",
|
|
|
|
|
opcode, resource->version, since,
|
2013-07-02 14:57:10 -04:00
|
|
|
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-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;
|
2014-05-05 16:28:26 -07:00
|
|
|
} else if (closure == NULL ||
|
2013-03-28 18:48:09 +00:00
|
|
|
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);
|
2014-05-05 16:28:26 -07:00
|
|
|
wl_closure_destroy(closure);
|
2011-08-29 15:01:41 -04:00
|
|
|
break;
|
2010-08-30 09:47:36 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-18 20:56:18 -06:00
|
|
|
if (debug_server)
|
2012-10-09 12:14:34 -04:00
|
|
|
wl_closure_print(closure, object, false);
|
|
|
|
|
|
2013-07-17 21:58:46 -05:00
|
|
|
if ((resource_flags & WL_MAP_ENTRY_LEGACY) ||
|
|
|
|
|
resource->dispatcher == NULL) {
|
|
|
|
|
wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER,
|
|
|
|
|
object, opcode, client);
|
|
|
|
|
} else {
|
|
|
|
|
wl_closure_dispatch(closure, resource->dispatcher,
|
|
|
|
|
object, opcode);
|
|
|
|
|
}
|
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;
|
2016-01-12 13:12:34 +09:00
|
|
|
|
|
|
|
|
len = wl_connection_pending_input(connection);
|
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
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Flush pending events to the client
|
|
|
|
|
*
|
|
|
|
|
* \param client The client object
|
|
|
|
|
*
|
|
|
|
|
* Events sent to clients are queued in a buffer and written to the
|
|
|
|
|
* socket later - typically when the compositor has handled all
|
|
|
|
|
* requests and goes back to block in the event loop. This function
|
|
|
|
|
* flushes all queued up events for a client immediately.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Get the display object for the given client
|
|
|
|
|
*
|
|
|
|
|
* \param client The client object
|
|
|
|
|
* \return The display object the client is associated with.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
2010-08-17 21:23:10 -04:00
|
|
|
WL_EXPORT struct wl_display *
|
|
|
|
|
wl_client_get_display(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->display;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 09:55:49 -04:00
|
|
|
static int
|
|
|
|
|
bind_display(struct wl_client *client, struct wl_display *display);
|
2011-08-19 16:57:48 -04:00
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Create a client for the given file descriptor
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
* \param fd The file descriptor for the socket to the client
|
|
|
|
|
* \return The new client object or NULL on failure.
|
|
|
|
|
*
|
|
|
|
|
* Given a file descriptor corresponding to one end of a socket, this
|
|
|
|
|
* function will create a wl_client struct and add the new client to
|
|
|
|
|
* the compositors client list. At that point, the client is
|
|
|
|
|
* initialized and ready to run, as if the client had connected to the
|
|
|
|
|
* servers listening socket. When the client eventually sends
|
|
|
|
|
* requests to the compositor, the wl_client argument to the request
|
|
|
|
|
* handler will be the wl_client returned from this function.
|
|
|
|
|
*
|
|
|
|
|
* The other end of the socket can be passed to
|
|
|
|
|
* wl_display_connect_to_fd() on the client side or used with the
|
|
|
|
|
* WAYLAND_SOCKET environment variable on the client side.
|
|
|
|
|
*
|
2016-08-09 12:46:51 +02:00
|
|
|
* Listeners added with wl_display_add_client_created_listener() will
|
|
|
|
|
* be notified by this function after the client is fully constructed.
|
|
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* On failure this function sets errno accordingly and returns NULL.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
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
|
|
|
|
2015-08-26 12:00:06 +08:00
|
|
|
client = zalloc(sizeof *client);
|
2008-10-08 12:48:46 -04:00
|
|
|
if (client == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2016-08-11 17:23:09 +02:00
|
|
|
wl_signal_init(&client->resource_created_signal);
|
2008-10-08 12:48:46 -04:00
|
|
|
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);
|
2014-08-07 09:55:49 -04:00
|
|
|
if (bind_display(client, display) < 0)
|
2012-10-16 20:32:19 +02:00
|
|
|
goto err_map;
|
|
|
|
|
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_insert(display->client_list.prev, &client->link);
|
|
|
|
|
|
2016-08-09 12:46:51 +02:00
|
|
|
wl_signal_emit(&display->create_client_signal, client);
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Return Unix credentials for the client
|
|
|
|
|
*
|
|
|
|
|
* \param client The display object
|
|
|
|
|
* \param pid Returns the process ID
|
|
|
|
|
* \param uid Returns the user ID
|
|
|
|
|
* \param gid Returns the group ID
|
|
|
|
|
*
|
|
|
|
|
* This function returns the process ID, the user ID and the group ID
|
|
|
|
|
* for the given client. The credentials come from getsockopt() with
|
|
|
|
|
* SO_PEERCRED, on the client socket fd. All the pointers can be
|
|
|
|
|
* NULL, if the caller is not interested in a particular ID.
|
|
|
|
|
*
|
|
|
|
|
* Be aware that for clients that a compositor forks and execs and
|
|
|
|
|
* then connects using socketpair(), this function will return the
|
|
|
|
|
* credentials for the compositor. The credentials for the socketpair
|
|
|
|
|
* are set at creation time in the compositor.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 16:03:43 +09:00
|
|
|
/** Get the file descriptor for the client
|
|
|
|
|
*
|
|
|
|
|
* \param client The display object
|
|
|
|
|
* \return The file descriptor to use for the connection
|
|
|
|
|
*
|
|
|
|
|
* This function returns the file descriptor for the given client.
|
|
|
|
|
*
|
|
|
|
|
* Be sure to use the file descriptor from the client for inspection only.
|
|
|
|
|
* If the caller does anything to the file descriptor that changes its state,
|
|
|
|
|
* it will likely cause problems.
|
|
|
|
|
*
|
|
|
|
|
* See also wl_client_get_credentials().
|
|
|
|
|
* It is recommended that you evaluate whether wl_client_get_credentials()
|
|
|
|
|
* can be applied to your use case instead of this function.
|
|
|
|
|
*
|
|
|
|
|
* If you would like to distinguish just between the client and the compositor
|
|
|
|
|
* itself from the client's request, it can be done by getting the client
|
|
|
|
|
* credentials and by checking the PID of the client and the compositor's PID.
|
|
|
|
|
* Regarding the case in which the socketpair() is being used, you need to be
|
|
|
|
|
* careful. Please note the documentation for wl_client_get_credentials().
|
|
|
|
|
*
|
|
|
|
|
* This function can be used for a compositor to validate a request from
|
|
|
|
|
* a client if there are additional information provided from the client's
|
|
|
|
|
* file descriptor. For instance, suppose you can get the security contexts
|
|
|
|
|
* from the client's file descriptor. The compositor can validate the client's
|
|
|
|
|
* request with the contexts and make a decision whether it permits or deny it.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_client_get_fd(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
return wl_connection_get_fd(client->connection);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Look up an object in the client name space
|
|
|
|
|
*
|
|
|
|
|
* \param client The client object
|
|
|
|
|
* \param id The object id
|
|
|
|
|
* \return The object or NULL if there is not object for the given ID
|
|
|
|
|
*
|
|
|
|
|
* This looks up an object in the client object name space by its
|
2015-01-26 11:30:57 -08:00
|
|
|
* object ID.
|
|
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
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)
|
|
|
|
|
{
|
2014-02-04 14:21:48 +00:00
|
|
|
struct wl_resource *resource;
|
2013-06-14 10:07:52 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2015-01-26 11:30:57 -08:00
|
|
|
wl_list_for_each(resource, list, link) {
|
|
|
|
|
if (resource->client == client)
|
|
|
|
|
return resource;
|
|
|
|
|
}
|
2013-06-14 10:07:52 -05:00
|
|
|
|
2015-01-26 11:30:57 -08:00
|
|
|
return NULL;
|
2013-06-14 10:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 12:46:52 +02:00
|
|
|
/** Retrieve the interface name (class) of a resource object.
|
|
|
|
|
*
|
|
|
|
|
* \param resource The resource object
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_resource
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT const char *
|
|
|
|
|
wl_resource_get_class(struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
return resource->object.interface->name;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
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);
|
2014-09-30 14:43:03 +02:00
|
|
|
close(wl_connection_destroy(client->connection));
|
2011-06-14 10:35:46 +02:00
|
|
|
wl_list_remove(&client->link);
|
2016-08-11 17:23:09 +02:00
|
|
|
wl_list_remove(&client->resource_created_signal.listener_list);
|
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-11-12 21:44:37 -05:00
|
|
|
if (&global->link == &display->global_list)
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_error(resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
2013-11-12 21:44:37 -05:00
|
|
|
"invalid global %s (%d)", interface, name);
|
2016-01-14 13:33:52 -06:00
|
|
|
else if (version == 0)
|
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid version for global %s (%d): 0 is not a valid version",
|
|
|
|
|
interface, name);
|
2013-11-12 21:44:37 -05:00
|
|
|
else if (global->version < version)
|
|
|
|
|
wl_resource_post_error(resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid version for global %s (%d): have %d, wanted %d",
|
|
|
|
|
interface, name, global->version, version);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 09:55:49 -04:00
|
|
|
static int
|
|
|
|
|
bind_display(struct wl_client *client, struct wl_display *display)
|
2011-08-19 16:57:48 -04:00
|
|
|
{
|
|
|
|
|
client->display_resource =
|
2014-08-07 09:55:49 -04:00
|
|
|
wl_resource_create(client, &wl_display_interface, 1, 1);
|
2013-07-02 15:39:03 -04:00
|
|
|
if (client->display_resource == NULL) {
|
2016-01-11 11:45:12 +01:00
|
|
|
/* DON'T send no-memory error to client - it has no
|
|
|
|
|
* resource to which it could post the event */
|
2014-08-07 09:55:49 -04:00
|
|
|
return -1;
|
2013-07-02 15:39:03 -04:00
|
|
|
}
|
|
|
|
|
|
2013-06-27 20:09:20 -05:00
|
|
|
wl_resource_set_implementation(client->display_resource,
|
|
|
|
|
&display_interface, display,
|
|
|
|
|
destroy_client_display_resource);
|
2014-08-07 09:55:49 -04:00
|
|
|
return 0;
|
2011-08-19 16:57:48 -04:00
|
|
|
}
|
2010-09-03 14:46:38 -04:00
|
|
|
|
2014-05-07 09:37:45 +05:30
|
|
|
/** Create Wayland display object.
|
|
|
|
|
*
|
|
|
|
|
* \return The Wayland display object. Null if failed to create
|
|
|
|
|
*
|
|
|
|
|
* This creates the wl_display object.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
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")))
|
2013-12-18 20:56:18 -06:00
|
|
|
debug_server = 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);
|
2016-08-09 12:46:51 +02:00
|
|
|
wl_signal_init(&display->create_client_signal);
|
2013-01-11 14:29:32 -06:00
|
|
|
|
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);
|
|
|
|
|
|
2010-09-03 14:46:38 -04:00
|
|
|
return display;
|
2008-09-30 09:46:10 -04:00
|
|
|
}
|
|
|
|
|
|
2014-05-08 10:22:25 -04:00
|
|
|
static void
|
|
|
|
|
wl_socket_destroy(struct wl_socket *s)
|
|
|
|
|
{
|
|
|
|
|
if (s->source)
|
|
|
|
|
wl_event_source_remove(s->source);
|
|
|
|
|
if (s->addr.sun_path[0])
|
|
|
|
|
unlink(s->addr.sun_path);
|
2014-08-07 16:46:52 +03:00
|
|
|
if (s->fd >= 0)
|
2014-05-08 10:22:25 -04:00
|
|
|
close(s->fd);
|
|
|
|
|
if (s->lock_addr[0])
|
|
|
|
|
unlink(s->lock_addr);
|
2014-08-07 16:46:52 +03:00
|
|
|
if (s->fd_lock >= 0)
|
2014-05-08 10:22:25 -04:00
|
|
|
close(s->fd_lock);
|
|
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-07 16:46:52 +03:00
|
|
|
static struct wl_socket *
|
|
|
|
|
wl_socket_alloc(void)
|
|
|
|
|
{
|
|
|
|
|
struct wl_socket *s;
|
|
|
|
|
|
2015-08-26 12:00:06 +08:00
|
|
|
s = zalloc(sizeof *s);
|
2014-08-07 16:46:52 +03:00
|
|
|
if (!s)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
s->fd = -1;
|
|
|
|
|
s->fd_lock = -1;
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:51:27 +05:30
|
|
|
/** Destroy Wayland display object.
|
|
|
|
|
*
|
|
|
|
|
* \param display The Wayland display object which should be destroyed.
|
|
|
|
|
* \return None.
|
|
|
|
|
*
|
|
|
|
|
* This function emits the wl_display destroy signal, releases
|
|
|
|
|
* all the sockets added to this display, free's all the globals associated
|
|
|
|
|
* with this display, free's memory of additional shared memory formats and
|
|
|
|
|
* destroy the display object.
|
|
|
|
|
*
|
|
|
|
|
* \sa wl_display_add_destroy_listener
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
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) {
|
2014-05-08 10:22:25 -04:00
|
|
|
wl_socket_destroy(s);
|
2010-12-01 15:36:20 -05:00
|
|
|
}
|
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
|
|
|
|
2016-01-14 11:02:18 -06:00
|
|
|
if (version < 1) {
|
|
|
|
|
wl_log("wl_global_create: failing to create interface "
|
|
|
|
|
"'%s' with version %d because it is less than 1\n",
|
|
|
|
|
interface->name, version);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 11:02:17 -06:00
|
|
|
if (version > interface->version) {
|
|
|
|
|
wl_log("wl_global_create: implemented version for '%s' "
|
|
|
|
|
"higher than interface version (%d > %d)\n",
|
|
|
|
|
interface->name, version, interface->version);
|
2013-07-08 18:45:41 -04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Get the current serial number
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
*
|
|
|
|
|
* This function returns the most recent serial number, but does not
|
|
|
|
|
* increment it.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 21:11:17 -08:00
|
|
|
/** Get the next serial number
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
*
|
|
|
|
|
* This function increments the display serial number and returns the
|
|
|
|
|
* new value.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2013-11-13 21:11:17 -08:00
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
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_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
|
2014-05-08 10:57:16 -04:00
|
|
|
wl_socket_lock(struct wl_socket *socket)
|
2011-04-13 09:38:29 +02:00
|
|
|
{
|
|
|
|
|
struct stat socket_stat;
|
|
|
|
|
|
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
|
|
|
|
2014-05-08 10:57:16 -04:00
|
|
|
socket->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
|
|
|
|
2014-05-08 10:57:16 -04:00
|
|
|
if (socket->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);
|
2014-08-06 11:21:59 +02:00
|
|
|
goto err;
|
2011-04-13 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-08 10:57:16 -04:00
|
|
|
if (flock(socket->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);
|
2014-08-06 11:21:59 +02:00
|
|
|
goto err_fd;
|
2011-04-13 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2014-08-06 11:21:59 +02:00
|
|
|
goto err_fd;
|
2011-04-13 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
} else if (socket_stat.st_mode & S_IWUSR ||
|
|
|
|
|
socket_stat.st_mode & S_IWGRP) {
|
|
|
|
|
unlink(socket->addr.sun_path);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 10:57:16 -04:00
|
|
|
return 0;
|
2014-08-06 11:21:59 +02:00
|
|
|
err_fd:
|
|
|
|
|
close(socket->fd_lock);
|
|
|
|
|
socket->fd_lock = -1;
|
|
|
|
|
err:
|
|
|
|
|
*socket->lock_addr = 0;
|
|
|
|
|
/* we did not set this value here, but without lock the
|
|
|
|
|
* socket won't be created anyway. This prevents the
|
|
|
|
|
* wl_socket_destroy from unlinking already existing socket
|
|
|
|
|
* created by other compositor */
|
|
|
|
|
*socket->addr.sun_path = 0;
|
|
|
|
|
|
|
|
|
|
return -1;
|
2011-04-13 09:38:29 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-08 10:25:13 -04:00
|
|
|
static int
|
|
|
|
|
wl_socket_init_for_display_name(struct wl_socket *s, const char *name)
|
2008-09-30 09:46:10 -04:00
|
|
|
{
|
2012-06-15 21:32:19 +00:00
|
|
|
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->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
|
|
|
|
2014-05-08 11:25:34 -04:00
|
|
|
s->display_name = (s->addr.sun_path + name_size - 1) - strlen(name);
|
|
|
|
|
|
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);
|
2014-08-06 11:21:59 +02:00
|
|
|
*s->addr.sun_path = 0;
|
2012-06-15 21:32:19 +00:00
|
|
|
/* to prevent programs reporting
|
|
|
|
|
* "failed to add socket: Success" */
|
|
|
|
|
errno = ENAMETOOLONG;
|
|
|
|
|
return -1;
|
2014-11-12 03:19:03 +01:00
|
|
|
}
|
2012-06-15 21:32:19 +00:00
|
|
|
|
2014-05-08 10:25:13 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 11:01:24 -04:00
|
|
|
static int
|
|
|
|
|
_wl_display_add_socket(struct wl_display *display, struct wl_socket *s)
|
|
|
|
|
{
|
|
|
|
|
socklen_t size;
|
|
|
|
|
|
|
|
|
|
s->fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
|
|
|
|
|
if (s->fd < 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
|
|
|
|
|
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
|
|
|
|
|
wl_log("bind() failed with error: %m\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 16:10:49 +02:00
|
|
|
if (listen(s->fd, 128) < 0) {
|
2014-05-08 11:01:24 -04:00
|
|
|
wl_log("listen() failed with error: %m\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s->source = wl_event_loop_add_fd(display->loop, s->fd,
|
|
|
|
|
WL_EVENT_READABLE,
|
|
|
|
|
socket_data, display);
|
|
|
|
|
if (s->source == NULL) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_list_insert(display->socket_list.prev, &s->link);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT const char *
|
|
|
|
|
wl_display_add_socket_auto(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
struct wl_socket *s;
|
|
|
|
|
int displayno = 0;
|
|
|
|
|
char display_name[16] = "";
|
|
|
|
|
|
|
|
|
|
/* A reasonable number of maximum default sockets. If
|
|
|
|
|
* you need more than this, use the explicit add_socket API. */
|
|
|
|
|
const int MAX_DISPLAYNO = 32;
|
|
|
|
|
|
2014-08-07 16:46:52 +03:00
|
|
|
s = wl_socket_alloc();
|
2014-05-08 11:01:24 -04:00
|
|
|
if (s == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
snprintf(display_name, sizeof display_name, "wayland-%d", displayno);
|
|
|
|
|
if (wl_socket_init_for_display_name(s, display_name) < 0) {
|
|
|
|
|
wl_socket_destroy(s);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wl_socket_lock(s) < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (_wl_display_add_socket(display, s) < 0) {
|
|
|
|
|
wl_socket_destroy(s);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s->display_name;
|
|
|
|
|
} while (displayno++ < MAX_DISPLAYNO);
|
|
|
|
|
|
|
|
|
|
/* Ran out of display names. */
|
|
|
|
|
wl_socket_destroy(s);
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 16:49:59 -08:00
|
|
|
/** Add a socket with an existing fd to Wayland display for the clients to connect.
|
|
|
|
|
*
|
|
|
|
|
* \param display Wayland display to which the socket should be added.
|
|
|
|
|
* \param sock_fd The existing socket file descriptor to be used
|
|
|
|
|
* \return 0 if success. -1 if failed.
|
|
|
|
|
*
|
|
|
|
|
* The existing socket fd must already be created, opened, and locked.
|
|
|
|
|
* The fd must be properly set to CLOEXEC and bound to a socket file
|
|
|
|
|
* with both bind() and listen() already called.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_display_add_socket_fd(struct wl_display *display, int sock_fd)
|
|
|
|
|
{
|
|
|
|
|
struct wl_socket *s;
|
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
|
|
/* Require a valid fd or fail */
|
|
|
|
|
if (sock_fd < 0 || fstat(sock_fd, &buf) < 0 || !S_ISSOCK(buf.st_mode)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = wl_socket_alloc();
|
|
|
|
|
if (s == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2016-02-01 19:35:51 +01:00
|
|
|
s->source = wl_event_loop_add_fd(display->loop, sock_fd,
|
2015-12-17 16:49:59 -08:00
|
|
|
WL_EVENT_READABLE,
|
|
|
|
|
socket_data, display);
|
|
|
|
|
if (s->source == NULL) {
|
|
|
|
|
wl_log("failed to establish event source\n");
|
2016-02-01 19:35:51 +01:00
|
|
|
wl_socket_destroy(s);
|
2015-12-17 16:49:59 -08:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 19:35:51 +01:00
|
|
|
/* Reuse the existing fd */
|
|
|
|
|
s->fd = sock_fd;
|
|
|
|
|
|
2015-12-17 16:49:59 -08:00
|
|
|
wl_list_insert(display->socket_list.prev, &s->link);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-15 14:51:27 +05:30
|
|
|
/** Add a socket to Wayland display for the clients to connect.
|
|
|
|
|
*
|
|
|
|
|
* \param display Wayland display to which the socket should be added.
|
|
|
|
|
* \param name Name of the Unix socket.
|
|
|
|
|
* \return 0 if success. -1 if failed.
|
|
|
|
|
*
|
|
|
|
|
* This adds a Unix socket to Wayland display which can be used by clients to
|
|
|
|
|
* connect to Wayland display.
|
|
|
|
|
*
|
|
|
|
|
* If NULL is passed as name, then it would look for WAYLAND_DISPLAY env
|
|
|
|
|
* variable for the socket name. If WAYLAND_DISPLAY is not set, then default
|
|
|
|
|
* wayland-0 is used.
|
|
|
|
|
*
|
|
|
|
|
* The Unix socket will be created in the directory pointed to by environment
|
|
|
|
|
* variable XDG_RUNTIME_DIR. If XDG_RUNTIME_DIR is not set, then this function
|
|
|
|
|
* fails and returns -1.
|
|
|
|
|
*
|
|
|
|
|
* The length of socket path, i.e., the path set in XDG_RUNTIME_DIR and the
|
2016-05-02 09:49:34 +01:00
|
|
|
* socket name, must not exceed the maximum length of a Unix socket path.
|
2014-10-15 14:51:27 +05:30
|
|
|
* The function also fails if the user do not have write permission in the
|
|
|
|
|
* XDG_RUNTIME_DIR path or if the socket name is already in use.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
2014-05-08 10:25:13 -04:00
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_display_add_socket(struct wl_display *display, const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct wl_socket *s;
|
|
|
|
|
|
2014-08-07 16:46:52 +03:00
|
|
|
s = wl_socket_alloc();
|
2014-05-08 10:25:13 -04:00
|
|
|
if (s == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = getenv("WAYLAND_DISPLAY");
|
|
|
|
|
if (name == NULL)
|
|
|
|
|
name = "wayland-0";
|
|
|
|
|
|
|
|
|
|
if (wl_socket_init_for_display_name(s, name) < 0) {
|
|
|
|
|
wl_socket_destroy(s);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 10:57:16 -04:00
|
|
|
if (wl_socket_lock(s) < 0) {
|
2014-05-08 10:22:25 -04:00
|
|
|
wl_socket_destroy(s);
|
2011-04-13 09:38:29 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-08 11:01:24 -04:00
|
|
|
if (_wl_display_add_socket(display, s) < 0) {
|
2014-05-08 10:24:06 -04:00
|
|
|
wl_socket_destroy(s);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 12:46:51 +02:00
|
|
|
/** Registers a listener for the client connection signal.
|
|
|
|
|
* When a new client object is created, \a listener will be notified, carrying
|
|
|
|
|
* a pointer to the new wl_client object.
|
|
|
|
|
*
|
|
|
|
|
* \ref wl_client_create
|
|
|
|
|
* \ref wl_display
|
|
|
|
|
* \ref wl_listener
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
* \param listener Signal handler object
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_add_client_created_listener(struct wl_display *display,
|
|
|
|
|
struct wl_listener *listener)
|
|
|
|
|
{
|
|
|
|
|
wl_signal_add(&display->create_client_signal, listener);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-11 14:29:32 -06:00
|
|
|
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;
|
2013-07-17 21:58:46 -05:00
|
|
|
resource->dispatcher = NULL;
|
2013-06-27 20:09:20 -05:00
|
|
|
}
|
|
|
|
|
|
2013-07-17 21:58:46 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_resource_set_dispatcher(struct wl_resource *resource,
|
|
|
|
|
wl_dispatcher_func_t dispatcher,
|
|
|
|
|
const void *implementation,
|
|
|
|
|
void *data, wl_resource_destroy_func_t destroy)
|
|
|
|
|
{
|
|
|
|
|
resource->dispatcher = dispatcher;
|
|
|
|
|
resource->object.implementation = implementation;
|
|
|
|
|
resource->data = data;
|
|
|
|
|
resource->destroy = destroy;
|
|
|
|
|
}
|
2013-06-27 20:09:20 -05:00
|
|
|
|
2016-08-11 17:23:09 +02:00
|
|
|
/** Create a new resource object
|
|
|
|
|
*
|
|
|
|
|
* \param client The client owner of the new resource.
|
|
|
|
|
* \param interface The interface of the new resource.
|
|
|
|
|
* \param version The version of the new resource.
|
|
|
|
|
* \param id The id of the new resource. If 0, an available id will be used.
|
|
|
|
|
*
|
|
|
|
|
* Listeners added with \a wl_client_add_resource_created_listener will be
|
|
|
|
|
* notified at the end of this function.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_resource
|
|
|
|
|
*/
|
2013-06-27 20:09:20 -05:00
|
|
|
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;
|
2013-07-17 21:58:46 -05:00
|
|
|
resource->dispatcher = NULL;
|
2011-08-19 16:57:48 -04:00
|
|
|
|
2015-01-23 16:21:15 +08:00
|
|
|
if (wl_map_insert_at(&client->objects, 0, id, resource) < 0) {
|
2012-07-18 15:51:45 +02:00
|
|
|
wl_resource_post_error(client->display_resource,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
2015-01-23 16:21:15 +08:00
|
|
|
"invalid new id %d", id);
|
2011-08-19 22:50:53 -04:00
|
|
|
free(resource);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-08-19 16:57:48 -04:00
|
|
|
|
2016-08-11 17:23:09 +02:00
|
|
|
wl_signal_emit(&client->resource_created_signal, resource);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 09:24:23 -06:00
|
|
|
/** Add support for a wl_shm pixel format
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
* \param format The wl_shm pixel format to advertise
|
|
|
|
|
* \return A pointer to the wl_shm format that was added to the list
|
|
|
|
|
* or NULL if adding it to the list failed.
|
|
|
|
|
*
|
|
|
|
|
* Add the specified wl_shm format to the list of formats the wl_shm
|
|
|
|
|
* object advertises when a client binds to it. Adding a format to
|
|
|
|
|
* the list means that clients will know that the compositor supports
|
|
|
|
|
* this format and may use it for creating wl_shm buffers. The
|
|
|
|
|
* compositor must be able to handle the pixel format when a client
|
|
|
|
|
* requests it.
|
|
|
|
|
*
|
|
|
|
|
* The compositor by default supports WL_SHM_FORMAT_ARGB8888 and
|
|
|
|
|
* WL_SHM_FORMAT_XRGB8888.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT uint32_t *
|
|
|
|
|
wl_display_add_shm_format(struct wl_display *display, uint32_t format)
|
|
|
|
|
{
|
|
|
|
|
uint32_t *p = NULL;
|
|
|
|
|
|
|
|
|
|
p = wl_array_add(&display->additional_shm_formats, sizeof *p);
|
|
|
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
|
*p = format;
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get list of additional wl_shm pixel formats
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
*
|
|
|
|
|
* This function returns the list of addition wl_shm pixel formats
|
|
|
|
|
* that the compositor supports. WL_SHM_FORMAT_ARGB8888 and
|
|
|
|
|
* WL_SHM_FORMAT_XRGB8888 are always supported and not included in the
|
|
|
|
|
* array, but all formats added through wl_display_add_shm_format()
|
|
|
|
|
* will be in the array.
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2015-01-24 09:24:23 -06:00
|
|
|
* \sa wl_display_add_shm_format()
|
2015-01-26 11:30:57 -08:00
|
|
|
*
|
2016-05-12 15:52:37 -05:00
|
|
|
* \private
|
|
|
|
|
*
|
2015-01-24 09:24:23 -06:00
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
|
|
|
|
struct wl_array *
|
|
|
|
|
wl_display_get_additional_shm_formats(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
return &display->additional_shm_formats;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-09 12:46:53 +02:00
|
|
|
/** Get the list of currently connected clients
|
|
|
|
|
*
|
|
|
|
|
* \param display The display object
|
|
|
|
|
*
|
|
|
|
|
* This function returns a pointer to the list of clients currently
|
|
|
|
|
* connected to the display. You can iterate on the list by using
|
|
|
|
|
* the \a wl_client_for_each macro.
|
|
|
|
|
* The returned value is valid for the lifetime of the \a display.
|
|
|
|
|
* You must not modify the returned list, but only access it.
|
|
|
|
|
*
|
|
|
|
|
* \sa wl_client_for_each()
|
|
|
|
|
* \sa wl_client_get_link()
|
|
|
|
|
* \sa wl_client_from_link()
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_display
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct wl_list *
|
|
|
|
|
wl_display_get_client_list(struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
return &display->client_list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get the link by which a client is inserted in the client list
|
|
|
|
|
*
|
|
|
|
|
* \param client The client object
|
|
|
|
|
*
|
|
|
|
|
* \sa wl_client_for_each()
|
|
|
|
|
* \sa wl_display_get_client_list()
|
|
|
|
|
* \sa wl_client_from_link()
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct wl_list *
|
|
|
|
|
wl_client_get_link(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
return &client->link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Get a wl_client by its link
|
|
|
|
|
*
|
|
|
|
|
* \param link The link of a wl_client
|
|
|
|
|
*
|
|
|
|
|
* \sa wl_client_for_each()
|
|
|
|
|
* \sa wl_display_get_client_list()
|
|
|
|
|
* \sa wl_client_get_link()
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT struct wl_client *
|
|
|
|
|
wl_client_from_link(struct wl_list *link)
|
|
|
|
|
{
|
|
|
|
|
return container_of(link, struct wl_client, link);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-11 17:23:09 +02:00
|
|
|
/** Add a listener for the client's resource creation signal
|
|
|
|
|
*
|
|
|
|
|
* \param client The client object
|
|
|
|
|
* \param listener The listener to be added
|
|
|
|
|
*
|
|
|
|
|
* When a new resource is created for this client the listener
|
|
|
|
|
* will be notified, carrying the new resource as the data argument.
|
|
|
|
|
*
|
|
|
|
|
* \memberof wl_client
|
|
|
|
|
*/
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_add_resource_created_listener(struct wl_client *client,
|
|
|
|
|
struct wl_listener *listener)
|
|
|
|
|
{
|
|
|
|
|
wl_signal_add(&client->resource_created_signal, listener);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-02 18:29:16 -08:00
|
|
|
/** \cond */ /* Deprecated functions below. */
|
2013-07-02 14:34:42 -04:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-01-02 18:29:16 -08:00
|
|
|
/** \endcond */
|
|
|
|
|
|
2015-01-24 09:24:23 -06:00
|
|
|
/* Functions at the end of this file are deprecated. Instead of adding new
|
|
|
|
|
* code here, add it before the comment above that states:
|
|
|
|
|
* Deprecated functions below.
|
2013-11-13 21:11:17 -08:00
|
|
|
*/
|