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;
|
2008-09-30 09:46:10 -04:00
|
|
|
};
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_global {
|
2011-08-19 16:57:48 -04:00
|
|
|
const struct wl_interface *interface;
|
|
|
|
|
uint32_t name;
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2010-09-07 10:58:19 -04:00
|
|
|
static int wl_debug = 0;
|
|
|
|
|
|
2012-02-29 11:07:48 -05:00
|
|
|
static void
|
|
|
|
|
destroy_client(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wl_client *client = data;
|
|
|
|
|
|
|
|
|
|
wl_client_destroy(client);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (closure == NULL)
|
2011-12-16 10:29:36 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (wl_closure_send(closure, resource->client->connection))
|
2012-02-29 11:07:48 -05:00
|
|
|
wl_event_loop_add_idle(resource->client->display->loop,
|
|
|
|
|
destroy_client, resource->client);
|
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);
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (closure == NULL)
|
2011-12-16 10:29:36 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (wl_closure_queue(closure, resource->client->connection))
|
2012-02-29 11:07:48 -05:00
|
|
|
wl_event_loop_add_idle(resource->client->display->loop,
|
|
|
|
|
destroy_client, resource->client);
|
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
|
|
|
}
|
|
|
|
|
|
2012-06-28 22:01:58 -04:00
|
|
|
static void
|
|
|
|
|
deref_new_objects(struct wl_closure *closure)
|
|
|
|
|
{
|
|
|
|
|
const char *signature;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
signature = closure->message->signature;
|
|
|
|
|
for (i = 0; signature[i]; i++) {
|
|
|
|
|
switch (signature[i]) {
|
|
|
|
|
case 'n':
|
|
|
|
|
closure->args[i + 2] = *(uint32_t **) closure->args[i + 2];
|
|
|
|
|
closure->types[i] = &ffi_type_uint32;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
|
|
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]);
|
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];
|
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
|
|
|
|
2012-07-23 19:54:42 +01:00
|
|
|
if (wl_debug)
|
|
|
|
|
wl_closure_print(closure, object, false);
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
if (closure == NULL && errno == EINVAL) {
|
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;
|
2012-06-12 17:45:25 -04:00
|
|
|
} else if (closure == NULL && errno == ENOMEM) {
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_no_memory(resource);
|
2011-08-29 15:01:41 -04:00
|
|
|
break;
|
2010-08-30 09:47:36 -04:00
|
|
|
}
|
|
|
|
|
|
2012-06-28 22:01:58 -04:00
|
|
|
deref_new_objects(closure);
|
|
|
|
|
|
2012-06-12 17:45:25 -04:00
|
|
|
wl_closure_invoke(closure, object,
|
2010-08-30 09:47:36 -04:00
|
|
|
object->implementation[opcode], client);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
len = sizeof client->ucred;
|
|
|
|
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
|
|
|
|
|
&client->ucred, &len) < 0) {
|
|
|
|
|
free(client);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 16:54:22 -04:00
|
|
|
client->connection = wl_connection_create(fd);
|
2011-03-11 14:43:10 +02:00
|
|
|
if (client->connection == NULL) {
|
|
|
|
|
free(client);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-12-21 22:45:33 -05:00
|
|
|
|
2011-08-19 22:50:53 -04:00
|
|
|
wl_map_init(&client->objects);
|
|
|
|
|
|
|
|
|
|
if (wl_map_insert_at(&client->objects, 0, NULL) < 0) {
|
|
|
|
|
wl_map_release(&client->objects);
|
2011-08-19 11:06:37 -04:00
|
|
|
free(client);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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-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-09-10 11:20:35 +02:00
|
|
|
WL_EXPORT uint32_t
|
2010-08-09 14:43:33 -04:00
|
|
|
wl_client_add_resource(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
2012-09-10 11:20:35 +02:00
|
|
|
if (resource->object.id == 0) {
|
2012-01-04 09:13:27 -05:00
|
|
|
resource->object.id =
|
|
|
|
|
wl_map_insert_new(&client->objects,
|
|
|
|
|
WL_MAP_SERVER_SIDE, resource);
|
2012-09-10 11:20:35 +02:00
|
|
|
} else if (wl_map_insert_at(&client->objects,
|
|
|
|
|
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);
|
2012-09-10 11:20:35 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
2012-01-04 09:13:27 -05:00
|
|
|
|
2011-08-18 17:53:50 -04:00
|
|
|
resource->client = client;
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_init(&resource->destroy_signal);
|
2012-09-10 11:20:35 +02:00
|
|
|
|
|
|
|
|
return resource->object.id;
|
2010-08-09 14:43:33 -04:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_emit(&resource->destroy_signal, resource);
|
2011-08-19 17:07:14 -04:00
|
|
|
|
|
|
|
|
if (resource->destroy)
|
|
|
|
|
resource->destroy(resource);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
2012-03-01 22:46:07 -05:00
|
|
|
wl_map_insert_at(&client->objects, 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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2010-12-06 21:35:19 -05:00
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
lose_pointer_focus(struct wl_listener *listener, void *data)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_pointer *pointer =
|
|
|
|
|
container_of(listener, struct wl_pointer, focus_listener);
|
2010-12-06 21:35:19 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
pointer->focus_resource = NULL;
|
2010-12-06 21:35:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-04-12 15:29:48 -04:00
|
|
|
lose_keyboard_focus(struct wl_listener *listener, void *data)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_keyboard *keyboard =
|
|
|
|
|
container_of(listener, struct wl_keyboard, focus_listener);
|
2010-12-06 21:35:19 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
keyboard->focus_resource = NULL;
|
2010-12-06 21:35:19 -05:00
|
|
|
}
|
|
|
|
|
|
2012-07-10 13:05:00 +03:00
|
|
|
static void
|
|
|
|
|
lose_touch_focus(struct wl_listener *listener, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wl_touch *touch =
|
|
|
|
|
container_of(listener, struct wl_touch, focus_listener);
|
|
|
|
|
|
|
|
|
|
touch->focus_resource = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-04 21:29:17 -05:00
|
|
|
static 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
|
|
|
default_grab_focus(struct wl_pointer_grab *grab,
|
2012-05-08 17:17:26 +01:00
|
|
|
struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y)
|
2012-01-04 21:29:17 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_pointer *pointer = grab->pointer;
|
2012-01-04 21:29:17 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (pointer->button_count > 0)
|
2012-01-04 21:29:17 -05:00
|
|
|
return;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_set_focus(pointer, surface, x, y);
|
2012-01-04 21:29:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-02-18 05:05:27 -07:00
|
|
|
default_grab_motion(struct wl_pointer_grab *grab,
|
2012-05-08 17:17:26 +01:00
|
|
|
uint32_t time, wl_fixed_t x, wl_fixed_t y)
|
2012-01-04 21:29:17 -05:00
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = grab->pointer->focus_resource;
|
2012-01-04 21:29:17 -05:00
|
|
|
if (resource)
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_send_motion(resource, time, x, y);
|
2012-01-04 21:29:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-02-18 05:05:27 -07:00
|
|
|
default_grab_button(struct wl_pointer_grab *grab,
|
2012-05-30 16:31:48 +01:00
|
|
|
uint32_t time, uint32_t button, uint32_t state_w)
|
2012-01-04 21:29:17 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_pointer *pointer = grab->pointer;
|
2012-01-04 21:29:17 -05:00
|
|
|
struct wl_resource *resource;
|
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;
|
2012-05-30 16:31:48 +01:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
2012-01-04 21:29:17 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = pointer->focus_resource;
|
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
|
|
|
if (resource) {
|
|
|
|
|
serial = wl_display_next_serial(resource->client->display);
|
2012-05-30 16:31:48 +01:00
|
|
|
wl_pointer_send_button(resource, serial, time, button, state_w);
|
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
|
|
|
}
|
2012-01-12 15:48:02 +00:00
|
|
|
|
2012-05-30 16:31:48 +01:00
|
|
|
if (pointer->button_count == 0 &&
|
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_set_focus(pointer, pointer->current,
|
|
|
|
|
pointer->current_x, pointer->current_y);
|
2012-01-04 21:29:17 -05:00
|
|
|
}
|
|
|
|
|
|
2012-02-18 05:05:27 -07:00
|
|
|
static const struct wl_pointer_grab_interface
|
|
|
|
|
default_pointer_grab_interface = {
|
2012-01-04 21:29:17 -05:00
|
|
|
default_grab_focus,
|
|
|
|
|
default_grab_motion,
|
|
|
|
|
default_grab_button
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-18 05:05:28 -07:00
|
|
|
static void
|
|
|
|
|
default_grab_key(struct wl_keyboard_grab *grab,
|
2012-05-04 11:21:20 +01:00
|
|
|
uint32_t time, uint32_t key, uint32_t state)
|
2012-02-18 05:05:28 -07:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
struct wl_keyboard *keyboard = grab->keyboard;
|
2012-02-18 05:05:28 -07:00
|
|
|
struct wl_resource *resource;
|
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;
|
2012-02-18 05:05:28 -07:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = keyboard->focus_resource;
|
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
|
|
|
if (resource) {
|
|
|
|
|
serial = wl_display_next_serial(resource->client->display);
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_send_key(resource, serial, time, key, state);
|
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
|
|
|
}
|
2012-02-18 05:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2012-06-22 14:38:12 -04:00
|
|
|
static struct wl_resource *
|
|
|
|
|
find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *r;
|
|
|
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(r, list, link) {
|
|
|
|
|
if (r->client == surface->resource.client)
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-30 16:31:47 +01:00
|
|
|
static void
|
|
|
|
|
default_grab_modifiers(struct wl_keyboard_grab *grab, uint32_t serial,
|
|
|
|
|
uint32_t mods_depressed, uint32_t mods_latched,
|
|
|
|
|
uint32_t mods_locked, uint32_t group)
|
|
|
|
|
{
|
|
|
|
|
struct wl_keyboard *keyboard = grab->keyboard;
|
2012-06-22 14:38:12 -04:00
|
|
|
struct wl_pointer *pointer = keyboard->seat->pointer;
|
|
|
|
|
struct wl_resource *resource, *pr;
|
2012-05-30 16:31:47 +01:00
|
|
|
|
|
|
|
|
resource = keyboard->focus_resource;
|
|
|
|
|
if (!resource)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
wl_keyboard_send_modifiers(resource, serial, mods_depressed,
|
|
|
|
|
mods_latched, mods_locked, group);
|
2012-06-22 14:38:12 -04:00
|
|
|
|
|
|
|
|
if (pointer && pointer->focus && pointer->focus != keyboard->focus) {
|
|
|
|
|
pr = find_resource_for_surface(&keyboard->resource_list,
|
|
|
|
|
pointer->focus);
|
|
|
|
|
if (pr) {
|
|
|
|
|
wl_keyboard_send_modifiers(pr,
|
|
|
|
|
serial,
|
|
|
|
|
keyboard->modifiers.mods_depressed,
|
|
|
|
|
keyboard->modifiers.mods_latched,
|
|
|
|
|
keyboard->modifiers.mods_locked,
|
|
|
|
|
keyboard->modifiers.group);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-30 16:31:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-02-18 05:05:28 -07:00
|
|
|
static const struct wl_keyboard_grab_interface
|
|
|
|
|
default_keyboard_grab_interface = {
|
2012-05-30 16:31:47 +01:00
|
|
|
default_grab_key,
|
|
|
|
|
default_grab_modifiers,
|
2012-02-18 05:05:28 -07:00
|
|
|
};
|
|
|
|
|
|
2010-12-06 21:35:19 -05:00
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_init(struct wl_pointer *pointer)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
memset(pointer, 0, sizeof *pointer);
|
|
|
|
|
wl_list_init(&pointer->resource_list);
|
|
|
|
|
pointer->focus_listener.notify = lose_pointer_focus;
|
|
|
|
|
pointer->default_grab.interface = &default_pointer_grab_interface;
|
|
|
|
|
pointer->default_grab.pointer = pointer;
|
|
|
|
|
pointer->grab = &pointer->default_grab;
|
2012-06-05 09:56:42 -04:00
|
|
|
wl_signal_init(&pointer->focus_signal);
|
2010-12-08 09:48:52 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
/* FIXME: Pick better co-ords. */
|
|
|
|
|
pointer->x = wl_fixed_from_int(100);
|
|
|
|
|
pointer->y = wl_fixed_from_int(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_pointer_release(struct wl_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
/* XXX: What about pointer->resource_list? */
|
|
|
|
|
if (pointer->focus_resource)
|
|
|
|
|
wl_list_remove(&pointer->focus_listener.link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_keyboard_init(struct wl_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
memset(keyboard, 0, sizeof *keyboard);
|
|
|
|
|
wl_list_init(&keyboard->resource_list);
|
|
|
|
|
wl_array_init(&keyboard->keys);
|
|
|
|
|
keyboard->focus_listener.notify = lose_keyboard_focus;
|
|
|
|
|
keyboard->default_grab.interface = &default_keyboard_grab_interface;
|
|
|
|
|
keyboard->default_grab.keyboard = keyboard;
|
|
|
|
|
keyboard->grab = &keyboard->default_grab;
|
2012-06-05 09:56:42 -04:00
|
|
|
wl_signal_init(&keyboard->focus_signal);
|
2012-05-16 18:44:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_keyboard_release(struct wl_keyboard *keyboard)
|
|
|
|
|
{
|
|
|
|
|
/* XXX: What about keyboard->resource_list? */
|
|
|
|
|
if (keyboard->focus_resource)
|
|
|
|
|
wl_list_remove(&keyboard->focus_listener.link);
|
|
|
|
|
wl_array_release(&keyboard->keys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_touch_init(struct wl_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
memset(touch, 0, sizeof *touch);
|
|
|
|
|
wl_list_init(&touch->resource_list);
|
2012-07-10 13:05:00 +03:00
|
|
|
touch->focus_listener.notify = lose_touch_focus;
|
2012-05-16 18:44:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_touch_release(struct wl_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
/* XXX: What about touch->resource_list? */
|
|
|
|
|
if (touch->focus_resource)
|
|
|
|
|
wl_list_remove(&touch->focus_listener.link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_seat_init(struct wl_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
memset(seat, 0, sizeof *seat);
|
2012-01-04 21:29:17 -05:00
|
|
|
|
2012-06-12 23:57:33 +02:00
|
|
|
wl_signal_init(&seat->destroy_signal);
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->selection_data_source = NULL;
|
|
|
|
|
wl_list_init(&seat->base_resource_list);
|
|
|
|
|
wl_signal_init(&seat->selection_signal);
|
|
|
|
|
wl_list_init(&seat->drag_resource_list);
|
|
|
|
|
wl_signal_init(&seat->drag_icon_signal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_seat_release(struct wl_seat *seat)
|
|
|
|
|
{
|
2012-06-12 23:57:33 +02:00
|
|
|
wl_signal_emit(&seat->destroy_signal, seat);
|
|
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (seat->pointer)
|
|
|
|
|
wl_pointer_release(seat->pointer);
|
|
|
|
|
if (seat->keyboard)
|
|
|
|
|
wl_keyboard_release(seat->keyboard);
|
|
|
|
|
if (seat->touch)
|
|
|
|
|
wl_touch_release(seat->touch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
seat_send_updated_caps(struct wl_seat *seat)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *r;
|
|
|
|
|
enum wl_seat_capability caps = 0;
|
|
|
|
|
|
|
|
|
|
if (seat->pointer)
|
|
|
|
|
caps |= WL_SEAT_CAPABILITY_POINTER;
|
|
|
|
|
if (seat->keyboard)
|
|
|
|
|
caps |= WL_SEAT_CAPABILITY_KEYBOARD;
|
|
|
|
|
if (seat->touch)
|
|
|
|
|
caps |= WL_SEAT_CAPABILITY_TOUCH;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(r, &seat->base_resource_list, link)
|
|
|
|
|
wl_seat_send_capabilities(r, caps);
|
|
|
|
|
}
|
2012-02-18 05:05:28 -07:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_seat_set_pointer(struct wl_seat *seat, struct wl_pointer *pointer)
|
|
|
|
|
{
|
|
|
|
|
if (pointer && (seat->pointer || pointer->seat))
|
|
|
|
|
return; /* XXX: error? */
|
|
|
|
|
if (!pointer && !seat->pointer)
|
|
|
|
|
return;
|
2012-03-27 17:36:35 +03:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->pointer = pointer;
|
|
|
|
|
if (pointer)
|
|
|
|
|
pointer->seat = seat;
|
|
|
|
|
|
|
|
|
|
seat_send_updated_caps(seat);
|
2010-12-06 21:35:19 -05:00
|
|
|
}
|
|
|
|
|
|
2012-01-03 16:32:40 +02:00
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_seat_set_keyboard(struct wl_seat *seat, struct wl_keyboard *keyboard)
|
2012-01-03 16:32:40 +02:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
if (keyboard && (seat->keyboard || keyboard->seat))
|
|
|
|
|
return; /* XXX: error? */
|
2012-07-10 13:05:01 +03:00
|
|
|
if (!keyboard && !seat->keyboard)
|
2012-05-16 18:44:40 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
seat->keyboard = keyboard;
|
|
|
|
|
if (keyboard)
|
|
|
|
|
keyboard->seat = seat;
|
2012-01-03 16:32:40 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat_send_updated_caps(seat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_seat_set_touch(struct wl_seat *seat, struct wl_touch *touch)
|
|
|
|
|
{
|
|
|
|
|
if (touch && (seat->touch || touch->seat))
|
|
|
|
|
return; /* XXX: error? */
|
|
|
|
|
if (!touch && !seat->touch)
|
|
|
|
|
return;
|
2012-01-03 16:32:40 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat->touch = touch;
|
2012-07-09 11:35:56 +02:00
|
|
|
if (touch)
|
2012-05-16 18:44:40 +01:00
|
|
|
touch->seat = seat;
|
2012-01-03 16:32:40 +02:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
seat_send_updated_caps(seat);
|
2012-01-03 16:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_set_focus(struct wl_pointer *pointer, struct wl_surface *surface,
|
|
|
|
|
wl_fixed_t sx, wl_fixed_t sy)
|
2010-12-01 10:17:47 -05:00
|
|
|
{
|
2012-06-22 13:21:26 +01:00
|
|
|
struct wl_keyboard *kbd = pointer->seat->keyboard;
|
|
|
|
|
struct wl_resource *resource, *kr;
|
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;
|
2011-08-18 17:53:50 -04:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = pointer->focus_resource;
|
2012-05-30 16:31:46 +01:00
|
|
|
if (resource && pointer->focus != surface) {
|
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_next_serial(resource->client->display);
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_send_leave(resource, serial,
|
|
|
|
|
&pointer->focus->resource);
|
|
|
|
|
wl_list_remove(&pointer->focus_listener.link);
|
2012-02-18 01:25:44 -05:00
|
|
|
}
|
2011-03-12 21:26:21 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = find_resource_for_surface(&pointer->resource_list,
|
|
|
|
|
surface);
|
2012-05-30 16:31:46 +01:00
|
|
|
if (resource &&
|
|
|
|
|
(pointer->focus != surface ||
|
|
|
|
|
pointer->focus_resource != resource)) {
|
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_next_serial(resource->client->display);
|
2012-06-22 13:21:26 +01:00
|
|
|
if (kbd) {
|
|
|
|
|
kr = find_resource_for_surface(&kbd->resource_list,
|
|
|
|
|
surface);
|
|
|
|
|
if (kr) {
|
2012-06-22 12:20:00 -04:00
|
|
|
wl_keyboard_send_modifiers(kr,
|
2012-06-22 13:21:26 +01:00
|
|
|
serial,
|
|
|
|
|
kbd->modifiers.mods_depressed,
|
|
|
|
|
kbd->modifiers.mods_latched,
|
|
|
|
|
kbd->modifiers.mods_locked,
|
|
|
|
|
kbd->modifiers.group);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_send_enter(resource, serial, &surface->resource,
|
|
|
|
|
sx, sy);
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_add(&resource->destroy_signal,
|
2012-05-16 18:44:40 +01:00
|
|
|
&pointer->focus_listener);
|
|
|
|
|
pointer->focus_serial = serial;
|
2011-03-12 21:26:21 -05:00
|
|
|
}
|
2010-12-01 10:17:47 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
pointer->focus_resource = resource;
|
|
|
|
|
pointer->focus = surface;
|
|
|
|
|
pointer->default_grab.focus = surface;
|
2012-06-05 09:56:42 -04:00
|
|
|
wl_signal_emit(&pointer->focus_signal, pointer);
|
2010-12-01 10:17:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_set_focus(struct wl_keyboard *keyboard, struct wl_surface *surface)
|
2010-12-01 10:17:47 -05:00
|
|
|
{
|
2011-08-18 17:53:50 -04:00
|
|
|
struct wl_resource *resource;
|
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;
|
2011-08-18 17:53:50 -04:00
|
|
|
|
2012-05-30 16:31:46 +01:00
|
|
|
if (keyboard->focus_resource && keyboard->focus != surface) {
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = keyboard->focus_resource;
|
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_next_serial(resource->client->display);
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_send_leave(resource, serial,
|
|
|
|
|
&keyboard->focus->resource);
|
|
|
|
|
wl_list_remove(&keyboard->focus_listener.link);
|
2012-02-18 01:25:44 -05:00
|
|
|
}
|
2010-12-01 10:17:47 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
resource = find_resource_for_surface(&keyboard->resource_list,
|
|
|
|
|
surface);
|
2012-05-30 16:31:46 +01:00
|
|
|
if (resource &&
|
|
|
|
|
(keyboard->focus != surface ||
|
|
|
|
|
keyboard->focus_resource != resource)) {
|
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_next_serial(resource->client->display);
|
2012-06-22 13:21:26 +01:00
|
|
|
wl_keyboard_send_modifiers(resource, serial,
|
|
|
|
|
keyboard->modifiers.mods_depressed,
|
|
|
|
|
keyboard->modifiers.mods_latched,
|
|
|
|
|
keyboard->modifiers.mods_locked,
|
|
|
|
|
keyboard->modifiers.group);
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_send_enter(resource, serial, &surface->resource,
|
|
|
|
|
&keyboard->keys);
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_add(&resource->destroy_signal,
|
2012-05-16 18:44:40 +01:00
|
|
|
&keyboard->focus_listener);
|
|
|
|
|
keyboard->focus_serial = serial;
|
2011-03-12 21:26:21 -05:00
|
|
|
}
|
2010-12-01 10:17:47 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
keyboard->focus_resource = resource;
|
|
|
|
|
keyboard->focus = surface;
|
2012-06-05 09:56:42 -04:00
|
|
|
wl_signal_emit(&keyboard->focus_signal, keyboard);
|
2010-12-01 10:17:47 -05:00
|
|
|
}
|
|
|
|
|
|
2012-02-18 05:05:28 -07:00
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_start_grab(struct wl_keyboard *keyboard,
|
|
|
|
|
struct wl_keyboard_grab *grab)
|
2012-02-18 05:05:28 -07:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
keyboard->grab = grab;
|
|
|
|
|
grab->keyboard = keyboard;
|
2012-02-18 05:05:28 -07:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
/* XXX focus? */
|
2012-02-18 05:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_keyboard_end_grab(struct wl_keyboard *keyboard)
|
2012-02-18 05:05:28 -07:00
|
|
|
{
|
2012-05-16 18:44:40 +01:00
|
|
|
keyboard->grab = &keyboard->default_grab;
|
2012-02-18 05:05:28 -07:00
|
|
|
}
|
|
|
|
|
|
2011-01-05 17:34:54 -05:00
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_start_grab(struct wl_pointer *pointer, struct wl_pointer_grab *grab)
|
2011-01-05 17:34:54 -05:00
|
|
|
{
|
2012-02-18 05:05:27 -07:00
|
|
|
const struct wl_pointer_grab_interface *interface;
|
2011-01-05 17:34:54 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
pointer->grab = grab;
|
|
|
|
|
interface = pointer->grab->interface;
|
|
|
|
|
grab->pointer = pointer;
|
2011-01-05 17:34:54 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
if (pointer->current)
|
|
|
|
|
interface->focus(pointer->grab, pointer->current,
|
|
|
|
|
pointer->current_x, pointer->current_y);
|
2011-01-05 17:34:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2012-05-16 18:44:40 +01:00
|
|
|
wl_pointer_end_grab(struct wl_pointer *pointer)
|
2011-01-05 17:34:54 -05:00
|
|
|
{
|
2012-02-18 05:05:27 -07:00
|
|
|
const struct wl_pointer_grab_interface *interface;
|
2011-01-05 17:34:54 -05:00
|
|
|
|
2012-05-16 18:44:40 +01:00
|
|
|
pointer->grab = &pointer->default_grab;
|
|
|
|
|
interface = pointer->grab->interface;
|
|
|
|
|
interface->focus(pointer->grab, pointer->current,
|
|
|
|
|
pointer->current_x, pointer->current_y);
|
2011-01-05 17:34:54 -05: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;
|
|
|
|
|
|
|
|
|
|
if (&global->link == &display->global_list)
|
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
|
|
|
|
2011-08-19 22:50:53 -04:00
|
|
|
callback = wl_client_add_object(client,
|
|
|
|
|
&wl_callback_interface, NULL, id, NULL);
|
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);
|
|
|
|
|
free(resource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 =
|
|
|
|
|
wl_client_add_object(client, &wl_registry_interface,
|
|
|
|
|
®istry_interface, id, display);
|
|
|
|
|
registry_resource->destroy = unbind_resource;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
global->interface->version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
free(resource);
|
|
|
|
|
}
|
|
|
|
|
|
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 =
|
|
|
|
|
wl_client_add_object(client, &wl_display_interface,
|
|
|
|
|
&display_interface, id, display);
|
2011-11-28 09:47:15 +02:00
|
|
|
client->display_resource->destroy = 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");
|
|
|
|
|
if (debug)
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
if (!wl_display_add_global(display, &wl_display_interface,
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2010-12-01 15:36:20 -05:00
|
|
|
free(display);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
WL_EXPORT struct wl_global *
|
2008-12-21 23:37:12 -05:00
|
|
|
wl_display_add_global(struct wl_display *display,
|
2011-08-19 16:57:48 -04:00
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
global->name = display->id++;
|
|
|
|
|
global->interface = interface;
|
|
|
|
|
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,
|
|
|
|
|
global->interface->version);
|
|
|
|
|
|
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
|
|
|
|
|
wl_display_remove_global(struct wl_display *display, struct wl_global *global)
|
2011-06-14 10:35:46 +02:00
|
|
|
{
|
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
|
|
|
|
|
wl_client_create(display, 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
|
|
|
|
2011-08-19 16:57:48 -04:00
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_client_add_object(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation,
|
|
|
|
|
uint32_t id, void *data)
|
|
|
|
|
{
|
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
|
|
resource = malloc(sizeof *resource);
|
|
|
|
|
if (resource == NULL) {
|
2011-09-01 09:53:33 -04:00
|
|
|
wl_resource_post_no_memory(client->display_resource);
|
2011-08-19 16:57:48 -04:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource->object.interface = interface;
|
|
|
|
|
resource->object.implementation = implementation;
|
|
|
|
|
resource->object.id = id;
|
|
|
|
|
resource->client = client;
|
|
|
|
|
resource->data = data;
|
|
|
|
|
resource->destroy = (void *) free;
|
2012-04-12 15:29:48 -04:00
|
|
|
wl_signal_init(&resource->destroy_signal);
|
2011-08-19 16:57:48 -04:00
|
|
|
|
2011-08-19 22:50:53 -04:00
|
|
|
if (wl_map_insert_at(&client->objects, 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
|
|
|
|
|
|
|
|
WL_EXPORT struct wl_resource *
|
|
|
|
|
wl_client_new_object(struct wl_client *client,
|
|
|
|
|
const struct wl_interface *interface,
|
|
|
|
|
const void *implementation, void *data)
|
|
|
|
|
{
|
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
|
|
id = wl_map_insert_new(&client->objects, WL_MAP_SERVER_SIDE, NULL);
|
|
|
|
|
return wl_client_add_object(client,
|
|
|
|
|
interface, implementation, id, data);
|
|
|
|
|
|
|
|
|
|
}
|
2012-05-29 17:37:02 +02:00
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_log_set_handler_server(wl_log_func_t handler)
|
|
|
|
|
{
|
|
|
|
|
wl_log_handler = handler;
|
|
|
|
|
}
|