diff options
author | Jonas Ådahl <jadahl@gmail.com> | 2017-07-10 16:50:43 +0800 |
---|---|---|
committer | Jonas Ådahl <jadahl@gmail.com> | 2017-08-21 21:19:18 +0800 |
commit | a6d67b164a0519022df49a782a688b64b022a5a0 (patch) | |
tree | 86a73281fd8bf24fdd2a57ec9c054a883976051e /src/backends | |
parent | f950380202a13c14234966acd9036ea48feb4007 (diff) | |
download | mutter-a6d67b164a0519022df49a782a688b64b022a5a0.tar.gz |
x11: Open backend X11 connection ourself
Don't wait for clutter to initialize for connecting to X11; do it when
constructing the backend instance. This way we can later depend on
having an X11 connection earlier during initialization.
https://bugzilla.gnome.org/show_bug.cgi?id=786408
Diffstat (limited to 'src/backends')
-rw-r--r-- | src/backends/x11/meta-backend-x11.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index 618babfa3..c299d263f 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -72,7 +72,15 @@ struct _MetaBackendX11Private }; typedef struct _MetaBackendX11Private MetaBackendX11Private; -G_DEFINE_TYPE_WITH_PRIVATE (MetaBackendX11, meta_backend_x11, META_TYPE_BACKEND); +static GInitableIface *initable_parent_iface; + +static void +initable_iface_init (GInitableIface *initable_iface); + +G_DEFINE_TYPE_WITH_CODE (MetaBackendX11, meta_backend_x11, META_TYPE_BACKEND, + G_ADD_PRIVATE (MetaBackendX11) + G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, + initable_iface_init)); static void handle_alarm_notify (MetaBackend *backend, @@ -392,8 +400,6 @@ meta_backend_x11_post_init (MetaBackend *backend) int major, minor; gboolean has_xi = FALSE; - priv->xdisplay = clutter_x11_get_default_display (); - priv->source = x_event_source_new (backend); if (!XSyncQueryExtension (priv->xdisplay, &priv->xsync_event_base, &priv->xsync_error_base) || @@ -586,6 +592,46 @@ meta_backend_x11_get_xkb_event_base (MetaBackendX11 *x11) return priv->xkb_event_base; } +static gboolean +meta_backend_x11_initable_init (GInitable *initable, + GCancellable *cancellable, + GError **error) +{ + MetaBackendX11 *x11 = META_BACKEND_X11 (initable); + MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); + Display *xdisplay; + const char *xdisplay_name; + + xdisplay_name = g_getenv ("DISPLAY"); + if (!xdisplay_name) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unable to open display, DISPLAY not set"); + return FALSE; + } + + xdisplay = XOpenDisplay (xdisplay_name); + if (!xdisplay) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, + "Unable to open display '%s'", xdisplay_name); + return FALSE; + } + + priv->xdisplay = xdisplay; + clutter_x11_set_display (xdisplay); + + return initable_parent_iface->init (initable, cancellable, error); +} + +static void +initable_iface_init (GInitableIface *initable_iface) +{ + initable_parent_iface = g_type_interface_peek_parent (initable_iface); + + initable_iface->init = meta_backend_x11_initable_init; +} + static void meta_backend_x11_class_init (MetaBackendX11Class *klass) { |