backend: Clean up the device manager creation
Create the device manager during the event initialization, where it makes sense. This allows us to get rid of the per-backend get_device_manager() virtual function, and just store the DeviceManager pointer into the ClutterBackend structure.
This commit is contained in:
parent
cd1e8da07f
commit
17c89bd0a0
@ -62,24 +62,6 @@ static guint gdl_n_buffers = CLUTTER_CEX100_TRIPLE_BUFFERING;
|
||||
|
||||
G_DEFINE_TYPE (ClutterBackendCex100, clutter_backend_cex100, CLUTTER_TYPE_BACKEND);
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_cex100_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendCex100 *backend_cex100 = CLUTTER_BACKEND_CEX100 (backend);
|
||||
|
||||
#ifdef HAVE_EVDEV
|
||||
if (G_UNLIKELY (backend_cex100->device_manager == NULL))
|
||||
{
|
||||
backend_cex100->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_EVDEV,
|
||||
"backend", backend_cex100,
|
||||
NULL);
|
||||
}
|
||||
#endif /* HAVE_EVDEV */
|
||||
|
||||
return backend_cex100->device_manager;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_backend_cex100_dispose (GObject *gobject)
|
||||
{
|
||||
@ -91,12 +73,6 @@ clutter_backend_cex100_dispose (GObject *gobject)
|
||||
backend_cex100->event_timer = NULL;
|
||||
}
|
||||
|
||||
if (backend_cex100->device_manager != NULL)
|
||||
{
|
||||
g_object_unref (backend_cex100->device_manager);
|
||||
backend_cex100->device_manager = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (clutter_backend_cex100_parent_class)->dispose (gobject);
|
||||
}
|
||||
|
||||
@ -145,7 +121,6 @@ clutter_backend_cex100_class_init (ClutterBackendCex100Class *klass)
|
||||
|
||||
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL;
|
||||
|
||||
backend_class->get_device_manager = clutter_backend_cex100_get_device_manager;
|
||||
backend_class->get_display = clutter_backend_cex100_get_display;
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,13 @@ typedef struct _ClutterBackendPrivate ClutterBackendPrivate;
|
||||
struct _ClutterBackend
|
||||
{
|
||||
/*< private >*/
|
||||
GObject parent_instance;
|
||||
GObject parent_instance;
|
||||
|
||||
CoglRenderer *cogl_renderer;
|
||||
CoglDisplay *cogl_display;
|
||||
CoglContext *cogl_context;
|
||||
CoglRenderer *cogl_renderer;
|
||||
CoglDisplay *cogl_display;
|
||||
CoglContext *cogl_context;
|
||||
|
||||
ClutterDeviceManager *device_manager;
|
||||
|
||||
ClutterBackendPrivate *priv;
|
||||
};
|
||||
|
@ -504,6 +504,18 @@ clutter_backend_real_init_events (ClutterBackend *backend)
|
||||
g_error ("Unknown input backend");
|
||||
}
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_real_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
if (G_UNLIKELY (backend->device_manager == NULL))
|
||||
{
|
||||
g_critical ("No device manager available, expect broken input");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return backend->device_manager;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_backend_real_translate_event (ClutterBackend *backend,
|
||||
gpointer native,
|
||||
@ -603,6 +615,7 @@ clutter_backend_class_init (ClutterBackendClass *klass)
|
||||
klass->font_changed = clutter_backend_real_font_changed;
|
||||
|
||||
klass->init_events = clutter_backend_real_init_events;
|
||||
klass->get_device_manager = clutter_backend_real_get_device_manager;
|
||||
klass->translate_event = clutter_backend_real_translate_event;
|
||||
klass->create_context = clutter_backend_real_create_context;
|
||||
klass->ensure_context = clutter_backend_real_ensure_context;
|
||||
|
@ -200,12 +200,9 @@ clutter_device_manager_init (ClutterDeviceManager *self)
|
||||
ClutterDeviceManager *
|
||||
clutter_device_manager_get_default (void)
|
||||
{
|
||||
ClutterBackendClass *klass;
|
||||
ClutterBackend *backend = clutter_get_default_backend ();
|
||||
|
||||
klass = CLUTTER_BACKEND_GET_CLASS (clutter_get_default_backend ());
|
||||
g_assert (klass->get_device_manager != NULL);
|
||||
|
||||
return klass->get_device_manager (clutter_get_default_backend ());
|
||||
return backend->device_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,24 +57,6 @@
|
||||
|
||||
G_DEFINE_TYPE (ClutterBackendEglNative, clutter_backend_egl_native, CLUTTER_TYPE_BACKEND);
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_egl_native_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendEglNative *backend_egl_native = CLUTTER_BACKEND_EGL_NATIVE (backend);
|
||||
|
||||
#ifdef HAVE_EVDEV
|
||||
if (G_UNLIKELY (backend_egl_native->device_manager == NULL))
|
||||
{
|
||||
backend_egl_native->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_EVDEV,
|
||||
"backend", backend_egl_native,
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
return backend_egl_native->device_manager;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_backend_egl_native_dispose (GObject *gobject)
|
||||
{
|
||||
@ -86,12 +68,6 @@ clutter_backend_egl_native_dispose (GObject *gobject)
|
||||
backend_egl_native->event_timer = NULL;
|
||||
}
|
||||
|
||||
if (backend_egl_native->device_manager != NULL)
|
||||
{
|
||||
g_object_unref (backend_egl_native->device_manager);
|
||||
backend_egl_native->device_manager = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (clutter_backend_egl_native_parent_class)->dispose (gobject);
|
||||
}
|
||||
|
||||
@ -104,8 +80,6 @@ clutter_backend_egl_native_class_init (ClutterBackendEglNativeClass *klass)
|
||||
gobject_class->dispose = clutter_backend_egl_native_dispose;
|
||||
|
||||
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL;
|
||||
|
||||
backend_class->get_device_manager = clutter_backend_egl_native_get_device_manager;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -847,20 +847,14 @@ clutter_device_manager_evdev_init (ClutterDeviceManagerEvdev *self)
|
||||
self->priv = CLUTTER_DEVICE_MANAGER_EVDEV_GET_PRIVATE (self);
|
||||
}
|
||||
|
||||
/*
|
||||
* _clutter_events_evdev_init() and _clutter_events_evdev_uninit() are the two
|
||||
* symbol to use the evdev event backend from the EGL backend
|
||||
*/
|
||||
|
||||
void
|
||||
_clutter_events_evdev_init (ClutterBackend *backend)
|
||||
{
|
||||
ClutterDeviceManager *dummy G_GNUC_UNUSED;
|
||||
|
||||
CLUTTER_NOTE (EVENT, "Initializing evdev backend");
|
||||
|
||||
/* we need to create the device manager here */
|
||||
dummy = clutter_device_manager_get_default ();
|
||||
backend->device_manager = g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_EVDEV,
|
||||
"backend", backend,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -191,8 +191,16 @@ gdk_event_handler (GdkEvent *event,
|
||||
void
|
||||
_clutter_backend_gdk_events_init (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendGdk *backend_gdk = CLUTTER_BACKEND_GDK (backend);
|
||||
|
||||
CLUTTER_NOTE (EVENT, "initialising the event loop");
|
||||
|
||||
backend->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_GDK,
|
||||
"backend", backend,
|
||||
"gdk-display", backend_gdk->display,
|
||||
NULL);
|
||||
|
||||
if (!disable_event_retrieval)
|
||||
gdk_event_handler_set (gdk_event_handler, NULL, NULL);
|
||||
}
|
||||
@ -249,22 +257,6 @@ clutter_backend_gdk_free_event_data (ClutterBackend *backend,
|
||||
gdk_event_free (gdk_event);
|
||||
}
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_gdk_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendGdk *backend_gdk = CLUTTER_BACKEND_GDK (backend);
|
||||
|
||||
if (G_UNLIKELY (backend_gdk->device_manager == NULL))
|
||||
{
|
||||
backend_gdk->device_manager = g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_GDK,
|
||||
"backend", backend_gdk,
|
||||
"gdk-display", backend_gdk->display,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return backend_gdk->device_manager;
|
||||
}
|
||||
|
||||
static CoglRenderer *
|
||||
clutter_backend_gdk_get_renderer (ClutterBackend *backend,
|
||||
GError **error)
|
||||
@ -381,7 +373,6 @@ clutter_backend_gdk_class_init (ClutterBackendGdkClass *klass)
|
||||
backend_class->post_parse = _clutter_backend_gdk_post_parse;
|
||||
|
||||
backend_class->get_features = clutter_backend_gdk_get_features;
|
||||
backend_class->get_device_manager = clutter_backend_gdk_get_device_manager;
|
||||
backend_class->copy_event_data = clutter_backend_gdk_copy_event_data;
|
||||
backend_class->free_event_data = clutter_backend_gdk_free_event_data;
|
||||
|
||||
|
@ -94,27 +94,6 @@ clutter_backend_osx_create_stage (ClutterBackend *backend,
|
||||
return impl;
|
||||
}
|
||||
|
||||
static inline void
|
||||
clutter_backend_osx_create_device_manager (ClutterBackendOSX *backend_osx)
|
||||
{
|
||||
if (backend_osx->device_manager != NULL)
|
||||
return;
|
||||
|
||||
backend_osx->device_manager = g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_OSX,
|
||||
"backend", CLUTTER_BACKEND(backend_osx),
|
||||
NULL);
|
||||
}
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_osx_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendOSX *backend_osx = CLUTTER_BACKEND_OSX (backend);
|
||||
|
||||
clutter_backend_osx_create_device_manager (backend_osx);
|
||||
|
||||
return backend_osx->device_manager;
|
||||
}
|
||||
|
||||
void
|
||||
_clutter_backend_osx_events_init (ClutterBackend *backend)
|
||||
{
|
||||
@ -125,7 +104,10 @@ _clutter_backend_osx_events_init (ClutterBackend *backend)
|
||||
|
||||
CLUTTER_NOTE (BACKEND, "init_events");
|
||||
|
||||
clutter_backend_osx_create_device_manager (backend_osx);
|
||||
backend->device_manager = backend_osx->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_OSX,
|
||||
"backend", CLUTTER_BACKEND(backend_osx),
|
||||
NULL);
|
||||
|
||||
_clutter_osx_event_loop_init ();
|
||||
}
|
||||
@ -256,5 +238,4 @@ clutter_backend_osx_class_init (ClutterBackendOSXClass *klass)
|
||||
backend_class->create_stage = clutter_backend_osx_create_stage;
|
||||
backend_class->create_context = clutter_backend_osx_create_context;
|
||||
backend_class->ensure_context = clutter_backend_osx_ensure_context;
|
||||
backend_class->get_device_manager = clutter_backend_osx_get_device_manager;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ clutter_backend_win32_init_events (ClutterBackend *backend)
|
||||
|
||||
CLUTTER_NOTE (EVENT, "initialising the event loop");
|
||||
|
||||
backend_win32->device_manager =
|
||||
backend->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
|
||||
"backend", backend_win32,
|
||||
NULL);
|
||||
@ -168,22 +168,6 @@ clutter_backend_win32_get_features (ClutterBackend *backend)
|
||||
| CLUTTER_FEATURE_STAGE_CURSOR;
|
||||
}
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_win32_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendWin32 *backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
|
||||
|
||||
if (G_UNLIKELY (backend_win32->device_manager == NULL))
|
||||
{
|
||||
backend_win32->device_manager =
|
||||
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
|
||||
"backend", backend_win32,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return backend_win32->device_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_win32_disable_event_retrieval
|
||||
*
|
||||
@ -222,7 +206,6 @@ clutter_backend_win32_class_init (ClutterBackendWin32Class *klass)
|
||||
backend_class->init_events = clutter_backend_win32_init_events;
|
||||
backend_class->add_options = clutter_backend_win32_add_options;
|
||||
backend_class->get_features = clutter_backend_win32_get_features;
|
||||
backend_class->get_device_manager = clutter_backend_win32_get_device_manager;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -277,6 +277,8 @@ clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
|
||||
}
|
||||
|
||||
backend = CLUTTER_BACKEND (backend_x11);
|
||||
backend->device_manager = backend_x11->device_manager;
|
||||
|
||||
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager);
|
||||
_clutter_backend_add_event_translator (backend, translator);
|
||||
}
|
||||
@ -589,16 +591,6 @@ clutter_backend_x11_free_event_data (ClutterBackend *backend,
|
||||
_clutter_event_x11_free (event_x11);
|
||||
}
|
||||
|
||||
static ClutterDeviceManager *
|
||||
clutter_backend_x11_get_device_manager (ClutterBackend *backend)
|
||||
{
|
||||
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
|
||||
|
||||
clutter_backend_x11_create_device_manager (backend_x11);
|
||||
|
||||
return backend_x11->device_manager;
|
||||
}
|
||||
|
||||
static void
|
||||
update_last_event_time (ClutterBackendX11 *backend_x11,
|
||||
XEvent *xevent)
|
||||
@ -815,7 +807,6 @@ clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
|
||||
backend_class->add_options = clutter_backend_x11_add_options;
|
||||
backend_class->get_features = clutter_backend_x11_get_features;
|
||||
|
||||
backend_class->get_device_manager = clutter_backend_x11_get_device_manager;
|
||||
backend_class->copy_event_data = clutter_backend_x11_copy_event_data;
|
||||
backend_class->free_event_data = clutter_backend_x11_free_event_data;
|
||||
backend_class->translate_event = clutter_backend_x11_translate_event;
|
||||
|
Loading…
Reference in New Issue
Block a user