backend: Move event translators to the base class

In the future, we want event translators to be the way to handle events
in backends. For this reason, they should be a part of the base abstract
ClutterBackend class, and not an X11-only concept.
This commit is contained in:
Emmanuele Bassi 2011-02-09 12:20:56 +00:00
parent e9fa986ccc
commit 56d133f908
8 changed files with 96 additions and 65 deletions

View File

@ -23,6 +23,7 @@
#define __CLUTTER_BACKEND_PRIVATE_H__
#include <clutter/clutter-backend.h>
#include "clutter-event-translator.h"
#define CLUTTER_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BACKEND, ClutterBackendClass))
#define CLUTTER_IS_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BACKEND))
@ -122,6 +123,12 @@ gboolean _clutter_backend_translate_event (ClutterBackend *backend,
gpointer native,
ClutterEvent *event);
void _clutter_backend_add_event_translator (ClutterBackend *backend,
ClutterEventTranslator *translator);
void _clutter_backend_remove_event_translator (ClutterBackend *backend,
ClutterEventTranslator *translator);
G_END_DECLS
#endif /* __CLUTTER_BACKEND_PRIVATE_H__ */

View File

@ -68,6 +68,8 @@ struct _ClutterBackendPrivate
gfloat units_per_em;
gint32 units_serial;
GList *event_translators;
};
enum
@ -84,6 +86,7 @@ static guint backend_signals[LAST_SIGNAL] = { 0, };
static void
clutter_backend_dispose (GObject *gobject)
{
ClutterBackendPrivate *priv = CLUTTER_BACKEND (gobject)->priv;
ClutterMainContext *clutter_context;
clutter_context = _clutter_context_get_default ();
@ -97,6 +100,12 @@ clutter_backend_dispose (GObject *gobject)
clutter_context->events_queue = NULL;
}
if (priv->event_translators != NULL)
{
g_list_free (priv->event_translators);
priv->event_translators = NULL;
}
G_OBJECT_CLASS (clutter_backend_parent_class)->dispose (gobject);
}
@ -220,6 +229,35 @@ clutter_backend_real_redraw (ClutterBackend *backend,
_clutter_stage_window_redraw (impl);
}
static gboolean
clutter_backend_real_translate_event (ClutterBackend *backend,
gpointer native,
ClutterEvent *event)
{
ClutterBackendPrivate *priv = backend->priv;
GList *l;
for (l = priv->event_translators;
l != NULL;
l = l->next)
{
ClutterEventTranslator *translator = l->data;
ClutterTranslateReturn retval;
retval = _clutter_event_translator_translate_event (translator,
native,
event);
if (retval == CLUTTER_TRANSLATE_QUEUE)
return TRUE;
if (retval == CLUTTER_TRANSLATE_REMOVE)
return FALSE;
}
return FALSE;
}
static void
clutter_backend_class_init (ClutterBackendClass *klass)
{
@ -259,6 +297,7 @@ clutter_backend_class_init (ClutterBackendClass *klass)
klass->resolution_changed = clutter_backend_real_resolution_changed;
klass->font_changed = clutter_backend_real_font_changed;
klass->translate_event = clutter_backend_real_translate_event;
klass->redraw = clutter_backend_real_redraw;
}
@ -907,3 +946,29 @@ _clutter_backend_translate_event (ClutterBackend *backend,
native,
event);
}
void
_clutter_backend_add_event_translator (ClutterBackend *backend,
ClutterEventTranslator *translator)
{
ClutterBackendPrivate *priv = backend->priv;
if (g_list_find (priv->event_translators, translator) != NULL)
return;
priv->event_translators =
g_list_prepend (priv->event_translators, translator);
}
void
_clutter_backend_remove_event_translator (ClutterBackend *backend,
ClutterEventTranslator *translator)
{
ClutterBackendPrivate *priv = backend->priv;
if (g_list_find (priv->event_translators, translator) == NULL)
return;
priv->event_translators =
g_list_remove (priv->event_translators, translator);
}

View File

