diff options
author | Erik Larsson <erik@ortogonal.com> | 2016-01-01 07:14:01 +0100 |
---|---|---|
committer | Erik Larsson <erik@ortogonal.com> | 2016-03-21 12:53:57 +0000 |
commit | fc4bc214eb2e7bfd257e932b4cd4668cc8739479 (patch) | |
tree | 6c5f9f3a8795474599e350074fc30469e60adc90 | |
parent | 178dc4df9c3f625b95413b597eaaad2216aec729 (diff) | |
download | qtwayland-fc4bc214eb2e7bfd257e932b4cd4668cc8739479.tar.gz |
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 <pierluigi.fiorini@gmail.com>
Reviewed-by: Johan Helsing <johan.helsing@theqtcompany.com>
-rw-r--r-- | src/compositor/compositor_api/qwaylandcompositor.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp index 5480b1cf..6d7954aa 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) { |