Updating src/3rdparty/wayland to head of Wayland master

In git://anongit.freedesktop.org/wayland/wayland its sha
f04e05ad76cd6af890b7b741a9e0f5181bd0ac10
This commit is contained in:
Jørgen Lind 2011-04-14 10:04:50 +02:00
parent 7b34bad810
commit 6981020be6
9 changed files with 200 additions and 69 deletions

View File

@ -160,6 +160,8 @@ wl_connection_create(int fd,
struct wl_connection *connection;
connection = malloc(sizeof *connection);
if (connection == NULL)
return NULL;
memset(connection, 0, sizeof *connection);
connection->fd = fd;
connection->update = update;

View File

@ -171,13 +171,10 @@ wl_event_source_timer_remove(struct wl_event_source *source)
{
struct wl_event_source_timer *timer_source =
(struct wl_event_source_timer *) source;
struct wl_event_loop *loop = source->loop;
int fd;
fd = timer_source->fd;
close(timer_source->fd);
free(source);
return epoll_ctl(loop->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
return 0;
}
struct wl_event_source_interface timer_source_interface = {
@ -200,7 +197,7 @@ wl_event_loop_add_timer(struct wl_event_loop *loop,
source->base.interface = &timer_source_interface;
source->base.loop = loop;
source->fd = timerfd_create(CLOCK_MONOTONIC, 0);
source->fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
if (source->fd < 0) {
fprintf(stderr, "could not create timerfd\n: %m");
free(source);
@ -215,6 +212,7 @@ wl_event_loop_add_timer(struct wl_event_loop *loop,
ep.data.ptr = source;
if (epoll_ctl(loop->epoll_fd, EPOLL_CTL_ADD, source->fd, &ep) < 0) {
close(source->fd);
free(source);
return NULL;
}
@ -231,8 +229,8 @@ wl_event_source_timer_update(struct wl_event_source *source, int ms_delay)
its.it_interval.tv_sec = 0;
its.it_interval.tv_nsec = 0;
its.it_value.tv_sec = 0;
its.it_value.tv_nsec = ms_delay * 1000 * 1000;
its.it_value.tv_sec = ms_delay / 1000;
its.it_value.tv_nsec = (ms_delay % 1000) * 1000 * 1000;
if (timerfd_settime(timer_source->fd, 0, &its, NULL) < 0) {
fprintf(stderr, "could not set timerfd\n: %m");
return -1;
@ -267,13 +265,10 @@ wl_event_source_signal_remove(struct wl_event_source *source)
{
struct wl_event_source_signal *signal_source =
(struct wl_event_source_signal *) source;
struct wl_event_loop *loop = source->loop;
int fd;
fd = signal_source->fd;
close(signal_source->fd);
free(source);
return epoll_ctl(loop->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
return 0;
}
struct wl_event_source_interface signal_source_interface = {
@ -297,10 +292,11 @@ wl_event_loop_add_signal(struct wl_event_loop *loop,
source->base.interface = &signal_source_interface;
source->base.loop = loop;
source->signal_number = signal_number;
sigemptyset(&mask);
sigaddset(&mask, signal_number);
source->fd = signalfd(-1, &mask, 0);
source->fd = signalfd(-1, &mask, SFD_CLOEXEC);
if (source->fd < 0) {
fprintf(stderr, "could not create fd to watch signal\n: %m");
free(source);
@ -316,6 +312,7 @@ wl_event_loop_add_signal(struct wl_event_loop *loop,
ep.data.ptr = source;
if (epoll_ctl(loop->epoll_fd, EPOLL_CTL_ADD, source->fd, &ep) < 0) {
close(source->fd);
free(source);
return NULL;
}
@ -392,7 +389,7 @@ wl_event_loop_create(void)
if (loop == NULL)
return NULL;
loop->epoll_fd = epoll_create(16);
loop->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (loop->epoll_fd < 0) {
free(loop);
return NULL;

View File

@ -140,10 +140,10 @@ wl_display_sync(struct wl_display *display, uint32_t key)
}
static inline void
wl_display_frame(struct wl_display *display, uint32_t key)
wl_display_frame(struct wl_display *display, struct wl_surface *surface, uint32_t key)
{
wl_proxy_marshal((struct wl_proxy *) display,
WL_DISPLAY_FRAME, key);
WL_DISPLAY_FRAME, surface, key);
}
#define WL_COMPOSITOR_CREATE_SURFACE 0

View File

@ -31,6 +31,7 @@
#include <sys/un.h>
#include <ctype.h>
#include <assert.h>
#include <fcntl.h>
#include <sys/poll.h>
#include "wayland-client-protocol.h"
@ -61,6 +62,7 @@ struct wl_frame_handler {
wl_display_frame_func_t func;
uint32_t key;
void *data;
struct wl_surface *surface;
struct wl_list link;
};
@ -303,7 +305,8 @@ display_handle_key(void *data,
if (!wl_list_empty(&display->frame_list) &&
frame_handler->key == key) {
wl_list_remove(&frame_handler->link);
frame_handler->func(frame_handler->data, time);
frame_handler->func(frame_handler->surface,
frame_handler->data, time);
free(frame_handler);
return;
}
@ -320,30 +323,17 @@ static const struct wl_display_listener display_listener = {
display_handle_key
};
WL_EXPORT struct wl_display *
wl_display_connect(const char *name)
static int
connect_to_socket(struct wl_display *display, const char *name)
{
struct wl_display *display;
struct sockaddr_un addr;
socklen_t size;
const char *runtime_dir;
const char *debug;
size_t name_size;
debug = getenv("WAYLAND_DEBUG");
if (debug)
wl_debug = 1;
display = malloc(sizeof *display);
if (display == NULL)
return NULL;
memset(display, 0, sizeof *display);
display->fd = socket(PF_LOCAL, SOCK_STREAM, 0);
if (display->fd < 0) {
free(display);
return NULL;
}
display->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (display->fd < 0)
return -1;
runtime_dir = getenv("XDG_RUNTIME_DIR");
if (runtime_dir == NULL) {
@ -368,11 +358,50 @@ wl_display_connect(const char *name)
if (connect(display->fd, (struct sockaddr *) &addr, size) < 0) {
close(display->fd);
return -1;
}
return 0;
}
WL_EXPORT struct wl_display *
wl_display_connect(const char *name)
{
struct wl_display *display;
const char *debug;
char *connection, *end;
int flags;
debug = getenv("WAYLAND_DEBUG");
if (debug)
wl_debug = 1;
display = malloc(sizeof *display);
if (display == NULL)
return NULL;
memset(display, 0, sizeof *display);
connection = getenv("WAYLAND_SOCKET");
if (connection) {
display->fd = strtol(connection, &end, 0);
if (*end != '\0') {
free(display);
return NULL;
}
flags = fcntl(display->fd, F_GETFD);
if (flags != -1)
fcntl(display->fd, F_SETFD, flags | FD_CLOEXEC);
} else if (connect_to_socket(display, name) < 0) {
free(display);
return NULL;
}
display->objects = wl_hash_table_create();
if (display->objects == NULL) {
close(display->fd);
free(display);
return NULL;
}
wl_list_init(&display->global_listener_list);
display->proxy.object.interface = &wl_display_interface;
@ -389,7 +418,12 @@ wl_display_connect(const char *name)
display->connection = wl_connection_create(display->fd,
connection_update,
display);
if (display->connection == NULL) {
wl_hash_table_destroy(display->objects);
close(display->fd);
free(display);
return NULL;
}
return display;
}
@ -397,6 +431,7 @@ WL_EXPORT void
wl_display_destroy(struct wl_display *display)
{
wl_connection_destroy(display->connection);
wl_hash_table_destroy(display->objects);
close(display->fd);
free(display);
}
@ -435,6 +470,7 @@ wl_display_sync_callback(struct wl_display *display,
WL_EXPORT int
wl_display_frame_callback(struct wl_display *display,
struct wl_surface *surface,
wl_display_frame_func_t func, void *data)
{
struct wl_frame_handler *handler;
@ -446,9 +482,10 @@ wl_display_frame_callback(struct wl_display *display,
handler->func = func;
handler->key = display->key++;
handler->data = data;
handler->surface = surface;
wl_list_insert(display->frame_list.prev, &handler->link);
wl_display_frame(display, handler->key);
wl_display_frame(display, handler->surface, handler->key);
return 0;
}

View File

@ -35,7 +35,8 @@ extern "C" {
typedef int (*wl_display_update_func_t)(uint32_t mask, void *data);
typedef void (*wl_display_sync_func_t)(void *data);
typedef void (*wl_display_frame_func_t)(void *data, uint32_t time);
typedef void (*wl_display_frame_func_t)(struct wl_surface *surface,
void *data, uint32_t time);
struct wl_display *wl_display_connect(const char *name);
void wl_display_destroy(struct wl_display *display);
@ -46,6 +47,7 @@ void wl_display_iterate(struct wl_display *display, uint32_t mask);
int wl_display_sync_callback(struct wl_display *display,
wl_display_sync_func_t func, void *data);
int wl_display_frame_callback(struct wl_display *display,
struct wl_surface *surface,
wl_display_frame_func_t func, void *data);
struct wl_global_listener;

View File

@ -27,7 +27,7 @@
static const struct wl_message display_requests[] = {
{ "sync", "u" },
{ "frame", "u" },
{ "frame", "ou" },
};
static const struct wl_message display_events[] = {

View File

@ -68,6 +68,7 @@ struct wl_display_interface {
uint32_t key);
void (*frame)(struct wl_client *client,
struct wl_display *display,
struct wl_surface *surface,
uint32_t key);
};

View File

@ -20,6 +20,8 @@
* OF THIS SOFTWARE.
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
@ -33,6 +35,9 @@
#include <dlfcn.h>
#include <assert.h>
#include <sys/time.h>
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <ffi.h>
#include "wayland-server.h"
@ -41,7 +46,9 @@
struct wl_socket {
int fd;
int fd_lock;
struct sockaddr_un addr;
char lock_addr[113];
struct wl_list link;
};
@ -71,6 +78,7 @@ struct wl_frame_listener {
struct wl_resource resource;
struct wl_client *client;
uint32_t key;
struct wl_surface *surface;
struct wl_list link;
};
@ -209,7 +217,7 @@ wl_display_post_range(struct wl_display *display, struct wl_client *client)
client->id_count += 256;
}
static struct wl_client *
WL_EXPORT struct wl_client *
wl_client_create(struct wl_display *display, int fd)
{
struct wl_client *client;
@ -226,6 +234,10 @@ wl_client_create(struct wl_display *display, int fd)
wl_client_connection_data, client);
client->connection =
wl_connection_create(fd, wl_client_connection_update, client);
if (client->connection == NULL) {
free(client);
return NULL;
}
wl_list_init(&client->resource_list);
@ -356,19 +368,21 @@ wl_input_device_set_pointer_focus(struct wl_input_device *device,
&device->object,
WL_INPUT_DEVICE_POINTER_FOCUS,
time, NULL, 0, 0, 0, 0);
if (surface)
if (device->pointer_focus)
wl_list_remove(&device->pointer_focus_listener.link);
if (surface) {
wl_client_post_event(surface->client,
&device->object,
WL_INPUT_DEVICE_POINTER_FOCUS,
time, surface, x, y, sx, sy);
wl_list_insert(surface->destroy_listener_list.prev,
&device->pointer_focus_listener.link);
}
device->pointer_focus = surface;
device->pointer_focus_time = time;
wl_list_remove(&device->pointer_focus_listener.link);
if (surface)
wl_list_insert(surface->destroy_listener_list.prev,
&device->pointer_focus_listener.link);
}
WL_EXPORT void
@ -385,20 +399,20 @@ wl_input_device_set_keyboard_focus(struct wl_input_device *device,
&device->object,
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
time, NULL, &device->keys);
if (device->keyboard_focus)
wl_list_remove(&device->keyboard_focus_listener.link);
if (surface)
if (surface) {
wl_client_post_event(surface->client,
&device->object,
WL_INPUT_DEVICE_KEYBOARD_FOCUS,
time, surface, &device->keys);
wl_list_insert(surface->destroy_listener_list.prev,
&device->keyboard_focus_listener.link);
}
device->keyboard_focus = surface;
device->keyboard_focus_time = time;
wl_list_remove(&device->keyboard_focus_listener.link);
if (surface)
wl_list_insert(surface->destroy_listener_list.prev,
&device->keyboard_focus_listener.link);
}
WL_EXPORT void
@ -480,7 +494,9 @@ destroy_frame_listener(struct wl_resource *resource, struct wl_client *client)
static void
display_frame(struct wl_client *client,
struct wl_display *display, uint32_t key)
struct wl_display *display,
struct wl_surface *surface,
uint32_t key)
{
struct wl_frame_listener *listener;
@ -496,6 +512,7 @@ display_frame(struct wl_client *client,
listener->resource.object.id = 0;
listener->client = client;
listener->key = key;
listener->surface = surface;
wl_list_insert(client->resource_list.prev, &listener->resource.link);
wl_list_insert(display->frame_list.prev, &listener->link);
}
@ -528,6 +545,7 @@ wl_display_create(void)
display->objects = wl_hash_table_create();
if (display->objects == NULL) {
wl_event_loop_destroy(display->loop);
free(display);
return NULL;
}
@ -543,6 +561,7 @@ wl_display_create(void)
display->object.implementation = (void (**)(void)) &display_interface;
wl_display_add_object(display, &display->object);
if (wl_display_add_global(display, &display->object, NULL)) {
wl_hash_table_destroy(display->objects);
wl_event_loop_destroy(display->loop);
free(display);
return NULL;
@ -562,6 +581,8 @@ wl_display_destroy(struct wl_display *display)
wl_list_for_each_safe(s, next, &display->socket_list, link) {
close(s->fd);
unlink(s->addr.sun_path);
close(s->fd_lock);
unlink(s->lock_addr);
free(s);
}
@ -593,11 +614,14 @@ wl_display_add_global(struct wl_display *display,
}
WL_EXPORT void
wl_display_post_frame(struct wl_display *display, uint32_t time)
wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
uint32_t time)
{
struct wl_frame_listener *listener, *next;
wl_list_for_each_safe(listener, next, &display->frame_list, link) {
if (listener->surface != surface)
continue;
wl_client_post_event(listener->client, &display->object,
WL_DISPLAY_KEY, listener->key, time);
wl_resource_destroy(&listener->resource, listener->client);
@ -634,13 +658,56 @@ socket_data(int fd, uint32_t mask, void *data)
int client_fd;
length = sizeof name;
client_fd = accept (fd, (struct sockaddr *) &name, &length);
client_fd =
accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
if (client_fd < 0)
fprintf(stderr, "failed to accept\n");
wl_client_create(display, client_fd);
}
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;
}
WL_EXPORT int
wl_display_add_socket(struct wl_display *display, const char *name)
{
@ -652,9 +719,11 @@ wl_display_add_socket(struct wl_display *display, const char *name)
if (s == NULL)
return -1;
s->fd = socket(PF_LOCAL, SOCK_STREAM, 0);
if (s->fd < 0)
s->fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (s->fd < 0) {
free(s);
return -1;
}
runtime_dir = getenv("XDG_RUNTIME_DIR");
if (runtime_dir == NULL) {
@ -675,16 +744,34 @@ wl_display_add_socket(struct wl_display *display, const char *name)
"%s/%s", runtime_dir, name) + 1;
fprintf(stderr, "using socket %s\n", s->addr.sun_path);
if (get_socket_lock(s,name_size) < 0) {
close(s->fd);
free(s);
return -1;
}
size = offsetof (struct sockaddr_un, sun_path) + name_size;
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0)
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
close(s->fd);
free(s);
return -1;
}
if (listen(s->fd, 1) < 0)
if (listen(s->fd, 1) < 0) {
close(s->fd);
unlink(s->addr.sun_path);
free(s);
return -1;
}
wl_event_loop_add_fd(display->loop, s->fd,
WL_EVENT_READABLE,
socket_data, display);
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;
}
wl_list_insert(display->socket_list.prev, &s->link);
return 0;
@ -704,23 +791,26 @@ wl_compositor_init(struct wl_compositor *compositor,
compositor->argb_visual.object.interface = &wl_visual_interface;
compositor->argb_visual.object.implementation = NULL;
wl_display_add_object(display, &compositor->argb_visual.object);
wl_display_add_global(display, &compositor->argb_visual.object, NULL);
if (wl_display_add_global(display, &compositor->argb_visual.object, NULL))
return -1;
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);
wl_display_add_global(display,
&compositor->premultiplied_argb_visual.object,
NULL);
if (wl_display_add_global(display,
&compositor->premultiplied_argb_visual.object,
NULL))
return -1;
compositor->rgb_visual.object.interface = &wl_visual_interface;
compositor->rgb_visual.object.implementation = NULL;
wl_display_add_object(display,
&compositor->rgb_visual.object);
wl_display_add_global(display,
&compositor->rgb_visual.object, NULL);
if (wl_display_add_global(display,
&compositor->rgb_visual.object, NULL))
return -1;
return 0;
}

View File

@ -87,6 +87,7 @@ typedef void (*wl_client_connect_func_t)(struct wl_client *client, struct wl_obj
int wl_display_add_global(struct wl_display *display, struct wl_object *object, wl_client_connect_func_t func);
struct wl_client *wl_client_create(struct wl_display *display, int fd);
void wl_client_destroy(struct wl_client *client);
void wl_client_post_no_memory(struct wl_client *client);
void wl_client_post_global(struct wl_client *client, struct wl_object *object);
@ -214,7 +215,8 @@ wl_display_set_compositor(struct wl_display *display,
const struct wl_compositor_interface *implementation);
void
wl_display_post_frame(struct wl_display *display, uint32_t msecs);
wl_display_post_frame(struct wl_display *display, struct wl_surface *surface,
uint32_t msecs);
void
wl_client_add_resource(struct wl_client *client,