GNOME Bugzilla – Bug 697673
Apps should connect only once when using Wayland
Last modified: 2013-04-19 13:07:01 UTC
GTK+ is connecting twice every time one application is starting. It checks whether a connection to the default display server is possible during initialisation and fail otherwise: https://bugzilla.gnome.org/show_bug.cgi?id=694465 GTK+ should be able to use the same access control style as toytoolkit clients for example, using WAYLAND_SOCKET probably.
Hi Tiago, I took a look at this but couldn't find much room for improvement. It wouldn't be possible for GtkWaylandDisplayManager to keep the display connection that is opened during initialization, as this would cause a leak in the case where the client doesn't intend to use the default display but instead opens a different display after initialization. WAYLAND_SOCKET is handled transparently by wl_display_connect() the same way in GTK+ as toytoolkit clients.
Closing on Chris's behalf.
I think it should be possible for GTK+ to do better. Surely some kind of two-phase approach where we try all connections and keep them around, then pick one and close all others. Or in case GDK_BACKEND is set to wayland, don't try other connections at all? Lastly, it's also not necessary to try to connect to see if it's possible if WAYLAND_SOCKET is set - if it is, we already have a connection.
In case that comment was unclear, there are three suggestions on how to avoid the double connect: 1) Try to open all types of displays, keep connections open, decide which one to use, close all others. Instead of the current open all, close all, decide which one to use, open that one again. 2) If GDK_BACKEND is set, skip the first step of opening all types of display and just open the one we're asked to open; fail if that doesn't work. 3) WAYLAND_SOCKET is typically used when a compositor launches a client and provides one end of a socketpair as the connection fd to the client. In that case, there's no reason to try to connect, since we know it will always succeed.
For 3.) I just pushed: commit bff5b2ae3ee51e83564ead19f410be9ff0c00326 Author: Rob Bradford <rob@linux.intel.com> Date: Fri Apr 12 18:39:20 2013 +0100 wayland: Don't "probe" for a Wayland compositor if started from compositor In the case that the client is started directly by the compositor the WAYLAND_SOCKET environment variable is set containing the fd to use that was created by a socketpair. This environment variable is consumed by a call to wl_display_connect so a second call will not take advantage of it. https://bugzilla.gnome.org/show_bug.cgi?id=697673
For 2.) if GDK_BACKEND is set only that backend (or backends since it can be a , separated list) will actually be tried. If that isn't set the application's defined allowable backend set is used which defaults to "*" for all backends. But GDK_BACKEND always takes precedence! For 1.) as soon as we find a working backend we use that type - but yes end up opening the connection closing it and then reopening it The code is a bit complex but i'm confident this is how it works. I agree that we could definitely try and reuse the "probe" connection for the real one - and i'll work on patch to that effect.
commit 524ce7f88e26a498c43729f99fda564f5e222582 Author: Rob Bradford <rob@linux.intel.com> Date: Fri Apr 19 13:59:58 2013 +0100 wayland: Cache the discovery connection and reuse if possible This will prevent us opening, closing and reopening the same display connection in the majority of cases. https://bugzilla.gnome.org/show_bug.cgi?id=694465