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
|
|
|
|
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"
|
2008-10-08 12:48:46 -04:00
|
|
|
#include "connection.h"
|
2008-09-30 09:46:10 -04:00
|
|
|
|
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;
|
2011-04-13 09:38:29 +02:00
|
|
|
char lock_addr[113];
|
2010-12-01 15:36:20 -05:00
|
|
|
struct wl_list link;
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
2010-08-09 14:43:33 -04:00
|
|
|
struct wl_list resource_list;
|
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;
|
2008-09-30 09:46:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct wl_display {
|
2010-12-01 17:07:41 -05:00
|
|
|
struct wl_object object;
|
2008-09-30 09:46:10 -04:00
|
|
|
struct wl_event_loop *loop;
|
2010-02-26 11:42:59 -05:00
|
|
|
struct wl_hash_table *objects;
|
2010-12-01 15:36:20 -05:00
|
|
|
int run;
|
2008-10-07 10:10:36 -04:00
|
|
|
|
2011-07-29 19:51:22 -07:00
|
|
|
struct wl_list callback_list;
|
2008-10-11 18:40:23 -04:00
|
|
|
uint32_t client_id_range;
|
2008-11-23 23:41:08 -05:00
|
|
|
uint32_t id;
|
2008-11-02 10:12:29 -05:00
|
|
|
|
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 {
|
|
|
|
|
struct wl_object *object;
|
2011-04-18 12:35:01 -04:00
|
|
|
wl_global_bind_func_t func;
|
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;
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_post_event(struct wl_client *client, struct wl_object *sender,
|
|
|
|
|
uint32_t opcode, ...)
|
|
|
|
|
{
|
2010-09-07 21:34:45 -04:00
|
|
|
struct wl_closure *closure;
|
2008-12-21 23:37:12 -05:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, opcode);
|
2010-09-07 21:34:45 -04:00
|
|
|
closure = wl_connection_vmarshal(client->connection,
|
|
|
|
|
sender, opcode, ap,
|
|
|
|
|
&sender->interface->events[opcode]);
|
2008-12-21 23:37:12 -05:00
|
|
|
va_end(ap);
|
2010-09-07 21:34:45 -04:00
|
|
|
|
|
|
|
|
wl_closure_send(closure, client->connection);
|
2010-09-07 21:40:31 -04:00
|
|
|
|
2011-07-14 18:56:40 +03:00
|
|
|
if (wl_debug)
|
|
|
|
|
wl_closure_print(closure, sender, true);
|
2010-09-07 21:40:31 -04:00
|
|
|
|
2010-09-07 21:34:45 -04:00
|
|
|
wl_closure_destroy(closure);
|
2008-12-21 23:37:12 -05:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 10:57:06 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_post_error(struct wl_client *client, struct wl_object *object,
|
|
|
|
|
uint32_t code, const char *msg, ...)
|
|
|
|
|
{
|
|
|
|
|
char buffer[128];
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
vsnprintf(buffer, sizeof buffer, msg, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
wl_client_post_event(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR, object, code, buffer);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2008-10-07 10:10:36 -04:00
|
|
|
struct wl_object *object;
|
2010-08-30 09:47:36 -04:00
|
|
|
struct wl_closure *closure;
|
|
|
|
|
const struct wl_message *message;
|
2008-10-08 12:48:46 -04:00
|
|
|
uint32_t p[2], opcode, size;
|
|
|
|
|
uint32_t cmask = 0;
|
2010-08-30 09:47:36 -04:00
|
|
|
int len;
|
2008-10-08 12:48:46 -04:00
|
|
|
|
|
|
|
|
if (mask & WL_EVENT_READABLE)
|
|
|
|
|
cmask |= WL_CONNECTION_READABLE;
|
|
|
|
|
if (mask & WL_EVENT_WRITEABLE)
|
|
|
|
|
cmask |= WL_CONNECTION_WRITABLE;
|
|
|
|
|
|
|
|
|
|
len = wl_connection_data(connection, cmask);
|
|
|
|
|
if (len < 0) {
|
|
|
|
|
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
|
|
|
|
2008-11-23 23:41:08 -05:00
|
|
|
while (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;
|
|
|
|
|
|
2010-02-26 11:42:59 -05:00
|
|
|
object = wl_hash_table_lookup(client->display->objects, p[0]);
|
2008-10-07 10:10:36 -04:00
|
|
|
if (object == NULL) {
|
2011-05-11 10:57:06 -04:00
|
|
|
wl_client_post_error(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid object %d", p[0]);
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_connection_consume(connection, size);
|
|
|
|
|
len -= size;
|
2008-10-07 10:10:36 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2008-10-07 10:10:36 -04:00
|
|
|
if (opcode >= object->interface->method_count) {
|
2011-05-11 10:57:06 -04:00
|
|
|
wl_client_post_error(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
|
|
|
|
"invalid method %d, object %s@%d",
|
|
|
|
|
object->interface->name,
|
|
|
|
|
object->id, opcode);
|
2008-10-08 12:48:46 -04:00
|
|
|
wl_connection_consume(connection, size);
|
|
|
|
|
len -= size;
|
2008-10-07 10:10:36 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2010-08-30 09:47:36 -04:00
|
|
|
message = &object->interface->methods[opcode];
|
|
|
|
|
closure = wl_connection_demarshal(client->connection, size,
|
|
|
|
|
client->display->objects,
|
|
|
|
|
message);
|
|
|
|
|
len -= size;
|
2010-08-09 14:34:11 -04:00
|
|
|
|
2010-08-30 09:47:36 -04:00
|
|
|
if (closure == NULL && errno == EINVAL) {
|
2011-05-11 10:57:06 -04:00
|
|
|
wl_client_post_error(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_METHOD,
|
|
|
|
|
"invalid arguments for %s@%d.%s",
|
|
|
|
|
object->interface->name,
|
|
|
|
|
object->id, message->name);
|
2010-08-30 09:47:36 -04:00
|
|
|
continue;
|
|
|
|
|
} else if (closure == NULL && errno == ENOMEM) {
|
2010-09-02 20:55:16 -04:00
|
|
|
wl_client_post_no_memory(client);
|
2010-08-30 09:47:36 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 10:58:19 -04:00
|
|
|
|
|
|
|
|
if (wl_debug)
|
2011-07-14 18:56:40 +03:00
|
|
|
wl_closure_print(closure, object, false);
|
2010-09-07 10:58:19 -04:00
|
|
|
|
2010-08-30 09:47:36 -04:00
|
|
|
wl_closure_invoke(closure, object,
|
|
|
|
|
object->implementation[opcode], client);
|
|
|
|
|
|
|
|
|
|
wl_closure_destroy(closure);
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
2011-04-22 12:06:34 -04:00
|
|
|
|
|
|
|
|
return 1;
|
2008-10-07 10:10:36 -04:00
|
|
|
}
|
|
|
|
|
|
2008-10-08 12:48:46 -04:00
|
|
|
static int
|
|
|
|
|
wl_client_connection_update(struct wl_connection *connection,
|
|
|
|
|
uint32_t mask, void *data)
|
2008-09-30 09:46:10 -04:00
|
|
|
{
|
|
|
|
|
struct wl_client *client = data;
|
2008-10-08 12:48:46 -04:00
|
|
|
uint32_t emask = 0;
|
2008-10-08 10:47:59 -04:00
|
|
|
|
2011-06-29 11:43:11 -04:00
|
|
|
client->mask = mask;
|
2008-10-08 12:48:46 -04:00
|
|
|
if (mask & WL_CONNECTION_READABLE)
|
|
|
|
|
emask |= WL_EVENT_READABLE;
|
|
|
|
|
if (mask & WL_CONNECTION_WRITABLE)
|
|
|
|
|
emask |= WL_EVENT_WRITEABLE;
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2010-12-11 21:08:53 -08:00
|
|
|
return wl_event_source_fd_update(client->source, emask);
|
2008-10-08 12:48:46 -04:00
|
|
|
}
|
2008-10-08 10:47:59 -04:00
|
|
|
|
2011-06-29 11:43:11 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_flush(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
if (client->mask & WL_CONNECTION_WRITABLE)
|
|
|
|
|
wl_connection_data(client->connection, WL_CONNECTION_WRITABLE);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 21:23:10 -04:00
|
|
|
WL_EXPORT struct wl_display *
|
|
|
|
|
wl_client_get_display(struct wl_client *client)
|
|
|
|
|
{
|
|
|
|
|
return client->display;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-21 22:45:33 -05:00
|
|
|
static void
|
|
|
|
|
wl_display_post_range(struct wl_display *display, struct wl_client *client)
|
|
|
|
|
{
|
2010-12-01 17:07:41 -05:00
|
|
|
wl_client_post_event(client, &client->display->object,
|
2008-12-24 19:30:25 -05:00
|
|
|
WL_DISPLAY_RANGE, display->client_id_range);
|
2008-12-21 22:45:33 -05:00
|
|
|
display->client_id_range += 256;
|
|
|
|
|
client->id_count += 256;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_global *global;
|
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);
|
2008-12-21 22:45:33 -05:00
|
|
|
client->connection =
|
|
|
|
|
wl_connection_create(fd, wl_client_connection_update, client);
|
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-06-14 10:35:46 +02:00
|
|
|
wl_list_insert(display->client_list.prev, &client->link);
|
|
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
wl_list_init(&client->resource_list);
|
2008-10-08 12:48:46 -04:00
|
|
|
|
2008-12-21 22:45:33 -05:00
|
|
|
wl_display_post_range(display, client);
|
2008-10-11 18:40:23 -04:00
|
|
|
|
2010-02-26 10:28:44 -05:00
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
2011-04-14 16:29:59 -04:00
|
|
|
wl_client_post_global(client, global->object);
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2008-10-08 12:48:46 -04:00
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_add_resource(struct wl_client *client,
|
|
|
|
|
struct wl_resource *resource)
|
|
|
|
|
{
|
|
|
|
|
struct wl_display *display = client->display;
|
|
|
|
|
|
|
|
|
|
if (client->id_count-- < 64)
|
|
|
|
|
wl_display_post_range(display, client);
|
|
|
|
|
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_list_init(&resource->destroy_listener_list);
|
|
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
wl_hash_table_insert(client->display->objects,
|
2010-12-01 17:07:41 -05:00
|
|
|
resource->object.id, resource);
|
2010-08-09 14:43:33 -04:00
|
|
|
wl_list_insert(client->resource_list.prev, &resource->link);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 20:55:16 -04:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_post_no_memory(struct wl_client *client)
|
|
|
|
|
{
|
2011-05-11 10:57:06 -04:00
|
|
|
wl_client_post_error(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
|
2010-09-02 20:55:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_client_post_global(struct wl_client *client, struct wl_object *object)
|
|
|
|
|
{
|
|
|
|
|
wl_client_post_event(client,
|
2010-12-01 17:07:41 -05:00
|
|
|
&client->display->object,
|
2010-09-02 20:55:16 -04:00
|
|
|
WL_DISPLAY_GLOBAL,
|
2011-07-18 02:00:25 -04:00
|
|
|
object->id,
|
2010-09-02 20:55:16 -04:00
|
|
|
object->interface->name,
|
|
|
|
|
object->interface->version);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
WL_EXPORT void
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_resource_destroy(struct wl_resource *resource,
|
|
|
|
|
struct wl_client *client, uint32_t time)
|
2008-12-15 20:35:24 -05:00
|
|
|
{
|
2010-08-09 14:43:33 -04:00
|
|
|
struct wl_display *display = client->display;
|
2011-05-06 17:09:51 +02:00
|
|
|
struct wl_listener *l, *next;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each_safe(l, next,
|
|
|
|
|
&resource->destroy_listener_list, link)
|
|
|
|
|
l->func(l, resource, time);
|
2008-12-15 20:35:24 -05:00
|
|
|
|
2010-08-09 14:43:33 -04:00
|
|
|
wl_list_remove(&resource->link);
|
2010-12-01 17:07:41 -05:00
|
|
|
if (resource->object.id > 0)
|
|
|
|
|
wl_hash_table_remove(display->objects, resource->object.id);
|
2010-08-09 14:43:33 -04:00
|
|
|
resource->destroy(resource, client);
|
2008-12-15 20:35:24 -05:00
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2010-08-09 14:43:33 -04:00
|
|
|
struct wl_resource *resource, *tmp;
|
2008-10-11 21:37:55 -04:00
|
|
|
|
2008-10-08 12:48:46 -04:00
|
|
|
printf("disconnect from client %p\n", client);
|
2008-10-11 21:37:55 -04:00
|
|
|
|
2010-09-03 14:46:38 -04:00
|
|
|
wl_list_for_each_safe(resource, tmp, &client->resource_list, link)
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_resource_destroy(resource, client, 0);
|
2008-10-11 21:37:55 -04:00
|
|
|
|
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
|
|
|
|
|
lose_pointer_focus(struct wl_listener *listener,
|
2011-05-06 17:09:51 +02:00
|
|
|
struct wl_resource *resource, uint32_t time)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
|
|
|
|
struct wl_input_device *device =
|
|
|
|
|
container_of(listener, struct wl_input_device,
|
|
|
|
|
pointer_focus_listener);
|
|
|
|
|
|
|
|
|
|
wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
lose_keyboard_focus(struct wl_listener *listener,
|
2011-05-06 17:09:51 +02:00
|
|
|
struct wl_resource *resource, uint32_t time)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
|
|
|
|
struct wl_input_device *device =
|
|
|
|
|
container_of(listener, struct wl_input_device,
|
|
|
|
|
keyboard_focus_listener);
|
|
|
|
|
|
|
|
|
|
wl_input_device_set_keyboard_focus(device, NULL, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
2010-12-08 09:48:52 -05:00
|
|
|
wl_input_device_init(struct wl_input_device *device,
|
|
|
|
|
struct wl_compositor *compositor)
|
2010-12-06 21:35:19 -05:00
|
|
|
{
|
|
|
|
|
wl_list_init(&device->pointer_focus_listener.link);
|
|
|
|
|
device->pointer_focus_listener.func = lose_pointer_focus;
|
|
|
|
|
wl_list_init(&device->keyboard_focus_listener.link);
|
|
|
|
|
device->keyboard_focus_listener.func = lose_keyboard_focus;
|
2010-12-08 09:48:52 -05:00
|
|
|
|
|
|
|
|
device->x = 100;
|
|
|
|
|
device->y = 100;
|
|
|
|
|
device->compositor = compositor;
|
2010-12-06 21:35:19 -05:00
|
|
|
}
|
|
|
|
|
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_input_device_set_pointer_focus(struct wl_input_device *device,
|
|
|
|
|
struct wl_surface *surface,
|
|
|
|
|
uint32_t time,
|
|
|
|
|
int32_t x, int32_t y,
|
|
|
|
|
int32_t sx, int32_t sy)
|
|
|
|
|
{
|
|
|
|
|
if (device->pointer_focus == surface)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (device->pointer_focus &&
|
|
|
|
|
(!surface || device->pointer_focus->client != surface->client))
|
|
|
|
|
wl_client_post_event(device->pointer_focus->client,
|
2010-12-01 17:07:41 -05:00
|
|
|
&device->object,
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
|
|
|
|
time, NULL, 0, 0, 0, 0);
|
2011-03-12 21:26:21 -05:00
|
|
|
if (device->pointer_focus)
|
|
|
|
|
wl_list_remove(&device->pointer_focus_listener.link);
|
|
|
|
|
|
|
|
|
|
if (surface) {
|
2010-12-01 10:17:47 -05:00
|
|
|
wl_client_post_event(surface->client,
|
2010-12-01 17:07:41 -05:00
|
|
|
&device->object,
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_INPUT_DEVICE_POINTER_FOCUS,
|
|
|
|
|
time, surface, x, y, sx, sy);
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
2011-03-12 21:26:21 -05:00
|
|
|
&device->pointer_focus_listener.link);
|
|
|
|
|
}
|
2010-12-01 10:17:47 -05:00
|
|
|
|
|
|
|
|
device->pointer_focus = surface;
|
|
|
|
|
device->pointer_focus_time = time;
|
2010-12-06 16:43:16 -05:00
|
|
|
|
2010-12-01 10:17:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_input_device_set_keyboard_focus(struct wl_input_device *device,
|
|
|
|
|
struct wl_surface *surface,
|
|
|
|
|
uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
if (device->keyboard_focus == surface)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (device->keyboard_focus &&
|
|
|
|
|
(!surface || device->keyboard_focus->client != surface->client))
|
|
|
|
|
wl_client_post_event(device->keyboard_focus->client,
|
2010-12-01 17:07:41 -05:00
|
|
|
&device->object,
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
|
|
|
|
time, NULL, &device->keys);
|
2011-03-12 21:26:21 -05:00
|
|
|
if (device->keyboard_focus)
|
|
|
|
|
wl_list_remove(&device->keyboard_focus_listener.link);
|
2010-12-01 10:17:47 -05:00
|
|
|
|
2011-03-12 21:26:21 -05:00
|
|
|
if (surface) {
|
2010-12-01 10:17:47 -05:00
|
|
|
wl_client_post_event(surface->client,
|
2010-12-01 17:07:41 -05:00
|
|
|
&device->object,
|
2010-12-01 10:17:47 -05:00
|
|
|
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
|
|
|
|
|
time, surface, &device->keys);
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
2011-03-12 21:26:21 -05:00
|
|
|
&device->keyboard_focus_listener.link);
|
|
|
|
|
}
|
2010-12-01 10:17:47 -05:00
|
|
|
|
|
|
|
|
device->keyboard_focus = surface;
|
|
|
|
|
device->keyboard_focus_time = time;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-05 17:34:54 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_input_device_end_grab(struct wl_input_device *device, uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
const struct wl_grab_interface *interface;
|
|
|
|
|
|
|
|
|
|
interface = device->grab->interface;
|
|
|
|
|
interface->end(device->grab, time);
|
|
|
|
|
device->grab->input_device = NULL;
|
|
|
|
|
device->grab = NULL;
|
|
|
|
|
|
|
|
|
|
wl_list_remove(&device->grab_listener.link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
lose_grab_surface(struct wl_listener *listener,
|
2011-05-06 17:09:51 +02:00
|
|
|
struct wl_resource *resource, uint32_t time)
|
2011-01-05 17:34:54 -05:00
|
|
|
{
|
|
|
|
|
struct wl_input_device *device =
|
|
|
|
|
container_of(listener,
|
|
|
|
|
struct wl_input_device, grab_listener);
|
|
|
|
|
|
|
|
|
|
wl_input_device_end_grab(device, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_input_device_start_grab(struct wl_input_device *device,
|
|
|
|
|
struct wl_grab *grab,
|
|
|
|
|
uint32_t button, uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
struct wl_surface *focus = device->pointer_focus;
|
|
|
|
|
|
|
|
|
|
device->grab = grab;
|
|
|
|
|
device->grab_button = button;
|
|
|
|
|
device->grab_time = time;
|
|
|
|
|
device->grab_x = device->x;
|
|
|
|
|
device->grab_y = device->y;
|
|
|
|
|
|
|
|
|
|
device->grab_listener.func = lose_grab_surface;
|
2011-05-06 17:09:51 +02:00
|
|
|
wl_list_insert(focus->resource.destroy_listener_list.prev,
|
2011-01-05 17:34:54 -05:00
|
|
|
&device->grab_listener.link);
|
|
|
|
|
|
|
|
|
|
grab->input_device = device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_input_device_update_grab(struct wl_input_device *device,
|
|
|
|
|
struct wl_grab *grab,
|
|
|
|
|
struct wl_surface *surface, uint32_t time)
|
|
|
|
|
{
|
|
|
|
|
if (device->grab != &device->motion_grab ||
|
|
|
|
|
device->grab_time != time ||
|
|
|
|
|
device->pointer_focus != surface)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
device->grab = grab;
|
|
|
|
|
grab->input_device = device;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 10:38:44 -04:00
|
|
|
static void
|
|
|
|
|
display_bind(struct wl_client *client,
|
|
|
|
|
struct wl_display *display, uint32_t id,
|
|
|
|
|
const char *interface, uint32_t version)
|
|
|
|
|
{
|
|
|
|
|
struct wl_global *global;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
2011-05-12 21:27:57 -04:00
|
|
|
if (global->object->id == id)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (&global->link == &display->global_list)
|
|
|
|
|
wl_client_post_error(client, &client->display->object,
|
|
|
|
|
WL_DISPLAY_ERROR_INVALID_OBJECT,
|
|
|
|
|
"invalid object %d", id);
|
|
|
|
|
else if (global->func)
|
|
|
|
|
global->func(client, global->object, version);
|
2011-04-14 10:38:44 -04:00
|
|
|
}
|
|
|
|
|
|
2010-09-03 14:46:38 -04:00
|
|
|
static void
|
|
|
|
|
display_sync(struct wl_client *client,
|
2011-07-29 19:51:22 -07:00
|
|
|
struct wl_display *display, uint32_t id)
|
2010-09-03 14:46:38 -04:00
|
|
|
{
|
2011-07-29 19:51:22 -07:00
|
|
|
struct wl_object object;
|
2010-09-03 14:46:38 -04:00
|
|
|
|
2011-07-29 19:51:22 -07:00
|
|
|
object.interface = &wl_callback_interface;
|
|
|
|
|
object.id = id;
|
2010-09-03 14:46:38 -04:00
|
|
|
|
2011-07-29 19:51:22 -07:00
|
|
|
wl_client_post_event(client, &object, WL_CALLBACK_DONE, 0);
|
2010-09-03 14:46:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wl_display_interface display_interface = {
|
2011-04-14 10:38:44 -04:00
|
|
|
display_bind,
|
2010-09-03 14:46:38 -04:00
|
|
|
display_sync,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-26 11:42:59 -05:00
|
|
|
display->objects = wl_hash_table_create();
|
2008-12-12 11:05:17 -05:00
|
|
|
if (display->objects == NULL) {
|
2011-03-11 14:19:00 +02:00
|
|
|
wl_event_loop_destroy(display->loop);
|
2008-12-12 11:05:17 -05:00
|
|
|
free(display);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-29 19:51:22 -07:00
|
|
|
wl_list_init(&display->callback_list);
|
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);
|
2008-11-02 10:12:29 -05:00
|
|
|
|
2008-10-11 18:40:23 -04:00
|
|
|
display->client_id_range = 256; /* Gah, arbitrary... */
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2008-11-23 23:41:08 -05:00
|
|
|
display->id = 1;
|
2010-12-01 17:07:41 -05:00
|
|
|
display->object.interface = &wl_display_interface;
|
|
|
|
|
display->object.implementation = (void (**)(void)) &display_interface;
|
|
|
|
|
wl_display_add_object(display, &display->object);
|
|
|
|
|
if (wl_display_add_global(display, &display->object, NULL)) {
|
2011-03-11 14:19:00 +02:00
|
|
|
wl_hash_table_destroy(display->objects);
|
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
|
|
|
|
2011-06-14 11:41:54 +02:00
|
|
|
wl_event_loop_destroy(display->loop);
|
|
|
|
|
wl_hash_table_destroy(display->objects);
|
2010-12-01 15:36:20 -05:00
|
|
|
wl_list_for_each_safe(s, next, &display->socket_list, link) {
|
|
|
|
|
close(s->fd);
|
|
|
|
|
unlink(s->addr.sun_path);
|
2011-04-13 09:38:29 +02:00
|
|
|
close(s->fd_lock);
|
|
|
|
|
unlink(s->lock_addr);
|
2010-12-01 15:36:20 -05:00
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-23 23:41:08 -05:00
|
|
|
WL_EXPORT void
|
|
|
|
|
wl_display_add_object(struct wl_display *display, struct wl_object *object)
|
|
|
|
|
{
|
|
|
|
|
object->id = display->id++;
|
2010-02-26 11:42:59 -05:00
|
|
|
wl_hash_table_insert(display->objects, object->id, object);
|
2008-11-23 23:41:08 -05:00
|
|
|
}
|
|
|
|
|
|
2008-11-23 19:10:23 -05:00
|
|
|
WL_EXPORT int
|
2008-12-21 23:37:12 -05:00
|
|
|
wl_display_add_global(struct wl_display *display,
|
2011-04-18 12:35:01 -04:00
|
|
|
struct wl_object *object, wl_global_bind_func_t func)
|
2008-11-23 19:10:23 -05:00
|
|
|
{
|
2008-12-21 23:37:12 -05:00
|
|
|
struct wl_global *global;
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
global = malloc(sizeof *global);
|
|
|
|
|
if (global == NULL)
|
2008-11-23 19:10:23 -05:00
|
|
|
return -1;
|
|
|
|
|
|
2008-12-21 23:37:12 -05:00
|
|
|
global->object = object;
|
|
|
|
|
global->func = func;
|
|
|
|
|
wl_list_insert(display->global_list.prev, &global->link);
|
2008-11-23 19:10:23 -05:00
|
|
|
|
2011-04-18 12:35:01 -04:00
|
|
|
return 0;
|
2008-11-23 19:10:23 -05:00
|
|
|
}
|
|
|
|
|
|
2011-06-14 10:35:46 +02:00
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_display_remove_global(struct wl_display *display,
|
|
|
|
|
struct wl_object *object)
|
|
|
|
|
{
|
|
|
|
|
struct wl_global *global;
|
|
|
|
|
struct wl_client *client;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
|
|
|
|
if (global->object == object)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (&global->link == &display->global_list)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
wl_list_for_each(client, &display->client_list, link)
|
|
|
|
|
wl_client_post_event(client,
|
|
|
|
|
&client->display->object,
|
|
|
|
|
WL_DISPLAY_GLOBAL_REMOVE,
|
|
|
|
|
global->object->id);
|
|
|
|
|
wl_list_remove(&global->link);
|
|
|
|
|
free(global);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
while (display->run)
|
2010-11-19 10:47:28 -05:00
|
|
|
wl_event_loop_dispatch(display->loop, -1);
|
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;
|
2011-04-11 09:24:11 -04:00
|
|
|
client_fd =
|
|
|
|
|
accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
|
2011-05-30 17:23:40 +02:00
|
|
|
if (client_fd < 0 && errno == ENOSYS) {
|
|
|
|
|
client_fd = accept(fd, (struct sockaddr *) &name, &length);
|
|
|
|
|
if (client_fd >= 0 && fcntl(client_fd, F_SETFD, FD_CLOEXEC) == -1)
|
|
|
|
|
fprintf(stderr, "failed to set FD_CLOEXEC flag on client fd, errno: %d\n", errno);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-30 09:46:10 -04:00
|
|
|
if (client_fd < 0)
|
2011-05-30 17:23:40 +02:00
|
|
|
fprintf(stderr, "failed to accept, errno: %d\n", errno);
|
2008-09-30 09:46:10 -04:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
get_socket_lock(struct wl_socket *socket, socklen_t name_size)
|
|
|
|
|
{
|
|
|
|
|
struct stat socket_stat;
|
|
|
|
|
int lock_size = name_size + 5;
|
|
|
|
|
|
|
|
|
|
snprintf(socket->lock_addr, lock_size,
|
|
|
|
|
"%s.lock", socket->addr.sun_path);
|
|
|
|
|
|
|
|
|
|
socket->fd_lock = open(socket->lock_addr, O_CREAT | O_CLOEXEC,
|
|
|
|
|
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
|
|
|
|
|
|
|
|
|
|
if (socket->fd_lock < 0) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"unable to open lockfile %s check permissions\n",
|
|
|
|
|
socket->lock_addr);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flock(socket->fd_lock, LOCK_EX | LOCK_NB) < 0) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"unable to lock lockfile %s, maybe another compositor is running\n",
|
|
|
|
|
socket->lock_addr);
|
|
|
|
|
close(socket->fd_lock);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stat(socket->addr.sun_path, &socket_stat) < 0 ) {
|
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
|
fprintf(stderr, "did not manage to stat file %s\n",
|
|
|
|
|
socket->addr.sun_path);
|
|
|
|
|
close(socket->fd_lock);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
} else if (socket_stat.st_mode & S_IWUSR ||
|
|
|
|
|
socket_stat.st_mode & S_IWGRP) {
|
|
|
|
|
unlink(socket->addr.sun_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
socklen_t size, name_size;
|
|
|
|
|
const char *runtime_dir;
|
2008-09-30 09:46:10 -04:00
|
|
|
|
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;
|
|
|
|
|
|
2011-04-11 09:24:11 -04:00
|
|
|
s->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 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
|
|
|
|
|
|
|
|
runtime_dir = getenv("XDG_RUNTIME_DIR");
|
|
|
|
|
if (runtime_dir == NULL) {
|
|
|
|
|
runtime_dir = ".";
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"XDG_RUNTIME_DIR not set, falling back to %s\n",
|
|
|
|
|
runtime_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
fprintf(stderr, "using socket %s\n", s->addr.sun_path);
|
2008-09-30 09:46:10 -04:00
|
|
|
|
2011-04-13 09:38:29 +02:00
|
|
|
if (get_socket_lock(s,name_size) < 0) {
|
|
|
|
|
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) {
|
|
|
|
|
close(s->fd);
|
|
|
|
|
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) {
|
|
|
|
|
close(s->fd);
|
|
|
|
|
unlink(s->addr.sun_path);
|
|
|
|
|
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 (wl_event_loop_add_fd(display->loop, s->fd,
|
|
|
|
|
WL_EVENT_READABLE,
|
|
|
|
|
socket_data, display) == NULL) {
|
|
|
|
|
close(s->fd);
|
|
|
|
|
unlink(s->addr.sun_path);
|
|
|
|
|
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-05-12 21:29:22 -04:00
|
|
|
static void
|
|
|
|
|
compositor_bind(struct wl_client *client,
|
|
|
|
|
struct wl_object *global, uint32_t version)
|
|
|
|
|
{
|
|
|
|
|
struct wl_compositor *compositor =
|
|
|
|
|
container_of(global, struct wl_compositor, object);
|
|
|
|
|
|
|
|
|
|
wl_client_post_event(client, global,
|
|
|
|
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
|
|
|
|
&compositor->argb_visual.object,
|
|
|
|
|
WL_COMPOSITOR_VISUAL_ARGB32);
|
|
|
|
|
|
|
|
|
|
wl_client_post_event(client, global,
|
|
|
|
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
|
|
|
|
&compositor->premultiplied_argb_visual.object,
|
|
|
|
|
WL_COMPOSITOR_VISUAL_PREMULTIPLIED_ARGB32);
|
|
|
|
|
|
|
|
|
|
wl_client_post_event(client, global,
|
|
|
|
|
WL_COMPOSITOR_TOKEN_VISUAL,
|
|
|
|
|
&compositor->rgb_visual.object,
|
|
|
|
|
WL_COMPOSITOR_VISUAL_XRGB32);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 15:12:58 -05:00
|
|
|
WL_EXPORT int
|
|
|
|
|
wl_compositor_init(struct wl_compositor *compositor,
|
|
|
|
|
const struct wl_compositor_interface *interface,
|
|
|
|
|
struct wl_display *display)
|
|
|
|
|
{
|
|
|
|
|
compositor->object.interface = &wl_compositor_interface;
|
|
|
|
|
compositor->object.implementation = (void (**)(void)) interface;
|
|
|
|
|
wl_display_add_object(display, &compositor->object);
|
2011-05-12 21:29:22 -04:00
|
|
|
if (wl_display_add_global(display,
|
|
|
|
|
&compositor->object, compositor_bind))
|
2010-12-08 15:12:58 -05:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
compositor->argb_visual.object.interface = &wl_visual_interface;
|
|
|
|
|
compositor->argb_visual.object.implementation = NULL;
|
|
|
|
|
wl_display_add_object(display, &compositor->argb_visual.object);
|
2011-05-12 21:29:22 -04:00
|
|
|
if (wl_display_add_global(display,
|
|
|
|
|
&compositor->argb_visual.object, NULL))
|
2011-03-11 16:59:53 +02:00
|
|
|
return -1;
|
2010-12-08 15:12:58 -05:00
|
|
|
|
|
|
|
|
compositor->premultiplied_argb_visual.object.interface =
|
|
|
|
|
&wl_visual_interface;
|
|
|
|
|
compositor->premultiplied_argb_visual.object.implementation = NULL;
|
|
|
|
|
wl_display_add_object(display,
|
|
|
|
|
&compositor->premultiplied_argb_visual.object);
|
2011-05-12 21:29:22 -04:00
|
|
|
if (wl_display_add_global(display,
|
|
|
|
|
&compositor->premultiplied_argb_visual.object,
|
|
|
|
|
NULL))
|
|
|
|
|
return -1;
|
2010-12-08 15:12:58 -05:00
|
|
|
|
|
|
|
|
compositor->rgb_visual.object.interface = &wl_visual_interface;
|
|
|
|
|
compositor->rgb_visual.object.implementation = NULL;
|
2011-05-12 21:29:22 -04:00
|
|
|
wl_display_add_object(display, &compositor->rgb_visual.object);
|
|
|
|
|
if (wl_display_add_global(display,
|
|
|
|
|
&compositor->rgb_visual.object, NULL))
|
|
|
|
|
return -1;
|
2010-12-08 15:12:58 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|