Merge branch 'caches' into 'master'
Fix leaks See merge request Librem5/squeekboard!237
This commit is contained in:
@ -54,7 +54,7 @@ enum {
|
|||||||
typedef struct _EekGtkKeyboardPrivate
|
typedef struct _EekGtkKeyboardPrivate
|
||||||
{
|
{
|
||||||
EekRenderer *renderer;
|
EekRenderer *renderer;
|
||||||
LevelKeyboard *keyboard;
|
LevelKeyboard *keyboard; // unowned reference; it's kept in server-context (FIXME)
|
||||||
|
|
||||||
GdkEventSequence *sequence; // unowned reference
|
GdkEventSequence *sequence; // unowned reference
|
||||||
} EekGtkKeyboardPrivate;
|
} EekGtkKeyboardPrivate;
|
||||||
|
|||||||
@ -39,6 +39,8 @@
|
|||||||
#include "eek-keyboard.h"
|
#include "eek-keyboard.h"
|
||||||
|
|
||||||
void level_keyboard_deinit(LevelKeyboard *self) {
|
void level_keyboard_deinit(LevelKeyboard *self) {
|
||||||
|
xkb_keymap_unref(self->keymap);
|
||||||
|
close(self->keymap_fd);
|
||||||
squeek_layout_free(self->layout);
|
squeek_layout_free(self->layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ G_BEGIN_DECLS
|
|||||||
/// Keyboard state holder
|
/// Keyboard state holder
|
||||||
struct _LevelKeyboard {
|
struct _LevelKeyboard {
|
||||||
struct squeek_layout *layout; // owned
|
struct squeek_layout *layout; // owned
|
||||||
struct xkb_keymap *keymap;
|
struct xkb_keymap *keymap; // owned
|
||||||
int keymap_fd; // keymap formatted as XKB string
|
int keymap_fd; // keymap formatted as XKB string
|
||||||
size_t keymap_len; // length of the data inside keymap_fd
|
size_t keymap_len; // length of the data inside keymap_fd
|
||||||
|
|
||||||
|
|||||||
@ -35,10 +35,10 @@ enum {
|
|||||||
|
|
||||||
typedef struct _EekRendererPrivate
|
typedef struct _EekRendererPrivate
|
||||||
{
|
{
|
||||||
LevelKeyboard *keyboard;
|
LevelKeyboard *keyboard; // unowned
|
||||||
PangoContext *pcontext;
|
PangoContext *pcontext; // owned
|
||||||
GtkCssProvider *css_provider;
|
GtkCssProvider *css_provider; // owned
|
||||||
GtkStyleContext *view_context;
|
GtkStyleContext *view_context; // owned
|
||||||
GtkStyleContext *button_context; // TODO: maybe move a copy to each button
|
GtkStyleContext *button_context; // TODO: maybe move a copy to each button
|
||||||
|
|
||||||
gdouble border_width;
|
gdouble border_width;
|
||||||
@ -52,10 +52,6 @@ typedef struct _EekRendererPrivate
|
|||||||
|
|
||||||
PangoFontDescription *ascii_font;
|
PangoFontDescription *ascii_font;
|
||||||
PangoFontDescription *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;
|
cairo_surface_t *keyboard_surface;
|
||||||
|
|
||||||
} EekRendererPrivate;
|
} EekRendererPrivate;
|
||||||
@ -539,8 +535,6 @@ eek_renderer_dispose (GObject *object)
|
|||||||
priv->pcontext = NULL;
|
priv->pcontext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_clear_pointer (&priv->icons, g_hash_table_destroy);
|
|
||||||
|
|
||||||
/* this will release all allocated surfaces and font if any */
|
/* this will release all allocated surfaces and font if any */
|
||||||
invalidate (EEK_RENDERER(object));
|
invalidate (EEK_RENDERER(object));
|
||||||
|
|
||||||
@ -553,8 +547,9 @@ eek_renderer_finalize (GObject *object)
|
|||||||
EekRenderer *self = EEK_RENDERER(object);
|
EekRenderer *self = EEK_RENDERER(object);
|
||||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
EekRendererPrivate *priv = eek_renderer_get_instance_private (self);
|
||||||
|
|
||||||
g_hash_table_destroy (priv->outline_surface_cache);
|
g_object_unref(priv->css_provider);
|
||||||
g_hash_table_destroy (priv->active_outline_surface_cache);
|
g_object_unref(priv->view_context);
|
||||||
|
g_object_unref(priv->button_context);
|
||||||
pango_font_description_free (priv->ascii_font);
|
pango_font_description_free (priv->ascii_font);
|
||||||
pango_font_description_free (priv->font);
|
pango_font_description_free (priv->font);
|
||||||
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
|
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
|
||||||
@ -624,25 +619,11 @@ eek_renderer_init (EekRenderer *self)
|
|||||||
priv->scale = 1.0;
|
priv->scale = 1.0;
|
||||||
priv->scale_factor = 1;
|
priv->scale_factor = 1;
|
||||||
priv->font = NULL;
|
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;
|
priv->keyboard_surface = NULL;
|
||||||
|
|
||||||
GtkIconTheme *theme = gtk_icon_theme_get_default ();
|
GtkIconTheme *theme = gtk_icon_theme_get_default ();
|
||||||
|
|
||||||
gtk_icon_theme_add_resource_path (theme, "/sm/puri/squeekboard/icons");
|
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 */
|
/* Create a default CSS provider and load a style sheet */
|
||||||
priv->css_provider = gtk_css_provider_new ();
|
priv->css_provider = gtk_css_provider_new ();
|
||||||
@ -655,12 +636,6 @@ invalidate (EekRenderer *renderer)
|
|||||||
{
|
{
|
||||||
EekRendererPrivate *priv = eek_renderer_get_instance_private (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) {
|
if (priv->keyboard_surface) {
|
||||||
cairo_surface_destroy (priv->keyboard_surface);
|
cairo_surface_destroy (priv->keyboard_surface);
|
||||||
priv->keyboard_surface = NULL;
|
priv->keyboard_surface = NULL;
|
||||||
@ -690,7 +665,6 @@ eek_renderer_new (LevelKeyboard *keyboard,
|
|||||||
gtk_style_context_add_provider (priv->view_context,
|
gtk_style_context_add_provider (priv->view_context,
|
||||||
GTK_STYLE_PROVIDER(priv->css_provider),
|
GTK_STYLE_PROVIDER(priv->css_provider),
|
||||||
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
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 */
|
/* Create a style context for the buttons */
|
||||||
path = gtk_widget_path_new();
|
path = gtk_widget_path_new();
|
||||||
@ -829,16 +803,6 @@ eek_renderer_set_scale_factor (EekRenderer *renderer, gint scale)
|
|||||||
priv->scale_factor = 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 *
|
cairo_surface_t *
|
||||||
eek_renderer_get_icon_surface (const gchar *icon_name,
|
eek_renderer_get_icon_surface (const gchar *icon_name,
|
||||||
gint size,
|
gint size,
|
||||||
|
|||||||
@ -74,8 +74,6 @@ gdouble eek_renderer_get_scale (EekRenderer *renderer);
|
|||||||
void eek_renderer_set_scale_factor (EekRenderer *renderer,
|
void eek_renderer_set_scale_factor (EekRenderer *renderer,
|
||||||
gint scale);
|
gint scale);
|
||||||
|
|
||||||
PangoLayout *eek_renderer_create_pango_layout
|
|
||||||
(EekRenderer *renderer);
|
|
||||||
void eek_renderer_render_button (EekRenderer *renderer,
|
void eek_renderer_render_button (EekRenderer *renderer,
|
||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
struct button_place *place,
|
struct button_place *place,
|
||||||
|
|||||||
@ -130,7 +130,6 @@ eekboard_context_service_real_create_keyboard (EekboardContextService *self,
|
|||||||
}
|
}
|
||||||
strncpy(ptr, keymap_str, keyboard->keymap_len);
|
strncpy(ptr, keymap_str, keyboard->keymap_len);
|
||||||
munmap(ptr, keyboard->keymap_len);
|
munmap(ptr, keyboard->keymap_len);
|
||||||
|
|
||||||
return keyboard;
|
return keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,23 +251,17 @@ eekboard_context_service_update_layout(EekboardContextService *context, enum squ
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generic part follows
|
// generic part follows
|
||||||
static guint keyboard_id = 0;
|
LevelKeyboard *keyboard = eekboard_context_service_real_create_keyboard(context, keyboard_layout, t);
|
||||||
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++;
|
|
||||||
}
|
|
||||||
// set as current
|
// set as current
|
||||||
|
LevelKeyboard *previous_keyboard = context->priv->keyboard;
|
||||||
context->priv->keyboard = keyboard;
|
context->priv->keyboard = keyboard;
|
||||||
|
|
||||||
g_object_notify (G_OBJECT(context), "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) {
|
static void update_layout_and_type(EekboardContextService *context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user