From 7eead1c1ff3678d4bb7fcbc31953e7f37341556b Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Tue, 20 Mar 2012 13:28:41 +0900 Subject: [PATCH] Fix some mistakes. --- eek/eek-element.c | 12 +- eek/eek-gtk-renderer.c | 12 +- eek/eek-key.c | 6 +- eek/eek-keyboard.c | 258 ++++++------------------ eek/eek-keyboard.h | 6 +- eek/eek-renderer.c | 191 +++++++----------- eek/eek-section.c | 14 +- eek/eek-xkl-layout.c | 20 +- eekboard/eekboard-client.c | 23 +-- eekboard/eekboard-context-service.c | 299 +++++++++++++--------------- eekboard/eekboard-context.c | 180 +++++++---------- eekboard/eekboard-service.c | 129 ++++++------ src/client.c | 6 +- src/preferences-dialog.c | 2 +- tests/eek-xml-test.c | 30 +-- 15 files changed, 445 insertions(+), 743 deletions(-) diff --git a/eek/eek-element.c b/eek/eek-element.c index 1895161c..62a34d25 100644 --- a/eek/eek-element.c +++ b/eek/eek-element.c @@ -488,7 +488,9 @@ eek_element_set_group (EekElement *element, g_return_if_fail (EEK_IS_ELEMENT(element)); if (element->priv->group != group) { element->priv->group = group; - g_object_notify (element, "group"); + g_object_notify (G_OBJECT(element), "group"); + g_signal_emit (element, signals[SYMBOL_INDEX_CHANGED], 0, + group, element->priv->level); } } @@ -509,7 +511,9 @@ eek_element_set_level (EekElement *element, g_return_if_fail (EEK_IS_ELEMENT(element)); if (element->priv->level != level) { element->priv->level = level; - g_object_notify (element, "level"); + g_object_notify (G_OBJECT(element), "level"); + g_signal_emit (element, signals[SYMBOL_INDEX_CHANGED], 0, + element->priv->group, level); } } @@ -525,7 +529,7 @@ eek_element_set_level (EekElement *element, gint eek_element_get_group (EekElement *element) { - g_return_if_fail (EEK_IS_ELEMENT(element)); + g_return_val_if_fail (EEK_IS_ELEMENT(element), -1); return element->priv->group; } @@ -541,6 +545,6 @@ eek_element_get_group (EekElement *element) gint eek_element_get_level (EekElement *element) { - g_return_if_fail (EEK_IS_ELEMENT(element)); + g_return_val_if_fail (EEK_IS_ELEMENT(element), -1); return element->priv->level; } diff --git a/eek/eek-gtk-renderer.c b/eek/eek-gtk-renderer.c index a25d1f83..6904b430 100644 --- a/eek/eek-gtk-renderer.c +++ b/eek/eek-gtk-renderer.c @@ -97,12 +97,8 @@ eek_gtk_renderer_new (EekKeyboard *keyboard, PangoContext *pcontext, GtkWidget *widget) { - EekRenderer *renderer; - - renderer = g_object_new (EEK_TYPE_GTK_RENDERER, - "keyboard", keyboard, - "pango-context", pcontext, - NULL); - - return renderer; + return g_object_new (EEK_TYPE_GTK_RENDERER, + "keyboard", keyboard, + "pango-context", pcontext, + NULL); } diff --git a/eek/eek-key.c b/eek/eek-key.c index 6196a9cc..8596489c 100644 --- a/eek/eek-key.c +++ b/eek/eek-key.c @@ -590,11 +590,11 @@ eek_key_set_index (EekKey *key, if (key->priv->column != column) { key->priv->column = column; - g_object_notify (key, "column"); + g_object_notify (G_OBJECT(key), "column"); } if (key->priv->row != row) { key->priv->row = row; - g_object_notify (key, "row"); + g_object_notify (G_OBJECT(key), "row"); } } @@ -634,7 +634,7 @@ eek_key_set_oref (EekKey *key, g_return_if_fail (EEK_IS_KEY(key)); if (key->priv->oref != oref) { key->priv->oref = oref; - g_object_notify (key, "oref"); + g_object_notify (G_OBJECT(key), "oref"); } } diff --git a/eek/eek-keyboard.c b/eek/eek-keyboard.c index 23f732b6..6371dd27 100644 --- a/eek/eek-keyboard.c +++ b/eek/eek-keyboard.c @@ -79,7 +79,7 @@ on_key_pressed (EekSection *section, EekKey *key, EekKeyboard *keyboard) { - g_signal_emit_by_name (keyboard, "key-pressed", key); + g_signal_emit (keyboard, signals[KEY_PRESSED], 0, key); } static void @@ -87,7 +87,7 @@ on_key_released (EekSection *section, EekKey *key, EekKeyboard *keyboard) { - g_signal_emit_by_name (keyboard, "key-released", key); + g_signal_emit (keyboard, signals[KEY_RELEASED], 0, key); } static void @@ -95,7 +95,7 @@ on_key_locked (EekSection *section, EekKey *key, EekKeyboard *keyboard) { - g_signal_emit_by_name (keyboard, "key-locked", key); + g_signal_emit (keyboard, signals[KEY_LOCKED], 0, key); } static void @@ -103,7 +103,7 @@ on_key_unlocked (EekSection *section, EekKey *key, EekKeyboard *keyboard) { - g_signal_emit_by_name (keyboard, "key-unlocked", key); + g_signal_emit (keyboard, signals[KEY_UNLOCKED], 0, key); } static void @@ -111,7 +111,7 @@ on_key_cancelled (EekSection *section, EekKey *key, EekKeyboard *keyboard) { - g_signal_emit_by_name (keyboard, "key-cancelled", key); + g_signal_emit (keyboard, signals[KEY_CANCELLED], 0, key); } static void @@ -558,122 +558,12 @@ eek_keyboard_class_init (EekKeyboardClass *klass) static void eek_keyboard_init (EekKeyboard *self) { - EekKeyboardPrivate *priv; - - priv = self->priv = EEK_KEYBOARD_GET_PRIVATE(self); - priv->modifier_behavior = EEK_MODIFIER_BEHAVIOR_NONE; - priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline)); + self->priv = EEK_KEYBOARD_GET_PRIVATE(self); + self->priv->modifier_behavior = EEK_MODIFIER_BEHAVIOR_NONE; + self->priv->outline_array = g_array_new (FALSE, TRUE, sizeof (EekOutline)); eek_element_set_symbol_index (EEK_ELEMENT(self), 0, 0); } -/** - * eek_keyboard_set_symbol_index: - * @keyboard: an #EekKeyboard - * @group: row index of the symbol matrix of keys on @keyboard - * @level: column index of the symbol matrix of keys on @keyboard - * - * Set the default index of the symbol matrices of keys in @keyboard. - * To unset, pass -1 as group/level. - * - * Deprecated: 1.0: Use eek_element_set_symbol_index() - */ -void -eek_keyboard_set_symbol_index (EekKeyboard *keyboard, - gint group, - gint level) -{ - g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); - eek_element_set_symbol_index (EEK_ELEMENT(keyboard), group, level); -} - -/** - * eek_keyboard_get_symbol_index: - * @keyboard: an #EekKeyboard - * @group: a pointer where the group value of the symbol index will be stored - * @level: a pointer where the level value of the symbol index will be stored - * - * Get the default index of the symbol matrices of keys in @keyboard. - * If the index is not set, -1 will be returned. - * - * Deprecated: 1.0: Use eek_element_get_symbol_index() - */ -void -eek_keyboard_get_symbol_index (EekKeyboard *keyboard, - gint *group, - gint *level) -{ - g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); - eek_element_get_symbol_index(EEK_ELEMENT(keyboard), group, level); -} - -/** - * eek_keyboard_set_group: - * @keyboard: an #EekKeyboard - * @group: group index of @keyboard - * - * Set the group value of the default symbol index of @keyboard. To - * unset, pass -1 as @group. - * - * See also: eek_keyboard_set_symbol_index() - * Deprecated: 1.0: Use eek_element_set_group() - */ -void -eek_keyboard_set_group (EekKeyboard *keyboard, - gint group) -{ - eek_element_set_group (EEK_ELEMENT(keyboard), group); -} - -/** - * eek_keyboard_set_level: - * @keyboard: an #EekKeyboard - * @level: level index of @keyboard - * - * Set the level value of the default symbol index of @keyboard. To - * unset, pass -1 as @level. - * - * See also: eek_keyboard_set_symbol_index() - * Deprecated: 1.0: Use eek_element_set_level() - */ -void -eek_keyboard_set_level (EekKeyboard *keyboard, - gint level) -{ - eek_element_set_level (EEK_ELEMENT(keyboard), level); -} - -/** - * eek_keyboard_get_group: - * @keyboard: an #EekKeyboard - * - * Return the group value of the default symbol index of @keyboard. - * If the value is not set, -1 will be returned. - * - * See also: eek_keyboard_get_symbol_index() - * Deprecated: 1.0: Use eek_element_get_group() - */ -gint -eek_keyboard_get_group (EekKeyboard *keyboard) -{ - return eek_element_get_group (EEK_ELEMENT(keyboard)); -} - -/** - * eek_keyboard_get_level: - * @keyboard: an #EekKeyboard - * - * Return the level value of the default symbol index of @keyboard. - * If the value is not set, -1 will be returned. - * - * See also: eek_keyboard_get_symbol_index() - * Deprecated: 1.0: Use eek_element_get_level() - */ -gint -eek_keyboard_get_level (EekKeyboard *keyboard) -{ - return eek_element_get_level (EEK_ELEMENT(keyboard)); -} - /** * eek_keyboard_create_section: * @keyboard: an #EekKeyboard @@ -685,10 +575,8 @@ eek_keyboard_get_level (EekKeyboard *keyboard) EekSection * eek_keyboard_create_section (EekKeyboard *keyboard) { - EekSection *section; g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); - section = EEK_KEYBOARD_GET_CLASS(keyboard)->create_section (keyboard); - return section; + return EEK_KEYBOARD_GET_CLASS(keyboard)->create_section (keyboard); } /** @@ -703,7 +591,7 @@ EekKey * eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard, guint keycode) { - g_assert (EEK_IS_KEYBOARD(keyboard)); + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); return EEK_KEYBOARD_GET_CLASS(keyboard)-> find_key_by_keycode (keyboard, keycode); } @@ -718,11 +606,8 @@ eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard, EekLayout * eek_keyboard_get_layout (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - return priv->layout; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); + return keyboard->priv->layout; } /** @@ -740,7 +625,6 @@ eek_keyboard_get_size (EekKeyboard *keyboard, { EekBounds bounds; - g_assert (EEK_IS_KEYBOARD(keyboard)); eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds); *width = bounds.width; *height = bounds.height; @@ -757,12 +641,8 @@ void eek_keyboard_set_modifier_behavior (EekKeyboard *keyboard, EekModifierBehavior modifier_behavior) { - EekKeyboardPrivate *priv; - g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - priv->modifier_behavior = modifier_behavior; + keyboard->priv->modifier_behavior = modifier_behavior; } /** @@ -775,24 +655,16 @@ eek_keyboard_set_modifier_behavior (EekKeyboard *keyboard, EekModifierBehavior eek_keyboard_get_modifier_behavior (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->modifier_behavior; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); + return keyboard->priv->modifier_behavior; } void eek_keyboard_set_modifiers (EekKeyboard *keyboard, EekModifierType modifiers) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - priv->modifiers = modifiers; + g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); + keyboard->priv->modifiers = modifiers; set_level_from_modifiers (keyboard); } @@ -806,12 +678,8 @@ eek_keyboard_set_modifiers (EekKeyboard *keyboard, EekModifierType eek_keyboard_get_modifiers (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->modifiers; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); + return keyboard->priv->modifiers; } /** @@ -820,46 +688,56 @@ eek_keyboard_get_modifiers (EekKeyboard *keyboard) * @outline: an #EekOutline * * Register an outline of @keyboard. - * Returns: an unsigned long id of the registered outline, for later reference + * Returns: an unsigned integer ID of the registered outline, for + * later reference */ -gulong +guint eek_keyboard_add_outline (EekKeyboard *keyboard, EekOutline *outline) { - EekKeyboardPrivate *priv; EekOutline *_outline; - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); _outline = eek_outline_copy (outline); - g_array_append_val (priv->outline_array, *_outline); + g_array_append_val (keyboard->priv->outline_array, *_outline); /* don't use eek_outline_free here, so as to keep _outline->points */ g_slice_free (EekOutline, _outline); - return priv->outline_array->len; + return keyboard->priv->outline_array->len - 1; } /** * eek_keyboard_get_outline: * @keyboard: an #EekKeyboard - * @oref: an unsigned long id + * @oref: ID of the outline * * Get an outline associated with @oref in @keyboard. * Returns: an #EekOutline, which should not be released */ EekOutline * eek_keyboard_get_outline (EekKeyboard *keyboard, - gulong oref) + guint oref) { - EekKeyboardPrivate *priv; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - if (oref > priv->outline_array->len) + if (oref > keyboard->priv->outline_array->len) return NULL; - return &g_array_index (priv->outline_array, EekOutline, oref - 1); + return &g_array_index (keyboard->priv->outline_array, EekOutline, oref); +} + +/** + * eek_keyboard_get_n_outlines: + * @keyboard: an #EekKeyboard + * + * Get the number of outlines defined in @keyboard. + * Returns: integer + */ +gsize +eek_keyboard_get_n_outlines (EekKeyboard *keyboard) +{ + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); + return keyboard->priv->outline_array->len; } /** @@ -873,12 +751,8 @@ void eek_keyboard_set_num_lock_mask (EekKeyboard *keyboard, EekModifierType num_lock_mask) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - priv->num_lock_mask = num_lock_mask; + g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); + keyboard->priv->num_lock_mask = num_lock_mask; } /** @@ -891,12 +765,8 @@ eek_keyboard_set_num_lock_mask (EekKeyboard *keyboard, EekModifierType eek_keyboard_get_num_lock_mask (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->num_lock_mask; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); + return keyboard->priv->num_lock_mask; } /** @@ -910,12 +780,8 @@ void eek_keyboard_set_alt_gr_mask (EekKeyboard *keyboard, EekModifierType alt_gr_mask) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - priv->alt_gr_mask = alt_gr_mask; + g_return_if_fail (EEK_IS_KEYBOARD(keyboard)); + keyboard->priv->alt_gr_mask = alt_gr_mask; } /** @@ -928,12 +794,8 @@ eek_keyboard_set_alt_gr_mask (EekKeyboard *keyboard, EekModifierType eek_keyboard_get_alt_gr_mask (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->alt_gr_mask; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), 0); + return keyboard->priv->alt_gr_mask; } /** @@ -947,12 +809,8 @@ eek_keyboard_get_alt_gr_mask (EekKeyboard *keyboard) GList * eek_keyboard_get_pressed_keys (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->pressed_keys; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); + return keyboard->priv->pressed_keys; } /** @@ -966,10 +824,6 @@ eek_keyboard_get_pressed_keys (EekKeyboard *keyboard) GList * eek_keyboard_get_locked_keys (EekKeyboard *keyboard) { - EekKeyboardPrivate *priv; - - g_assert (EEK_IS_KEYBOARD(keyboard)); - priv = EEK_KEYBOARD_GET_PRIVATE(keyboard); - - return priv->locked_keys; + g_return_val_if_fail (EEK_IS_KEYBOARD(keyboard), NULL); + return keyboard->priv->locked_keys; } diff --git a/eek/eek-keyboard.h b/eek/eek-keyboard.h index cc820723..1e6315ac 100644 --- a/eek/eek-keyboard.h +++ b/eek/eek-keyboard.h @@ -156,13 +156,15 @@ EekKey *eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard, guint keycode); -gulong eek_keyboard_add_outline +guint eek_keyboard_add_outline (EekKeyboard *keyboard, EekOutline *outline); EekOutline *eek_keyboard_get_outline (EekKeyboard *keyboard, - gulong oref); + guint oref); +gsize eek_keyboard_get_n_outlines + (EekKeyboard *keyboard); void eek_keyboard_set_num_lock_mask (EekKeyboard *keyboard, diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 266266d9..29f27ea9 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -23,6 +23,7 @@ #endif /* HAVE_CONFIG_H */ #include +#include #include "eek-key.h" #include "eek-section.h" @@ -497,21 +498,25 @@ render_key (EekRenderer *self, cairo_surface_t *icon_surface = eek_renderer_get_icon_surface (self, eek_symbol_get_icon_name (symbol), - MIN(bounds.width, bounds.height)); + MIN(bounds.width, bounds.height) * 0.7); if (icon_surface) { gint width = cairo_image_surface_get_width (icon_surface); gint height = cairo_image_surface_get_height (icon_surface); gdouble scale; - if (height * bounds.width / width <= bounds.height) - scale = bounds.width / width; - else if (width * bounds.height / height <= bounds.width) - scale = bounds.height / height; + if (width < bounds.width && height < bounds.height) + scale = 1; else { - if (width * bounds.height < height * bounds.width) - scale = width / bounds.width; - else - scale = height / bounds.height; + if (height * bounds.width / width <= bounds.height) + scale = bounds.width / width; + else if (width * bounds.height / height <= bounds.width) + scale = bounds.height / height; + else { + if (width * bounds.height < height * bounds.width) + scale = width / bounds.width; + else + scale = height / bounds.height; + } } cairo_save (cr); @@ -861,17 +866,15 @@ eek_renderer_init (EekRenderer *self) static void invalidate (EekRenderer *renderer) { - EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(renderer); + if (renderer->priv->outline_surface_cache) + g_hash_table_remove_all (renderer->priv->outline_surface_cache); - if (priv->outline_surface_cache) - g_hash_table_remove_all (priv->outline_surface_cache); + if (renderer->priv->active_outline_surface_cache) + g_hash_table_remove_all (renderer->priv->active_outline_surface_cache); - if (priv->active_outline_surface_cache) - g_hash_table_remove_all (priv->active_outline_surface_cache); - - if (priv->keyboard_surface) { - cairo_surface_destroy (priv->keyboard_surface); - priv->keyboard_surface = NULL; + if (renderer->priv->keyboard_surface) { + cairo_surface_destroy (renderer->priv->keyboard_surface); + renderer->priv->keyboard_surface = NULL; } } @@ -889,14 +892,10 @@ EekRenderer * eek_renderer_new (EekKeyboard *keyboard, PangoContext *pcontext) { - EekRenderer *renderer; - - renderer = g_object_new (EEK_TYPE_RENDERER, - "keyboard", keyboard, - "pango-context", pcontext, - NULL); - - return renderer; + return g_object_new (EEK_TYPE_RENDERER, + "keyboard", keyboard, + "pango-context", pcontext, + NULL); } void @@ -904,19 +903,16 @@ eek_renderer_set_allocation_size (EekRenderer *renderer, gdouble width, gdouble height) { - EekRendererPrivate *priv; EekBounds bounds; gdouble scale; g_return_if_fail (EEK_IS_RENDERER(renderer)); g_return_if_fail (width > 0.0 && height > 0.0); - priv = EEK_RENDERER_GET_PRIVATE(renderer); + renderer->priv->allocation_width = width; + renderer->priv->allocation_height = height; - priv->allocation_width = width; - priv->allocation_height = height; - - eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds); + eek_element_get_bounds (EEK_ELEMENT(renderer->priv->keyboard), &bounds); if (bounds.height * width / bounds.width <= height) scale = width / bounds.width; @@ -929,8 +925,8 @@ eek_renderer_set_allocation_size (EekRenderer *renderer, scale = bounds.height / height; } - if (scale != priv->scale) { - priv->scale = scale; + if (scale != renderer->priv->scale) { + renderer->priv->scale = scale; invalidate (renderer); } } @@ -940,18 +936,15 @@ eek_renderer_get_size (EekRenderer *renderer, gdouble *width, gdouble *height) { - EekRendererPrivate *priv; EekBounds bounds; g_return_if_fail (EEK_IS_RENDERER(renderer)); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - - eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds); + eek_element_get_bounds (EEK_ELEMENT(renderer->priv->keyboard), &bounds); if (width) - *width = bounds.width * priv->scale; + *width = bounds.width * renderer->priv->scale; if (height) - *height = bounds.height * priv->scale; + *height = bounds.height * renderer->priv->scale; } void @@ -960,7 +953,6 @@ eek_renderer_get_key_bounds (EekRenderer *renderer, EekBounds *bounds, gboolean rotate) { - EekRendererPrivate *priv; EekElement *section; EekBounds section_bounds, keyboard_bounds; gint angle = 0; @@ -971,21 +963,20 @@ eek_renderer_get_key_bounds (EekRenderer *renderer, g_return_if_fail (EEK_IS_KEY(key)); g_return_if_fail (bounds != NULL); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - section = eek_element_get_parent (EEK_ELEMENT(key)); eek_element_get_bounds (EEK_ELEMENT(key), bounds); eek_element_get_bounds (section, §ion_bounds); - eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &keyboard_bounds); + eek_element_get_bounds (EEK_ELEMENT(renderer->priv->keyboard), + &keyboard_bounds); if (!rotate) { bounds->x += keyboard_bounds.x + section_bounds.x; bounds->y += keyboard_bounds.y + section_bounds.y; - bounds->x *= priv->scale; - bounds->y *= priv->scale; - bounds->width *= priv->scale; - bounds->height *= priv->scale; + bounds->x *= renderer->priv->scale; + bounds->y *= renderer->priv->scale; + bounds->width *= renderer->priv->scale; + bounds->height *= renderer->priv->scale; return; } points[0].x = bounds->x; @@ -1017,34 +1008,24 @@ eek_renderer_get_key_bounds (EekRenderer *renderer, bounds->y = keyboard_bounds.y + section_bounds.y + min.y; bounds->width = (max.x - min.x); bounds->height = (max.y - min.y); - bounds->x *= priv->scale; - bounds->y *= priv->scale; - bounds->width *= priv->scale; - bounds->height *= priv->scale; + bounds->x *= renderer->priv->scale; + bounds->y *= renderer->priv->scale; + bounds->width *= renderer->priv->scale; + bounds->height *= renderer->priv->scale; } gdouble eek_renderer_get_scale (EekRenderer *renderer) { - EekRendererPrivate *priv; - - g_assert (EEK_IS_RENDERER(renderer)); - - priv = EEK_RENDERER_GET_PRIVATE(renderer); - - return priv->scale; + g_return_val_if_fail (EEK_IS_RENDERER(renderer), 0); + return renderer->priv->scale; } PangoLayout * eek_renderer_create_pango_layout (EekRenderer *renderer) { - EekRendererPrivate *priv; - - g_assert (EEK_IS_RENDERER(renderer)); - - priv = EEK_RENDERER_GET_PRIVATE(renderer); - - return pango_layout_new (priv->pcontext); + g_return_val_if_fail (EEK_IS_RENDERER(renderer), NULL); + return pango_layout_new (renderer->priv->pcontext); } void @@ -1119,26 +1100,20 @@ void eek_renderer_set_default_foreground_color (EekRenderer *renderer, const EekColor *color) { - EekRendererPrivate *priv; - g_return_if_fail (EEK_IS_RENDERER(renderer)); g_return_if_fail (color); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - priv->default_foreground_color = *color; + memcpy (&renderer->priv->default_foreground_color, color, sizeof(EekColor)); } void eek_renderer_set_default_background_color (EekRenderer *renderer, const EekColor *color) { - EekRendererPrivate *priv; - g_return_if_fail (EEK_IS_RENDERER(renderer)); g_return_if_fail (color); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - priv->default_background_color = *color; + memcpy (&renderer->priv->default_background_color, color, sizeof(EekColor)); } void @@ -1146,19 +1121,17 @@ eek_renderer_get_foreground_color (EekRenderer *renderer, EekElement *element, EekColor *color) { - EekRendererPrivate *priv; EekThemeNode *theme_node; g_return_if_fail (EEK_IS_RENDERER(renderer)); g_return_if_fail (color); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - theme_node = g_object_get_data (G_OBJECT(element), "theme-node"); if (theme_node) eek_theme_node_get_foreground_color (theme_node, color); else - *color = priv->default_foreground_color; + memcpy (color, &renderer->priv->default_foreground_color, + sizeof(EekColor)); } void @@ -1166,19 +1139,17 @@ eek_renderer_get_background_color (EekRenderer *renderer, EekElement *element, EekColor *color) { - EekRendererPrivate *priv; EekThemeNode *theme_node; g_return_if_fail (EEK_IS_RENDERER(renderer)); g_return_if_fail (color); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - theme_node = g_object_get_data (G_OBJECT(element), "theme-node"); if (theme_node) eek_theme_node_get_background_color (theme_node, color); else - *color = priv->default_background_color; + memcpy (color, &renderer->priv->default_background_color, + sizeof(EekColor)); } void @@ -1225,13 +1196,10 @@ find_key_by_position_key_callback (EekElement *element, { FindKeyByPositionCallbackData *data = user_data; EekBounds bounds; - EekRendererPrivate *priv; EekPoint points[4]; gint i; gboolean b1, b2, b3; - priv = EEK_RENDERER_GET_PRIVATE(data->renderer); - eek_element_get_bounds (element, &bounds); points[0].x = bounds.x; @@ -1247,8 +1215,8 @@ find_key_by_position_key_callback (EekElement *element, eek_point_rotate (&points[i], data->angle); points[i].x += data->origin.x; points[i].y += data->origin.y; - points[i].x *= priv->scale; - points[i].y *= priv->scale; + points[i].x *= data->renderer->priv->scale; + points[i].y *= data->renderer->priv->scale; } b1 = sign (&data->point, &points[0], &points[1]) < 0.0; @@ -1298,19 +1266,17 @@ eek_renderer_find_key_by_position (EekRenderer *renderer, gdouble x, gdouble y) { - EekRendererPrivate *priv; EekBounds bounds; FindKeyByPositionCallbackData data; - g_assert (EEK_IS_RENDERER(renderer)); + g_return_val_if_fail (EEK_IS_RENDERER(renderer), NULL); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - eek_element_get_bounds (EEK_ELEMENT(priv->keyboard), &bounds); + eek_element_get_bounds (EEK_ELEMENT(renderer->priv->keyboard), &bounds); - if (x < bounds.x * priv->scale || - y < bounds.y * priv->scale || - x > bounds.width * priv->scale || - y > bounds.height * priv->scale) + if (x < bounds.x * renderer->priv->scale || + y < bounds.y * renderer->priv->scale || + x > bounds.width * renderer->priv->scale || + y > bounds.height * renderer->priv->scale) return NULL; data.point.x = x; @@ -1320,7 +1286,7 @@ eek_renderer_find_key_by_position (EekRenderer *renderer, data.key = NULL; data.renderer = renderer; - eek_container_find (EEK_CONTAINER(priv->keyboard), + eek_container_find (EEK_CONTAINER(renderer->priv->keyboard), find_key_by_position_section_callback, &data); return data.key; @@ -1338,14 +1304,11 @@ create_theme_node_key_callback (EekElement *element, gpointer user_data) { CreateThemeNodeData *data = user_data; - EekRendererPrivate *priv; EekThemeNode *theme_node; - priv = EEK_RENDERER_GET_PRIVATE(data->renderer); - theme_node = eek_theme_node_new (data->context, data->parent, - priv->theme, + data->renderer->priv->theme, EEK_TYPE_KEY, eek_element_get_name (element), "key", @@ -1358,7 +1321,7 @@ create_theme_node_key_callback (EekElement *element, theme_node = eek_theme_node_new (data->context, data->parent, - priv->theme, + data->renderer->priv->theme, EEK_TYPE_KEY, eek_element_get_name (element), "key", @@ -1375,14 +1338,11 @@ create_theme_node_section_callback (EekElement *element, gpointer user_data) { CreateThemeNodeData *data = user_data; - EekRendererPrivate *priv; EekThemeNode *theme_node, *parent; - priv = EEK_RENDERER_GET_PRIVATE(data->renderer); - theme_node = eek_theme_node_new (data->context, data->parent, - priv->theme, + data->renderer->priv->theme, EEK_TYPE_SECTION, eek_element_get_name (element), "section", @@ -1405,31 +1365,28 @@ void eek_renderer_set_theme (EekRenderer *renderer, EekTheme *theme) { - EekRendererPrivate *priv; EekThemeContext *theme_context; EekThemeNode *theme_node; CreateThemeNodeData data; - g_assert (EEK_IS_RENDERER(renderer)); - g_assert (EEK_IS_THEME(theme)); + g_return_if_fail (EEK_IS_RENDERER(renderer)); + g_return_if_fail (EEK_IS_THEME(theme)); + g_return_if_fail (renderer->priv->keyboard); - priv = EEK_RENDERER_GET_PRIVATE(renderer); - g_assert (priv->keyboard); - - if (priv->theme) - g_object_unref (priv->theme); - priv->theme = g_object_ref (theme); + if (renderer->priv->theme) + g_object_unref (renderer->priv->theme); + renderer->priv->theme = g_object_ref (theme); theme_context = eek_theme_context_new (); theme_node = eek_theme_node_new (theme_context, NULL, - priv->theme, + renderer->priv->theme, EEK_TYPE_KEYBOARD, "keyboard", "keyboard", NULL, NULL); - g_object_set_data_full (G_OBJECT(priv->keyboard), + g_object_set_data_full (G_OBJECT(renderer->priv->keyboard), "theme-node", theme_node, (GDestroyNotify)g_object_unref); @@ -1437,7 +1394,7 @@ eek_renderer_set_theme (EekRenderer *renderer, data.context = theme_context; data.parent = theme_node; data.renderer = renderer; - eek_container_foreach_child (EEK_CONTAINER(priv->keyboard), + eek_container_foreach_child (EEK_CONTAINER(renderer->priv->keyboard), create_theme_node_section_callback, &data); } diff --git a/eek/eek-section.c b/eek/eek-section.c index 02afefbf..868174ce 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -118,35 +118,35 @@ static void on_pressed (EekKey *key, EekSection *section) { - g_signal_emit_by_name (section, "key-pressed", key); + g_signal_emit (section, signals[KEY_PRESSED], 0, key); } static void on_released (EekKey *key, EekSection *section) { - g_signal_emit_by_name (section, "key-released", key); + g_signal_emit (section, signals[KEY_RELEASED], 0, key); } static void on_locked (EekKey *key, - EekSection *section) + EekSection *section) { - g_signal_emit_by_name (section, "key-locked", key); + g_signal_emit (section, signals[KEY_LOCKED], 0, key); } static void on_unlocked (EekKey *key, EekSection *section) { - g_signal_emit_by_name (section, "key-unlocked", key); + g_signal_emit (section, signals[KEY_UNLOCKED], 0, key); } static void on_cancelled (EekKey *key, EekSection *section) { - g_signal_emit_by_name (section, "key-cancelled", key); + g_signal_emit (section, signals[KEY_CANCELLED], 0, key); } static EekKey * @@ -488,7 +488,7 @@ eek_section_set_angle (EekSection *section, g_return_if_fail (EEK_IS_SECTION(section)); if (section->priv->angle != angle) { section->priv->angle = angle; - g_object_notify (section, "angle"); + g_object_notify (G_OBJECT(section), "angle"); } } diff --git a/eek/eek-xkl-layout.c b/eek/eek-xkl-layout.c index e498b0b2..9972c180 100644 --- a/eek/eek-xkl-layout.c +++ b/eek/eek-xkl-layout.c @@ -103,20 +103,16 @@ eek_xkl_layout_set_property (GObject *object, switch (prop_id) { case PROP_MODEL: - eek_xkl_layout_set_model (EEK_XKL_LAYOUT(object), - g_value_get_string (value)); + eek_xkl_layout_set_model (layout, g_value_get_string (value)); break; case PROP_LAYOUTS: - eek_xkl_layout_set_layouts (EEK_XKL_LAYOUT(object), - g_value_get_boxed (value)); + eek_xkl_layout_set_layouts (layout, g_value_get_boxed (value)); break; case PROP_VARIANTS: - eek_xkl_layout_set_variants (EEK_XKL_LAYOUT(object), - g_value_get_boxed (value)); + eek_xkl_layout_set_variants (layout, g_value_get_boxed (value)); break; case PROP_OPTIONS: - eek_xkl_layout_set_options (EEK_XKL_LAYOUT(object), - g_value_get_boxed (value)); + eek_xkl_layout_set_options (layout, g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -135,19 +131,19 @@ eek_xkl_layout_get_property (GObject *object, switch (prop_id) { case PROP_MODEL: g_value_set_string (value, - eek_xkl_layout_get_model (EEK_XKL_LAYOUT(object))); + eek_xkl_layout_get_model (layout)); break; case PROP_LAYOUTS: g_value_set_boxed (value, - eek_xkl_layout_get_layouts (EEK_XKL_LAYOUT(object))); + eek_xkl_layout_get_layouts (layout)); break; case PROP_VARIANTS: g_value_set_boxed (value, - eek_xkl_layout_get_variants (EEK_XKL_LAYOUT(object))); + eek_xkl_layout_get_variants (layout)); break; case PROP_OPTIONS: g_value_set_boxed (value, - eek_xkl_layout_get_options (EEK_XKL_LAYOUT(object))); + eek_xkl_layout_get_options (layout)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); diff --git a/eekboard/eekboard-client.c b/eekboard/eekboard-client.c index 75c72425..bc76e33f 100644 --- a/eekboard/eekboard-client.c +++ b/eekboard/eekboard-client.c @@ -115,10 +115,8 @@ eekboard_client_class_init (EekboardClientClass *klass) static void eekboard_client_init (EekboardClient *self) { - EekboardClientPrivate *priv; - - priv = self->priv = EEKBOARD_CLIENT_GET_PRIVATE(self); - priv->context_hash = + self->priv = EEKBOARD_CLIENT_GET_PRIVATE(self); + self->priv->context_hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, @@ -191,9 +189,7 @@ on_context_destroyed (EekboardContext *context, gpointer user_data) { EekboardClient *client = user_data; - EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(client); - - g_hash_table_remove (priv->context_hash, + g_hash_table_remove (client->priv->context_hash, g_dbus_proxy_get_object_path (G_DBUS_PROXY(context))); } @@ -215,7 +211,6 @@ eekboard_client_create_context (EekboardClient *client, GVariant *variant; const gchar *object_path; EekboardContext *context; - EekboardClientPrivate *priv; GError *error; GDBusConnection *connection; @@ -244,8 +239,7 @@ eekboard_client_create_context (EekboardClient *client, return NULL; } - priv = EEKBOARD_CLIENT_GET_PRIVATE(client); - g_hash_table_insert (priv->context_hash, + g_hash_table_insert (client->priv->context_hash, g_strdup (object_path), g_object_ref (context)); g_signal_connect (context, "destroyed", @@ -285,7 +279,6 @@ eekboard_client_push_context (EekboardClient *client, EekboardContext *context, GCancellable *cancellable) { - EekboardClientPrivate *priv; const gchar *object_path; g_return_if_fail (EEKBOARD_IS_CLIENT(client)); @@ -293,8 +286,8 @@ eekboard_client_push_context (EekboardClient *client, object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)); - priv = EEKBOARD_CLIENT_GET_PRIVATE(client); - context = g_hash_table_lookup (priv->context_hash, object_path); + context = g_hash_table_lookup (client->priv->context_hash, + object_path); if (!context) return; @@ -364,15 +357,13 @@ eekboard_client_destroy_context (EekboardClient *client, EekboardContext *context, GCancellable *cancellable) { - EekboardClientPrivate *priv; const gchar *object_path; g_return_if_fail (EEKBOARD_IS_CLIENT(client)); g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CLIENT_GET_PRIVATE(client); object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)); - g_hash_table_remove (priv->context_hash, object_path); + g_hash_table_remove (client->priv->context_hash, object_path); send_destroy_context (client, context, cancellable); } diff --git a/eekboard/eekboard-context-service.c b/eekboard/eekboard-context-service.c index df4cd076..46569f90 100644 --- a/eekboard/eekboard-context-service.c +++ b/eekboard/eekboard-context-service.c @@ -187,7 +187,7 @@ eekboard_context_service_real_create_keyboard (EekboardContextService *self, error = NULL; layout = eek_xml_layout_new (keyboard_type, &error); if (layout == NULL) { - g_warning ("can't create keyboard: %s", + g_warning ("can't create keyboard %s: %s", keyboard_type, error->message); g_error_free (error); return NULL; @@ -206,41 +206,40 @@ eekboard_context_service_set_property (GObject *object, GParamSpec *pspec) { EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object); - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); GDBusConnection *connection; gboolean was_visible; switch (prop_id) { case PROP_OBJECT_PATH: - if (priv->object_path) - g_free (priv->object_path); - priv->object_path = g_strdup (g_value_get_string (value)); + if (context->priv->object_path) + g_free (context->priv->object_path); + context->priv->object_path = g_value_dup_string (value); break; case PROP_CONNECTION: connection = g_value_get_object (value); - if (priv->connection) - g_object_unref (priv->connection); - priv->connection = g_object_ref (connection); + if (context->priv->connection) + g_object_unref (context->priv->connection); + context->priv->connection = g_object_ref (connection); break; case PROP_CLIENT_NAME: - if (priv->client_name) - g_free (priv->client_name); - priv->client_name = g_strdup (g_value_get_string (value)); + if (context->priv->client_name) + g_free (context->priv->client_name); + context->priv->client_name = g_value_dup_string (value); break; case PROP_KEYBOARD: - if (priv->keyboard) - g_object_unref (priv->keyboard); - priv->keyboard = g_value_get_object (value); + if (context->priv->keyboard) + g_object_unref (context->priv->keyboard); + context->priv->keyboard = g_value_get_object (value); break; case PROP_VISIBLE: - was_visible = priv->visible; - priv->visible = g_value_get_boolean (value); - if (was_visible != priv->visible) - emit_visibility_changed_signal (EEKBOARD_CONTEXT_SERVICE(object), - priv->visible); + was_visible = context->priv->visible; + context->priv->visible = g_value_get_boolean (value); + if (was_visible != context->priv->visible) + emit_visibility_changed_signal (context, + context->priv->visible); break; case PROP_FULLSCREEN: - priv->fullscreen = g_value_get_boolean (value); + context->priv->fullscreen = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -255,26 +254,25 @@ eekboard_context_service_get_property (GObject *object, GParamSpec *pspec) { EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object); - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); switch (prop_id) { case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); + g_value_set_string (value, context->priv->object_path); break; case PROP_CONNECTION: - g_value_set_object (value, priv->connection); + g_value_set_object (value, context->priv->connection); break; case PROP_CLIENT_NAME: - g_value_set_string (value, priv->client_name); + g_value_set_string (value, context->priv->client_name); break; case PROP_KEYBOARD: - g_value_set_object (value, priv->keyboard); + g_value_set_object (value, context->priv->keyboard); break; case PROP_VISIBLE: - g_value_set_boolean (value, priv->visible); + g_value_set_boolean (value, context->priv->visible); break; case PROP_FULLSCREEN: - g_value_set_boolean (value, priv->fullscreen); + g_value_set_boolean (value, context->priv->fullscreen); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -286,63 +284,61 @@ static void eekboard_context_service_dispose (GObject *object) { EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object); - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - if (priv->keyboard_hash) { - g_hash_table_destroy (priv->keyboard_hash); - priv->keyboard_hash = NULL; + if (context->priv->keyboard_hash) { + g_hash_table_destroy (context->priv->keyboard_hash); + context->priv->keyboard_hash = NULL; } - if (priv->connection) { - if (priv->registration_id > 0) { - g_dbus_connection_unregister_object (priv->connection, - priv->registration_id); - priv->registration_id = 0; + if (context->priv->connection) { + if (context->priv->registration_id > 0) { + g_dbus_connection_unregister_object (context->priv->connection, + context->priv->registration_id); + context->priv->registration_id = 0; } - g_object_unref (priv->connection); - priv->connection = NULL; + g_object_unref (context->priv->connection); + context->priv->connection = NULL; } - if (priv->introspection_data) { - g_dbus_node_info_unref (priv->introspection_data); - priv->introspection_data = NULL; + if (context->priv->introspection_data) { + g_dbus_node_info_unref (context->priv->introspection_data); + context->priv->introspection_data = NULL; } - G_OBJECT_CLASS (eekboard_context_service_parent_class)->dispose (object); + G_OBJECT_CLASS (eekboard_context_service_parent_class)-> + dispose (object); } static void eekboard_context_service_finalize (GObject *object) { EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object); - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - g_free (priv->object_path); - g_free (priv->client_name); + g_free (context->priv->object_path); + g_free (context->priv->client_name); - G_OBJECT_CLASS (eekboard_context_service_parent_class)->finalize (object); + G_OBJECT_CLASS (eekboard_context_service_parent_class)-> + finalize (object); } static void eekboard_context_service_constructed (GObject *object) { EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE (object); - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - if (priv->connection && priv->object_path) { + if (context->priv->connection && context->priv->object_path) { GError *error = NULL; - - priv->registration_id = g_dbus_connection_register_object - (priv->connection, - priv->object_path, - priv->introspection_data->interfaces[0], + context->priv->registration_id = g_dbus_connection_register_object + (context->priv->connection, + context->priv->object_path, + context->priv->introspection_data->interfaces[0], &interface_vtable, context, NULL, &error); - if (priv->registration_id == 0) { + if (context->priv->registration_id == 0) { g_warning ("failed to register context object: %s", error->message); g_error_free (error); @@ -489,57 +485,53 @@ eekboard_context_service_class_init (EekboardContextServiceClass *klass) } static void -eekboard_context_service_init (EekboardContextService *context) +eekboard_context_service_init (EekboardContextService *self) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); GError *error; + self->priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(self); error = NULL; - priv->introspection_data = + self->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error); - if (priv->introspection_data == NULL) { + if (self->priv->introspection_data == NULL) { g_warning ("failed to parse D-Bus XML: %s", error->message); g_error_free (error); g_assert_not_reached (); } - priv->keyboard_hash = + self->priv->keyboard_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref); - priv->settings = g_settings_new ("org.fedorahosted.eekboard"); + self->priv->settings = g_settings_new ("org.fedorahosted.eekboard"); } static void disconnect_keyboard_signals (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - if (g_signal_handler_is_connected (priv->keyboard, - priv->key_pressed_handler)) - g_signal_handler_disconnect (priv->keyboard, - priv->key_pressed_handler); - if (g_signal_handler_is_connected (priv->keyboard, - priv->key_released_handler)) - g_signal_handler_disconnect (priv->keyboard, - priv->key_released_handler); + if (g_signal_handler_is_connected (context->priv->keyboard, + context->priv->key_pressed_handler)) + g_signal_handler_disconnect (context->priv->keyboard, + context->priv->key_pressed_handler); + if (g_signal_handler_is_connected (context->priv->keyboard, + context->priv->key_released_handler)) + g_signal_handler_disconnect (context->priv->keyboard, + context->priv->key_released_handler); } static void emit_visibility_changed_signal (EekboardContextService *context, gboolean visible) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - if (priv->connection && priv->enabled) { + if (context->priv->connection && context->priv->enabled) { GError *error = NULL; gboolean retval; - retval = g_dbus_connection_emit_signal (priv->connection, + retval = g_dbus_connection_emit_signal (context->priv->connection, NULL, - priv->object_path, + context->priv->object_path, EEKBOARD_CONTEXT_SERVICE_INTERFACE, "VisibilityChanged", g_variant_new ("(b)", visible), @@ -557,15 +549,13 @@ static void emit_group_changed_signal (EekboardContextService *context, gint group) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - if (priv->connection && priv->enabled) { + if (context->priv->connection && context->priv->enabled) { GError *error = NULL; gboolean retval; - retval = g_dbus_connection_emit_signal (priv->connection, + retval = g_dbus_connection_emit_signal (context->priv->connection, NULL, - priv->object_path, + context->priv->object_path, EEKBOARD_CONTEXT_SERVICE_INTERFACE, "GroupChanged", g_variant_new ("(i)", group), @@ -583,12 +573,10 @@ static void emit_key_activated_dbus_signal (EekboardContextService *context, EekKey *key) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - if (priv->connection && priv->enabled) { + if (context->priv->connection && context->priv->enabled) { const gchar *keyname = eek_element_get_name (EEK_ELEMENT(key)); EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0); - guint modifiers = eek_keyboard_get_modifiers (priv->keyboard); + guint modifiers = eek_keyboard_get_modifiers (context->priv->keyboard); GVariant *variant; GError *error; gboolean retval; @@ -596,9 +584,9 @@ emit_key_activated_dbus_signal (EekboardContextService *context, variant = eek_serializable_serialize (EEK_SERIALIZABLE(symbol)); error = NULL; - retval = g_dbus_connection_emit_signal (priv->connection, + retval = g_dbus_connection_emit_signal (context->priv->connection, NULL, - priv->object_path, + context->priv->object_path, EEKBOARD_CONTEXT_SERVICE_INTERFACE, "KeyActivated", g_variant_new ("(svu)", @@ -606,7 +594,6 @@ emit_key_activated_dbus_signal (EekboardContextService *context, variant, modifiers), &error); - g_variant_unref (variant); if (!retval) { g_warning ("failed to emit KeyActivated signal: %s", error->message); @@ -621,14 +608,13 @@ static gboolean on_repeat_timeout (EekboardContextService *context); static gboolean on_repeat_timeout (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); guint delay; - g_settings_get (priv->settings, "repeat-interval", "u", &delay); + g_settings_get (context->priv->settings, "repeat-interval", "u", &delay); - emit_key_activated_dbus_signal (context, priv->repeat_key); + emit_key_activated_dbus_signal (context, context->priv->repeat_key); - priv->repeat_timeout_id = + context->priv->repeat_timeout_id = g_timeout_add (delay, (GSourceFunc)on_repeat_timeout, context); @@ -639,25 +625,23 @@ on_repeat_timeout (EekboardContextService *context) static gboolean on_repeat_timeout_init (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - emit_key_activated_dbus_signal (context, priv->repeat_key); + emit_key_activated_dbus_signal (context, context->priv->repeat_key); /* FIXME: clear modifiers for further key repeat; better not depend on modifier behavior is LATCH */ - eek_keyboard_set_modifiers (priv->keyboard, 0); + eek_keyboard_set_modifiers (context->priv->keyboard, 0); /* reschedule repeat timeout only when "repeat" option is set */ - if (g_settings_get_boolean (priv->settings, "repeat")) { + if (g_settings_get_boolean (context->priv->settings, "repeat")) { guint delay; - g_settings_get (priv->settings, "repeat-interval", "u", &delay); - priv->repeat_timeout_id = + g_settings_get (context->priv->settings, "repeat-interval", "u", &delay); + context->priv->repeat_timeout_id = g_timeout_add (delay, (GSourceFunc)on_repeat_timeout, context); } else - priv->repeat_timeout_id = 0; + context->priv->repeat_timeout_id = 0; return FALSE; } @@ -668,18 +652,17 @@ on_key_pressed (EekKeyboard *keyboard, gpointer user_data) { EekboardContextService *context = user_data; - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); guint delay; - g_settings_get (priv->settings, "repeat-delay", "u", &delay); + g_settings_get (context->priv->settings, "repeat-delay", "u", &delay); - if (priv->repeat_timeout_id) { - g_source_remove (priv->repeat_timeout_id); - priv->repeat_timeout_id = 0; + if (context->priv->repeat_timeout_id) { + g_source_remove (context->priv->repeat_timeout_id); + context->priv->repeat_timeout_id = 0; } - priv->repeat_key = key; - priv->repeat_timeout_id = + context->priv->repeat_key = key; + context->priv->repeat_timeout_id = g_timeout_add (delay, (GSourceFunc)on_repeat_timeout_init, context); @@ -691,28 +674,26 @@ on_key_released (EekKeyboard *keyboard, gpointer user_data) { EekboardContextService *context = user_data; - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - if (priv->repeat_timeout_id > 0) { - g_source_remove (priv->repeat_timeout_id); - priv->repeat_timeout_id = 0; + if (context->priv->repeat_timeout_id > 0) { + g_source_remove (context->priv->repeat_timeout_id); + context->priv->repeat_timeout_id = 0; /* KeyActivated signal has not been emitted in repeat handler */ - emit_key_activated_dbus_signal (context, priv->repeat_key); + emit_key_activated_dbus_signal (context, + context->priv->repeat_key); } } static void connect_keyboard_signals (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - - priv->key_pressed_handler = - g_signal_connect (priv->keyboard, "key-pressed", + context->priv->key_pressed_handler = + g_signal_connect (context->priv->keyboard, "key-pressed", G_CALLBACK(on_key_pressed), context); - priv->key_released_handler = - g_signal_connect (priv->keyboard, "key-released", + context->priv->key_released_handler = + g_signal_connect (context->priv->keyboard, "key-released", G_CALLBACK(on_key_released), context); } @@ -728,7 +709,6 @@ handle_method_call (GDBusConnection *connection, gpointer user_data) { EekboardContextService *context = user_data; - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); EekboardContextServiceClass *klass = EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context); if (g_strcmp0 (method_name, "AddKeyboard") == 0) { @@ -751,7 +731,7 @@ handle_method_call (GDBusConnection *connection, EEK_MODIFIER_BEHAVIOR_LATCH); keyboard_id++; - g_hash_table_insert (priv->keyboard_hash, + g_hash_table_insert (context->priv->keyboard_hash, GUINT_TO_POINTER(keyboard_id), keyboard); g_object_set_data (G_OBJECT(keyboard), @@ -769,15 +749,15 @@ handle_method_call (GDBusConnection *connection, g_variant_get (parameters, "(u)", &keyboard_id); current_keyboard_id = - GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(priv->keyboard), + GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(context->priv->keyboard), "keyboard-id")); if (keyboard_id == current_keyboard_id) { disconnect_keyboard_signals (context); - priv->keyboard = NULL; + context->priv->keyboard = NULL; g_object_notify (G_OBJECT(context), "keyboard"); } - g_hash_table_remove (priv->keyboard_hash, + g_hash_table_remove (context->priv->keyboard_hash, GUINT_TO_POINTER(keyboard_id)); g_dbus_method_invocation_return_value (invocation, NULL); return; @@ -790,7 +770,7 @@ handle_method_call (GDBusConnection *connection, g_variant_get (parameters, "(u)", &keyboard_id); - keyboard = g_hash_table_lookup (priv->keyboard_hash, + keyboard = g_hash_table_lookup (context->priv->keyboard_hash, GUINT_TO_POINTER(keyboard_id)); if (!keyboard) { g_dbus_method_invocation_return_error (invocation, @@ -800,20 +780,20 @@ handle_method_call (GDBusConnection *connection, return; } - if (keyboard == priv->keyboard) { + if (keyboard == context->priv->keyboard) { g_dbus_method_invocation_return_value (invocation, NULL); return; } - if (priv->keyboard) + if (context->priv->keyboard) disconnect_keyboard_signals (context); - priv->keyboard = keyboard; + context->priv->keyboard = keyboard; connect_keyboard_signals (context); g_dbus_method_invocation_return_value (invocation, NULL); - group = eek_element_get_group (EEK_ELEMENT(priv->keyboard)); + group = eek_element_get_group (EEK_ELEMENT(context->priv->keyboard)); emit_group_changed_signal (context, group); g_object_notify (G_OBJECT(context), "keyboard"); @@ -825,11 +805,11 @@ handle_method_call (GDBusConnection *connection, g_variant_get (parameters, "(b)", &fullscreen); - if (priv->fullscreen == fullscreen) { + if (context->priv->fullscreen == fullscreen) { g_dbus_method_invocation_return_value (invocation, NULL); return; } - priv->fullscreen = fullscreen; + context->priv->fullscreen = fullscreen; g_dbus_method_invocation_return_value (invocation, NULL); g_object_notify (G_OBJECT(context), "fullscreen"); @@ -839,7 +819,7 @@ handle_method_call (GDBusConnection *connection, if (g_strcmp0 (method_name, "SetGroup") == 0) { gint group; - if (!priv->keyboard) { + if (!context->priv->keyboard) { g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED, @@ -848,14 +828,14 @@ handle_method_call (GDBusConnection *connection, } g_variant_get (parameters, "(i)", &group); - eek_element_set_group (EEK_ELEMENT(priv->keyboard), group); + eek_element_set_group (EEK_ELEMENT(context->priv->keyboard), group); g_dbus_method_invocation_return_value (invocation, NULL); emit_group_changed_signal (context, group); return; } if (g_strcmp0 (method_name, "ShowKeyboard") == 0) { - if (!priv->keyboard) { + if (!context->priv->keyboard) { g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED, @@ -881,7 +861,7 @@ handle_method_call (GDBusConnection *connection, EekKey *key; guint keycode; - if (!priv->keyboard) { + if (!context->priv->keyboard) { g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED, @@ -890,7 +870,7 @@ handle_method_call (GDBusConnection *connection, } g_variant_get (parameters, "(u)", &keycode); - key = eek_keyboard_find_key_by_keycode (priv->keyboard, keycode); + key = eek_keyboard_find_key_by_keycode (context->priv->keyboard, keycode); if (!key) { g_dbus_method_invocation_return_error (invocation, @@ -902,17 +882,17 @@ handle_method_call (GDBusConnection *connection, } if (g_strcmp0 (method_name, "PressKeycode") == 0) { - g_signal_handler_block (priv->keyboard, - priv->key_pressed_handler); + g_signal_handler_block (context->priv->keyboard, + context->priv->key_pressed_handler); g_signal_emit_by_name (key, "pressed"); - g_signal_handler_unblock (priv->keyboard, - priv->key_pressed_handler); + g_signal_handler_unblock (context->priv->keyboard, + context->priv->key_pressed_handler); } else { - g_signal_handler_block (priv->keyboard, - priv->key_released_handler); + g_signal_handler_block (context->priv->keyboard, + context->priv->key_released_handler); g_signal_emit_by_name (key, "released"); - g_signal_handler_unblock (priv->keyboard, - priv->key_released_handler); + g_signal_handler_unblock (context->priv->keyboard, + context->priv->key_released_handler); } g_dbus_method_invocation_return_value (invocation, NULL); @@ -932,21 +912,20 @@ handle_method_call (GDBusConnection *connection, void eekboard_context_service_enable (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); GError *error; g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context)); - g_return_if_fail (priv->connection); + g_return_if_fail (context->priv->connection); - if (!priv->enabled) { + if (!context->priv->enabled) { gboolean retval; - priv->enabled = TRUE; + context->priv->enabled = TRUE; error = NULL; - retval = g_dbus_connection_emit_signal (priv->connection, + retval = g_dbus_connection_emit_signal (context->priv->connection, NULL, - priv->object_path, + context->priv->object_path, EEKBOARD_CONTEXT_SERVICE_INTERFACE, "Enabled", NULL, @@ -957,7 +936,7 @@ eekboard_context_service_enable (EekboardContextService *context) g_error_free (error); g_assert_not_reached (); } - g_signal_emit_by_name (context, "enabled", NULL); + g_signal_emit (context, signals[ENABLED], 0); } } @@ -971,21 +950,20 @@ eekboard_context_service_enable (EekboardContextService *context) void eekboard_context_service_disable (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); GError *error; g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context)); - g_return_if_fail (priv->connection); + g_return_if_fail (context->priv->connection); - if (priv->enabled) { + if (context->priv->enabled) { gboolean retval; - priv->enabled = FALSE; + context->priv->enabled = FALSE; error = NULL; - retval = g_dbus_connection_emit_signal (priv->connection, + retval = g_dbus_connection_emit_signal (context->priv->connection, NULL, - priv->object_path, + context->priv->object_path, EEKBOARD_CONTEXT_SERVICE_INTERFACE, "Disabled", NULL, @@ -996,7 +974,7 @@ eekboard_context_service_disable (EekboardContextService *context) g_error_free (error); g_assert_not_reached (); } - g_signal_emit_by_name (context, "disabled", NULL); + g_signal_emit (context, signals[DISABLED], 0); } } @@ -1010,8 +988,7 @@ eekboard_context_service_disable (EekboardContextService *context) EekKeyboard * eekboard_context_service_get_keyboard (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - return priv->keyboard; + return context->priv->keyboard; } /** @@ -1024,8 +1001,7 @@ eekboard_context_service_get_keyboard (EekboardContextService *context) gboolean eekboard_context_service_get_fullscreen (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - return priv->fullscreen; + return context->priv->fullscreen; } /** @@ -1038,6 +1014,5 @@ eekboard_context_service_get_fullscreen (EekboardContextService *context) const gchar * eekboard_context_service_get_client_name (EekboardContextService *context) { - EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context); - return priv->client_name; + return context->priv->client_name; } diff --git a/eekboard/eekboard-context.c b/eekboard/eekboard-context.c index f696f287..6591b5fd 100644 --- a/eekboard/eekboard-context.c +++ b/eekboard/eekboard-context.c @@ -69,15 +69,14 @@ eekboard_context_real_g_signal (GDBusProxy *self, GVariant *parameters) { EekboardContext *context = EEKBOARD_CONTEXT (self); - EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); if (g_strcmp0 (signal_name, "Enabled") == 0) { - g_signal_emit_by_name (context, "enabled"); + g_signal_emit (context, signals[ENABLED], 0); return; } if (g_strcmp0 (signal_name, "Disabled") == 0) { - g_signal_emit_by_name (context, "disabled"); + g_signal_emit (context, signals[DISABLED], 0); return; } @@ -87,7 +86,8 @@ eekboard_context_real_g_signal (GDBusProxy *self, guint modifiers = 0; EekSerializable *serializable; - g_variant_get (parameters, "(&svu)", &keyname, &variant, &modifiers); + g_variant_get (parameters, "(&svu)", + &keyname, &variant, &modifiers); g_return_if_fail (variant != NULL); serializable = eek_serializable_deserialize (variant); @@ -95,8 +95,8 @@ eekboard_context_real_g_signal (GDBusProxy *self, g_return_if_fail (EEK_IS_SYMBOL(serializable)); - g_signal_emit_by_name (context, "key-pressed", - keyname, EEK_SYMBOL(serializable), modifiers); + g_signal_emit (context, signals[KEY_PRESSED], 0, + keyname, EEK_SYMBOL(serializable), modifiers); g_object_unref (serializable); return; @@ -106,8 +106,8 @@ eekboard_context_real_g_signal (GDBusProxy *self, gboolean visible = FALSE; g_variant_get (parameters, "(b)", &visible); - if (visible != priv->visible) { - priv->visible = visible; + if (visible != context->priv->visible) { + context->priv->visible = visible; g_object_notify (G_OBJECT(context), "visible"); } return; @@ -117,9 +117,9 @@ eekboard_context_real_g_signal (GDBusProxy *self, gint group = 0; g_variant_get (parameters, "(i)", &group); - if (group != priv->group) { - priv->group = group; - //g_object_notify (G_OBJECT(context), "group"); + if (group != context->priv->group) { + context->priv->group = group; + /* g_object_notify (G_OBJECT(context), "group"); */ } return; } @@ -130,15 +130,13 @@ eekboard_context_real_g_signal (GDBusProxy *self, static void eekboard_context_real_enabled (EekboardContext *self) { - EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self); - priv->enabled = TRUE; + self->priv->enabled = TRUE; } static void eekboard_context_real_disabled (EekboardContext *self) { - EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(self); - priv->enabled = FALSE; + self->priv->enabled = FALSE; } static void @@ -160,15 +158,13 @@ eekboard_context_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(object); + EekboardContext *context = EEKBOARD_CONTEXT(object); switch (prop_id) { case PROP_VISIBLE: - g_value_set_boolean (value, priv->visible); + g_value_set_boolean (value, context->priv->visible); break; default: - g_object_get_property (object, - g_param_spec_get_name (pspec), - value); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } } @@ -295,7 +291,7 @@ context_name_vanished_callback (GDBusConnection *connection, gpointer user_data) { EekboardContext *context = user_data; - g_signal_emit_by_name (context, "destroyed", NULL); + g_signal_emit (context, signals[DESTROYED], 0); } /** @@ -316,8 +312,8 @@ eekboard_context_new (GDBusConnection *connection, GInitable *initable; GError *error; - g_assert (object_path != NULL); - g_assert (G_IS_DBUS_CONNECTION(connection)); + g_return_val_if_fail (object_path != NULL, NULL); + g_return_val_if_fail (G_IS_DBUS_CONNECTION(connection), NULL); error = NULL; initable = @@ -481,13 +477,9 @@ eekboard_context_set_group (EekboardContext *context, gint group, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - - if (priv->group != group) { + if (context->priv->group != group) { g_dbus_proxy_call (G_DBUS_PROXY(context), "SetGroup", g_variant_new ("(i)", group), @@ -510,12 +502,8 @@ gint eekboard_context_get_group (EekboardContext *context, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), 0); - - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - return priv->group; + return context->priv->group; } /** @@ -530,22 +518,18 @@ void eekboard_context_show_keyboard (EekboardContext *context, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - if (!priv->enabled) - return; - - g_dbus_proxy_call (G_DBUS_PROXY(context), - "ShowKeyboard", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - context_async_ready_callback, - NULL); + if (context->priv->enabled) { + g_dbus_proxy_call (G_DBUS_PROXY(context), + "ShowKeyboard", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + context_async_ready_callback, + NULL); + } } /** @@ -559,22 +543,18 @@ void eekboard_context_hide_keyboard (EekboardContext *context, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - if (!priv->enabled) - return; - - g_dbus_proxy_call (G_DBUS_PROXY(context), - "HideKeyboard", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - context_async_ready_callback, - NULL); + if (context->priv->enabled) { + g_dbus_proxy_call (G_DBUS_PROXY(context), + "HideKeyboard", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + context_async_ready_callback, + NULL); + } } /** @@ -590,22 +570,18 @@ eekboard_context_press_keycode (EekboardContext *context, guint keycode, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - if (!priv->enabled) - return; - - g_dbus_proxy_call (G_DBUS_PROXY(context), - "PressKeycode", - g_variant_new ("(u)", keycode), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - context_async_ready_callback, - NULL); + if (context->priv->enabled) { + g_dbus_proxy_call (G_DBUS_PROXY(context), + "PressKeycode", + g_variant_new ("(u)", keycode), + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + context_async_ready_callback, + NULL); + } } /** @@ -621,22 +597,18 @@ eekboard_context_release_keycode (EekboardContext *context, guint keycode, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - if (!priv->enabled) - return; - - g_dbus_proxy_call (G_DBUS_PROXY(context), - "ReleaseKeycode", - g_variant_new ("(u)", keycode), - G_DBUS_CALL_FLAGS_NONE, - -1, - cancellable, - context_async_ready_callback, - NULL); + if (context->priv->enabled) { + g_dbus_proxy_call (G_DBUS_PROXY(context), + "ReleaseKeycode", + g_variant_new ("(u)", keycode), + G_DBUS_CALL_FLAGS_NONE, + -1, + cancellable, + context_async_ready_callback, + NULL); + } } /** @@ -648,12 +620,8 @@ eekboard_context_release_keycode (EekboardContext *context, gboolean eekboard_context_is_visible (EekboardContext *context) { - EekboardContextPrivate *priv; - - g_assert (EEKBOARD_IS_CONTEXT(context)); - - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - return priv->enabled && priv->visible; + g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), FALSE); + return context->priv->enabled && context->priv->visible; } /** @@ -669,12 +637,8 @@ void eekboard_context_set_enabled (EekboardContext *context, gboolean enabled) { - EekboardContextPrivate *priv; - - g_assert (EEKBOARD_IS_CONTEXT(context)); - - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - priv->enabled = enabled; + g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); + context->priv->enabled = enabled; } /** @@ -686,12 +650,8 @@ eekboard_context_set_enabled (EekboardContext *context, gboolean eekboard_context_is_enabled (EekboardContext *context) { - EekboardContextPrivate *priv; - - g_assert (EEKBOARD_IS_CONTEXT(context)); - - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - return priv->enabled; + g_return_val_if_fail (EEKBOARD_IS_CONTEXT(context), FALSE); + return context->priv->enabled; } /** @@ -707,12 +667,8 @@ eekboard_context_set_fullscreen (EekboardContext *context, gboolean fullscreen, GCancellable *cancellable) { - EekboardContextPrivate *priv; - g_return_if_fail (EEKBOARD_IS_CONTEXT(context)); - - priv = EEKBOARD_CONTEXT_GET_PRIVATE (context); - if (priv->fullscreen != fullscreen) { + if (context->priv->fullscreen != fullscreen) { g_dbus_proxy_call (G_DBUS_PROXY(context), "SetFullscreen", g_variant_new ("(b)", fullscreen), diff --git a/eekboard/eekboard-service.c b/eekboard/eekboard-service.c index 8bbd2ac9..6fed3e67 100644 --- a/eekboard/eekboard-service.c +++ b/eekboard/eekboard-service.c @@ -101,20 +101,19 @@ eekboard_service_set_property (GObject *object, GParamSpec *pspec) { EekboardService *service = EEKBOARD_SERVICE(object); - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); GDBusConnection *connection; switch (prop_id) { case PROP_OBJECT_PATH: - if (priv->object_path) - g_free (priv->object_path); - priv->object_path = g_strdup (g_value_get_string (value)); + if (service->priv->object_path) + g_free (service->priv->object_path); + service->priv->object_path = g_value_dup_string (value); break; case PROP_CONNECTION: connection = g_value_get_object (value); - if (priv->connection) - g_object_unref (priv->connection); - priv->connection = g_object_ref (connection); + if (service->priv->connection) + g_object_unref (service->priv->connection); + service->priv->connection = g_object_ref (connection); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -129,14 +128,13 @@ eekboard_service_get_property (GObject *object, GParamSpec *pspec) { EekboardService *service = EEKBOARD_SERVICE(object); - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); switch (prop_id) { case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); + g_value_set_string (value, service->priv->object_path); break; case PROP_CONNECTION: - g_value_set_object (value, priv->connection); + g_value_set_object (value, service->priv->connection); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -148,34 +146,33 @@ static void eekboard_service_dispose (GObject *object) { EekboardService *service = EEKBOARD_SERVICE(object); - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); GSList *head; - if (priv->context_hash) { - g_hash_table_destroy (priv->context_hash); - priv->context_hash = NULL; + if (service->priv->context_hash) { + g_hash_table_destroy (service->priv->context_hash); + service->priv->context_hash = NULL; } - for (head = priv->context_stack; head; head = priv->context_stack) { + for (head = service->priv->context_stack; head; head = service->priv->context_stack) { g_object_unref (head->data); - priv->context_stack = g_slist_next (head); + service->priv->context_stack = g_slist_next (head); g_slist_free1 (head); } - if (priv->connection) { - if (priv->registration_id > 0) { - g_dbus_connection_unregister_object (priv->connection, - priv->registration_id); - priv->registration_id = 0; + if (service->priv->connection) { + if (service->priv->registration_id > 0) { + g_dbus_connection_unregister_object (service->priv->connection, + service->priv->registration_id); + service->priv->registration_id = 0; } - g_object_unref (priv->connection); - priv->connection = NULL; + g_object_unref (service->priv->connection); + service->priv->connection = NULL; } - if (priv->introspection_data) { - g_dbus_node_info_unref (priv->introspection_data); - priv->introspection_data = NULL; + if (service->priv->introspection_data) { + g_dbus_node_info_unref (service->priv->introspection_data); + service->priv->introspection_data = NULL; } G_OBJECT_CLASS (eekboard_service_parent_class)->dispose (object); @@ -184,9 +181,9 @@ eekboard_service_dispose (GObject *object) static void eekboard_service_finalize (GObject *object) { - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(object); + EekboardService *service = EEKBOARD_SERVICE(object); - g_free (priv->object_path); + g_free (service->priv->object_path); G_OBJECT_CLASS (eekboard_service_parent_class)->finalize (object); } @@ -194,20 +191,20 @@ eekboard_service_finalize (GObject *object) static void eekboard_service_constructed (GObject *object) { - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(object); - if (priv->connection && priv->object_path) { + EekboardService *service = EEKBOARD_SERVICE(object); + if (service->priv->connection && service->priv->object_path) { GError *error = NULL; - priv->registration_id = g_dbus_connection_register_object - (priv->connection, - priv->object_path, - priv->introspection_data->interfaces[0], + service->priv->registration_id = g_dbus_connection_register_object + (service->priv->connection, + service->priv->object_path, + service->priv->introspection_data->interfaces[0], &interface_vtable, object, NULL, &error); - if (priv->registration_id == 0) { + if (service->priv->registration_id == 0) { g_warning ("failed to register context object: %s", error->message); g_error_free (error); @@ -279,23 +276,22 @@ eekboard_service_class_init (EekboardServiceClass *klass) } static void -eekboard_service_init (EekboardService *service) +eekboard_service_init (EekboardService *self) { - EekboardServicePrivate *priv; GError *error; - priv = service->priv = EEKBOARD_SERVICE_GET_PRIVATE(service); + self->priv = EEKBOARD_SERVICE_GET_PRIVATE(self); error = NULL; - priv->introspection_data = + self->priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error); - if (priv->introspection_data == NULL) { + if (self->priv->introspection_data == NULL) { g_warning ("failed to parse D-Bus XML: %s", error->message); g_error_free (error); g_assert_not_reached (); } - priv->context_hash = + self->priv->context_hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, @@ -306,17 +302,16 @@ static void remove_context_from_stack (EekboardService *service, EekboardContextService *context) { - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); GSList *head; - head = g_slist_find (priv->context_stack, context); + head = g_slist_find (service->priv->context_stack, context); if (head) { - priv->context_stack = g_slist_remove_link (priv->context_stack, head); + service->priv->context_stack = g_slist_remove_link (service->priv->context_stack, head); g_object_unref (head->data); g_slist_free1 (head); } - if (priv->context_stack) - eekboard_context_service_enable (priv->context_stack->data); + if (service->priv->context_stack) + eekboard_context_service_enable (service->priv->context_stack->data); } static void @@ -325,25 +320,24 @@ service_name_vanished_callback (GDBusConnection *connection, gpointer user_data) { EekboardService *service = user_data; - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); GSList *head; GHashTableIter iter; gpointer k, v; - g_hash_table_iter_init (&iter, priv->context_hash); + g_hash_table_iter_init (&iter, service->priv->context_hash); while (g_hash_table_iter_next (&iter, &k, &v)) { const gchar *owner = g_object_get_data (G_OBJECT(v), "owner"); if (g_strcmp0 (owner, name) == 0) g_hash_table_iter_remove (&iter); } - for (head = priv->context_stack; head; ) { + for (head = service->priv->context_stack; head; ) { const gchar *owner = g_object_get_data (G_OBJECT(head->data), "owner"); GSList *next = g_slist_next (head); if (g_strcmp0 (owner, name) == 0) { - priv->context_stack = - g_slist_remove_link (priv->context_stack, head); + service->priv->context_stack = + g_slist_remove_link (service->priv->context_stack, head); g_object_unref (head->data); g_slist_free1 (head); } @@ -351,8 +345,8 @@ service_name_vanished_callback (GDBusConnection *connection, head = next; } - if (priv->context_stack) - eekboard_context_service_enable (priv->context_stack->data); + if (service->priv->context_stack) + eekboard_context_service_enable (service->priv->context_stack->data); } static void @@ -366,7 +360,6 @@ handle_method_call (GDBusConnection *connection, gpointer user_data) { EekboardService *service = user_data; - EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service); EekboardServiceClass *klass = EEKBOARD_SERVICE_GET_CLASS(service); if (g_strcmp0 (method_name, "CreateContext") == 0) { @@ -382,12 +375,12 @@ handle_method_call (GDBusConnection *connection, g_object_set_data_full (G_OBJECT(context), "owner", g_strdup (sender), (GDestroyNotify)g_free); - g_hash_table_insert (priv->context_hash, + g_hash_table_insert (service->priv->context_hash, object_path, context); /* the vanished callback is called when clients are disconnected */ - g_bus_watch_name_on_connection (priv->connection, + g_bus_watch_name_on_connection (service->priv->connection, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, @@ -405,7 +398,7 @@ handle_method_call (GDBusConnection *connection, EekboardContextService *context; g_variant_get (parameters, "(&s)", &object_path); - context = g_hash_table_lookup (priv->context_hash, object_path); + context = g_hash_table_lookup (service->priv->context_hash, object_path); if (!context) { g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, @@ -413,9 +406,9 @@ handle_method_call (GDBusConnection *connection, "context not found"); return; } - if (priv->context_stack) - eekboard_context_service_disable (priv->context_stack->data); - priv->context_stack = g_slist_prepend (priv->context_stack, + if (service->priv->context_stack) + eekboard_context_service_disable (service->priv->context_stack->data); + service->priv->context_stack = g_slist_prepend (service->priv->context_stack, g_object_ref (context)); eekboard_context_service_enable (context); @@ -424,8 +417,8 @@ handle_method_call (GDBusConnection *connection, } if (g_strcmp0 (method_name, "PopContext") == 0) { - if (priv->context_stack) { - EekboardContextService *context = priv->context_stack->data; + if (service->priv->context_stack) { + EekboardContextService *context = service->priv->context_stack->data; gchar *object_path; const gchar *owner; @@ -443,9 +436,9 @@ handle_method_call (GDBusConnection *connection, g_free (object_path); eekboard_context_service_disable (context); - priv->context_stack = g_slist_next (priv->context_stack); - if (priv->context_stack) - eekboard_context_service_enable (priv->context_stack->data); + service->priv->context_stack = g_slist_next (service->priv->context_stack); + if (service->priv->context_stack) + eekboard_context_service_enable (service->priv->context_stack->data); } g_dbus_method_invocation_return_value (invocation, NULL); @@ -458,7 +451,7 @@ handle_method_call (GDBusConnection *connection, const gchar *owner; g_variant_get (parameters, "(&s)", &object_path); - context = g_hash_table_lookup (priv->context_hash, object_path); + context = g_hash_table_lookup (service->priv->context_hash, object_path); if (!context) { g_dbus_method_invocation_return_error (invocation, G_IO_ERROR, @@ -479,13 +472,13 @@ handle_method_call (GDBusConnection *connection, } remove_context_from_stack (service, context); - g_hash_table_remove (priv->context_hash, object_path); + g_hash_table_remove (service->priv->context_hash, object_path); g_dbus_method_invocation_return_value (invocation, NULL); return; } if (g_strcmp0 (method_name, "Destroy") == 0) { - g_signal_emit_by_name (service, "destroyed", NULL); + g_signal_emit (service, signals[DESTROYED], 0); g_dbus_method_invocation_return_value (invocation, NULL); return; } diff --git a/src/client.c b/src/client.c index 8cba3a21..b328cdf9 100644 --- a/src/client.c +++ b/src/client.c @@ -442,8 +442,8 @@ client_enable_atspi_keystroke (Client *client) client->keystroke_listener = atspi_device_listener_new ((AtspiDeviceListenerCB)keystroke_listener_cb, - NULL, - client); + client, + NULL); error = NULL; if (!atspi_register_keystroke_listener @@ -521,7 +521,7 @@ focus_listener_cb (const AtspiEvent *event, error = NULL; role = atspi_accessible_get_role (accessible, &error); - if (role == NULL) { + if (role == ATSPI_ROLE_INVALID) { g_warning ("can't get accessible role: %s", error->message); g_error_free (error); diff --git a/src/preferences-dialog.c b/src/preferences-dialog.c index 8733b2a6..fe0e3eb7 100644 --- a/src/preferences-dialog.c +++ b/src/preferences-dialog.c @@ -108,7 +108,7 @@ preferences_dialog_new (void) ui_path = g_strdup_printf ("%s/%s", PKGDATADIR, "preferences-dialog.ui"); error = NULL; if (gtk_builder_add_from_file (builder, ui_path, &error) == 0) { - g_warning ("can't load %s: %s", error->message); + g_warning ("can't load %s: %s", ui_path, error->message); g_error_free (error); } g_free (ui_path); diff --git a/tests/eek-xml-test.c b/tests/eek-xml-test.c index ae2debe6..7beb7bc9 100644 --- a/tests/eek-xml-test.c +++ b/tests/eek-xml-test.c @@ -26,43 +26,21 @@ #endif /* HAVE_CONFIG_H */ #include "eek/eek.h" -#include "eek/eek-xkl.h" static void test_output_parse (void) { - GString *output; - GInputStream *input; EekLayout *layout; EekKeyboard *keyboard; - Display *display; + GError *error; - output = g_string_sized_new (8192); - - display = XOpenDisplay (NULL); - layout = eek_xkl_layout_new (display, NULL); - - keyboard = eek_keyboard_new (layout, 640, 480); - g_object_unref (layout); - - eek_keyboard_output (keyboard, output, 0); - g_object_unref (keyboard); - -#if 0 - fwrite (output->str, sizeof(gchar), output->len, stdout); -#endif - - input = g_memory_input_stream_new_from_data (output->str, - output->len, - NULL); - layout = eek_xml_layout_new (input); - g_object_unref (input); + error = NULL; + layout = eek_xml_layout_new ("us", &error); + g_assert_no_error (error); keyboard = eek_keyboard_new (layout, 640, 480); g_object_unref (layout); g_object_unref (keyboard); - - g_string_free (output, TRUE); } int