From fc4bc214eb2e7bfd257e932b4cd4668cc8739479 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Fri, 1 Jan 2016 07:14:01 +0100 Subject: Add automatic socket name detection in compositor The compositor automatically finds a free socket name using wl_display_add_socket_auto. Also fix the order in which the compositor uses --wayland-socket-name or the content of the socketName property. The documentation states the content of the socketName property should be used before the content of --wayland-socket-name. The commit also removes the reference to the WAYLAND_DISPLAY environment variable from the docs. Change-Id: I33dff4e4627d95f5894a5a1e2f308d747f449691 Reviewed-by: Pier Luigi Fiorini Reviewed-by: Johan Helsing --- .../compositor_api/qwaylandcompositor.cpp | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/compositor/compositor_api/qwaylandcompositor.cpp') diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp index 5480b1cf1..6d7954aa7 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandcompositor.cpp @@ -153,10 +153,11 @@ void QWaylandCompositorPrivate::init() Q_Q(QWaylandCompositor); QStringList arguments = QCoreApplication::instance()->arguments(); - int socketArg = arguments.indexOf(QLatin1String("--wayland-socket-name")); - if (socketArg != -1 && socketArg + 1 < arguments.size()) - socket_name = arguments.at(socketArg + 1).toLocal8Bit(); - + if (socket_name.isEmpty()) { + const int socketArg = arguments.indexOf(QLatin1String("--wayland-socket-name")); + if (socketArg != -1 && socketArg + 1 < arguments.size()) + socket_name = arguments.at(socketArg + 1).toLocal8Bit(); + } wl_compositor::init(display, 3); wl_subcompositor::init(display, 1); @@ -167,11 +168,14 @@ void QWaylandCompositorPrivate::init() foreach (wl_shm_format format, formats) wl_display_add_shm_format(display, format); - const char *socketName = 0; - if (socket_name.size()) - socketName = socket_name.constData(); - if (wl_display_add_socket(display, socketName)) { - qFatal("Fatal: Failed to open server socket\n"); + if (!socket_name.isEmpty()) { + if (wl_display_add_socket(display, socket_name.constData())) + qFatal("Fatal: Failed to open server socket\n"); + } else { + const char *autoSocketName = wl_display_add_socket_auto(display); + if (!autoSocketName) + qFatal("Fatal: Failed to open server socket\n"); + socket_name = autoSocketName; } loop = wl_display_get_event_loop(display); @@ -467,9 +471,10 @@ bool QWaylandCompositor::isCreated() const * This property holds the socket name used by WaylandCompositor to communicate with * clients. It must be set before the component is completed. * - * If the socketName is empty (the default), the contents of the environment - * variable WAYLAND_DISPLAY is used instead. If this is not set, the - * default "wayland-0" is used. + * If the socketName is empty (the default), the contents of the start argument + * --wayland-socket-name is used instead. If this is not set, then the compositor + * will try to find a socket name automatically, which in the default case will + * be "wayland-0". */ /*! @@ -478,9 +483,10 @@ bool QWaylandCompositor::isCreated() const * This property holds the socket name used by QWaylandCompositor to communicate with * clients. This must be set before the QWaylandCompositor is \l{create()}{created}. * - * If the socketName is empty (the default), the contents of the environment - * variable WAYLAND_DISPLAY is used instead. If this is not set, the - * default "wayland-0" is used. + * If the socketName is empty (the default), the contents of the start argument + * --wayland-socket-name is used instead. If this is not set, then the compositor + * will try to find a socket name automatically, which in the default case will + * be "wayland-0". */ void QWaylandCompositor::setSocketName(const QByteArray &name) { -- cgit v1.2.3