From: Emmanuele Bassi Date: Mon, 12 Jul 2010 16:11:30 +0000 (+0100) Subject: x11: Add a Keymap ancillary object X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bea657d3d5e7306c10b245d5cf348e80e0084719;p=profile%2Fivi%2Fclutter.git x11: Add a Keymap ancillary object We should try to abstract everything that is related with the key mapping to its own object, to avoid complicating ClutterBackendX11 any further. --- diff --git a/clutter/x11/Makefile.am b/clutter/x11/Makefile.am index 6e227bb..b8c7c03 100644 --- a/clutter/x11/Makefile.am +++ b/clutter/x11/Makefile.am @@ -46,6 +46,8 @@ libclutter_x11_la_SOURCES = \ $(srcdir)/clutter-event-x11.c \ $(srcdir)/clutter-input-device-x11.h \ $(srcdir)/clutter-input-device-x11.c \ + $(srcdir)/clutter-keymap-x11.h \ + $(srcdir)/clutter-keymap-x11.c \ $(srcdir)/clutter-settings-x11.h \ $(srcdir)/clutter-stage-x11.h \ $(srcdir)/clutter-stage-x11.c \ diff --git a/clutter/x11/clutter-backend-x11.c b/clutter/x11/clutter-backend-x11.c index 8bc13ec..8a78c19 100644 --- a/clutter/x11/clutter-backend-x11.c +++ b/clutter/x11/clutter-backend-x11.c @@ -319,6 +319,12 @@ clutter_backend_x11_post_parse (ClutterBackend *backend, "backend", backend_x11, NULL); + /* register keymap */ + backend_x11->keymap = + g_object_new (CLUTTER_TYPE_KEYMAP_X11, + "backend", backend_x11, + NULL); + /* create XSETTINGS client */ backend_x11->xsettings = _clutter_xsettings_client_new (backend_x11->xdpy, diff --git a/clutter/x11/clutter-backend-x11.h b/clutter/x11/clutter-backend-x11.h index 4826343..78a15cf 100644 --- a/clutter/x11/clutter-backend-x11.h +++ b/clutter/x11/clutter-backend-x11.h @@ -30,6 +30,7 @@ #include "clutter-x11.h" +#include "clutter-keymap-x11.h" #include "xsettings/xsettings-client.h" G_BEGIN_DECLS @@ -88,6 +89,8 @@ struct _ClutterBackendX11 XSettingsClient *xsettings; Window xsettings_xwin; + + ClutterKeymapX11 *keymap; }; struct _ClutterBackendX11Class diff --git a/clutter/x11/clutter-event-x11.c b/clutter/x11/clutter-event-x11.c index 9643f18..9e65d9f 100644 --- a/clutter/x11/clutter-event-x11.c +++ b/clutter/x11/clutter-event-x11.c @@ -30,6 +30,7 @@ #include "clutter-stage-x11.h" #include "clutter-backend-x11.h" +#include "clutter-keymap-x11.h" #include "clutter-x11.h" #include "../clutter-backend.h" @@ -343,19 +344,6 @@ translate_key_event (ClutterBackend *backend, event_x11 = _clutter_event_x11_new (); _clutter_event_set_platform_data (event, event_x11); -#ifdef HAVE_XKB - event_x11->key_group = XkbGroupForCoreState (xevent->xkey.state); - - CLUTTER_NOTE (EVENT, "Key group: %d (xkb enabled: yes)", - event_x11->key_group); -#else - /* we force the key group to 0 */ - event_x11->key_group = 0; - - CLUTTER_NOTE (EVENT, "Key group: %d (xkb enabled: no)", - event_x11->key_group); -#endif /* HAVE_XKB */ - event->key.time = xevent->xkey.time; event->key.modifier_state = (ClutterModifierType) xevent->xkey.state; event->key.hardware_keycode = xevent->xkey.keycode; @@ -366,6 +354,9 @@ translate_key_event (ClutterBackend *backend, xevent->xkey.keycode, 0); + event_x11->key_group = + _clutter_keymap_x11_get_key_group (event->key.modifier_state); + /* unicode_value is the printable representation */ n = XLookupString (&xevent->xkey, buffer, sizeof (buffer) - 1, NULL, NULL); diff --git a/clutter/x11/clutter-keymap-x11.c b/clutter/x11/clutter-keymap-x11.c new file mode 100644 index 0000000..4e5561b --- /dev/null +++ b/clutter/x11/clutter-keymap-x11.c @@ -0,0 +1,123 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2010 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: Emmanuele Bassi + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "clutter-keymap-x11.h" + +#include "clutter-debug.h" +#include "clutter-private.h" + +#include + +#ifdef HAVE_XINPUT +#include +#endif + +#ifdef HAVE_XKB +#include +#endif + +typedef struct _ClutterKeymapX11Class ClutterKeymapX11Class; + +struct _ClutterKeymapX11 +{ + GObject parent_instance; + + ClutterBackend *backend; +}; + +struct _ClutterKeymapX11Class +{ + GObjectClass parent_class; +}; + +enum +{ + PROP_0, + + PROP_BACKEND +}; + +G_DEFINE_TYPE (ClutterKeymapX11, clutter_keymap_x11, G_TYPE_OBJECT); + +static void +clutter_keymap_x11_set_property (GObject *gobject, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + ClutterKeymapX11 *keymap = CLUTTER_KEYMAP_X11 (gobject); + + switch (prop_id) + { + case PROP_BACKEND: + keymap->backend = g_value_get_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); + break; + } +} + +static void +clutter_keymap_x11_finalize (GObject *gobject) +{ + G_OBJECT_CLASS (clutter_keymap_x11_parent_class)->finalize (gobject); +} + +static void +clutter_keymap_x11_class_init (ClutterKeymapX11Class *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; + + gobject_class->set_property = clutter_keymap_x11_set_property; + gobject_class->finalize = clutter_keymap_x11_finalize; + + pspec = g_param_spec_object ("backend", + "Backend", + "The Clutter backend", + CLUTTER_TYPE_BACKEND, + CLUTTER_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property (gobject_class, PROP_BACKEND, pspec); +} + +static void +clutter_keymap_x11_init (ClutterKeymapX11 *keymap) +{ +} + +gint +_clutter_keymap_x11_get_key_group (ClutterModifierType state) +{ +#ifdef HAVE_XKB + return XkbGroupForCoreState (state); +#else + return 0; +#endif /* HAVE_XKB */ +} diff --git a/clutter/x11/clutter-keymap-x11.h b/clutter/x11/clutter-keymap-x11.h new file mode 100644 index 0000000..a64c8b2 --- /dev/null +++ b/clutter/x11/clutter-keymap-x11.h @@ -0,0 +1,44 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2009 Intel Corp. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: Emmanuele Bassi + */ + +#ifndef __CLUTTER_KEYMAP_X11_H__ +#define __CLUTTER_KEYMAP_X11_H__ + +#include +#include + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_KEYMAP_X11 (clutter_keymap_x11_get_type ()) +#define CLUTTER_KEYMAP_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_KEYMAP_X11, ClutterKeymapX11)) +#define CLUTTER_IS_KEYMAP_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_KEYMAP_X11)) + +typedef struct _ClutterKeymapX11 ClutterKeymapX11; + +GType clutter_keymap_x11_get_type (void) G_GNUC_CONST; + +gint _clutter_keymap_x11_get_key_group (ClutterModifierType state); + +G_END_DECLS + +#endif /* __CLUTTER_KEYMAP_X11_H__ */