x11-display: Clean up GdkDisplay opening

It exposed unnecessary public and private API, and used a global static
variable instead of a return value, none which was necessary. Remove
both API and use a return value for communicating to the caller.

This doesn't remove a public symbol, lets do that for GNOME 44.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2619>
This commit is contained in:
Jonas Ådahl 2022-05-28 23:39:30 +02:00 committed by Marge Bot
parent dc5130ac01
commit b8cdc91c19
2 changed files with 24 additions and 29 deletions

View File

@ -251,6 +251,4 @@ void meta_x11_display_set_input_focus (MetaX11Display *x11_display,
MetaDisplay * meta_x11_display_get_display (MetaX11Display *x11_display);
const gchar * meta_x11_get_display_name (void);
#endif /* META_X11_DISPLAY_PRIVATE_H */

View File

@ -80,8 +80,6 @@ typedef struct _MetaX11DisplayLogicalMonitorData
int xinerama_index;
} MetaX11DisplayLogicalMonitorData;
static GdkDisplay *prepared_gdk_display = NULL;
static char *get_screen_name (Display *xdisplay,
int number);
@ -985,27 +983,24 @@ set_work_area_hint (MetaDisplay *display,
g_free (data);
}
const gchar *
meta_x11_get_display_name (void)
static const char *
get_display_name (MetaDisplay *display)
{
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ())
{
MetaWaylandCompositor *compositor;
compositor = meta_wayland_compositor_get_default ();
MetaContext *context = meta_display_get_context (display);
MetaWaylandCompositor *compositor =
meta_context_get_wayland_compositor (context);
if (compositor)
return meta_wayland_get_private_xwayland_display_name (compositor);
}
else
#endif
{
return g_getenv ("DISPLAY");
}
}
gboolean
meta_x11_init_gdk_display (GError **error)
static GdkDisplay *
open_gdk_display (MetaDisplay *display,
GError **error)
{
const char *xdisplay_name;
GdkDisplay *gdk_display;
@ -1014,12 +1009,12 @@ meta_x11_init_gdk_display (GError **error)
const char *old_no_at_bridge;
Display *xdisplay;
xdisplay_name = meta_x11_get_display_name ();
xdisplay_name = get_display_name (display);
if (!xdisplay_name)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unable to open display, DISPLAY not set");
return FALSE;
return NULL;
}
gdk_set_allowed_backends ("x11");
@ -1036,7 +1031,7 @@ meta_x11_init_gdk_display (GError **error)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to initialize gtk");
return FALSE;
return NULL;
}
old_no_at_bridge = g_getenv ("NO_AT_BRIDGE");
@ -1054,8 +1049,7 @@ meta_x11_init_gdk_display (GError **error)
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to initialize GDK");
return FALSE;
return NULL;
}
if (gdk_backend_env)
@ -1085,12 +1079,16 @@ meta_x11_init_gdk_display (GError **error)
gdk_display_close (gdk_display);
return FALSE;
return NULL;
}
prepared_gdk_display = gdk_display;
return gdk_display;
}
return TRUE;
gboolean
meta_x11_init_gdk_display (GError **error)
{
return !!open_gdk_display (meta_get_display (), error);
}
static void
@ -1151,11 +1149,10 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
};
Atom atoms[G_N_ELEMENTS(atom_names)];
if (!meta_x11_init_gdk_display (error))
gdk_display = open_gdk_display (display, error);
if (!gdk_display)
return NULL;
g_assert (prepared_gdk_display);
gdk_display = g_steal_pointer (&prepared_gdk_display);
xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display);
XSynchronize (xdisplay, meta_context_is_x11_sync (context));