Allow eekboard UI toolkit to be changed at runtime.

This commit is contained in:
Daiki Ueno
2011-04-27 17:54:20 +09:00
parent a9d9274e78
commit cae9c89b64
4 changed files with 88 additions and 25 deletions

View File

@ -89,6 +89,8 @@ PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.26.0], ,
[AC_MSG_ERROR([GLib2 not found])]) [AC_MSG_ERROR([GLib2 not found])])
PKG_CHECK_MODULES([GIO2], [gio-2.0], , PKG_CHECK_MODULES([GIO2], [gio-2.0], ,
[AC_MSG_ERROR([Gio2 not found])]) [AC_MSG_ERROR([Gio2 not found])])
GLIB_GSETTINGS
PKG_CHECK_MODULES([PANGOCAIRO], [pangocairo], , PKG_CHECK_MODULES([PANGOCAIRO], [pangocairo], ,
[AC_MSG_ERROR([PangoCairo not found])]) [AC_MSG_ERROR([PangoCairo not found])])
PKG_CHECK_MODULES([GTK], [ PKG_CHECK_MODULES([GTK], [

View File

@ -1,5 +1,10 @@
SUBDIRS = icons themes keyboards SUBDIRS = icons themes keyboards
@GSETTINGS_RULES@
@INTLTOOL_XML_NOMERGE_RULE@
gsettings_schemas_in_files = org.fedorahosted.eekboard.gschema.xml.in
gsettings_SCHEMAS = $(gsettings_schemas_in_files:.gschema.xml.in=.gschema.xml)
desktopdir = $(datadir)/applications desktopdir = $(datadir)/applications
desktop_in_files = eekboard.desktop.in desktop_in_files = eekboard.desktop.in
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@ -12,8 +17,8 @@ endif
@INTLTOOL_DESKTOP_RULE@ @INTLTOOL_DESKTOP_RULE@
CLEANFILES = $(desktop_DATA) CLEANFILES = $(desktop_DATA) $(gsettings_SCHEMAS)
EXTRA_DIST = $(desktop_in_files) EXTRA_DIST = $(desktop_in_files) $(gsettings_schemas_in_files)
if ENABLE_ATSPI if ENABLE_ATSPI
CLEANFILES += $(autostart_DATA) CLEANFILES += $(autostart_DATA)

View File

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<schemalist>
<schema id="org.fedorahosted.eekboard" path="/org/fedorahosted/eekboard/">
<key name="ui-toolkit" type="s">
<default>'gtk'</default>
<summary>GUI toolkit used to render keyboard</summary>
<description>The name of GUI toolkit (either 'gtk' or 'clutter') used to render keyboard on screen.</description>
</key>
</schema>
</schemalist>

View File

@ -27,9 +27,8 @@
#if HAVE_CLUTTER_GTK #if HAVE_CLUTTER_GTK
#include <clutter-gtk/clutter-gtk.h> #include <clutter-gtk/clutter-gtk.h>
#include "eek/eek-clutter.h" #include "eek/eek-clutter.h"
#else /* HAVE_CLUTTER_GTK */ #endif
#include "eek/eek-gtk.h" #include "eek/eek-gtk.h"
#endif /* !HAVE_CLUTTER_GTK */
#include "server-context.h" #include "server-context.h"
@ -40,6 +39,7 @@ enum {
PROP_0, PROP_0,
PROP_OBJECT_PATH, PROP_OBJECT_PATH,
PROP_CONNECTION, PROP_CONNECTION,
PROP_UI_TOOLKIT,
PROP_LAST PROP_LAST
}; };
@ -85,6 +85,12 @@ static const gchar introspection_xml[] =
" </interface>" " </interface>"
"</node>"; "</node>";
typedef enum {
UI_TOOLKIT_GTK,
UI_TOOLKIT_CLUTTER,
UI_TOOLKIT_DEFAULT = UI_TOOLKIT_GTK
} ServerContextUIToolkitType;
typedef struct _ServerContextClass ServerContextClass; typedef struct _ServerContextClass ServerContextClass;
struct _ServerContext { struct _ServerContext {
@ -109,6 +115,8 @@ struct _ServerContext {
gulong key_pressed_handler; gulong key_pressed_handler;
gulong key_released_handler; gulong key_released_handler;
gulong notify_visible_handler; gulong notify_visible_handler;
ServerContextUIToolkitType ui_toolkit;
}; };
struct _ServerContextClass { struct _ServerContextClass {
@ -227,6 +235,7 @@ set_geometry (ServerContext *context)
rect.height / 2); rect.height / 2);
gtk_window_set_opacity (GTK_WINDOW(context->window), 0.8); gtk_window_set_opacity (GTK_WINDOW(context->window), 0.8);
} else { } else {
if (context->ui_toolkit == UI_TOOLKIT_CLUTTER) {
#if HAVE_CLUTTER_GTK #if HAVE_CLUTTER_GTK
ClutterActor *stage = ClutterActor *stage =
gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget)); gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
@ -238,7 +247,10 @@ set_geometry (ServerContext *context)
"allocation-changed", "allocation-changed",
G_CALLBACK(on_allocation_changed), G_CALLBACK(on_allocation_changed),
NULL); NULL);
#else
g_return_if_reached ();
#endif #endif
}
gtk_widget_set_size_request (context->widget, gtk_widget_set_size_request (context->widget,
bounds.width, bounds.width,
bounds.height); bounds.height);
@ -263,6 +275,7 @@ update_widget (ServerContext *context)
theme = eek_theme_new (DEFAULT_THEME, NULL, NULL); theme = eek_theme_new (DEFAULT_THEME, NULL, NULL);
eek_element_get_bounds (EEK_ELEMENT(context->keyboard), &bounds); eek_element_get_bounds (EEK_ELEMENT(context->keyboard), &bounds);
if (context->ui_toolkit == UI_TOOLKIT_CLUTTER) {
#if HAVE_CLUTTER_GTK #if HAVE_CLUTTER_GTK
context->widget = gtk_clutter_embed_new (); context->widget = gtk_clutter_embed_new ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget)); stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED(context->widget));
@ -274,10 +287,14 @@ update_widget (ServerContext *context)
clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color); clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
#else #else
g_return_if_reached ();
#endif
} else {
context->widget = eek_gtk_keyboard_new (context->keyboard); context->widget = eek_gtk_keyboard_new (context->keyboard);
if (theme) if (theme)
eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget), theme); eek_gtk_keyboard_set_theme (EEK_GTK_KEYBOARD(context->widget),
#endif theme);
}
if (!context->window) { if (!context->window) {
context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); context->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@ -312,6 +329,7 @@ server_context_set_property (GObject *object,
{ {
ServerContext *context = SERVER_CONTEXT(object); ServerContext *context = SERVER_CONTEXT(object);
GDBusConnection *connection; GDBusConnection *connection;
const gchar *ui_toolkit;
switch (prop_id) { switch (prop_id) {
case PROP_OBJECT_PATH: case PROP_OBJECT_PATH:
@ -325,6 +343,17 @@ server_context_set_property (GObject *object,
g_object_unref (context->connection); g_object_unref (context->connection);
context->connection = g_object_ref (connection); context->connection = g_object_ref (connection);
break; break;
case PROP_UI_TOOLKIT:
ui_toolkit = g_value_get_string (value);
if (g_strcmp0 (ui_toolkit, "gtk") == 0)
context->ui_toolkit = UI_TOOLKIT_GTK;
#if HAVE_CLUTTER_GTK
else if (g_strcmp0 (ui_toolkit, "clutter") == 0)
context->ui_toolkit = UI_TOOLKIT_CLUTTER;
#endif /* HAVE_CLUTTER_GTK */
else
g_warning ("unknown UI toolkit %s", ui_toolkit);
break;
default: default:
g_object_set_property (object, g_object_set_property (object,
g_param_spec_get_name (pspec), g_param_spec_get_name (pspec),
@ -430,11 +459,21 @@ server_context_class_init (ServerContextClass *klass)
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_CONNECTION, PROP_CONNECTION,
pspec); pspec);
pspec = g_param_spec_string ("ui-toolkit",
"UI toolkit",
"UI toolkit",
NULL,
G_PARAM_WRITABLE);
g_object_class_install_property (gobject_class,
PROP_UI_TOOLKIT,
pspec);
} }
static void static void
server_context_init (ServerContext *context) server_context_init (ServerContext *context)
{ {
GSettings *settings;
GError *error; GError *error;
context->connection = NULL; context->connection = NULL;
@ -459,6 +498,13 @@ server_context_init (ServerContext *context)
context->window = NULL; context->window = NULL;
context->key_pressed_handler = 0; context->key_pressed_handler = 0;
context->key_released_handler = 0; context->key_released_handler = 0;
context->ui_toolkit = UI_TOOLKIT_DEFAULT;
settings = g_settings_new ("org.fedorahosted.eekboard");
g_settings_bind (settings, "ui-toolkit",
context, "ui-toolkit",
G_SETTINGS_BIND_GET);
} }
static void static void