[Xfce4-commits] <xfce4-xkb-plugin:master> Pre-create country flag pixbufs whenever config changes.
Igor Slepchin
noreply at xfce.org
Wed Aug 22 23:24:13 CEST 2012
Updating branch refs/heads/master
to 47e9bac2f8b29fc04c2a0d60ce8ebc85bcc18722 (commit)
from 67c86b0294aa5f79f14f122be94dcc5aae68c5cf (commit)
commit 47e9bac2f8b29fc04c2a0d60ce8ebc85bcc18722
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date: Tue Jul 24 15:05:39 2012 -0400
Pre-create country flag pixbufs whenever config changes.
This is a fairly slow operation; this change speeds up country
flag redraws on group change fairly noticeably for more complex svgs.
Pre-create the displayed layout name strings as well while at it.
We'll also now keep track of the current layout group based on
xkl state updates rather than querying xklavier every time.
panel-plugin/xkb-callbacks.c | 31 ++-----------
panel-plugin/xkb-config.c | 102 ++++++++++++++++++++++++++++++------------
panel-plugin/xkb-config.h | 4 ++
3 files changed, 82 insertions(+), 55 deletions(-)
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index e300989..87fb638 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -198,33 +198,12 @@ xkb_plugin_set_tooltip (GtkWidget *widget,
GtkTooltip *tooltip,
t_xkb *xkb)
{
- RsvgHandle *handle;
- GdkPixbuf *pixbuf, *tmp;
- gchar *imgfilename;
- gchar *text;
+ gint group = xkb_config_get_current_group ();
+ GdkPixbuf *pixbuf = xkb_config_get_tooltip_pixbuf (group);
+ gchar *layout_name = xkb_config_get_pretty_layout_name (group);
- imgfilename = xkb_util_get_flag_filename (xkb_config_get_group_name (-1));
- handle = rsvg_handle_new_from_file (imgfilename, NULL);
- g_free (imgfilename);
-
- if (handle)
- {
- tmp = rsvg_handle_get_pixbuf (handle);
- pixbuf = gdk_pixbuf_scale_simple (tmp, 24, 24, GDK_INTERP_BILINEAR);
- gtk_tooltip_set_icon (tooltip, pixbuf);
-
- g_object_unref (pixbuf);
- g_object_unref (tmp);
- g_object_unref (handle);
- }
- else
- gtk_tooltip_set_icon (tooltip, NULL);
-
- text = xkb_util_get_layout_string (xkb_config_get_group_name (-1),
- xkb_config_get_variant (-1));
-
- gtk_tooltip_set_text (tooltip, text);
- g_free (text);
+ gtk_tooltip_set_icon (tooltip, pixbuf);
+ gtk_tooltip_set_text (tooltip, layout_name);
return TRUE;
}
diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c
index 63f5108..6acd315 100644
--- a/panel-plugin/xkb-config.c
+++ b/panel-plugin/xkb-config.c
@@ -24,6 +24,7 @@
*/
#include "xkb-config.h"
+#include "xkb-util.h"
#include <stdio.h>
#include <stdlib.h>
@@ -34,6 +35,7 @@
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
+#include <librsvg/rsvg.h>
#ifndef DEBUG
#define G_DISABLE_ASSERT
@@ -41,14 +43,21 @@
typedef struct
{
+ gchar *group_name;
+ gchar *variant;
+ gchar *pretty_layout_name;
+ GdkPixbuf *tooltip_pixbuf;
+} t_group_data;
+
+typedef struct
+{
XklEngine *engine;
- gchar **group_names;
- gchar **variants;
+ t_group_data *group_data;
+
t_group_policy group_policy;
GHashTable *variant_index_by_group;
-
GHashTable *application_map;
GHashTable *window_map;
@@ -56,6 +65,7 @@ typedef struct
guint current_application_id;
gint group_count;
+ gint current_group;
XkbCallback callback;
gpointer callback_data;
@@ -127,6 +137,7 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
gchar **group;
gint val, i;
gpointer pval;
+ gchar *imgfilename;
xkb_config_free ();
@@ -140,23 +151,24 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
config->window_map = g_hash_table_new (g_direct_hash, NULL);
config->application_map = g_hash_table_new (g_direct_hash, NULL);
-
- config->group_names = (gchar **) g_new0 (typeof (gchar **), config->group_count);
- config->variants = (gchar **) g_new0 (typeof (gchar **), config->group_count);
+ config->group_data = (t_group_data *) g_new0 (typeof (t_group_data),
+ config->group_count);
config->variant_index_by_group = g_hash_table_new (NULL, NULL);
index_variants = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < config->group_count; i++)
{
+ t_group_data *group_data = &config->group_data[i];
+ RsvgHandle *handle;
- config->group_names[i] = g_strdup (config_rec->layouts[i]);
+ group_data->group_name = g_strdup (config_rec->layouts[i]);
- config->variants[i] = (config_rec->variants[i] == NULL)
+ group_data->variant = (config_rec->variants[i] == NULL)
? g_strdup ("") : g_strdup (config_rec->variants[i]);
pval = g_hash_table_lookup (
index_variants,
- config->group_names[i]
+ group_data->group_name
);
val = (pval != NULL) ? GPOINTER_TO_INT (pval) : 0;
val++;
@@ -167,9 +179,26 @@ xkb_config_initialize_xkb_options (const XklConfigRec *config_rec)
);
g_hash_table_insert (
index_variants,
- config->group_names[i],
+ group_data->group_name,
GINT_TO_POINTER (val)
);
+
+ imgfilename = xkb_util_get_flag_filename (group_data->group_name);
+ handle = rsvg_handle_new_from_file (imgfilename, NULL);
+ if (handle)
+ {
+ GdkPixbuf *tmp = rsvg_handle_get_pixbuf (handle);
+ group_data->tooltip_pixbuf =
+ gdk_pixbuf_scale_simple (tmp, 24, 24, GDK_INTERP_BILINEAR);
+ g_object_unref (tmp);
+ rsvg_handle_close (handle, NULL);
+ g_object_unref (handle);
+ }
+ g_free (imgfilename);
+
+ group_data->pretty_layout_name =
+ xkb_util_get_layout_string (group_data->group_name,
+ group_data->variant);
}
g_hash_table_destroy (index_variants);
}
@@ -181,20 +210,6 @@ xkb_config_free (void)
g_assert (config != NULL);
- if (config->group_names)
- {
- for (i = 0; i < config->group_count; i++)
- g_free (config->group_names[i]);
- g_free (config->group_names);
- }
-
- if (config->variants)
- {
- for (i = 0; i < config->group_count; i++)
- g_free (config->variants[i]);
- g_free (config->variants);
- }
-
if (config->variant_index_by_group)
g_hash_table_destroy (config->variant_index_by_group);
@@ -203,6 +218,22 @@ xkb_config_free (void)
if (config->application_map)
g_hash_table_destroy (config->application_map);
+
+ if (config->group_data)
+ {
+ for (i = 0; i < config->group_count; i++)
+ {
+ t_group_data *group_data = &config->group_data[i];
+ g_free (group_data->group_name);
+ g_free (group_data->variant);
+ g_free (group_data->pretty_layout_name);
+ if (group_data->tooltip_pixbuf)
+ {
+ g_object_unref (group_data->tooltip_pixbuf);
+ }
+ }
+ g_free (config->group_data);
+ }
}
void
@@ -217,11 +248,10 @@ xkb_config_finalize (void)
gdk_window_remove_filter (NULL, (GdkFilterFunc) handle_xevent, NULL);
}
-static gint
+gint
xkb_config_get_current_group (void)
{
- XklState* state = xkl_engine_get_current_state (config->engine);
- return state->group;
+ return config->current_group;
}
gboolean
@@ -235,6 +265,7 @@ xkb_config_set_group (gint group)
}
xkl_engine_lock_group (config->engine, group);
+ config->current_group = group;
return TRUE;
}
@@ -388,7 +419,7 @@ xkb_config_get_group_name (gint group)
if (group == -1)
group = xkb_config_get_current_group ();
- return config->group_names[group];
+ return config->group_data[group].group_name;
}
const gchar*
@@ -402,7 +433,7 @@ xkb_config_get_variant (gint group)
if (group == -1)
group = xkb_config_get_current_group ();
- return config->variants[group];
+ return config->group_data[group].variant;
}
void
@@ -414,6 +445,8 @@ xkb_config_xkl_state_changed (XklEngine *engine,
{
if (change == GROUP_CHANGED)
{
+ config->current_group = group;
+
switch (config->group_policy)
{
case GROUP_POLICY_GLOBAL:
@@ -496,3 +529,14 @@ xkb_config_get_xkl_registry (void)
return registry;
}
+GdkPixbuf*
+xkb_config_get_tooltip_pixbuf (gint group)
+{
+ return config->group_data[group].tooltip_pixbuf;
+}
+
+gchar*
+xkb_config_get_pretty_layout_name (gint group)
+{
+ return config->group_data[group].pretty_layout_name;
+}
diff --git a/panel-plugin/xkb-config.h b/panel-plugin/xkb-config.h
index 0eee773..69888d3 100644
--- a/panel-plugin/xkb-config.h
+++ b/panel-plugin/xkb-config.h
@@ -32,6 +32,7 @@
#include <glib.h>
#include <glib/gstdio.h>
+#include <gdk/gdk.h>
#include <libxklavier/xklavier.h>
typedef enum
@@ -62,6 +63,9 @@ void xkb_config_window_changed (guint new_window_id,
guint application_id);
void xkb_config_application_closed (guint application_id);
void xkb_config_window_closed (guint window_id);
+GdkPixbuf* xkb_config_get_tooltip_pixbuf (gint group);
+gchar* xkb_config_get_pretty_layout_name (gint group);
+gint xkb_config_get_current_group (void);
/* TODO: remove this function - xkl structures should not be used outside xkb-config */
XklConfigRegistry*
More information about the Xfce4-commits
mailing list