Remove useless get_group method and group_changed signal of EekLayout.

This commit is contained in:
Daiki Ueno
2011-01-27 10:01:34 +09:00
parent 20acd11425
commit 4008706bb0
5 changed files with 119 additions and 272 deletions

View File

@ -33,56 +33,11 @@
#include "eek-layout.h" #include "eek-layout.h"
#include "eek-keyboard.h" #include "eek-keyboard.h"
enum {
GROUP_CHANGED,
CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (EekLayout, eek_layout, G_TYPE_OBJECT); G_DEFINE_TYPE (EekLayout, eek_layout, G_TYPE_OBJECT);
static void static void
eek_layout_class_init (EekLayoutClass *klass) eek_layout_class_init (EekLayoutClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
/**
* EekLayout::group-changed:
* @layout: an #EekLayout that received the signal
* @group: group index
*
* The ::group-changed signal is emitted each time group
* configuration of @layout changed.
*/
signals[GROUP_CHANGED] =
g_signal_new ("group-changed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(EekLayoutClass, group_changed),
NULL,
NULL,
g_cclosure_marshal_VOID__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
/**
* EekLayout::changed:
* @layout: an #EekLayout that received the signal
*
* The ::changed signal is emitted each time @layout changed
* and re-layout of #EekKeyboard is needed.
*/
signals[CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET(EekLayoutClass, changed),
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
} }
void void
@ -110,20 +65,3 @@ eek_keyboard_new (EekLayout *layout,
initial_width, initial_width,
initial_height); initial_height);
} }
/**
* eek_layout_get_group:
* @layout: an #EekLayout
*
* Get the group index from the @layout. This function normally
* called after #EekLayout::group-changed signal to change group index
* of all the keys in #EekKeyboard at a time.
*/
gint
eek_layout_get_group (EekLayout *layout)
{
g_assert (EEK_IS_LAYOUT(layout));
g_assert (EEK_LAYOUT_GET_CLASS(layout)->get_group);
return EEK_LAYOUT_GET_CLASS(layout)->get_group (layout);
}

View File

