diff --git a/eek/eek-gtk-keyboard.c b/eek/eek-gtk-keyboard.c index 5d28a764..3da830f6 100644 --- a/eek/eek-gtk-keyboard.c +++ b/eek/eek-gtk-keyboard.c @@ -54,7 +54,7 @@ enum { typedef struct _EekGtkKeyboardPrivate { EekRenderer *renderer; - LevelKeyboard *keyboard; + LevelKeyboard *keyboard; // unowned reference; it's kept in server-context (FIXME) GdkEventSequence *sequence; // unowned reference } EekGtkKeyboardPrivate; diff --git a/eek/eek-keyboard.c b/eek/eek-keyboard.c index 40e86fcc..ee750abb 100644 --- a/eek/eek-keyboard.c +++ b/eek/eek-keyboard.c @@ -39,6 +39,8 @@ #include "eek-keyboard.h" void level_keyboard_deinit(LevelKeyboard *self) { + xkb_keymap_unref(self->keymap); + close(self->keymap_fd); squeek_layout_free(self->layout); } diff --git a/eek/eek-keyboard.h b/eek/eek-keyboard.h index 60dbf3f3..05bf5330 100644 --- a/eek/eek-keyboard.h +++ b/eek/eek-keyboard.h @@ -36,7 +36,7 @@ G_BEGIN_DECLS /// Keyboard state holder struct _LevelKeyboard { struct squeek_layout *layout; // owned - struct xkb_keymap *keymap; + struct xkb_keymap *keymap; // owned int keymap_fd; // keymap formatted as XKB string size_t keymap_len; // length of the data inside keymap_fd diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 2cac6742..079e3a67 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -35,10 +35,10 @@ enum { typedef struct _EekRendererPrivate { - LevelKeyboard *keyboard; - PangoContext *pcontext; - GtkCssProvider *css_provider; - GtkStyleContext *view_context; + LevelKeyboard *keyboard; // unowned + PangoContext *pcontext; // owned + GtkCssProvider *css_provider; // owned + GtkStyleContext *view_context; // owned GtkStyleContext *button_context; // TODO: maybe move a copy to each button gdouble border_width; @@ -52,10 +52,6 @@ typedef struct _EekRendererPrivate PangoFontDescription *ascii_font; PangoFontDescription *font; - // TODO: Drop those or transform into general button surface caches - GHashTable *outline_surface_cache; - GHashTable *active_outline_surface_cache; - GHashTable *icons; cairo_surface_t *keyboard_surface; } EekRendererPrivate; @@ -539,8 +535,6 @@ eek_renderer_dispose (GObject *object) priv->pcontext = NULL; } - g_clear_pointer (&priv->icons, g_hash_table_destroy); - /* this will release all allocated surfaces and font if any */ invalidate (EEK_RENDERER(object)); @@ -553,8 +547,9 @@ eek_renderer_finalize (GObject *object) EekRenderer *self = EEK_RENDERER(object); EekRendererPrivate *priv = eek_renderer_get_instance_private (self); - g_hash_table_destroy (priv->outline_surface_cache); - g_hash_table_destroy (priv->active_outline_surface_cache); + g_object_unref(priv->css_provider); + g_object_unref(priv->view_context); + g_object_unref(priv->button_context); pango_font_description_free (priv->ascii_font); pango_font_description_free (priv->font); G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object); @@ -624,25 +619,11 @@ eek_renderer_init (EekRenderer *self) priv->scale = 1.0; priv->scale_factor = 1; priv->font = NULL; - priv->outline_surface_cache = - g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - (GDestroyNotify)cairo_surface_destroy); - priv->active_outline_surface_cache = - g_hash_table_new_full (g_direct_hash, - g_direct_equal, - NULL, - (GDestroyNotify)cairo_surface_destroy); priv->keyboard_surface = NULL; GtkIconTheme *theme = gtk_icon_theme_get_default (); gtk_icon_theme_add_resource_path (theme, "/sm/puri/squeekboard/icons"); - priv->icons = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - (GDestroyNotify)cairo_surface_destroy); /* Create a default CSS provider and load a style sheet */ priv->css_provider = gtk_css_provider_new (); @@ -655,12 +636,6 @@ invalidate (EekRenderer *renderer) { EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); - if (priv->outline_surface_cache) - g_hash_table_remove_all (priv->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; @@ -690,7 +665,6 @@ eek_renderer_new (LevelKeyboard *keyboard, gtk_style_context_add_provider (priv->view_context, GTK_STYLE_PROVIDER(priv->css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); - printf("view: %s\n", gtk_style_context_to_string(priv->view_context, GTK_STYLE_CONTEXT_PRINT_SHOW_STYLE)); /* Create a style context for the buttons */ path = gtk_widget_path_new(); @@ -829,16 +803,6 @@ eek_renderer_set_scale_factor (EekRenderer *renderer, gint scale) priv->scale_factor = scale; } -PangoLayout * -eek_renderer_create_pango_layout (EekRenderer *renderer) -{ - g_return_val_if_fail (EEK_IS_RENDERER(renderer), NULL); - - EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); - - return pango_layout_new (priv->pcontext); -} - cairo_surface_t * eek_renderer_get_icon_surface (const gchar *icon_name, gint size, diff --git a/eek/eek-renderer.h b/eek/eek-renderer.h index 3fe2ec7d..690635c0 100644 --- a/eek/eek-renderer.h +++ b/eek/eek-renderer.h @@ -74,8 +74,6 @@ gdouble eek_renderer_get_scale (EekRenderer *renderer); void eek_renderer_set_scale_factor (EekRenderer *renderer, gint scale); -PangoLayout *eek_renderer_create_pango_layout - (EekRenderer *renderer); void eek_renderer_render_button (EekRenderer *renderer, cairo_t *cr, struct button_place *place, diff --git a/eekboard/eekboard-context-service.c b/eekboard/eekboard-context-service.c index 17410c20..c0be23fb 100644 --- a/eekboard/eekboard-context-service.c +++ b/eekboard/eekboard-context-service.c @@ -130,7 +130,6 @@ eekboard_context_service_real_create_keyboard (EekboardContextService *self, } strncpy(ptr, keymap_str, keyboard->keymap_len); munmap(ptr, keyboard->keymap_len); - return keyboard; } @@ -252,23 +251,17 @@ eekboard_context_service_update_layout(EekboardContextService *context, enum squ } // generic part follows - static guint keyboard_id = 0; - LevelKeyboard *keyboard = g_hash_table_lookup(context->priv->keyboard_hash, - GUINT_TO_POINTER(keyboard_id)); - // create a keyboard - if (!keyboard) { - keyboard = eekboard_context_service_real_create_keyboard(context, keyboard_layout, t); - - g_hash_table_insert (context->priv->keyboard_hash, - GUINT_TO_POINTER(keyboard_id), - keyboard); - keyboard->id = keyboard_id; - keyboard_id++; - } + LevelKeyboard *keyboard = eekboard_context_service_real_create_keyboard(context, keyboard_layout, t); // set as current + LevelKeyboard *previous_keyboard = context->priv->keyboard; context->priv->keyboard = keyboard; g_object_notify (G_OBJECT(context), "keyboard"); + + // replacing the keyboard above will cause the previous keyboard to get destroyed from the UI side (eek_gtk_keyboard_dispose) + if (previous_keyboard) { + level_keyboard_free(previous_keyboard); + } } static void update_layout_and_type(EekboardContextService *context) {