Commit 09d0d32a authored by Thomas Wood's avatar Thomas Wood Committed by Matthias Clasen

wayland: implement GInitable and check the connection to the display server

Add GInitable implementation and fail the initialisation if it is not
possible to connect to the display server.

https://bugzilla.gnome.org/show_bug.cgi?id=694465
parent 3a9de35a
......@@ -259,14 +259,14 @@ gdk_display_manager_get (void)
if (!manager && (backend == NULL || strcmp (backend, "win32") == 0))
manager = g_initable_new (gdk_win32_display_manager_get_type (), NULL, NULL, NULL);
#endif
#ifdef GDK_WINDOWING_X11
if (!manager && (backend == NULL || strcmp (backend, "x11") == 0))
manager = g_initable_new (gdk_x11_display_manager_get_type (), NULL, NULL, NULL);
#endif
#ifdef GDK_WINDOWING_WAYLAND
if (!manager && (backend == NULL || strcmp (backend, "wayland") == 0))
manager = g_initable_new (gdk_wayland_display_manager_get_type (), NULL, NULL, NULL);
#endif
#ifdef GDK_WINDOWING_X11
if (!manager && (backend == NULL || strcmp (backend, "x11") == 0))
manager = g_initable_new (gdk_x11_display_manager_get_type (), NULL, NULL, NULL);
#endif
#ifdef GDK_WINDOWING_BROADWAY
if (!manager && (backend == NULL || strcmp (backend, "broadway") == 0))
manager = g_initable_new (gdk_broadway_display_manager_get_type (), NULL, NULL, NULL);
......
......@@ -38,6 +38,8 @@ struct _GdkWaylandDisplayManager
GHashTable *name_to_atoms;
guint next_atom;
gboolean init_failed;
};
struct _GdkWaylandDisplayManagerClass
......@@ -45,12 +47,44 @@ struct _GdkWaylandDisplayManagerClass
GdkDisplayManagerClass parent_class;
};
G_DEFINE_TYPE (GdkWaylandDisplayManager, gdk_wayland_display_manager, GDK_TYPE_DISPLAY_MANAGER)
static void g_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GdkWaylandDisplayManager, gdk_wayland_display_manager, GDK_TYPE_DISPLAY_MANAGER,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, g_initable_iface_init))
static gboolean
gdk_wayland_display_manager_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
struct wl_display *wl_display;
/* check that a connection to the default display is possible */
wl_display = wl_display_connect (gdk_get_display_arg_name ());
if (!wl_display)
{
GDK_WAYLAND_DISPLAY_MANAGER (initable)->init_failed = TRUE;
return FALSE;
}
wl_display_disconnect (wl_display);
return TRUE;
}
void
g_initable_iface_init (GInitableIface *iface)
{
iface->init = gdk_wayland_display_manager_initable_init;
}
static void
gdk_wayland_display_manager_finalize (GObject *object)
{
g_error ("A GdkWaylandDisplayManager object was finalized. This should not happen");
if (GDK_WAYLAND_DISPLAY_MANAGER (object)->init_failed == FALSE)
g_error ("A GdkWaylandDisplayManager object was finalized. This should not happen");
G_OBJECT_CLASS (gdk_wayland_display_manager_parent_class)->finalize (object);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment