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:
Emmanuele Bassi 2011-11-04 19:25:54 +00:00
parent cd1e8da07f
commit 17c89bd0a0
10 changed files with 39 additions and 138 deletions

View File

@ -62,24 +62,6 @@ static guint gdl_n_buffers = CLUTTER_CEX100_TRIPLE_BUFFERING;
G_DEFINE_TYPE (ClutterBackendCex100, clutter_backend_cex100, CLUTTER_TYPE_BACKEND); 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 static void
clutter_backend_cex100_dispose (GObject *gobject) clutter_backend_cex100_dispose (GObject *gobject)
{ {
@ -91,12 +73,6 @@ clutter_backend_cex100_dispose (GObject *gobject)
backend_cex100->event_timer = NULL; 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); 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->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; backend_class->get_display = clutter_backend_cex100_get_display;
} }

View File

@ -39,11 +39,13 @@ typedef struct _ClutterBackendPrivate ClutterBackendPrivate;
struct _ClutterBackend struct _ClutterBackend
{ {
/*< private >*/ /*< private >*/
GObject parent_instance; GObject parent_instance;
CoglRenderer *cogl_renderer; CoglRenderer *cogl_renderer;
CoglDisplay *cogl_display; CoglDisplay *cogl_display;
CoglContext *cogl_context; CoglContext *cogl_context;
ClutterDeviceManager *device_manager;
ClutterBackendPrivate *priv; ClutterBackendPrivate *priv;
}; };

View File

@ -504,6 +504,18 @@ clutter_backend_real_init_events (ClutterBackend *backend)
g_error ("Unknown input 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 static gboolean
clutter_backend_real_translate_event (ClutterBackend *backend, clutter_backend_real_translate_event (ClutterBackend *backend,
gpointer native, gpointer native,
@ -603,6 +615,7 @@ clutter_backend_class_init (ClutterBackendClass *klass)
klass->font_changed = clutter_backend_real_font_changed; klass->font_changed = clutter_backend_real_font_changed;
klass->init_events = clutter_backend_real_init_events; 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->translate_event = clutter_backend_real_translate_event;
klass->create_context = clutter_backend_real_create_context; klass->create_context = clutter_backend_real_create_context;
klass->ensure_context = clutter_backend_real_ensure_context; klass->ensure_context = clutter_backend_real_ensure_context;

View File

@ -200,12 +200,9 @@ clutter_device_manager_init (ClutterDeviceManager *self)
ClutterDeviceManager * ClutterDeviceManager *
clutter_device_manager_get_default (void) clutter_device_manager_get_default (void)
{ {
ClutterBackendClass *klass; ClutterBackend *backend = clutter_get_default_backend ();
klass = CLUTTER_BACKEND_GET_CLASS (clutter_get_default_backend ()); return backend->device_manager;
g_assert (klass->get_device_manager != NULL);
return klass->get_device_manager (clutter_get_default_backend ());
} }
/** /**

View File

@ -57,24 +57,6 @@
G_DEFINE_TYPE (ClutterBackendEglNative, clutter_backend_egl_native, CLUTTER_TYPE_BACKEND); 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 static void
clutter_backend_egl_native_dispose (GObject *gobject) clutter_backend_egl_native_dispose (GObject *gobject)
{ {
@ -86,12 +68,6 @@ clutter_backend_egl_native_dispose (GObject *gobject)
backend_egl_native->event_timer = NULL; 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); 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; gobject_class->dispose = clutter_backend_egl_native_dispose;
backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL; backend_class->stage_window_type = CLUTTER_TYPE_STAGE_COGL;
backend_class->get_device_manager = clutter_backend_egl_native_get_device_manager;
} }
static void static void

View File

@ -847,20 +847,14 @@ clutter_device_manager_evdev_init (ClutterDeviceManagerEvdev *self)
self->priv = CLUTTER_DEVICE_MANAGER_EVDEV_GET_PRIVATE (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 void
_clutter_events_evdev_init (ClutterBackend *backend) _clutter_events_evdev_init (ClutterBackend *backend)
{ {
ClutterDeviceManager *dummy G_GNUC_UNUSED;
CLUTTER_NOTE (EVENT, "Initializing evdev backend"); CLUTTER_NOTE (EVENT, "Initializing evdev backend");
/* we need to create the device manager here */ backend->device_manager = g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_EVDEV,
dummy = clutter_device_manager_get_default (); "backend", backend,
NULL);
} }
void void