@ -755,7 +755,7 @@ clutter_backend_egl_create_stage (ClutterBackend *backend,
stage_x11->backend = backend_x11;
translator = CLUTTER_EVENT_TRANSLATOR (stage_x11);
_clutter_backend_x11_add_event_translator (backend_x11, translator);
_clutter_backend_add_event_translator (backend, translator);
CLUTTER_NOTE (MISC, "EGLX stage created (display:%p, screen:%d, root:%u)",
backend_x11->xdpy,

View File

@ -793,7 +793,7 @@ clutter_backend_glx_create_stage (ClutterBackend *backend,
stage_x11->backend = backend_x11;
translator = CLUTTER_EVENT_TRANSLATOR (stage_x11);
_clutter_backend_x11_add_event_translator (backend_x11, translator);
_clutter_backend_add_event_translator (backend, translator);
CLUTTER_NOTE (BACKEND,
"GLX stage created[%p] (dpy:%p, screen:%d, root:%u, wrap:%p)",

View File

@ -228,6 +228,7 @@ clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
if (G_UNLIKELY (backend_x11->device_manager == NULL))
{
ClutterEventTranslator *translator;
ClutterBackend *backend;
#if defined(HAVE_XINPUT) || defined(HAVE_XINPUT_2)
if (clutter_enable_xinput)
@ -278,8 +279,9 @@ clutter_backend_x11_create_device_manager (ClutterBackendX11 *backend_x11)
NULL);
}
backend = CLUTTER_BACKEND (backend_x11);
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->device_manager);
_clutter_backend_x11_add_event_translator (backend_x11, translator);
_clutter_backend_add_event_translator (backend, translator);
}
}
@ -288,10 +290,17 @@ clutter_backend_x11_create_keymap (ClutterBackendX11 *backend_x11)
{
if (backend_x11->keymap == NULL)
{
ClutterEventTranslator *translator;
ClutterBackend *backend;
backend_x11->keymap =
g_object_new (CLUTTER_TYPE_KEYMAP_X11,
"backend", backend_x11,
NULL);
backend = CLUTTER_BACKEND (backend_x11);
translator = CLUTTER_EVENT_TRANSLATOR (backend_x11->keymap);
_clutter_backend_add_event_translator (backend, translator);
}
}
@ -652,10 +661,11 @@ clutter_backend_x11_translate_event (ClutterBackend *backend,
ClutterEvent *event)
{
ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
ClutterBackendClass *parent_class;
XEvent *xevent = native;
GList *l;
if (backend_x11->event_filters)
/* X11 filter functions have a higher priority */
if (backend_x11->event_filters != NULL)
{
GSList *node = backend_x11->event_filters;
@ -687,25 +697,11 @@ clutter_backend_x11_translate_event (ClutterBackend *backend,
*/
update_last_event_time (backend_x11, xevent);
for (l = backend_x11->event_translators;
l != NULL;
l = l->next)
{
ClutterEventTranslator *translator = l->data;
ClutterTranslateReturn retval;
retval = _clutter_event_translator_translate_event (translator,
native,
event);
if (retval == CLUTTER_TRANSLATE_QUEUE)
return TRUE;
if (retval == CLUTTER_TRANSLATE_REMOVE)
return FALSE;
}
return FALSE;
/* chain up to the parent implementation, which will handle
* event translators
*/
parent_class = CLUTTER_BACKEND_CLASS (clutter_backend_x11_parent_class);
return parent_class->translate_event (backend, native, event);
}
static void
@ -1194,28 +1190,6 @@ clutter_x11_get_visual_info (void)
return _clutter_backend_x11_get_visual_info (backend_x11);
}
void
_clutter_backend_x11_add_event_translator (ClutterBackendX11 *backend_x11,
ClutterEventTranslator *translator)
{
if (g_list_find (backend_x11->event_translators, translator) != NULL)
return;
backend_x11->event_translators =
g_list_prepend (backend_x11->event_translators, translator);
}
void
_clutter_backend_x11_remove_event_translator (ClutterBackendX11 *backend_x11,
ClutterEventTranslator *translator)
{
if (g_list_find (backend_x11->event_translators, translator) == NULL)
return;
backend_x11->event_translators =
g_list_remove (backend_x11->event_translators, translator);
}
gboolean
_clutter_x11_input_device_translate_screen_coord (ClutterInputDevice *device,
gint stage_root_x,

View File

@ -30,7 +30,6 @@
#include "clutter-x11.h"
#include "clutter-backend-private.h"
#include "clutter-event-translator.h"
#include "clutter-keymap-x11.h"
#include "xsettings/xsettings-client.h"
@ -109,8 +108,6 @@ struct _ClutterBackendX11
gboolean use_xkb;
gboolean have_xkb_autorepeat;
guint keymap_serial;
GList *event_translators;
};
struct _ClutterBackendX11Class
@ -146,14 +143,6 @@ _clutter_event_x11_copy (ClutterEventX11 *event_x11);
void
_clutter_event_x11_free (ClutterEventX11 *event_x11);
void
_clutter_backend_x11_add_event_translator (ClutterBackendX11 *backend_x11,
ClutterEventTranslator *translator);
void
_clutter_backend_x11_remove_event_translator (ClutterBackendX11 *backend_x11,
ClutterEventTranslator *translator);
gboolean
_clutter_x11_input_device_translate_screen_coord (ClutterInputDevice *device,
gint stage_root_x,

View File

@ -250,10 +250,6 @@ clutter_keymap_x11_constructed (GObject *gobject)
XkbAllStateComponentsMask,
XkbGroupLockMask | XkbModifierLockMask);
/* add ourselves as an event translator for XKB events */
t = CLUTTER_EVENT_TRANSLATOR (keymap_x11);
_clutter_backend_x11_add_event_translator (backend_x11, t);
/* enable XKB autorepeat */
XkbSetDetectableAutoRepeat (backend_x11->xdpy,
True,
@ -298,11 +294,10 @@ clutter_keymap_x11_finalize (GObject *gobject)
ClutterEventTranslator *translator;
keymap = CLUTTER_KEYMAP_X11 (gobject);
backend = CLUTTER_BACKEND_X11 (keymap->backend);
translator = CLUTTER_EVENT_TRANSLATOR (keymap);
#ifdef HAVE_XKB
_clutter_backend_x11_remove_event_translator (backend, translator);
_clutter_backend_remove_event_translator (keymap->backend, translator);
if (keymap->xkb_desc != NULL)
XkbFreeKeyboard (keymap->xkb_desc, XkbAllComponentsMask, True);

View File

@ -707,9 +707,10 @@ static void
clutter_stage_x11_dispose (GObject *gobject)
{
ClutterEventTranslator *translator = CLUTTER_EVENT_TRANSLATOR (gobject);
ClutterBackendX11 *backend_x11 = CLUTTER_STAGE_X11 (gobject)->backend;
ClutterBackendX11 *backend = CLUTTER_STAGE_X11 (gobject)->backend;
_clutter_backend_x11_remove_event_translator (backend_x11, translator);
_clutter_backend_remove_event_translator (CLUTTER_BACKEND (backend),
translator);
G_OBJECT_CLASS (clutter_stage_x11_parent_class)->dispose (gobject);
}