[PATCH wayland] Revert "client: require WAYLAND_DISPLAY to be set"

Pekka Paalanen ppaalanen at gmail.com
Mon Aug 17 06:17:57 PDT 2015

From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

This reverts commit fb7e13021730d0a5516ecbd3712ea4235e05d24d.

Developers have been trying to reduce the number of by default required
environment variables, and the mentioned commit is a step backwards in
that sense. The fundamental assumption is that a user has only one main
(Wayland) display server where all programs should connect to by
default, and do so with an a priori known socket name.

The commit also broke various use cases in the wild, some accidentally
due to other causes, some intentionally. This revert allows those use
cases to continue.

The original problem of running Weston in a window in an existing GNOME
X11 session and getting applications unintentionally launched into
Weston can be circumvented by letting Weston use a non-default socket
name, leaving wayland-0 unused.


Cc: Dima Ryazanov <dima at gmail.com>
Cc: Giulio Camuffo <giuliocamuffo at gmail.com>
Cc: Daniel Stone <daniel at fooishbar.org>
Cc: Jasper St. Pierre <jstpierre at mecheye.net>
Cc: Ryo Munakata <ryomnktml at gmail.com>
Cc: Ray Strode <halfline at gmail.com>
Cc: Peter Hutterer <peter.hutterer at who-t.net>
Cc: Matthias Clasen <mclasen at redhat.com>
Cc: Sjoerd Simons <sjoerd.simons at collabora.co.uk>
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
 doc/man/wl_display_connect.xml    |  5 +++--
 doc/publican/sources/Protocol.xml |  8 ++++----
 src/wayland-client.c              | 10 ++++------
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/doc/man/wl_display_connect.xml b/doc/man/wl_display_connect.xml
index ded3cbd..7e6e05c 100644
--- a/doc/man/wl_display_connect.xml
+++ b/doc/man/wl_display_connect.xml
@@ -57,8 +57,9 @@
           that was previously opened by a Wayland server. The server socket must
           be placed in <envar>XDG_RUNTIME_DIR</envar> for this function to
           find it. The <varname>name</varname> argument specifies the name of
-          the socket or <constant>NULL</constant> to use the default
-          (which is the value of <envar>WAYLAND_DISPLAY</envar>). If
+          the socket or <constant>NULL</constant> to use the default (which is
+          <constant>"wayland-0"</constant>). The environment variable
+          <envar>WAYLAND_DISPLAY</envar> replaces the default value. If
           <envar>WAYLAND_SOCKET</envar> is set, this function behaves like
           <function>wl_display_connect_to_fd</function> with the file-descriptor
           number taken from the environment variable.</para>
diff --git a/doc/publican/sources/Protocol.xml b/doc/publican/sources/Protocol.xml
index 9464953..477063b 100644
--- a/doc/publican/sources/Protocol.xml
+++ b/doc/publican/sources/Protocol.xml
@@ -60,10 +60,10 @@
     <title>Wire Format</title>
       The protocol is sent over a UNIX domain stream socket, where the endpoint
-      name is determined by the <emphasis>WAYLAND_DISPLAY</emphasis>
-      environment variable.  Its value will usually be
-      <systemitem class="service">wayland-0</systemitem>.  The protocol is message-based.
-      A message sent by a client to the server is called request.  A message
+      usually is named <systemitem class="service">wayland-0</systemitem>
+      (although it can be changed via <emphasis>WAYLAND_DISPLAY</emphasis>
+      in the environment).  The protocol is message-based.  A
+      message sent by a client to the server is called request.  A message
       from the server to a client is called event.  Every message is
       structured as 32-bit words, values are represented in the host's
diff --git a/src/wayland-client.c b/src/wayland-client.c
index ffbca4b..09c594a 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -764,11 +764,8 @@ connect_to_socket(const char *name)
 	if (name == NULL)
 		name = getenv("WAYLAND_DISPLAY");
-	if (name == NULL) {
-		wl_log("error: WAYLAND_DISPLAY not set in the environment.\n");
-		errno = ENOENT;
-		return -1;
-	}
+	if (name == NULL)
+		name = "wayland-0";
 	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 	if (fd < 0)
@@ -872,7 +869,8 @@ wl_display_connect_to_fd(int fd)
  * \return A \ref wl_display object or \c NULL on failure
  * Connect to the Wayland display named \c name. If \c name is \c NULL,
- * its value will be replaced with the WAYLAND_DISPLAY environment variable.
+ * its value will be replaced with the WAYLAND_DISPLAY environment
+ * variable if it is set, otherwise display "wayland-0" will be used.
  * \memberof wl_display

More information about the wayland-devel mailing list