2012-01-07 17:21:32 -05:00
|
|
|
/*
|
|
|
|
* Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012,2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2014-10-07 23:05:57 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "meta-wayland.h"
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <clutter/wayland/clutter-wayland-compositor.h>
|
|
|
|
#include <clutter/wayland/clutter-wayland-surface.h>
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <wayland-server.h>
|
|
|
|
|
|
|
|
#include "meta-wayland-private.h"
|
|
|
|
#include "meta-xwayland-private.h"
|
2014-10-07 23:12:36 -04:00
|
|
|
#include "meta-wayland-region.h"
|
2013-05-03 13:51:22 -04:00
|
|
|
#include "meta-wayland-seat.h"
|
2014-04-22 18:03:40 -04:00
|
|
|
#include "meta-wayland-outputs.h"
|
2013-05-03 13:51:22 -04:00
|
|
|
#include "meta-wayland-data-device.h"
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
static MetaWaylandCompositor _meta_wayland_compositor;
|
|
|
|
|
|
|
|
MetaWaylandCompositor *
|
|
|
|
meta_wayland_compositor_get_default (void)
|
|
|
|
{
|
|
|
|
return &_meta_wayland_compositor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint32
|
|
|
|
get_time (void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
|
|
|
}
|
|
|
|
|
2014-10-07 23:50:57 -04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
struct wl_display *display;
|
|
|
|
} WaylandEventSource;
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
static gboolean
|
|
|
|
wayland_event_source_prepare (GSource *base, int *timeout)
|
|
|
|
{
|
|
|
|
WaylandEventSource *source = (WaylandEventSource *)base;
|
|
|
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
|
|
|
wl_display_flush_clients (source->display);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
wayland_event_source_dispatch (GSource *base,
|
|
|
|
GSourceFunc callback,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
WaylandEventSource *source = (WaylandEventSource *)base;
|
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop (source->display);
|
|
|
|
|
|
|
|
wl_event_loop_dispatch (loop, 0);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSourceFuncs wayland_event_source_funcs =
|
|
|
|
{
|
|
|
|
wayland_event_source_prepare,
|
2014-12-15 17:42:33 -05:00
|
|
|
NULL,
|
2012-01-07 17:21:32 -05:00
|
|
|
wayland_event_source_dispatch,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GSource *
|
|
|
|
wayland_event_source_new (struct wl_display *display)
|
|
|
|
{
|
|
|
|
WaylandEventSource *source;
|
|
|
|
struct wl_event_loop *loop = wl_display_get_event_loop (display);
|
|
|
|
|
|
|
|
source = (WaylandEventSource *) g_source_new (&wayland_event_source_funcs,
|
|
|
|
sizeof (WaylandEventSource));
|
|
|
|
source->display = display;
|
2014-12-15 17:42:33 -05:00
|
|
|
g_source_add_unix_fd (&source->source,
|
|
|
|
wl_event_loop_get_fd (loop),
|
|
|
|
G_IO_IN | G_IO_ERR);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
return &source->source;
|
|
|
|
}
|
|
|
|
|
2013-05-03 13:51:22 -04:00
|
|
|
void
|
|
|
|
meta_wayland_compositor_set_input_focus (MetaWaylandCompositor *compositor,
|
|
|
|
MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = window ? window->surface : NULL;
|
|
|
|
|
2014-07-10 10:13:54 -04:00
|
|
|
meta_wayland_seat_set_input_focus (compositor->seat, surface);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_compositor_repick (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
2014-04-17 18:46:14 -04:00
|
|
|
meta_wayland_seat_repick (compositor->seat);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:08:31 -04:00
|
|
|
static void
|
|
|
|
wl_compositor_create_surface (struct wl_client *client,
|
|
|
|
struct wl_resource *resource,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = wl_resource_get_user_data (resource);
|
|
|
|
meta_wayland_surface_create (compositor, client, resource, id);
|
|
|
|
}
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
static void
|
2014-08-04 10:26:55 -04:00
|
|
|
wl_compositor_create_region (struct wl_client *client,
|
2014-10-07 23:12:36 -04:00
|
|
|
struct wl_resource *resource,
|
2014-08-04 10:26:55 -04:00
|
|
|
uint32_t id)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-10-07 23:12:36 -04:00
|
|
|
MetaWaylandCompositor *compositor = wl_resource_get_user_data (resource);
|
|
|
|
meta_wayland_region_create (compositor, client, resource, id);
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:08:31 -04:00
|
|
|
const static struct wl_compositor_interface meta_wayland_wl_compositor_interface = {
|
2014-08-04 10:26:55 -04:00
|
|
|
wl_compositor_create_surface,
|
|
|
|
wl_compositor_create_region
|
2012-01-07 17:21:32 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
compositor_bind (struct wl_client *client,
|
|
|
|
void *data,
|
|
|
|
guint32 version,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = data;
|
|
|
|
struct wl_resource *resource;
|
|
|
|
|
2014-08-04 10:24:59 -04:00
|
|
|
resource = wl_resource_create (client, &wl_compositor_interface, version, id);
|
2014-10-07 23:08:31 -04:00
|
|
|
wl_resource_set_implementation (resource, &meta_wayland_wl_compositor_interface, compositor, NULL);
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
2014-03-18 13:00:48 -04:00
|
|
|
/**
|
|
|
|
* meta_wayland_compositor_update:
|
|
|
|
* @compositor: the #MetaWaylandCompositor instance
|
|
|
|
* @event: the #ClutterEvent used to update @seat's state
|
|
|
|
*
|
|
|
|
* This is used to update display server state like updating cursor
|
|
|
|
* position and keeping track of buttons and keys pressed. It must be
|
|
|
|
* called for all input events coming from the underlying devices.
|
|
|
|
*/
|
2013-11-13 15:41:29 -05:00
|
|
|
void
|
|
|
|
meta_wayland_compositor_update (MetaWaylandCompositor *compositor,
|
|
|
|
const ClutterEvent *event)
|
2013-08-23 09:07:57 -04:00
|
|
|
{
|
2014-03-18 13:00:48 -04:00
|
|
|
meta_wayland_seat_update (compositor->seat, event);
|
2013-08-23 09:07:57 -04:00
|
|
|
}
|
|
|
|
|
2014-10-07 23:08:31 -04:00
|
|
|
void
|
|
|
|
meta_wayland_compositor_paint_finished (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
while (!wl_list_empty (&compositor->frame_callbacks))
|
|
|
|
{
|
|
|
|
MetaWaylandFrameCallback *callback =
|
|
|
|
wl_container_of (compositor->frame_callbacks.next, callback, link);
|
|
|
|
|
|
|
|
wl_callback_send_done (callback->resource, get_time ());
|
|
|
|
wl_resource_destroy (callback->resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 13:00:48 -04:00
|
|
|
/**
|
|
|
|
* meta_wayland_compositor_handle_event:
|
|
|
|
* @compositor: the #MetaWaylandCompositor instance
|
|
|
|
* @event: the #ClutterEvent to be sent
|
|
|
|
*
|
|
|
|
* This method sends events to the focused wayland client, if any.
|
|
|
|
*
|
|
|
|
* Return value: whether @event was sent to a wayland client.
|
|
|
|
*/
|
2013-10-04 02:29:43 -04:00
|
|
|
gboolean
|
|
|
|
meta_wayland_compositor_handle_event (MetaWaylandCompositor *compositor,
|
|
|
|
const ClutterEvent *event)
|
2013-05-03 13:51:22 -04:00
|
|
|
{
|
2013-10-04 02:33:10 -04:00
|
|
|
return meta_wayland_seat_handle_event (compositor->seat, event);
|
2013-05-03 13:51:22 -04:00
|
|
|
}
|
|
|
|
|
2015-08-21 16:25:53 -04:00
|
|
|
/* meta_wayland_compositor_update_key_state:
|
|
|
|
* @compositor: the #MetaWaylandCompositor
|
|
|
|
* @key_vector: bit vector of key states
|
|
|
|
* @key_vector_len: length of @key_vector
|
|
|
|
* @offset: the key for the first evdev keycode is found at this offset in @key_vector
|
|
|
|
*
|
|
|
|
* This function is used to resynchronize the key state that Mutter
|
|
|
|
* is tracking with the actual keyboard state. This is useful, for example,
|
|
|
|
* to handle changes in key state when a nested compositor doesn't
|
|
|
|
* have focus. We need to fix up the XKB modifier tracking and deliver
|
|
|
|
* any modifier changes to clients.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
meta_wayland_compositor_update_key_state (MetaWaylandCompositor *compositor,
|
|
|
|
char *key_vector,
|
|
|
|
int key_vector_len,
|
|
|
|
int offset)
|
|
|
|
{
|
|
|
|
meta_wayland_keyboard_update_key_state (&compositor->seat->keyboard,
|
|
|
|
key_vector, key_vector_len, offset);
|
|
|
|
}
|
|
|
|
|
2015-02-25 10:26:01 -05:00
|
|
|
void
|
|
|
|
meta_wayland_compositor_destroy_frame_callbacks (MetaWaylandCompositor *compositor,
|
|
|
|
MetaWaylandSurface *surface)
|
|
|
|
{
|
|
|
|
MetaWaylandFrameCallback *callback, *next;
|
|
|
|
|
|
|
|
wl_list_for_each_safe (callback, next, &compositor->frame_callbacks, link)
|
|
|
|
{
|
|
|
|
if (callback->surface == surface)
|
|
|
|
wl_resource_destroy (callback->resource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 12:03:26 -04:00
|
|
|
static void
|
|
|
|
set_gnome_env (const char *name,
|
|
|
|
const char *value)
|
|
|
|
{
|
|
|
|
GDBusConnection *session_bus;
|
2014-03-26 12:02:08 -04:00
|
|
|
GError *error = NULL;
|
2013-08-20 12:03:26 -04:00
|
|
|
|
|
|
|
setenv (name, value, TRUE);
|
|
|
|
|
|
|
|
session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
|
|
|
g_assert (session_bus);
|
|
|
|
|
|
|
|
g_dbus_connection_call_sync (session_bus,
|
|
|
|
"org.gnome.SessionManager",
|
|
|
|
"/org/gnome/SessionManager",
|
|
|
|
"org.gnome.SessionManager",
|
|
|
|
"Setenv",
|
|
|
|
g_variant_new ("(ss)", name, value),
|
|
|
|
NULL,
|
2014-05-15 14:16:20 -04:00
|
|
|
G_DBUS_CALL_FLAGS_NO_AUTO_START,
|
2013-08-20 12:03:26 -04:00
|
|
|
-1, NULL, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
2014-03-26 12:02:08 -04:00
|
|
|
if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.gnome.SessionManager.NotInInitialization") != 0)
|
|
|
|
meta_warning ("Failed to set environment variable %s for gnome-session: %s\n", name, error->message);
|
|
|
|
|
|
|
|
g_error_free (error);
|
2013-08-20 12:03:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 19:18:15 -04:00
|
|
|
static void meta_wayland_log_func (const char *, va_list) G_GNUC_PRINTF (1, 0);
|
|
|
|
|
2013-11-19 20:04:49 -05:00
|
|
|
static void
|
|
|
|
meta_wayland_log_func (const char *fmt,
|
|
|
|
va_list arg)
|
|
|
|
{
|
|
|
|
char *str = g_strdup_vprintf (fmt, arg);
|
|
|
|
g_warning ("WL: %s", str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2014-08-18 16:54:15 -04:00
|
|
|
static void
|
|
|
|
meta_wayland_compositor_init (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
memset (compositor, 0, sizeof (MetaWaylandCompositor));
|
|
|
|
wl_list_init (&compositor->frame_callbacks);
|
|
|
|
}
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
void
|
2014-08-18 16:54:15 -04:00
|
|
|
meta_wayland_pre_clutter_init (void)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = &_meta_wayland_compositor;
|
|
|
|
|
2014-08-18 16:54:15 -04:00
|
|
|
meta_wayland_compositor_init (compositor);
|
|
|
|
|
|
|
|
wl_log_set_handler_server (meta_wayland_log_func);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
compositor->wayland_display = wl_display_create ();
|
|
|
|
if (compositor->wayland_display == NULL)
|
2014-08-18 16:54:15 -04:00
|
|
|
g_error ("Failed to create the global wl_display");
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-08-18 16:54:15 -04:00
|
|
|
clutter_wayland_set_compositor_display (compositor->wayland_display);
|
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-08-18 16:54:15 -04:00
|
|
|
void
|
|
|
|
meta_wayland_init (void)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
|
|
|
GSource *wayland_event_source;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-07-10 11:05:59 -04:00
|
|
|
wayland_event_source = wayland_event_source_new (compositor->wayland_display);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
/* XXX: Here we are setting the wayland event source to have a
|
|
|
|
* slightly lower priority than the X event source, because we are
|
|
|
|
* much more likely to get confused being told about surface changes
|
|
|
|
* relating to X clients when we don't know what's happened to them
|
|
|
|
* according to the X protocol.
|
2014-10-07 23:51:28 -04:00
|
|
|
*/
|
2014-07-10 11:05:59 -04:00
|
|
|
g_source_set_priority (wayland_event_source, GDK_PRIORITY_EVENTS + 1);
|
|
|
|
g_source_attach (wayland_event_source, NULL);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-10-07 23:54:28 -04:00
|
|
|
if (!wl_global_create (compositor->wayland_display,
|
|
|
|
&wl_compositor_interface,
|
|
|
|
META_WL_COMPOSITOR_VERSION,
|
|
|
|
compositor, compositor_bind))
|
|
|
|
g_error ("Failed to register the global wl_compositor");
|
|
|
|
|
2014-08-19 18:27:21 -04:00
|
|
|
wl_display_init_shm (compositor->wayland_display);
|
|
|
|
|
2014-04-22 18:05:44 -04:00
|
|
|
meta_wayland_outputs_init (compositor);
|
|
|
|
meta_wayland_data_device_manager_init (compositor);
|
|
|
|
meta_wayland_shell_init (compositor);
|
2015-07-22 10:50:20 -04:00
|
|
|
meta_wayland_pointer_gestures_init (compositor);
|
2014-04-22 18:05:44 -04:00
|
|
|
meta_wayland_seat_init (compositor);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-08-05 16:10:17 -04:00
|
|
|
compositor->display_name = wl_display_add_socket_auto (compositor->wayland_display);
|
|
|
|
if (compositor->display_name == NULL)
|
2012-01-07 17:21:32 -05:00
|
|
|
g_error ("Failed to create socket");
|
|
|
|
|
2014-02-07 19:26:35 -05:00
|
|
|
if (!meta_xwayland_start (&compositor->xwayland_manager, compositor->wayland_display))
|
2012-01-07 17:21:32 -05:00
|
|
|
g_error ("Failed to start X Wayland");
|
|
|
|
|
2014-09-11 10:07:34 -04:00
|
|
|
set_gnome_env ("DISPLAY", meta_wayland_get_xwayland_display_name (compositor));
|
|
|
|
set_gnome_env ("WAYLAND_DISPLAY", meta_wayland_get_wayland_display_name (compositor));
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
meta_wayland_get_wayland_display_name (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
return compositor->display_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
meta_wayland_get_xwayland_display_name (MetaWaylandCompositor *compositor)
|
|
|
|
{
|
|
|
|
return compositor->xwayland_manager.display_name;
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_wayland_finalize (void)
|
|
|
|
{
|
2013-08-19 08:57:16 -04:00
|
|
|
MetaWaylandCompositor *compositor;
|
|
|
|
|
|
|
|
compositor = meta_wayland_compositor_get_default ();
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
meta_xwayland_stop (&compositor->xwayland_manager);
|
2014-03-11 17:04:22 -04:00
|
|
|
}
|