2014-04-01 20:35:26 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
/*
|
|
|
|
* X Wayland Support
|
|
|
|
*
|
|
|
|
* Copyright (C) 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-04-01 20:35:26 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
#include "meta-xwayland.h"
|
2014-04-01 20:35:26 -04:00
|
|
|
#include "meta-xwayland-private.h"
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-01 20:35:26 -04:00
|
|
|
#include <glib.h>
|
2014-04-02 10:25:56 -04:00
|
|
|
#include <glib-unix.h>
|
2012-01-07 17:21:32 -05:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
2013-08-12 04:06:13 -04:00
|
|
|
static void
|
2014-04-02 10:19:39 -04:00
|
|
|
associate_window_with_surface (MetaWindow *window,
|
|
|
|
MetaWaylandSurface *surface)
|
2013-08-12 04:06:13 -04:00
|
|
|
{
|
2014-04-02 10:19:39 -04:00
|
|
|
MetaDisplay *display = window->display;
|
2014-01-31 11:24:02 -05:00
|
|
|
|
2014-03-11 10:23:35 -04:00
|
|
|
/* If the window has an existing surface, like if we're
|
|
|
|
* undecorating or decorating the window, then we need
|
|
|
|
* to detach the window from its old surface.
|
|
|
|
*/
|
|
|
|
if (window->surface)
|
|
|
|
window->surface->window = NULL;
|
|
|
|
|
2014-04-02 10:37:08 -04:00
|
|
|
meta_wayland_surface_set_window (surface, window);
|
2014-01-31 11:24:02 -05:00
|
|
|
window->surface = surface;
|
2014-02-24 19:22:56 -05:00
|
|
|
|
|
|
|
meta_compositor_window_surface_changed (display->compositor, window);
|
2014-04-02 11:20:30 -04:00
|
|
|
|
2014-04-08 12:39:15 -04:00
|
|
|
/* Now that we have a surface check if it should have focus. */
|
|
|
|
meta_display_sync_wayland_input_focus (display);
|
2013-08-12 04:06:13 -04:00
|
|
|
}
|
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
static gboolean
|
|
|
|
associate_window_with_surface_id (MetaXWaylandManager *manager,
|
|
|
|
MetaWindow *window,
|
|
|
|
guint32 surface_id)
|
2014-04-02 10:19:39 -04:00
|
|
|
{
|
2014-03-20 13:12:43 -04:00
|
|
|
struct wl_resource *resource;
|
|
|
|
|
|
|
|
resource = wl_client_get_object (manager->client, surface_id);
|
|
|
|
if (resource)
|
|
|
|
{
|
|
|
|
MetaWaylandSurface *surface = wl_resource_get_user_data (resource);
|
|
|
|
associate_window_with_surface (window, surface);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
MetaXWaylandManager *manager;
|
2014-04-02 10:19:39 -04:00
|
|
|
MetaWindow *window;
|
2014-03-20 13:12:43 -04:00
|
|
|
guint32 surface_id;
|
2014-09-15 15:15:27 -04:00
|
|
|
guint later_id;
|
2014-03-20 13:12:43 -04:00
|
|
|
} AssociateWindowWithSurfaceOp;
|
2014-04-02 10:19:39 -04:00
|
|
|
|
2014-09-15 15:32:31 -04:00
|
|
|
static void associate_window_with_surface_window_unmanaged (MetaWindow *window,
|
|
|
|
AssociateWindowWithSurfaceOp *op);
|
2014-05-04 15:48:41 -04:00
|
|
|
static void
|
2014-09-15 15:32:31 -04:00
|
|
|
associate_window_with_surface_op_free (AssociateWindowWithSurfaceOp *op)
|
2014-05-04 15:48:41 -04:00
|
|
|
{
|
2014-09-15 15:32:31 -04:00
|
|
|
if (op->later_id != 0)
|
|
|
|
meta_later_remove (op->later_id);
|
|
|
|
g_signal_handlers_disconnect_by_func (op->window,
|
|
|
|
(gpointer) associate_window_with_surface_window_unmanaged,
|
|
|
|
op);
|
2014-05-04 15:48:41 -04:00
|
|
|
g_free (op);
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:32:31 -04:00
|
|
|
static void
|
|
|
|
associate_window_with_surface_window_unmanaged (MetaWindow *window,
|
|
|
|
AssociateWindowWithSurfaceOp *op)
|
|
|
|
{
|
|
|
|
associate_window_with_surface_op_free (op);
|
|
|
|
}
|
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
static gboolean
|
2014-09-15 15:15:27 -04:00
|
|
|
associate_window_with_surface_later (gpointer user_data)
|
2014-03-20 13:12:43 -04:00
|
|
|
{
|
|
|
|
AssociateWindowWithSurfaceOp *op = user_data;
|
2014-09-15 15:32:31 -04:00
|
|
|
|
|
|
|
op->later_id = 0;
|
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
if (!associate_window_with_surface_id (op->manager, op->window, op->surface_id))
|
|
|
|
{
|
|
|
|
/* Not here? Oh well... nothing we can do */
|
|
|
|
g_warning ("Unknown surface ID %d (from window %s)", op->surface_id, op->window->desc);
|
|
|
|
}
|
2014-09-15 15:32:31 -04:00
|
|
|
|
|
|
|
associate_window_with_surface_op_free (op);
|
2014-04-02 10:19:39 -04:00
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
return G_SOURCE_REMOVE;
|
2014-04-02 10:19:39 -04:00
|
|
|
}
|
|
|
|
|
2014-03-20 13:12:43 -04:00
|
|
|
void
|
|
|
|
meta_xwayland_handle_wl_surface_id (MetaWindow *window,
|
|
|
|
guint32 surface_id)
|
2013-08-12 04:06:13 -04:00
|
|
|
{
|
2014-03-20 13:12:43 -04:00
|
|
|
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
|
|
|
|
MetaXWaylandManager *manager = &compositor->xwayland_manager;
|
|
|
|
|
|
|
|
if (!associate_window_with_surface_id (manager, window, surface_id))
|
|
|
|
{
|
|
|
|
/* No surface ID yet... it should arrive after the next
|
2014-09-15 15:15:27 -04:00
|
|
|
* iteration through the loop, so queue a later and see
|
2014-03-20 13:12:43 -04:00
|
|
|
* what happens.
|
|
|
|
*/
|
|
|
|
AssociateWindowWithSurfaceOp *op = g_new0 (AssociateWindowWithSurfaceOp, 1);
|
|
|
|
op->manager = manager;
|
|
|
|
op->window = window;
|
|
|
|
op->surface_id = surface_id;
|
2014-09-15 15:15:27 -04:00
|
|
|
op->later_id = meta_later_add (META_LATER_BEFORE_REDRAW,
|
|
|
|
associate_window_with_surface_later,
|
|
|
|
op,
|
|
|
|
NULL);
|
2014-05-04 15:48:41 -04:00
|
|
|
|
2014-09-15 15:32:31 -04:00
|
|
|
g_signal_connect (op->window, "unmanaged",
|
|
|
|
G_CALLBACK (associate_window_with_surface_window_unmanaged), op);
|
2014-03-20 13:12:43 -04:00
|
|
|
}
|
2013-08-12 04:06:13 -04:00
|
|
|
}
|
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
static gboolean
|
|
|
|
try_display (int display,
|
|
|
|
char **filename_out,
|
|
|
|
int *fd_out)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-04-17 15:03:45 -04:00
|
|
|
gboolean ret = FALSE;
|
2012-01-07 17:21:32 -05:00
|
|
|
char *filename;
|
|
|
|
int fd;
|
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
filename = g_strdup_printf ("/tmp/.X%d-lock", display);
|
|
|
|
|
|
|
|
again:
|
|
|
|
fd = open (filename, O_WRONLY | O_CLOEXEC | O_CREAT | O_EXCL, 0444);
|
|
|
|
|
|
|
|
if (fd < 0 && errno == EEXIST)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-04-17 15:03:45 -04:00
|
|
|
char pid[11];
|
2012-01-07 17:21:32 -05:00
|
|
|
char *end;
|
|
|
|
pid_t other;
|
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
fd = open (filename, O_CLOEXEC, O_RDONLY);
|
|
|
|
if (fd < 0 || read (fd, pid, 11) != 11)
|
|
|
|
{
|
|
|
|
g_warning ("can't read lock file %s: %m", filename);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
close (fd);
|
|
|
|
fd = -1;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
other = strtol (pid, &end, 0);
|
|
|
|
if (end != pid + 10)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-04-17 15:03:45 -04:00
|
|
|
g_warning ("can't parse lock file %s", filename);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
if (kill (other, 0) < 0 && errno == ESRCH)
|
|
|
|
{
|
|
|
|
/* Process is dead. Try unlinking the lockfile and trying again. */
|
|
|
|
if (unlink (filename) < 0)
|
|
|
|
{
|
|
|
|
g_warning ("failed to unlink stale lock file %s: %m", filename);
|
|
|
|
goto out;
|
2014-01-29 10:23:58 -05:00
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
goto again;
|
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
else if (fd < 0)
|
|
|
|
{
|
|
|
|
g_warning ("failed to create lock file %s: %m", filename);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
ret = TRUE;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
out:
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
g_free (filename);
|
|
|
|
filename = NULL;
|
|
|
|
|
|
|
|
if (fd >= 0)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-04-17 15:03:45 -04:00
|
|
|
close (fd);
|
|
|
|
fd = -1;
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
2014-04-17 15:03:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*filename_out = filename;
|
|
|
|
*fd_out = fd;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
create_lockfile (int display, int *display_out)
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
char pid[11];
|
|
|
|
int size;
|
|
|
|
|
|
|
|
while (!try_display (display, &filename, &fd))
|
|
|
|
{
|
|
|
|
display++;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-17 15:03:45 -04:00
|
|
|
/* If display is above 50, then something's wrong. Just
|
|
|
|
* abort in this case. */
|
|
|
|
if (display > 50)
|
|
|
|
return NULL;
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Subtle detail: we use the pid of the wayland compositor, not the xserver
|
|
|
|
* in the lock file. */
|
|
|
|
size = snprintf (pid, 11, "%10d\n", getpid ());
|
|
|
|
if (size != 11 || write (fd, pid, 11) != 11)
|
|
|
|
{
|
|
|
|
unlink (filename);
|
|
|
|
close (fd);
|
|
|
|
g_warning ("failed to write pid to lock file %s", filename);
|
|
|
|
g_free (filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
|
|
|
|
*display_out = display;
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bind_to_abstract_socket (int display)
|
|
|
|
{
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
socklen_t size, name_size;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
addr.sun_family = AF_LOCAL;
|
|
|
|
name_size = snprintf (addr.sun_path, sizeof addr.sun_path,
|
|
|
|
"%c/tmp/.X11-unix/X%d", 0, display);
|
|
|
|
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
|
|
|
if (bind (fd, (struct sockaddr *) &addr, size) < 0)
|
|
|
|
{
|
2014-04-01 19:57:55 -04:00
|
|
|
g_warning ("failed to bind to @%s: %m", addr.sun_path + 1);
|
2012-01-07 17:21:32 -05:00
|
|
|
close (fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listen (fd, 1) < 0)
|
|
|
|
{
|
|
|
|
close (fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bind_to_unix_socket (int display)
|
|
|
|
{
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
socklen_t size, name_size;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = socket (PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
addr.sun_family = AF_LOCAL;
|
|
|
|
name_size = snprintf (addr.sun_path, sizeof addr.sun_path,
|
|
|
|
"/tmp/.X11-unix/X%d", display) + 1;
|
|
|
|
size = offsetof (struct sockaddr_un, sun_path) + name_size;
|
|
|
|
unlink (addr.sun_path);
|
|
|
|
if (bind (fd, (struct sockaddr *) &addr, size) < 0)
|
|
|
|
{
|
2014-04-01 19:57:55 -04:00
|
|
|
g_warning ("failed to bind to %s: %m\n", addr.sun_path);
|
2012-01-07 17:21:32 -05:00
|
|
|
close (fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-29 10:23:58 -05:00
|
|
|
if (listen (fd, 1) < 0)
|
|
|
|
{
|
2012-01-07 17:21:32 -05:00
|
|
|
unlink (addr.sun_path);
|
|
|
|
close (fd);
|
|
|
|
return -1;
|
2014-01-29 10:23:58 -05:00
|
|
|
}
|
2012-01-07 17:21:32 -05:00
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2013-08-12 03:46:07 -04:00
|
|
|
static void
|
2015-03-21 21:24:37 -04:00
|
|
|
xserver_died (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
2013-08-12 03:46:07 -04:00
|
|
|
{
|
2015-03-21 21:24:37 -04:00
|
|
|
GSubprocess *proc = G_SUBPROCESS (source);
|
|
|
|
|
|
|
|
if (!g_subprocess_get_successful (proc))
|
2013-08-12 03:46:07 -04:00
|
|
|
g_error ("X Wayland crashed; aborting");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For now we simply abort if we see the server exit.
|
|
|
|
*
|
|
|
|
* In the future X will only be loaded lazily for legacy X support
|
|
|
|
* but for now it's a hard requirement. */
|
|
|
|
g_error ("Spurious exit of X Wayland server");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:31:18 -04:00
|
|
|
static int
|
|
|
|
x_io_error (Display *display)
|
|
|
|
{
|
|
|
|
g_error ("Connection to xwayland lost");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-04-01 20:00:59 -04:00
|
|
|
static gboolean
|
|
|
|
choose_xdisplay (MetaXWaylandManager *manager)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
int display = 0;
|
|
|
|
char *lockfile = NULL;
|
|
|
|
|
2015-03-16 10:57:44 -04:00
|
|
|
/* Hack to keep the unused Xwayland instance on
|
|
|
|
* the login screen from taking the prime :0 display
|
|
|
|
* number.
|
|
|
|
*/
|
|
|
|
if (g_getenv ("RUNNING_UNDER_GDM") != NULL)
|
|
|
|
display = 1024;
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
do
|
|
|
|
{
|
|
|
|
lockfile = create_lockfile (display, &display);
|
|
|
|
if (!lockfile)
|
|
|
|
{
|
2014-01-29 10:23:58 -05:00
|
|
|
g_warning ("Failed to create an X lock file");
|
|
|
|
return FALSE;
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
manager->abstract_fd = bind_to_abstract_socket (display);
|
|
|
|
if (manager->abstract_fd < 0)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
unlink (lockfile);
|
|
|
|
|
|
|
|
if (errno == EADDRINUSE)
|
|
|
|
{
|
|
|
|
display++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
manager->unix_fd = bind_to_unix_socket (display);
|
|
|
|
if (manager->abstract_fd < 0)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
unlink (lockfile);
|
2014-02-03 19:37:23 -05:00
|
|
|
close (manager->abstract_fd);
|
2012-01-07 17:21:32 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
manager->display_index = display;
|
2014-04-01 19:38:05 -04:00
|
|
|
manager->display_name = g_strdup_printf (":%d", manager->display_index);
|
2014-02-03 19:37:23 -05:00
|
|
|
manager->lockfile = lockfile;
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2014-04-01 20:00:59 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-02 10:22:01 -04:00
|
|
|
static void
|
|
|
|
xserver_finished_init (MetaXWaylandManager *manager)
|
|
|
|
{
|
|
|
|
/* At this point xwayland is all setup to start accepting
|
|
|
|
* connections so we can quit the transient initialization mainloop
|
|
|
|
* and unblock meta_wayland_init() to continue initializing mutter.
|
|
|
|
* */
|
|
|
|
g_main_loop_quit (manager->init_loop);
|
|
|
|
g_clear_pointer (&manager->init_loop, g_main_loop_unref);
|
|
|
|
}
|
|
|
|
|
2014-04-02 10:25:56 -04:00
|
|
|
static gboolean
|
2014-04-17 16:05:08 -04:00
|
|
|
on_displayfd_ready (int fd,
|
|
|
|
GIOCondition condition,
|
|
|
|
gpointer user_data)
|
2014-04-02 10:25:56 -04:00
|
|
|
{
|
|
|
|
MetaXWaylandManager *manager = user_data;
|
|
|
|
|
2014-04-17 16:05:08 -04:00
|
|
|
/* The server writes its display name to the displayfd
|
|
|
|
* socket when it's ready. We don't care about the data
|
|
|
|
* in the socket, just that it wrote something, since
|
|
|
|
* that means it's ready. */
|
2014-04-02 10:25:56 -04:00
|
|
|
xserver_finished_init (manager);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2014-04-01 20:00:59 -04:00
|
|
|
gboolean
|
|
|
|
meta_xwayland_start (MetaXWaylandManager *manager,
|
|
|
|
struct wl_display *wl_display)
|
|
|
|
{
|
2014-04-17 15:37:53 -04:00
|
|
|
int xwayland_client_fd[2];
|
2014-04-17 16:05:08 -04:00
|
|
|
int displayfd[2];
|
2015-03-31 14:47:34 -04:00
|
|
|
g_autoptr(GSubprocessLauncher) launcher = NULL;
|
2015-03-21 21:24:37 -04:00
|
|
|
GSubprocessFlags flags;
|
|
|
|
GSubprocess *proc;
|
|
|
|
GError *error = NULL;
|
2014-04-01 20:00:59 -04:00
|
|
|
|
|
|
|
if (!choose_xdisplay (manager))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
/* We want xwayland to be a wayland client so we make a socketpair to setup a
|
|
|
|
* wayland protocol connection. */
|
2014-04-17 15:37:53 -04:00
|
|
|
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, xwayland_client_fd) < 0)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
2014-04-17 15:37:53 -04:00
|
|
|
g_warning ("xwayland_client_fd socketpair failed\n");
|
2014-04-01 20:00:59 -04:00
|
|
|
unlink (manager->lockfile);
|
2015-03-21 21:25:02 -04:00
|
|
|
return FALSE;
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|
|
|
|
|
2014-04-17 16:05:08 -04:00
|
|
|
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, displayfd) < 0)
|
|
|
|
{
|
|
|
|
g_warning ("displayfd socketpair failed\n");
|
|
|
|
unlink (manager->lockfile);
|
2015-03-21 21:25:02 -04:00
|
|
|
return FALSE;
|
2014-04-17 16:05:08 -04:00
|
|
|
}
|
|
|
|
|
2015-03-21 21:24:37 -04:00
|
|
|
/* xwayland, please. */
|
|
|
|
flags = G_SUBPROCESS_FLAGS_NONE;
|
2014-04-01 19:51:43 -04:00
|
|
|
|
2015-03-21 21:24:37 -04:00
|
|
|
if (getenv ("XWAYLAND_STFU"))
|
|
|
|
{
|
|
|
|
flags |= G_SUBPROCESS_FLAGS_STDOUT_SILENCE;
|
|
|
|
flags |= G_SUBPROCESS_FLAGS_STDERR_SILENCE;
|
2014-04-01 19:51:43 -04:00
|
|
|
}
|
2015-03-21 21:24:37 -04:00
|
|
|
|
|
|
|
launcher = g_subprocess_launcher_new (flags);
|
|
|
|
|
|
|
|
g_subprocess_launcher_take_fd (launcher, xwayland_client_fd[1], 3);
|
|
|
|
g_subprocess_launcher_take_fd (launcher, manager->abstract_fd, 4);
|
|
|
|
g_subprocess_launcher_take_fd (launcher, manager->unix_fd, 5);
|
|
|
|
g_subprocess_launcher_take_fd (launcher, displayfd[1], 6);
|
|
|
|
|
|
|
|
g_subprocess_launcher_setenv (launcher, "WAYLAND_SOCKET", "3", TRUE);
|
|
|
|
proc = g_subprocess_launcher_spawn (launcher, &error,
|
|
|
|
XWAYLAND_PATH, manager->display_name,
|
|
|
|
"-rootless", "-noreset",
|
|
|
|
"-listen", "4",
|
|
|
|
"-listen", "5",
|
|
|
|
"-displayfd", "6",
|
|
|
|
NULL);
|
|
|
|
if (!proc)
|
2014-04-02 13:03:17 -04:00
|
|
|
{
|
2015-03-21 21:24:37 -04:00
|
|
|
g_error ("Failed to spawn Xwayland: %s", error->message);
|
|
|
|
return FALSE;
|
2014-04-02 13:03:17 -04:00
|
|
|
}
|
2014-04-01 19:51:43 -04:00
|
|
|
|
2015-03-21 21:24:37 -04:00
|
|
|
g_subprocess_wait_async (proc, NULL, xserver_died, NULL);
|
2014-04-17 16:05:08 -04:00
|
|
|
g_unix_fd_add (displayfd[0], G_IO_IN, on_displayfd_ready, manager);
|
2014-04-17 15:37:53 -04:00
|
|
|
manager->client = wl_client_create (wl_display, xwayland_client_fd[0]);
|
2012-01-07 17:21:32 -05:00
|
|
|
|
2013-08-12 04:06:13 -04:00
|
|
|
/* We need to run a mainloop until we know xwayland has a binding
|
|
|
|
* for our xserver interface at which point we can assume it's
|
|
|
|
* ready to start accepting connections. */
|
2014-02-03 19:37:23 -05:00
|
|
|
manager->init_loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
g_main_loop_run (manager->init_loop);
|
2013-08-12 04:06:13 -04:00
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:31:18 -04:00
|
|
|
/* To be called right after connecting */
|
|
|
|
void
|
|
|
|
meta_xwayland_complete_init (void)
|
|
|
|
{
|
|
|
|
/* We install an X IO error handler in addition to the child watch,
|
|
|
|
because after Xlib connects our child watch may not be called soon
|
|
|
|
enough, and therefore we won't crash when X exits (and most important
|
|
|
|
we won't reset the tty).
|
|
|
|
*/
|
|
|
|
XSetIOErrorHandler (x_io_error);
|
|
|
|
}
|
|
|
|
|
2012-01-07 17:21:32 -05:00
|
|
|
void
|
2014-02-03 19:37:23 -05:00
|
|
|
meta_xwayland_stop (MetaXWaylandManager *manager)
|
2012-01-07 17:21:32 -05:00
|
|
|
{
|
|
|
|
char path[256];
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
snprintf (path, sizeof path, "/tmp/.X%d-lock", manager->display_index);
|
2012-01-07 17:21:32 -05:00
|
|
|
unlink (path);
|
2014-02-03 19:37:23 -05:00
|
|
|
snprintf (path, sizeof path, "/tmp/.X11-unix/X%d", manager->display_index);
|
2012-01-07 17:21:32 -05:00
|
|
|
unlink (path);
|
|
|
|
|
2014-02-03 19:37:23 -05:00
|
|
|
unlink (manager->lockfile);
|
2012-01-07 17:21:32 -05:00
|
|
|
}
|