backend: Unify the event initialization

Input backends are, in some cases, independent from the windowing system
backends; we can initialize input handling using a model similar to what
we use for windowing backends, including an environment variable and
compile-/run-time checks.

This model allows us to remove the backend-specific init_events(), and
use a generic implementation directly inside the base ClutterBackend
class, thus further reducing the backend-specific code that every
platform has to implement.

This requires some minor surgery to every single backend, to make sure
that the function exposed to initialize the event loop is similar and
performs roughly the same operations.
This commit is contained in:
Emmanuele Bassi
2011-11-03 17:53:54 +00:00
parent 84d208b2c6
commit adb6ffbd0e
14 changed files with 206 additions and 303 deletions

View File

@ -55,6 +55,23 @@
#include <cogl/cogl.h>
#ifdef CLUTTER_INPUT_X11
#include "x11/clutter-backend-x11.h"
#endif
#ifdef CLUTTER_INPUT_WIN32
#include "win32/clutter-backend-win32.h"
#endif
#ifdef CLUTTER_INPUT_OSX
#include "osx/clutter-backend-osx.h"
#endif
#ifdef CLUTTER_INPUT_EVDEV
#include "evdev/clutter-device-manager-evdev.h"
#endif
#ifdef CLUTTER_INPUT_TSLIB
/* XXX - should probably warn, here */
#include "tslib/clutter-event-tslib.h"
#endif
G_DEFINE_ABSTRACT_TYPE (ClutterBackend, clutter_backend, G_TYPE_OBJECT);
#define DEFAULT_FONT_NAME "Sans 10"
@ -243,6 +260,70 @@ clutter_backend_real_redraw (ClutterBackend *backend,
_clutter_stage_window_redraw (impl);
}
static void
clutter_backend_real_init_events (ClutterBackend *backend)
{
const char *input_backend = NULL;
input_backend = g_getenv ("CLUTTER_INPUT_BACKEND");
if (input_backend != NULL)
input_backend = g_intern_string (input_backend);
#ifdef CLUTTER_INPUT_X11
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_X11) &&
(input_backend == NULL || input_backend == I_(CLUTTER_INPUT_X11)))
{
_clutter_backend_x11_events_init (backend);
}
else
#endif
#ifdef CLUTTER_INPUT_OSX
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_OSX) &&
(input_backend == NULL || input_backend == I_(CLUTTER_INPUT_OSX)))
{
_clutter_backend_osx_events_init (backend);
}
#endif
#ifdef CLUTTER_INPUT_WIN32
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_WIN32) &&
(input_backend == NULL || input_backend == I_(CLUTTER_INPUT_WIN32)))
{
_clutter_backend_win32_events_init (backend);
}
else
#endif
#ifdef CLUTTER_INPUT_GDK
if (clutter_check_windowing_backend (CLUTTER_WINDOWING_GDK) &&
(input_backend == NULL || input_backend == I_(CLUTTER_INPUT_GDK)))
{
_clutter_backend_gdk_events_init (backend);
}
else
#endif
#ifdef CLUTTER_INPUT_EVDEV
/* Evdev can be used regardless of the windowing system */
if (input_backend != NULL &&
strcmp (input_backend, CLUTTER_INPUT_EVDEV) == 0)
{
_clutter_events_evdev_init (backend);
}
else
#endif
#ifdef CLUTTER_INPUT_TSLIB
/* Tslib can be used regardless of the windowing system */
if (input_backend != NULL &&
strcmp (input_backend, CLUTTER_INPUT_TSLIB) == 0)
{
_clutter_events_tslib_init (backend);
}
else
#endif
if (input_backend != NULL)
g_error ("Unrecognized input backend '%s'", input_backend);
else
g_error ("Unknown input backend");
}
static gboolean
clutter_backend_real_translate_event (ClutterBackend *backend,
gpointer native,
@ -339,6 +420,7 @@ clutter_backend_class_init (ClutterBackendClass *klass)
klass->resolution_changed = clutter_backend_real_resolution_changed;
klass->font_changed = clutter_backend_real_font_changed;
klass->init_events = clutter_backend_real_init_events;
klass->translate_event = clutter_backend_real_translate_event;
klass->ensure_context = clutter_backend_real_ensure_context;
klass->redraw = clutter_backend_real_redraw;
@ -591,8 +673,7 @@ _clutter_backend_init_events (ClutterBackend *backend)
g_assert (CLUTTER_IS_BACKEND (backend));
klass = CLUTTER_BACKEND_GET_CLASS (backend);
if (klass->init_events)
klass->init_events (backend);
klass->init_events (backend);
}
gfloat