View File

@ -191,8 +191,16 @@ gdk_event_handler (GdkEvent *event,
void void
_clutter_backend_gdk_events_init (ClutterBackend *backend) _clutter_backend_gdk_events_init (ClutterBackend *backend)
{ {
ClutterBackendGdk *backend_gdk = CLUTTER_BACKEND_GDK (backend);
CLUTTER_NOTE (EVENT, "initialising the event loop"); 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) if (!disable_event_retrieval)
gdk_event_handler_set (gdk_event_handler, NULL, NULL); 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); 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 * static CoglRenderer *
clutter_backend_gdk_get_renderer (ClutterBackend *backend, clutter_backend_gdk_get_renderer (ClutterBackend *backend,
GError **error) GError **error)
@ -381,7 +373,6 @@ clutter_backend_gdk_class_init (ClutterBackendGdkClass *klass)
backend_class->post_parse = _clutter_backend_gdk_post_parse; backend_class->post_parse = _clutter_backend_gdk_post_parse;
backend_class->get_features = clutter_backend_gdk_get_features; 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->copy_event_data = clutter_backend_gdk_copy_event_data;
backend_class->free_event_data = clutter_backend_gdk_free_event_data; backend_class->free_event_data = clutter_backend_gdk_free_event_data;

View File

@ -94,27 +94,6 @@ clutter_backend_osx_create_stage (ClutterBackend *backend,
return impl; 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 void
_clutter_backend_osx_events_init (ClutterBackend *backend) _clutter_backend_osx_events_init (ClutterBackend *backend)
{ {
@ -125,7 +104,10 @@ _clutter_backend_osx_events_init (ClutterBackend *backend)
CLUTTER_NOTE (BACKEND, "init_events"); 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 (); _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_stage = clutter_backend_osx_create_stage;
backend_class->create_context = clutter_backend_osx_create_context; backend_class->create_context = clutter_backend_osx_create_context;
backend_class->ensure_context = clutter_backend_osx_ensure_context; backend_class->ensure_context = clutter_backend_osx_ensure_context;
backend_class->get_device_manager = clutter_backend_osx_get_device_manager;
} }

View File

@ -59,7 +59,7 @@ clutter_backend_win32_init_events (ClutterBackend *backend)
CLUTTER_NOTE (EVENT, "initialising the event loop"); CLUTTER_NOTE (EVENT, "initialising the event loop");
backend_win32->device_manager = backend->device_manager =
g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32, g_object_new (CLUTTER_TYPE_DEVICE_MANAGER_WIN32,
"backend", backend_win32, "backend", backend_win32,
NULL); NULL);
@ -168,22 +168,6 @@ clutter_backend_win32_get_features (ClutterBackend *backend)
| CLUTTER_FEATURE_STAGE_CURSOR; | 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 * 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->init_events = clutter_backend_win32_init_events;
backend_class->add_options = clutter_backend_win32_add_options; backend_class->add_options = clutter_backend_win32_add_options;
backend_class->get_features = clutter_backend_win32_get_features; backend_class->get_features = clutter_backend_win32_get_features;
backend_class->get_device_manager = clutter_backend_win32_get_device_manager;
} }
static void static void

View File

@ -277,6 +277,8 @@ clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
} }
backend = CLUTTER_BACKEND (backend_x11); backend = CLUTTER_BACKEND (backend_x11);
backend->device_manager = backend_x11->device_manager;
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager); translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager);
_clutter_backend_add_event_translator (backend, translator); _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); _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 static void
update_last_event_time (ClutterBackendX11 *backend_x11, update_last_event_time (ClutterBackendX11 *backend_x11,
XEvent *xevent) XEvent *xevent)
@ -815,7 +807,6 @@ clutter_backend_x11_class_init (ClutterBackendX11Class *klass)
backend_class->add_options = clutter_backend_x11_add_options; backend_class->add_options = clutter_backend_x11_add_options;
backend_class->get_features = clutter_backend_x11_get_features; 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->copy_event_data = clutter_backend_x11_copy_event_data;
backend_class->free_event_data = clutter_backend_x11_free_event_data; backend_class->free_event_data = clutter_backend_x11_free_event_data;
backend_class->translate_event = clutter_backend_x11_translate_event; backend_class->translate_event = clutter_backend_x11_translate_event;