@ -45,10 +45,6 @@ struct _EekLayout
/** /**
* EekLayoutClass: * EekLayoutClass:
* @create_keyboard: virtual function for creating a keyboard * @create_keyboard: virtual function for creating a keyboard
* @get_group: virtual function for getting the current group setting
* of the layout
* @group_changed: class handler for #EekLayout::group-changed signal
* @changed: class handler for #EekLayout::changed signal
*/ */
struct _EekLayoutClass struct _EekLayoutClass
{ {
@ -59,12 +55,6 @@ struct _EekLayoutClass
EekKeyboard* (* create_keyboard) (EekLayout *self, EekKeyboard* (* create_keyboard) (EekLayout *self,
gdouble initial_width, gdouble initial_width,
gdouble initial_height); gdouble initial_height);
gint (* get_group) (EekLayout *self);
/* signals */
void (* group_changed) (EekLayout *self,
gint group);
void (* changed) (EekLayout *self);
/*< private >*/ /*< private >*/
/* padding */ /* padding */
@ -75,7 +65,6 @@ GType eek_layout_get_type (void) G_GNUC_CONST;
EekKeyboard *eek_layout_new (EekLayout *layout, EekKeyboard *eek_layout_new (EekLayout *layout,
gdouble initial_width, gdouble initial_width,
gdouble initial_height); gdouble initial_height);
gint eek_layout_get_group (EekLayout *layout);
G_END_DECLS G_END_DECLS
#endif /* EEK_LAYOUT_H */ #endif /* EEK_LAYOUT_H */

View File

@ -336,19 +336,6 @@ eek_xkb_layout_real_create_keyboard (EekLayout *self,
return keyboard; return keyboard;
} }
static gint
compare_component_name (gchar *name0, gchar *name1)
{
if (name0 && name1)
return g_strcmp0 (name0, name1);
else if (!name0 && name1)
return -1;
else if (name0 && !name1)
return 1;
else
return 0;
}
static void static void
eek_xkb_layout_finalize (GObject *object) eek_xkb_layout_finalize (GObject *object)
{ {
@ -423,17 +410,6 @@ eek_xkb_layout_get_property (GObject *object,
} }
} }
static gint
eek_xkb_layout_real_get_group (EekLayout *self)
{
EekXkbLayoutPrivate *priv = EEK_XKB_LAYOUT_GET_PRIVATE (self);
XkbStateRec state;
g_return_val_if_fail (XkbGetState (priv->display, XkbUseCoreKbd, &state),
-1);
return state.group;
}
static void static void
eek_xkb_layout_class_init (EekXkbLayoutClass *klass) eek_xkb_layout_class_init (EekXkbLayoutClass *klass)
{ {
@ -444,7 +420,6 @@ eek_xkb_layout_class_init (EekXkbLayoutClass *klass)
g_type_class_add_private (gobject_class, sizeof (EekXkbLayoutPrivate)); g_type_class_add_private (gobject_class, sizeof (EekXkbLayoutPrivate));
layout_class->create_keyboard = eek_xkb_layout_real_create_keyboard; layout_class->create_keyboard = eek_xkb_layout_real_create_keyboard;
layout_class->get_group = eek_xkb_layout_real_get_group;
gobject_class->finalize = eek_xkb_layout_finalize; gobject_class->finalize = eek_xkb_layout_finalize;
gobject_class->set_property = eek_xkb_layout_set_property; gobject_class->set_property = eek_xkb_layout_set_property;
@ -578,42 +553,38 @@ eek_xkb_layout_new (void)
* @names: XKB component names * @names: XKB component names
* *
* Set the XKB component names to @layout. * Set the XKB component names to @layout.
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if any of the component names changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkb_layout_set_names (EekXkbLayout *layout, XkbComponentNamesRec *names) eek_xkb_layout_set_names (EekXkbLayout *layout, XkbComponentNamesRec *names)
{ {
EekXkbLayoutPrivate *priv = EEK_XKB_LAYOUT_GET_PRIVATE (layout); EekXkbLayoutPrivate *priv = EEK_XKB_LAYOUT_GET_PRIVATE (layout);
gboolean is_changed; gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
/* keycodes */ if (g_strcmp0 (names->keycodes, priv->names.keycodes)) {
if (compare_component_name (names->keycodes, priv->names.keycodes) != 0)
is_changed = TRUE;
g_free (priv->names.keycodes); g_free (priv->names.keycodes);
priv->names.keycodes = g_strdup (names->keycodes); priv->names.keycodes = g_strdup (names->keycodes);
retval = TRUE;
}
/* geometry */ if (g_strcmp0 (names->geometry, priv->names.geometry)) {
if (compare_component_name (names->geometry, priv->names.geometry) != 0)
is_changed = TRUE;
g_free (priv->names.geometry); g_free (priv->names.geometry);
priv->names.geometry = g_strdup (names->geometry); priv->names.geometry = g_strdup (names->geometry);
retval = TRUE;
}
/* symbols */ if (g_strcmp0 (names->symbols, priv->names.symbols)) {
if (compare_component_name (names->symbols, priv->names.symbols) != 0)
is_changed = TRUE;
g_free (priv->names.symbols); g_free (priv->names.symbols);
priv->names.symbols = g_strdup (names->symbols); priv->names.symbols = g_strdup (names->symbols);
retval = TRUE;
}
get_keyboard (layout); get_keyboard (layout);
if (!priv->xkb) g_assert (priv->xkb);
return FALSE;
if (is_changed) return retval;
g_signal_emit_by_name (layout, "changed");
return TRUE;
} }
/** /**

View File

@ -74,17 +74,6 @@ extern void xkl_xkb_config_native_cleanup (XklEngine * engine,
static gboolean set_xkb_component_names (EekXklLayout *layout, static gboolean set_xkb_component_names (EekXklLayout *layout,
XklConfigRec *config); XklConfigRec *config);
static gint
eek_xkl_layout_real_get_group (EekLayout *self)
{
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (self);
XklState *state;
state = xkl_engine_get_current_state (priv->engine);
g_return_val_if_fail (state, -1);
return state->group;
}
static void static void
eek_xkl_layout_dispose (GObject *object) eek_xkl_layout_dispose (GObject *object)
{ {
@ -174,14 +163,11 @@ eek_xkl_layout_get_property (GObject *object,
static void static void
eek_xkl_layout_class_init (EekXklLayoutClass *klass) eek_xkl_layout_class_init (EekXklLayoutClass *klass)
{ {
EekLayoutClass *layout_class = EEK_LAYOUT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GParamSpec *pspec; GParamSpec *pspec;
g_type_class_add_private (gobject_class, sizeof (EekXklLayoutPrivate)); g_type_class_add_private (gobject_class, sizeof (EekXklLayoutPrivate));
layout_class->get_group = eek_xkl_layout_real_get_group;
gobject_class->dispose = eek_xkl_layout_dispose; gobject_class->dispose = eek_xkl_layout_dispose;
gobject_class->set_property = eek_xkl_layout_set_property; gobject_class->set_property = eek_xkl_layout_set_property;
gobject_class->get_property = eek_xkl_layout_get_property; gobject_class->get_property = eek_xkl_layout_get_property;
@ -290,7 +276,7 @@ merge_xkl_config_rec (XklConfigRec *dst, XklConfigRec *src)
* @config: Libxklavier configuration * @config: Libxklavier configuration
* *
* Reconfigure @layout with @config. * Reconfigure @layout with @config.
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_set_config (EekXklLayout *layout, eek_xkl_layout_set_config (EekXklLayout *layout,
@ -298,18 +284,16 @@ eek_xkl_layout_set_config (EekXklLayout *layout,
{ {
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout); EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout);
XklConfigRec *c; XklConfigRec *c;
gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
c = xkl_config_rec_new (); c = xkl_config_rec_new ();
merge_xkl_config_rec (c, priv->config); merge_xkl_config_rec (c, priv->config);
merge_xkl_config_rec (c, config); merge_xkl_config_rec (c, config);
if (set_xkb_component_names (layout, c)) { retval = set_xkb_component_names (layout, c);
g_object_unref (c); g_object_unref (c);
merge_xkl_config_rec (priv->config, config); merge_xkl_config_rec (priv->config, config);
return TRUE; return retval;
}
g_object_unref (c);
return FALSE;
} }
/** /**
@ -326,7 +310,7 @@ eek_xkl_layout_set_config (EekXklLayout *layout,
* XklConfigRec, which is not currently available in the * XklConfigRec, which is not currently available in the
* gobject-introspection repository. * gobject-introspection repository.
* *
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
* Since: 0.0.2 * Since: 0.0.2
*/ */
gboolean gboolean
@ -337,16 +321,16 @@ eek_xkl_layout_set_config_full (EekXklLayout *layout,
gchar **options) gchar **options)
{ {
XklConfigRec *config; XklConfigRec *config;
gboolean success; gboolean retval;
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
config->model = g_strdup (model); config->model = g_strdup (model);
config->layouts = g_strdupv (layouts); config->layouts = g_strdupv (layouts);
config->variants = g_strdupv (variants); config->variants = g_strdupv (variants);
config->options = g_strdupv (options); config->options = g_strdupv (options);
success = eek_xkl_layout_set_config (layout, config); retval = eek_xkl_layout_set_config (layout, config);
g_object_unref (config); g_object_unref (config);
return success; return retval;
} }
/** /**
@ -355,7 +339,7 @@ eek_xkl_layout_set_config_full (EekXklLayout *layout,
* @model: model name * @model: model name
* *
* Set the model name of @layout configuration (in the Libxklavier terminology). * Set the model name of @layout configuration (in the Libxklavier terminology).
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_set_model (EekXklLayout *layout, eek_xkl_layout_set_model (EekXklLayout *layout,
@ -363,7 +347,7 @@ eek_xkl_layout_set_model (EekXklLayout *layout,
{ {
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout); EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout);
XklConfigRec *config; XklConfigRec *config;
gboolean success; gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
@ -372,9 +356,9 @@ eek_xkl_layout_set_model (EekXklLayout *layout,
config->model = g_strdup (model); config->model = g_strdup (model);
else else
config->model = NULL; config->model = NULL;
success = eek_xkl_layout_set_config (layout, config); retval = eek_xkl_layout_set_config (layout, config);
g_object_unref (config); g_object_unref (config);
return success; return retval;
} }
/** /**
@ -383,7 +367,7 @@ eek_xkl_layout_set_model (EekXklLayout *layout,
* @layouts: layout names * @layouts: layout names
* *
* Set the layout names of @layout (in the Libxklavier terminology). * Set the layout names of @layout (in the Libxklavier terminology).
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_set_layouts (EekXklLayout *layout, eek_xkl_layout_set_layouts (EekXklLayout *layout,
@ -391,7 +375,7 @@ eek_xkl_layout_set_layouts (EekXklLayout *layout,
{ {
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout); EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout);
XklConfigRec *config; XklConfigRec *config;
gboolean success; gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
@ -400,9 +384,9 @@ eek_xkl_layout_set_layouts (EekXklLayout *layout,
config->layouts = g_strdupv (layouts); config->layouts = g_strdupv (layouts);
else else
config->layouts = layouts; config->layouts = layouts;
success = eek_xkl_layout_set_config (layout, config); retval = eek_xkl_layout_set_config (layout, config);
g_object_unref (config); g_object_unref (config);
return success; return retval;
} }
/** /**
@ -411,7 +395,7 @@ eek_xkl_layout_set_layouts (EekXklLayout *layout,
* @variants: variant names * @variants: variant names
* *
* Set the variant names of @layout (in the Libxklavier terminology). * Set the variant names of @layout (in the Libxklavier terminology).
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_set_variants (EekXklLayout *layout, eek_xkl_layout_set_variants (EekXklLayout *layout,
@ -419,7 +403,7 @@ eek_xkl_layout_set_variants (EekXklLayout *layout,
{ {
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout); EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout);
XklConfigRec *config; XklConfigRec *config;
gboolean success; gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
@ -428,9 +412,9 @@ eek_xkl_layout_set_variants (EekXklLayout *layout,
config->variants = g_strdupv (variants); config->variants = g_strdupv (variants);
else else
config->variants = NULL; config->variants = NULL;
success = eek_xkl_layout_set_config (layout, config); retval = eek_xkl_layout_set_config (layout, config);
g_object_unref (config); g_object_unref (config);
return success; return retval;
} }
/** /**
@ -439,7 +423,7 @@ eek_xkl_layout_set_variants (EekXklLayout *layout,
* @options: option names * @options: option names
* *
* Set the option names of @layout (in the Libxklavier terminology). * Set the option names of @layout (in the Libxklavier terminology).
* Returns: %TRUE if the component name is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_set_options (EekXklLayout *layout, eek_xkl_layout_set_options (EekXklLayout *layout,
@ -447,7 +431,7 @@ eek_xkl_layout_set_options (EekXklLayout *layout,
{ {
EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout); EekXklLayoutPrivate *priv = EEK_XKL_LAYOUT_GET_PRIVATE (layout);
XklConfigRec *config; XklConfigRec *config;
gboolean success; gboolean retval;
g_return_val_if_fail (priv, FALSE); g_return_val_if_fail (priv, FALSE);
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
@ -456,9 +440,9 @@ eek_xkl_layout_set_options (EekXklLayout *layout,
config->options = options; config->options = options;
else else
config->options = NULL; config->options = NULL;
success = eek_xkl_layout_set_config (layout, config); retval = eek_xkl_layout_set_config (layout, config);
g_object_unref (config); g_object_unref (config);
return success; return retval;
} }
/** /**
@ -467,7 +451,7 @@ eek_xkl_layout_set_options (EekXklLayout *layout,
* @option: option name * @option: option name
* *
* Set the option of @layout (in the Libxklavier terminology). * Set the option of @layout (in the Libxklavier terminology).
* Returns: %TRUE if the option is successfully set, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_enable_option (EekXklLayout *layout, eek_xkl_layout_enable_option (EekXklLayout *layout,
@ -494,7 +478,7 @@ eek_xkl_layout_enable_option (EekXklLayout *layout,
* @option: option name * @option: option name
* *
* Unset the option of @layout (in the Libxklavier terminology). * Unset the option of @layout (in the Libxklavier terminology).
* Returns: %TRUE if the option is successfully unset, %FALSE otherwise * Returns: %TRUE if the current layout changed, %FALSE otherwise
*/ */
gboolean gboolean
eek_xkl_layout_disable_option (EekXklLayout *layout, eek_xkl_layout_disable_option (EekXklLayout *layout,
@ -588,7 +572,7 @@ set_xkb_component_names (EekXklLayout *layout, XklConfigRec *config)
{ {
EekXklLayoutPrivate *priv = layout->priv; EekXklLayoutPrivate *priv = layout->priv;
XkbComponentNamesRec names; XkbComponentNamesRec names;
gboolean success = FALSE; gboolean retval = FALSE;
#if DEBUG #if DEBUG
if (config->layouts) { if (config->layouts) {
@ -620,16 +604,11 @@ set_xkb_component_names (EekXklLayout *layout, XklConfigRec *config)
fprintf (stderr, "options = NULL\n"); fprintf (stderr, "options = NULL\n");
#endif #endif
/* Disabled since the current EekXklLayout implementation does not
change the server setting. */
#if 0
xkl_config_rec_activate (priv->engine, config);
#endif
if (xkl_xkb_config_native_prepare (priv->engine, config, &names)) { if (xkl_xkb_config_native_prepare (priv->engine, config, &names)) {
success = eek_xkb_layout_set_names (EEK_XKB_LAYOUT(layout), &names); retval = eek_xkb_layout_set_names (EEK_XKB_LAYOUT(layout), &names);
xkl_xkb_config_native_cleanup (priv->engine, &names); xkl_xkb_config_native_cleanup (priv->engine, &names);
} }
return success; return retval;
} }
/** /**

View File

@ -79,7 +79,6 @@ struct _Eekboard {
GConfClient *gconfc; GConfClient *gconfc;
Accessible *acc; Accessible *acc;
GtkWidget *widget, *window, *combo; GtkWidget *widget, *window, *combo;
gint width, height;
XklEngine *engine; XklEngine *engine;
XklConfigRegistry *registry; XklConfigRegistry *registry;
GtkUIManager *ui_manager; GtkUIManager *ui_manager;
@ -103,7 +102,6 @@ struct _Eekboard {
GtkActionGroup *options_action_group; GtkActionGroup *options_action_group;
EekKeyboard *keyboard; EekKeyboard *keyboard;
EekLayout *layout; /* FIXME: eek_keyboard_get_layout() */
}; };
typedef struct _Eekboard Eekboard; typedef struct _Eekboard Eekboard;
@ -141,9 +139,8 @@ static void on_about (GtkAction *action,
static void on_quit_from_menu (GtkAction * action, static void on_quit_from_menu (GtkAction * action,
GtkWidget *window); GtkWidget *window);
static void eekboard_free (Eekboard *eekboard); static void eekboard_free (Eekboard *eekboard);
static GtkWidget *create_widget (Eekboard *eekboard, static void create_widget (Eekboard *eekboard);
gint initial_width, static void update_widget (Eekboard *eekboard);
gint initial_height);
static const char ui_description[] = static const char ui_description[] =
"<ui>" "<ui>"
@ -461,8 +458,9 @@ on_config_activate (GtkAction *action,
gpointer user_data) gpointer user_data)
{ {
SetConfigCallbackData *data = user_data; SetConfigCallbackData *data = user_data;
eek_xkl_layout_set_config (EEK_XKL_LAYOUT(data->eekboard->layout), EekLayout *layout = eek_keyboard_get_layout (data->eekboard->keyboard);
data->config); if (eek_xkl_layout_set_config (EEK_XKL_LAYOUT(layout), data->config))
update_widget (data->eekboard);
} }
static void static void
@ -470,29 +468,41 @@ on_option_toggled (GtkToggleAction *action,
gpointer user_data) gpointer user_data)
{ {
SetConfigCallbackData *data = user_data; SetConfigCallbackData *data = user_data;
if (gtk_toggle_action_get_active (action)) EekLayout *layout = eek_keyboard_get_layout (data->eekboard->keyboard);
eek_xkl_layout_enable_option (EEK_XKL_LAYOUT(data->eekboard->layout),
data->config->options[0]); if (gtk_toggle_action_get_active (action)) {
else if (eek_xkl_layout_enable_option (EEK_XKL_LAYOUT(layout),
eek_xkl_layout_disable_option (EEK_XKL_LAYOUT(data->eekboard->layout), data->config->options[0]))
data->config->options[0]); update_widget (data->eekboard);
} else {
if (eek_xkl_layout_disable_option (EEK_XKL_LAYOUT(layout),
data->config->options[0]))
update_widget (data->eekboard);
}
} }
static void static void
on_changed (EekLayout *layout, gpointer user_data) update_widget (Eekboard *eekboard)
{ {
Eekboard *eekboard = user_data; GtkWidget *vbox;
GtkWidget *vbox, *widget;
GtkAllocation allocation; GtkAllocation allocation;
EekLayout *layout;
EekKeyboard *keyboard;
gtk_widget_get_allocation (GTK_WIDGET (eekboard->widget), &allocation); gtk_widget_get_allocation (GTK_WIDGET (eekboard->widget), &allocation);
vbox = gtk_widget_get_parent (eekboard->widget); vbox = gtk_widget_get_parent (eekboard->widget);
/* gtk_widget_destroy() seems not usable for GtkClutterEmbed */ /* gtk_widget_destroy() seems not usable for GtkClutterEmbed */
gtk_container_remove (GTK_CONTAINER(vbox), eekboard->widget); gtk_container_remove (GTK_CONTAINER(vbox), eekboard->widget);
layout = eek_keyboard_get_layout (eekboard->keyboard);
keyboard = eek_keyboard_new (layout, allocation.width, allocation.height);
eek_keyboard_set_modifier_behavior (keyboard,
EEK_MODIFIER_BEHAVIOR_LATCH);
g_object_unref (eekboard->keyboard); g_object_unref (eekboard->keyboard);
widget = create_widget (eekboard, allocation.width, allocation.height); eekboard->keyboard = keyboard;
gtk_container_add (GTK_CONTAINER(vbox), widget);
create_widget (eekboard);
gtk_container_add (GTK_CONTAINER(vbox), eekboard->widget);
gtk_widget_show_all (vbox); gtk_widget_show_all (vbox);
} }
@ -1027,26 +1037,8 @@ on_allocation_changed (ClutterActor *stage,
} }
#endif #endif
static EekKeyboard * static void
create_keyboard (Eekboard *eekboard, create_widget (Eekboard *eekboard)
gint initial_width,
gint initial_height)
{
EekKeyboard *keyboard;
keyboard = eek_keyboard_new (eekboard->layout,
initial_width,
initial_height);
eek_keyboard_set_modifier_behavior (keyboard,
EEK_MODIFIER_BEHAVIOR_LATCH);
return keyboard;
}
static GtkWidget *
create_widget (Eekboard *eekboard,
gint initial_width,
gint initial_height)
{ {
#if HAVE_CLUTTER_GTK #if HAVE_CLUTTER_GTK
ClutterActor *stage; ClutterActor *stage;
@ -1054,9 +1046,6 @@ create_widget (Eekboard *eekboard,
#endif #endif
EekBounds bounds; EekBounds bounds;
eekboard->keyboard = create_keyboard (eekboard,
initial_width,
initial_height);
eekboard->on_key_pressed_id = eekboard->on_key_pressed_id =
g_signal_connect (eekboard->keyboard, "key-pressed", g_signal_connect (eekboard->keyboard, "key-pressed",
G_CALLBACK(on_key_pressed), eekboard); G_CALLBACK(on_key_pressed), eekboard);
@ -1085,9 +1074,7 @@ create_widget (Eekboard *eekboard,
eekboard->widget = eek_gtk_keyboard_new (eekboard->keyboard); eekboard->widget = eek_gtk_keyboard_new (eekboard->keyboard);
#endif #endif
eekboard->width = bounds.width; gtk_widget_set_size_request (eekboard->widget, bounds.width, bounds.height);
eekboard->height = bounds.height;
return eekboard->widget;
} }
static void static void
@ -1140,16 +1127,13 @@ on_xkl_state_changed (XklEngine *xklengine,
gboolean restore, gboolean restore,
gpointer user_data) gpointer user_data)
{ {
Eekboard *eekboard = user_data;
if (type == GROUP_CHANGED)
g_signal_emit_by_name (eekboard->layout, "group_changed", value);
} }
Eekboard * Eekboard *
eekboard_new (gboolean accessibility_enabled) eekboard_new (gboolean accessibility_enabled)
{ {
Eekboard *eekboard; Eekboard *eekboard;
EekLayout *layout;
eekboard = g_slice_new0 (Eekboard); eekboard = g_slice_new0 (Eekboard);
eekboard->accessibility_enabled = accessibility_enabled; eekboard->accessibility_enabled = accessibility_enabled;
@ -1168,44 +1152,33 @@ eekboard_new (gboolean accessibility_enabled)
return NULL; return NULL;
} }
eekboard->layout = eek_xkl_layout_new (); layout = eek_xkl_layout_new ();
if (!eekboard->layout) { if (!layout) {
g_slice_free (Eekboard, eekboard); g_slice_free (Eekboard, eekboard);
g_warning ("Can't create layout"); g_warning ("Can't create layout");
return NULL; return NULL;
} }
if (opt_model) if (opt_model)
eek_xkl_layout_set_model (EEK_XKL_LAYOUT(eekboard->layout), opt_model); eek_xkl_layout_set_model (EEK_XKL_LAYOUT(layout), opt_model);
if (opt_layouts) { if (opt_layouts) {
XklConfigRec *rec = xkl_config_rec_new (); XklConfigRec *rec = xkl_config_rec_new ();
parse_layouts (rec, opt_layouts); parse_layouts (rec, opt_layouts);
eek_xkl_layout_set_layouts (EEK_XKL_LAYOUT(eekboard->layout), eek_xkl_layout_set_layouts (EEK_XKL_LAYOUT(layout), rec->layouts);
rec->layouts); eek_xkl_layout_set_variants (EEK_XKL_LAYOUT(layout), rec->variants);
eek_xkl_layout_set_variants (EEK_XKL_LAYOUT(eekboard->layout),
rec->variants);
g_object_unref (rec); g_object_unref (rec);
} }
if (opt_options) { if (opt_options) {
gchar **options; gchar **options;
options = g_strsplit (opt_options, ",", -1); options = g_strsplit (opt_options, ",", -1);
eek_xkl_layout_set_options (EEK_XKL_LAYOUT(eekboard->layout), options); eek_xkl_layout_set_options (EEK_XKL_LAYOUT(layout), options);
g_strfreev (options); g_strfreev (options);
} }
if (opt_xml) {
EekKeyboard *keyboard;
GString *output;
output = g_string_sized_new (BUFSIZ); eekboard->keyboard = eek_keyboard_new (layout, CSW, CSH);
keyboard = create_keyboard (eekboard, CSW, CSH); eek_keyboard_set_modifier_behavior (eekboard->keyboard,
eek_keyboard_output (keyboard, output, 0); EEK_MODIFIER_BEHAVIOR_LATCH);
fwrite (output->str, output->len, 1, stdout);
g_string_free (output, TRUE);
exit (0);
}
g_signal_connect (eekboard->layout, "changed",
G_CALLBACK(on_changed), eekboard);
eekboard->ui_manager = gtk_ui_manager_new (); eekboard->ui_manager = gtk_ui_manager_new ();
eekboard->engine = xkl_engine_get_instance (eekboard->display); eekboard->engine = xkl_engine_get_instance (eekboard->display);
@ -1230,12 +1203,8 @@ eekboard_new (gboolean accessibility_enabled)
static void static void
eekboard_free (Eekboard *eekboard) eekboard_free (Eekboard *eekboard)
{ {
if (eekboard->layout)
g_object_unref (eekboard->layout);
#if 0
if (eekboard->keyboard) if (eekboard->keyboard)
g_object_unref (eekboard->keyboard); g_object_unref (eekboard->keyboard);
#endif
if (eekboard->registry) if (eekboard->registry)
g_object_unref (eekboard->registry); g_object_unref (eekboard->registry);
if (eekboard->engine) if (eekboard->engine)
@ -1333,33 +1302,34 @@ on_layout_changed (GtkComboBox *combo,
if (eekboard->active_config != active) { if (eekboard->active_config != active) {
XklConfigRec *config, *config_base = eekboard->config[active]->rec; XklConfigRec *config, *config_base = eekboard->config[active]->rec;
EekLayout *layout;
layout = eek_keyboard_get_layout (eekboard->keyboard);
config = xkl_config_rec_new (); config = xkl_config_rec_new ();
if (config_base->model) if (config_base->model)
config->model = g_strdup (config_base->model); config->model = g_strdup (config_base->model);
else else
config->model = config->model = eek_xkl_layout_get_model (EEK_XKL_LAYOUT(layout));
eek_xkl_layout_get_model (EEK_XKL_LAYOUT(eekboard->layout));
if (config_base->layouts) if (config_base->layouts)
config->layouts = g_strdupv (config_base->layouts); config->layouts = g_strdupv (config_base->layouts);
else else
config->layouts = config->layouts =
eek_xkl_layout_get_layouts (EEK_XKL_LAYOUT(eekboard->layout)); eek_xkl_layout_get_layouts (EEK_XKL_LAYOUT(layout));
if (config_base->variants) if (config_base->variants)
config->variants = g_strdupv (config_base->variants); config->variants = g_strdupv (config_base->variants);
else else
config->variants = config->variants =
eek_xkl_layout_get_variants (EEK_XKL_LAYOUT(eekboard->layout)); eek_xkl_layout_get_variants (EEK_XKL_LAYOUT(layout));
if (config_base->options) if (config_base->options)
config->options = g_strdupv (config_base->options); config->options = g_strdupv (config_base->options);
else else
config->options = config->options =
eek_xkl_layout_get_options (EEK_XKL_LAYOUT(eekboard->layout)); eek_xkl_layout_get_options (EEK_XKL_LAYOUT(layout));
eek_xkl_layout_set_config (EEK_XKL_LAYOUT(eekboard->layout), config); eek_xkl_layout_set_config (EEK_XKL_LAYOUT(layout), config);
g_object_unref (config); g_object_unref (config);
eekboard->active_config = active; eekboard->active_config = active;
@ -1445,7 +1415,7 @@ main (int argc, char *argv[])
{ {
gboolean accessibility_enabled = FALSE; gboolean accessibility_enabled = FALSE;
Eekboard *eekboard; Eekboard *eekboard;
GtkWidget *widget, *vbox, *menubar, *window, *combo = NULL; GtkWidget *vbox, *menubar, *window, *combo = NULL;
GOptionContext *context; GOptionContext *context;
GConfClient *gconfc; GConfClient *gconfc;
GError *error; GError *error;
@ -1585,7 +1555,8 @@ main (int argc, char *argv[])
vbox = gtk_vbox_new (FALSE, 0); vbox = gtk_vbox_new (FALSE, 0);
g_object_set_data (G_OBJECT(window), "eekboard", eekboard); g_object_set_data (G_OBJECT(window), "eekboard", eekboard);
widget = create_widget (eekboard, CSW, CSH);
create_widget (eekboard);
if (!opt_popup) { if (!opt_popup) {
create_menus (eekboard, window); create_menus (eekboard, window);
@ -1618,12 +1589,11 @@ main (int argc, char *argv[])
eekboard); eekboard);
} }
gtk_container_add (GTK_CONTAINER(vbox), widget); gtk_container_add (GTK_CONTAINER(vbox), eekboard->widget);
gtk_container_add (GTK_CONTAINER(window), vbox); gtk_container_add (GTK_CONTAINER(window), vbox);
gtk_widget_set_size_request (widget, eekboard->width, eekboard->height);
gtk_widget_show_all (window); gtk_widget_show_all (window);
gtk_widget_set_size_request (widget, -1, -1); gtk_widget_set_size_request (eekboard->widget, -1, -1);
notify_init ("eekboard"); notify_init ("eekboard");
eekboard->window = window; eekboard->window = window;