x11: Add meta_x11_get_display_name() function

Instead of poking the DISPLAY envvar at places.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/709
This commit is contained in:
Carlos Garnacho 2019-05-24 19:51:00 +02:00 committed by Carlos Garnacho
parent 79b5ece241
commit 9109fa0eb8
3 changed files with 23 additions and 2 deletions

View File

@ -114,7 +114,7 @@ meta_launch_context_constructed (GObject *object)
G_OBJECT_CLASS (meta_launch_context_parent_class)->constructed (object); G_OBJECT_CLASS (meta_launch_context_parent_class)->constructed (object);
x11_display = getenv ("DISPLAY"); x11_display = meta_x11_get_display_name ();
wayland_display = getenv ("WAYLAND_DISPLAY"); wayland_display = getenv ("WAYLAND_DISPLAY");
if (x11_display) if (x11_display)

View File

@ -249,4 +249,6 @@ void meta_x11_display_set_input_focus (MetaX11Display *x11_display,
Window xwindow, Window xwindow,
guint32 timestamp); guint32 timestamp);
const gchar * meta_x11_get_display_name (void);
#endif /* META_X11_DISPLAY_PRIVATE_H */ #endif /* META_X11_DISPLAY_PRIVATE_H */

View File

@ -988,6 +988,25 @@ meta_set_gnome_wm_keybindings (const char *wm_keybindings)
gnome_wm_keybindings = wm_keybindings; gnome_wm_keybindings = wm_keybindings;
} }
const gchar *
meta_x11_get_display_name (void)
{
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ())
{
MetaWaylandCompositor *compositor;
compositor = meta_wayland_compositor_get_default ();
return meta_wayland_get_xwayland_display_name (compositor);
}
else
#endif
{
return g_getenv ("DISPLAY");
}
}
gboolean gboolean
meta_x11_init_gdk_display (GError **error) meta_x11_init_gdk_display (GError **error)
{ {
@ -996,7 +1015,7 @@ meta_x11_init_gdk_display (GError **error)
const char *gdk_gl_env = NULL; const char *gdk_gl_env = NULL;
Display *xdisplay; Display *xdisplay;
xdisplay_name = g_getenv ("DISPLAY"); xdisplay_name = meta_x11_get_display_name ();
if (!xdisplay_name) if (!xdisplay_name)
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,