Commit bfcf9e47 authored by Matthias Clasen's avatar Matthias Clasen

Implement GInitable in GdkX11DisplayManager

Add GInitable implementation and fail the initialisation if it is not
possible to connect to the display server.
parent 09d0d32a
......@@ -34,6 +34,8 @@ struct _GdkX11DisplayManager
GdkDisplay *default_display;
GSList *displays;
gboolean init_failed;
};
struct _GdkX11DisplayManagerClass
......@@ -41,7 +43,37 @@ struct _GdkX11DisplayManagerClass
GdkDisplayManagerClass parent_class;
};
G_DEFINE_TYPE (GdkX11DisplayManager, gdk_x11_display_manager, GDK_TYPE_DISPLAY_MANAGER)
static void g_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (GdkX11DisplayManager, gdk_x11_display_manager, GDK_TYPE_DISPLAY_MANAGER,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, g_initable_iface_init))
static gboolean
gdk_x11_display_manager_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
Display *display;
/* check that a connection to the default display is possible */
display = XOpenDisplay (gdk_get_display_arg_name ());
if (!display)
{
GDK_X11_DISPLAY_MANAGER (initable)->init_failed = TRUE;
return FALSE;
}
XCloseDisplay (display);
return TRUE;
}
void
g_initable_iface_init (GInitableIface *iface)
{
iface->init = gdk_x11_display_manager_initable_init;
}
static GdkDisplay *
gdk_x11_display_manager_open_display (GdkDisplayManager *manager,
......@@ -93,7 +125,8 @@ gdk_x11_display_manager_init (GdkX11DisplayManager *manager)
static void
gdk_x11_display_manager_finalize (GObject *object)
{
g_error ("A GdkX11DisplayManager object was finalized. This should not happen");
if (GDK_X11_DISPLAY_MANAGER (object)->init_failed == FALSE)
g_error ("A GdkX11DisplayManager object was finalized. This should not happen");
G_OBJECT_CLASS (gdk_x11_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