mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	client: require WAYLAND_DISPLAY to be set
Although defaulting to wayland-0 seems convenient, it has an undesirable side effect: clients may unintentionally connect to the wrong compositor. Generally, it's safer to fail instead. Here's a real example: In Fedora 22, Gtk+ prefers Wayland over X11, though the default session is still a normal X11 Gnome session. When you launch a Gtk+ app, it will try Wayland, fail, then try X11, and succesfully start up. That works fine. Now suppose you launch Weston while running the Gnome session. Suddenly, all of the Gtk+ apps launched from Gnome will show up inside Weston instead. That's unexpected. There's also no good way to prevent that from happening (other than perhaps setting WAYLAND_DISPLAY to an invalid value when launching an app). Not using wayland-0 as the default will solve that problem: an app launched from the X11 Gnome session will use the X11 backend regardless of whether there's a wayland compositor running at the same time. Everything else should work as before. The compositor already sets the WAYLAND_DISPLAY when starting the session, so the lack of the default value should not make a difference to the user. Signed-off-by: Dima Ryazanov <dima@gmail.com> Acked-by: Pekka Paalanen <ppaalanen@gmail.com> Acked-by: Giulio Camuffo <giuliocamuffo@gmail.com> Acked-by: Daniel Stone <daniel@fooishbar.org> Acked-by: Jasper St. Pierre <jstpierre@mecheye.net> Reviewed-by: Ryo Munakata <ryomnktml@gmail.com> [Pekka: dropped the wayland-server.c hunk, adjusted summary] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
		
							parent
							
								
									441f9bb144
								
							
						
					
					
						commit
						fb7e130217
					
				
					 3 changed files with 12 additions and 11 deletions
				
			
		| 
						 | 
					@ -57,9 +57,8 @@
 | 
				
			||||||
          that was previously opened by a Wayland server. The server socket must
 | 
					          that was previously opened by a Wayland server. The server socket must
 | 
				
			||||||
          be placed in <envar>XDG_RUNTIME_DIR</envar> for this function to
 | 
					          be placed in <envar>XDG_RUNTIME_DIR</envar> for this function to
 | 
				
			||||||
          find it. The <varname>name</varname> argument specifies the name of
 | 
					          find it. The <varname>name</varname> argument specifies the name of
 | 
				
			||||||
          the socket or <constant>NULL</constant> to use the default (which is
 | 
					          the socket or <constant>NULL</constant> to use the default
 | 
				
			||||||
          <constant>"wayland-0"</constant>). The environment variable
 | 
					          (which is the value of <envar>WAYLAND_DISPLAY</envar>). If
 | 
				
			||||||
          <envar>WAYLAND_DISPLAY</envar> replaces the default value. If
 | 
					 | 
				
			||||||
          <envar>WAYLAND_SOCKET</envar> is set, this function behaves like
 | 
					          <envar>WAYLAND_SOCKET</envar> is set, this function behaves like
 | 
				
			||||||
          <function>wl_display_connect_to_fd</function> with the file-descriptor
 | 
					          <function>wl_display_connect_to_fd</function> with the file-descriptor
 | 
				
			||||||
          number taken from the environment variable.</para>
 | 
					          number taken from the environment variable.</para>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,10 +60,10 @@
 | 
				
			||||||
    <title>Wire Format</title>
 | 
					    <title>Wire Format</title>
 | 
				
			||||||
    <para>
 | 
					    <para>
 | 
				
			||||||
      The protocol is sent over a UNIX domain stream socket, where the endpoint
 | 
					      The protocol is sent over a UNIX domain stream socket, where the endpoint
 | 
				
			||||||
      usually is named <systemitem class="service">wayland-0</systemitem>
 | 
					      name is determined by the <emphasis>WAYLAND_DISPLAY</emphasis>
 | 
				
			||||||
      (although it can be changed via <emphasis>WAYLAND_DISPLAY</emphasis>
 | 
					      environment variable.  Its value will usually be
 | 
				
			||||||
      in the environment).  The protocol is message-based.  A
 | 
					      <systemitem class="service">wayland-0</systemitem>.  The protocol is message-based.
 | 
				
			||||||
      message sent by a client to the server is called request.  A message
 | 
					      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
 | 
					      from the server to a client is called event.  Every message is
 | 
				
			||||||
      structured as 32-bit words, values are represented in the host's
 | 
					      structured as 32-bit words, values are represented in the host's
 | 
				
			||||||
      byte-order.
 | 
					      byte-order.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -764,8 +764,11 @@ connect_to_socket(const char *name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (name == NULL)
 | 
						if (name == NULL)
 | 
				
			||||||
		name = getenv("WAYLAND_DISPLAY");
 | 
							name = getenv("WAYLAND_DISPLAY");
 | 
				
			||||||
	if (name == NULL)
 | 
						if (name == NULL) {
 | 
				
			||||||
		name = "wayland-0";
 | 
							wl_log("error: WAYLAND_DISPLAY not set in the environment.\n");
 | 
				
			||||||
 | 
							errno = ENOENT;
 | 
				
			||||||
 | 
							return -1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 | 
						fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 | 
				
			||||||
	if (fd < 0)
 | 
						if (fd < 0)
 | 
				
			||||||
| 
						 | 
					@ -869,8 +872,7 @@ wl_display_connect_to_fd(int fd)
 | 
				
			||||||
 * \return A \ref wl_display object or \c NULL on failure
 | 
					 * \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,
 | 
					 * Connect to the Wayland display named \c name. If \c name is \c NULL,
 | 
				
			||||||
 * its value will be replaced with the WAYLAND_DISPLAY environment
 | 
					 * its value will be replaced with the WAYLAND_DISPLAY environment variable.
 | 
				
			||||||
 * variable if it is set, otherwise display "wayland-0" will be used.
 | 
					 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \memberof wl_display
 | 
					 * \memberof wl_display
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue