summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey V. Udaltsov <svu@gnome.org>2010-12-31 02:57:48 +0000
committerSergey V. Udaltsov <svu@gnome.org>2010-12-31 02:57:48 +0000
commit11bb6388f548c0037a49799831416132ce63c06f (patch)
tree7edbf1bc3cdcd8c9b4176bbc55c18213d7660de4
parente431fae90ed97debb86fc9e0c89622e524feb213 (diff)
downloadlibgnomekbd-11bb6388f548c0037a49799831416132ce63c06f.tar.gz
Introduced GkbdConfiguration
Trying to refactor the code by reusing some shared bits. Hopefully will be useful for 3.0 (introspection, js) Based on https://bugzilla.gnome.org/show_bug.cgi?id=610836
-rw-r--r--libgnomekbd/Makefile.am2
-rw-r--r--libgnomekbd/gkbd-configuration.c506
-rw-r--r--libgnomekbd/gkbd-configuration.h92
-rw-r--r--libgnomekbd/gkbd-indicator.c389
-rw-r--r--libgnomekbd/gkbd-indicator.h55
-rw-r--r--libgnomekbd/gkbd-status.c325
-rw-r--r--libgnomekbd/gkbd-status.h46
-rw-r--r--test/gkbd-indicator-test.c3
8 files changed, 755 insertions, 663 deletions
diff --git a/libgnomekbd/Makefile.am b/libgnomekbd/Makefile.am
index 1f100cd..fe760d3 100644
--- a/libgnomekbd/Makefile.am
+++ b/libgnomekbd/Makefile.am
@@ -51,6 +51,7 @@ libgnomekbd_la_SOURCES = \
gkbd-util.c
libgnomekbdui_la_SOURCES = \
+ gkbd-configuration.c \
gkbd-indicator-config.c \
gkbd-indicator.c \
gkbd-status.c \
@@ -73,6 +74,7 @@ MAINTAINERCLEANFILES = \
gnomekbdincdir = $(includedir)/libgnomekbd
gnomekbdinc_HEADERS = \
+ gkbd-configuration.h \
gkbd-desktop-config.h \
gkbd-keyboard-config.h \
gkbd-indicator.h \
diff --git a/libgnomekbd/gkbd-configuration.c b/libgnomekbd/gkbd-configuration.c
new file mode 100644
index 0000000..4c392f0
--- /dev/null
+++ b/libgnomekbd/gkbd-configuration.c
@@ -0,0 +1,506 @@
+/*
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Authors: Jan Arne Petersen <jpetersen@openismus.com>
+ *
+ * Based on gkbd-status.c by Sergey V. Udaltsov <svu@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <memory.h>
+
+#include <gdk/gdkkeysyms.h>
+#include <gdk/gdkx.h>
+#include <glib/gi18n.h>
+
+#include <gkbd-configuration.h>
+
+#include <gkbd-desktop-config.h>
+
+struct _GkbdConfigurationPrivate {
+ XklEngine *engine;
+ XklConfigRegistry *registry;
+
+ GkbdDesktopConfig cfg;
+ GkbdIndicatorConfig ind_cfg;
+ GkbdKeyboardConfig kbd_cfg;
+
+ gchar **full_group_names;
+ gchar **short_group_names;
+
+ const gchar *tooltips_format;
+
+ gulong state_changed_handler;
+ gulong config_changed_handler;
+};
+
+enum {
+ SIGNAL_CHANGED,
+ SIGNAL_GROUP_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+#define GKBD_CONFIGURATION_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GKBD_TYPE_CONFIGURATION, GkbdConfigurationPrivate))
+
+G_DEFINE_TYPE (GkbdConfiguration, gkbd_configuration, G_TYPE_OBJECT)
+
+/* Should be called once for all widgets */
+static void
+gkbd_configuration_cfg_changed (GSettings * settings, gchar * key,
+ GkbdConfiguration * configuration)
+{
+ GkbdConfigurationPrivate *priv = configuration->priv;
+
+ xkl_debug (100,
+ "General configuration changed in GConf - reiniting...\n");
+ gkbd_desktop_config_load (&priv->cfg);
+ gkbd_desktop_config_activate (&priv->cfg);
+
+ g_signal_emit (configuration, signals[SIGNAL_CHANGED], 0);
+}
+
+/* Should be called once for all widgets */
+static void
+gkbd_configuration_ind_cfg_changed (GSettings * settings, gchar * key,
+ GkbdConfiguration * configuration)
+{
+ GkbdConfigurationPrivate *priv = configuration->priv;
+ xkl_debug (100,
+ "Applet configuration changed in GConf - reiniting...\n");
+ gkbd_indicator_config_load (&priv->ind_cfg);
+
+ gkbd_indicator_config_free_image_filenames (&priv->ind_cfg);
+ gkbd_indicator_config_load_image_filenames (&priv->ind_cfg,
+ &priv->kbd_cfg);
+
+ gkbd_indicator_config_activate (&priv->ind_cfg);
+
+ g_signal_emit (configuration, signals[SIGNAL_CHANGED], 0);
+}
+
+static void
+gkbd_configuration_load_group_names (GkbdConfiguration * configuration,
+ XklConfigRec * xklrec)
+{
+ GkbdConfigurationPrivate *priv = configuration->priv;
+
+ if (!gkbd_desktop_config_load_group_descriptions (&priv->cfg,
+ priv->registry,
+ (const char **)
+ xklrec->layouts,
+ (const char **)
+ xklrec->variants,
+ &priv->
+ short_group_names,
+ &priv->
+ full_group_names))
+ {
+ /* We just populate no short names (remain NULL) -
+ * full names are going to be used anyway */
+ gint i, total_groups =
+ xkl_engine_get_num_groups (priv->engine);
+ xkl_debug (150, "group descriptions loaded: %d!\n",
+ total_groups);
+
+ if (xkl_engine_get_features (priv->engine) &
+ XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
+ priv->full_group_names =
+ g_strdupv (priv->kbd_cfg.layouts_variants);
+ } else {
+ priv->full_group_names =
+ g_new0 (char *, total_groups + 1);
+ for (i = total_groups; --i >= 0;) {
+ priv->full_group_names[i] =
+ g_strdup_printf ("Group %d", i);
+ }
+ }
+ }
+}
+
+/* Should be called once for all widgets */
+static void
+gkbd_configuration_kbd_cfg_callback (XklEngine * engine,
+ GkbdConfiguration * configuration)
+{
+ GkbdConfigurationPrivate *priv = configuration->priv;
+ XklConfigRec *xklrec = xkl_config_rec_new ();
+ xkl_debug (100,
+ "XKB configuration changed on X Server - reiniting...\n");
+
+ gkbd_keyboard_config_load_from_x_current (&priv->kbd_cfg, xklrec);
+
+ gkbd_indicator_config_free_image_filenames (&priv->ind_cfg);
+ gkbd_indicator_config_load_image_filenames (&priv->ind_cfg,
+ &priv->kbd_cfg);
+
+ g_strfreev (priv->full_group_names);
+ priv->full_group_names = NULL;
+
+ g_strfreev (priv->short_group_names);
+ priv->short_group_names = NULL;
+
+ gkbd_configuration_load_group_names (configuration, xklrec);
+
+ g_signal_emit (configuration, signals[SIGNAL_CHANGED], 0);
+
+ g_object_unref (G_OBJECT (xklrec));
+}
+
+/* Should be called once for all applets */
+static void
+gkbd_configuration_state_callback (XklEngine * engine,
+ XklEngineStateChange changeType,
+ gint group, gboolean restore,
+ GkbdConfiguration * configuration)
+{
+ xkl_debug (150, "group is now %d, restore: %d\n", group, restore);
+
+ if (changeType == GROUP_CHANGED) {
+ g_signal_emit (configuration,
+ signals[SIGNAL_GROUP_CHANGED], 0, group);
+ }
+}
+
+static void
+gkbd_configuration_init (GkbdConfiguration * configuration)
+{
+ GkbdConfigurationPrivate *priv;
+ XklConfigRec *xklrec = xkl_config_rec_new ();
+
+ priv = GKBD_CONFIGURATION_GET_PRIVATE (configuration);
+ configuration->priv = priv;
+
+ /* Initing some global vars */
+ priv->tooltips_format = "%s";
+
+ priv->engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
+ (gdk_display_get_default
+ ()));
+ if (priv->engine == NULL) {
+ xkl_debug (0, "Libxklavier initialization error");
+ return;
+ }
+
+ priv->state_changed_handler =
+ g_signal_connect (priv->engine, "X-state-changed",
+ G_CALLBACK
+ (gkbd_configuration_state_callback),
+ configuration);
+ priv->config_changed_handler =
+ g_signal_connect (priv->engine, "X-config-changed",
+ G_CALLBACK
+ (gkbd_configuration_kbd_cfg_callback),
+ configuration);
+
+ gkbd_desktop_config_init (&priv->cfg, priv->engine);
+ gkbd_keyboard_config_init (&priv->kbd_cfg, priv->engine);
+ gkbd_indicator_config_init (&priv->ind_cfg, priv->engine);
+
+ gkbd_desktop_config_load (&priv->cfg);
+ gkbd_desktop_config_activate (&priv->cfg);
+
+ priv->registry = xkl_config_registry_get_instance (priv->engine);
+ xkl_config_registry_load (priv->registry,
+ priv->cfg.load_extra_items);
+
+ gkbd_keyboard_config_load_from_x_current (&priv->kbd_cfg, xklrec);
+
+ gkbd_indicator_config_load (&priv->ind_cfg);
+
+ gkbd_indicator_config_load_image_filenames (&priv->ind_cfg,
+ &priv->kbd_cfg);
+
+ gkbd_indicator_config_activate (&priv->ind_cfg);
+
+ gkbd_configuration_load_group_names (configuration, xklrec);
+ g_object_unref (G_OBJECT (xklrec));
+
+ gkbd_desktop_config_start_listen (&priv->cfg,
+ G_CALLBACK
+ (gkbd_configuration_cfg_changed),
+ configuration);
+ gkbd_indicator_config_start_listen (&priv->ind_cfg,
+ G_CALLBACK
+ (gkbd_configuration_ind_cfg_changed),
+ configuration);
+ xkl_engine_start_listen (priv->engine, XKLL_TRACK_KEYBOARD_STATE);
+
+ xkl_debug (100, "Initiating the widget startup process for %p\n",
+ configuration);
+}
+
+static void
+gkbd_configuration_finalize (GObject * obj)
+{
+ GkbdConfiguration *configuration = GKBD_CONFIGURATION (obj);
+ GkbdConfigurationPrivate *priv = configuration->priv;
+
+ xkl_debug (100,
+ "Starting the gnome-kbd-configuration widget shutdown process for %p\n",
+ configuration);
+
+ xkl_engine_stop_listen (priv->engine, XKLL_TRACK_KEYBOARD_STATE);
+
+ gkbd_desktop_config_stop_listen (&priv->cfg);
+ gkbd_indicator_config_stop_listen (&priv->ind_cfg);
+
+ gkbd_indicator_config_term (&priv->ind_cfg);
+ gkbd_keyboard_config_term (&priv->kbd_cfg);
+ gkbd_desktop_config_term (&priv->cfg);
+
+ if (g_signal_handler_is_connected (priv->engine,
+ priv->state_changed_handler)) {
+ g_signal_handler_disconnect (priv->engine,
+ priv->state_changed_handler);
+ priv->state_changed_handler = 0;
+ }
+ if (g_signal_handler_is_connected (priv->engine,
+ priv->config_changed_handler)) {
+ g_signal_handler_disconnect (priv->engine,
+ priv->config_changed_handler);
+ priv->config_changed_handler = 0;
+ }
+
+ g_object_unref (priv->registry);
+ priv->registry = NULL;
+ g_object_unref (priv->engine);
+ priv->engine = NULL;
+
+ G_OBJECT_CLASS (gkbd_configuration_parent_class)->finalize (obj);
+}
+
+static void
+gkbd_configuration_class_init (GkbdConfigurationClass * klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ /* Initing vtable */
+ object_class->finalize = gkbd_configuration_finalize;
+
+ /* Signals */
+ signals[SIGNAL_CHANGED] = g_signal_new ("changed",
+ GKBD_TYPE_CONFIGURATION,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[SIGNAL_GROUP_CHANGED] = g_signal_new ("group-changed",
+ GKBD_TYPE_CONFIGURATION,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE,
+ 1, G_TYPE_INT);
+
+ g_type_class_add_private (klass,
+ sizeof (GkbdConfigurationPrivate));
+}
+
+GkbdConfiguration *
+gkbd_configuration_get (void)
+{
+ static gpointer instance = NULL;
+
+ if (!instance) {
+ instance = g_object_new (GKBD_TYPE_CONFIGURATION, NULL);
+ g_object_add_weak_pointer (instance, &instance);
+ } else {
+ g_object_ref (instance);
+ }
+
+ return instance;
+}
+
+XklEngine *
+gkbd_configuration_get_xkl_engine (GkbdConfiguration * configuration)
+{
+ return configuration->priv->engine;
+}
+
+gchar **
+gkbd_configuration_get_group_names (GkbdConfiguration * configuration)
+{
+ return configuration->priv->full_group_names;
+}
+
+gchar *
+gkbd_configuration_get_image_filename (GkbdConfiguration * configuration,
+ guint group)
+{
+ if (!configuration->priv->ind_cfg.show_flags)
+ return NULL;
+ return (gchar *) g_slist_nth_data (configuration->priv->ind_cfg.
+ image_filenames, group);
+}
+
+gchar **
+gkbd_configuration_get_short_group_names (GkbdConfiguration *
+ configuration)
+{
+ return configuration->priv->short_group_names;
+}
+
+gchar *
+gkbd_configuration_get_current_tooltip (GkbdConfiguration * configuration)
+{
+ XklState *state =
+ xkl_engine_get_current_state (configuration->priv->engine);
+ gchar *buf;
+ if (state == NULL || state->group < 0
+ || state->group >=
+ g_strv_length (configuration->priv->full_group_names))
+ return NULL;
+
+ return g_strdup_printf (configuration->priv->tooltips_format,
+ configuration->priv->
+ full_group_names[state->group]);
+}
+
+gboolean
+gkbd_configuration_if_flags_shown (GkbdConfiguration * configuration)
+{
+ return configuration->priv->ind_cfg.show_flags;
+}
+
+gchar *
+gkbd_configuration_extract_layout_name (GkbdConfiguration * configuration,
+ int group)
+{
+ char *layout_name = NULL;
+ gchar **short_group_names = configuration->priv->short_group_names;
+ gchar **full_group_names = configuration->priv->full_group_names;
+ XklEngine *engine = configuration->priv->engine;
+ if (group < g_strv_length (short_group_names)) {
+ if (xkl_engine_get_features (engine) &
+ XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
+ char *full_layout_name =
+ configuration->priv->kbd_cfg.
+ layouts_variants[group];
+ char *variant_name;
+ if (!gkbd_keyboard_config_split_items
+ (full_layout_name, &layout_name,
+ &variant_name))
+ /* just in case */
+ layout_name = full_layout_name;
+
+ /* make it freeable */
+ layout_name = g_strdup (layout_name);
+
+ if (short_group_names != NULL) {
+ char *short_group_name =
+ short_group_names[group];
+ if (short_group_name != NULL
+ && *short_group_name != '\0') {
+ /* drop the long name */
+ g_free (layout_name);
+ layout_name =
+ g_strdup (short_group_name);
+ }
+ }
+ } else {
+ layout_name = g_strdup (full_group_names[group]);
+ }
+ }
+
+ if (layout_name == NULL)
+ layout_name = g_strdup ("");
+
+ return layout_name;
+}
+
+void
+gkbd_configuration_lock_next_group (GkbdConfiguration * configuration)
+{
+ gkbd_desktop_config_lock_next_group (&configuration->priv->cfg);
+}
+
+GkbdIndicatorConfig *
+gkbd_configuration_get_indicator_config (GkbdConfiguration * configuration)
+{
+ return &configuration->priv->ind_cfg;
+}
+
+GkbdKeyboardConfig *
+gkbd_configuration_get_keyboard_config (GkbdConfiguration * configuration)
+{
+ return &configuration->priv->kbd_cfg;
+}
+
+GSList *
+gkbd_configuration_load_images (GkbdConfiguration * configuration)
+{
+ int i;
+ GSList *image_filename, *images;
+
+ images = NULL;
+ gkbd_indicator_config_load_image_filenames (&configuration->
+ priv->ind_cfg,
+ &configuration->
+ priv->kbd_cfg);
+
+ if (!configuration->priv->ind_cfg.show_flags)
+ return NULL;
+
+ image_filename = configuration->priv->ind_cfg.image_filenames;
+
+ for (i =
+ xkl_engine_get_max_num_groups (configuration->priv->engine);
+ --i >= 0; image_filename = image_filename->next) {
+ GdkPixbuf *image = NULL;
+ char *image_file = (char *) image_filename->data;
+
+ if (image_file != NULL) {
+ GError *gerror = NULL;
+ image =
+ gdk_pixbuf_new_from_file (image_file, &gerror);
+ xkl_debug (150,
+ "Image %d[%s] loaded -> %p[%dx%d]\n",
+ i, image_file, image,
+ gdk_pixbuf_get_width (image),
+ gdk_pixbuf_get_height (image));
+ }
+ /* We append the image anyway - even if it is NULL! */
+ images = g_slist_append (images, image);
+ }
+ return images;
+}
+
+void
+gkbd_configuration_free_images (GkbdConfiguration * configuration,
+ GSList * images)
+{
+ GdkPixbuf *pi;
+ GSList *img_node;
+
+ gkbd_indicator_config_free_image_filenames (&configuration->
+ priv->ind_cfg);
+
+ while ((img_node = images) != NULL) {
+ pi = GDK_PIXBUF (img_node->data);
+ /* It can be NULL - some images may be missing */
+ if (pi != NULL) {
+ g_object_unref (pi);
+ }
+ images = g_slist_remove_link (images, img_node);
+ g_slist_free_1 (img_node);
+ }
+}
diff --git a/libgnomekbd/gkbd-configuration.h b/libgnomekbd/gkbd-configuration.h
new file mode 100644
index 0000000..3caa1f8
--- /dev/null
+++ b/libgnomekbd/gkbd-configuration.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2010 Canonical Ltd.
+ *
+ * Authors: Jan Arne Petersen <jpetersen@openismus.com>
+ *
+ * Based on gkbd-status.h by Sergey V. Udaltsov <svu@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GKBD_CONFIGURATION_H__
+#define __GKBD_CONFIGURATION_H__
+
+#include <glib-object.h>
+
+#include <libxklavier/xklavier.h>
+
+#include <libgnomekbd/gkbd-indicator-config.h>
+
+G_BEGIN_DECLS typedef struct _GkbdConfiguration GkbdConfiguration;
+typedef struct _GkbdConfigurationPrivate GkbdConfigurationPrivate;
+typedef struct _GkbdConfigurationClass GkbdConfigurationClass;
+
+#define GKBD_TYPE_CONFIGURATION (gkbd_configuration_get_type ())
+#define GKBD_CONFIGURATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKBD_TYPE_CONFIGURATION, GkbdConfiguration))
+#define GKBD_INDCATOR_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GKBD_TYPE_CONFIGURATION, GkbdConfigurationClass))
+#define GKBD_IS_CONFIGURATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GKBD_TYPE_CONFIGURATION))
+#define GKBD_IS_CONFIGURATION_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GKBD_TYPE_CONFIGURATION))
+#define GKBD_CONFIGURATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKBD_TYPE_CONFIGURATION, GkbdConfigurationClass))
+
+struct _GkbdConfiguration {
+ GObject parent;
+
+ GkbdConfigurationPrivate *priv;
+};
+
+struct _GkbdConfigurationClass {
+ GObjectClass parent_class;
+};
+
+extern GType gkbd_configuration_get_type (void);
+
+extern GkbdConfiguration *gkbd_configuration_get (void);
+
+extern XklEngine *gkbd_configuration_get_xkl_engine (GkbdConfiguration *
+ configuration);
+
+extern gchar **gkbd_configuration_get_group_names (GkbdConfiguration *
+ configuration);
+extern gchar **gkbd_configuration_get_short_group_names (GkbdConfiguration
+ * configuration);
+extern gchar *gkbd_configuration_get_image_filename (GkbdConfiguration *
+ configuration,
+ guint group);
+extern gchar *gkbd_configuration_get_current_tooltip (GkbdConfiguration *
+ configuration);
+extern gboolean gkbd_configuration_if_flags_shown (GkbdConfiguration *
+ configuration);
+extern gchar *gkbd_configuration_extract_layout_name (GkbdConfiguration *
+ configuration,
+ int group);
+extern void gkbd_configuration_lock_next_group (GkbdConfiguration *
+ configuration);
+extern GkbdIndicatorConfig
+ * gkbd_configuration_get_indicator_config (GkbdConfiguration *
+ configuration);
+extern GkbdKeyboardConfig
+ *gkbd_configuration_get_keyboard_config (GkbdConfiguration *
+ configuration);
+
+extern GSList *gkbd_configuration_load_images (GkbdConfiguration *
+ configuration);
+
+extern void gkbd_configuration_free_images (GkbdConfiguration *
+ configuration,
+ GSList * images);
+
+G_END_DECLS
+#endif
diff --git a/libgnomekbd/gkbd-indicator.c b/libgnomekbd/gkbd-indicator.c
index 58f21ca..fcd920e 100644
--- a/libgnomekbd/gkbd-indicator.c
+++ b/libgnomekbd/gkbd-indicator.c
@@ -28,23 +28,16 @@
#include <gkbd-desktop-config.h>
#include <gkbd-indicator-config.h>
+#include <gkbd-configuration.h>
#include <gkbd-indicator-plugin-manager.h>
typedef struct _gki_globals {
- XklEngine *engine;
- XklConfigRegistry *registry;
-
- GkbdDesktopConfig cfg;
- GkbdIndicatorConfig ind_cfg;
- GkbdKeyboardConfig kbd_cfg;
+ GkbdConfiguration *config;
GkbdIndicatorPluginContainer plugin_container;
GkbdIndicatorPluginManager plugin_manager;
- const gchar *tooltips_format;
- gchar **full_group_names;
- gchar **short_group_names;
GSList *widget_instances;
GSList *images;
} gki_globals;
@@ -88,78 +81,14 @@ gkbd_indicator_set_tooltips (GkbdIndicator * gki, const char *str);
void
gkbd_indicator_load_images ()
{
- int i;
- GSList *image_filename;
-
- globals.images = NULL;
- gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
- &globals.kbd_cfg);
-
- if (!globals.ind_cfg.show_flags)
- return;
-
- image_filename = globals.ind_cfg.image_filenames;
-
- for (i = xkl_engine_get_max_num_groups (globals.engine);
- --i >= 0; image_filename = image_filename->next) {
- GdkPixbuf *image = NULL;
- char *image_file = (char *) image_filename->data;
-
- if (image_file != NULL) {
- GError *gerror = NULL;
- image =
- gdk_pixbuf_new_from_file (image_file, &gerror);
- if (image == NULL) {
- GtkWidget *dialog =
- gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _
- ("There was an error loading an image: %s"),
- gerror->
- message);
- g_signal_connect (G_OBJECT (dialog),
- "response",
- G_CALLBACK
- (gtk_widget_destroy),
- NULL);
-
- gtk_window_set_resizable (GTK_WINDOW
- (dialog), FALSE);
-
- gtk_widget_show (dialog);
- g_error_free (gerror);
- }
- xkl_debug (150,
- "Image %d[%s] loaded -> %p[%dx%d]\n",
- i, image_file, image,
- gdk_pixbuf_get_width (image),
- gdk_pixbuf_get_height (image));
- }
- /* We append the image anyway - even if it is NULL! */
- globals.images = g_slist_append (globals.images, image);
- }
+ globals.images = gkbd_configuration_load_images (globals.config);
}
static void
gkbd_indicator_free_images ()
{
- GdkPixbuf *pi;
- GSList *img_node;
-
- gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
-
- while ((img_node = globals.images) != NULL) {
- pi = GDK_PIXBUF (img_node->data);
- /* It can be NULL - some images may be missing */
- if (pi != NULL) {
- g_object_unref (pi);
- }
- globals.images =
- g_slist_remove_link (globals.images, img_node);
- g_slist_free_1 (img_node);
- }
+ gkbd_configuration_free_images (globals.config, globals.images);
+ globals.images = NULL;
}
static void
@@ -201,15 +130,19 @@ void
gkbd_indicator_fill (GkbdIndicator * gki)
{
int grp;
- int total_groups = xkl_engine_get_num_groups (globals.engine);
+ int total_groups =
+ xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
+ (globals.config));
GtkNotebook *notebook = GTK_NOTEBOOK (gki);
+ gchar **full_group_names =
+ gkbd_configuration_get_group_names (globals.config);
for (grp = 0; grp < total_groups; grp++) {
GtkWidget *page, *decorated_page = NULL;
gchar *full_group_name =
(grp <
- g_strv_length (globals.full_group_names)) ?
- globals.full_group_names[grp] : "?";
+ g_strv_length (full_group_names)) ?
+ full_group_names[grp] : "?";
page = gkbd_indicator_prepare_drawing (gki, grp);
if (page == NULL)
@@ -218,7 +151,9 @@ gkbd_indicator_fill (GkbdIndicator * gki)
decorated_page =
gkbd_indicator_plugin_manager_decorate_widget
(&globals.plugin_manager, page, grp,
- full_group_name, &globals.kbd_cfg);
+ full_group_name,
+ gkbd_configuration_get_keyboard_config (globals.
+ config));
page = decorated_page == NULL ? page : decorated_page;
@@ -239,7 +174,7 @@ gkbd_indicator_key_pressed (GtkWidget *
case GDK_KEY_Return:
case GDK_KEY_space:
case GDK_KEY_KP_Space:
- gkbd_desktop_config_lock_next_group (&globals.cfg);
+ gkbd_configuration_lock_next_group (globals.config);
return TRUE;
default:
break;
@@ -259,7 +194,7 @@ gkbd_indicator_button_pressed (GtkWidget *
allocation.width, allocation.height);
if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
xkl_debug (150, "Mouse button pressed on applet\n");
- gkbd_desktop_config_lock_next_group (&globals.cfg);
+ gkbd_configuration_lock_next_group (globals.config);
return TRUE;
}
return FALSE;
@@ -299,50 +234,6 @@ flag_exposed (GtkWidget * flag, GdkEventExpose * event, GdkPixbuf * image)
}
gchar *
-gkbd_indicator_extract_layout_name (int group, XklEngine * engine,
- GkbdKeyboardConfig * kbd_cfg,
- gchar ** short_group_names,
- gchar ** full_group_names)
-{
- char *layout_name = NULL;
- if (group < g_strv_length (short_group_names)) {
- if (xkl_engine_get_features (engine) &
- XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
- char *full_layout_name =
- kbd_cfg->layouts_variants[group];
- char *variant_name;
- if (!gkbd_keyboard_config_split_items
- (full_layout_name, &layout_name,
- &variant_name))
- /* just in case */
- layout_name = full_layout_name;
-
- /* make it freeable */
- layout_name = g_strdup (layout_name);
-
- if (short_group_names != NULL) {
- char *short_group_name =
- short_group_names[group];
- if (short_group_name != NULL
- && *short_group_name != '\0') {
- /* drop the long name */
- g_free (layout_name);
- layout_name =
- g_strdup (short_group_name);
- }
- }
- } else {
- layout_name = g_strdup (full_group_names[group]);
- }
- }
-
- if (layout_name == NULL)
- layout_name = g_strdup ("");
-
- return layout_name;
-}
-
-gchar *
gkbd_indicator_create_label_title (int group, GHashTable ** ln2cnt_map,
gchar * layout_name)
{
@@ -390,7 +281,7 @@ gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
pimage = g_slist_nth_data (globals.images, group);
ebox = gtk_event_box_new ();
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
- if (globals.ind_cfg.show_flags) {
+ if (gkbd_configuration_if_flags_shown (globals.config)) {
GtkWidget *flag;
if (pimage == NULL)
return NULL;
@@ -408,11 +299,8 @@ gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
static GHashTable *ln2cnt_map = NULL;
layout_name =
- gkbd_indicator_extract_layout_name (group,
- globals.engine,
- &globals.kbd_cfg,
- globals.short_group_names,
- globals.full_group_names);
+ gkbd_configuration_extract_layout_name (globals.config,
+ group);
lbl_title =
gkbd_indicator_create_label_title (group,
@@ -425,7 +313,8 @@ gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
gtk_label_set_angle (GTK_LABEL (label), gki->priv->angle);
if (group + 1 ==
- xkl_engine_get_num_groups (globals.engine)) {
+ xkl_engine_get_num_groups
+ (gkbd_configuration_get_xkl_engine (globals.config))) {
g_hash_table_destroy (ln2cnt_map);
ln2cnt_map = NULL;
}
@@ -452,17 +341,12 @@ gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
static void
gkbd_indicator_update_tooltips (GkbdIndicator * gki)
{
- XklState *state = xkl_engine_get_current_state (globals.engine);
- gchar *buf;
- if (state == NULL || state->group < 0
- || state->group >= g_strv_length (globals.full_group_names))
- return;
-
- buf = g_strdup_printf (globals.tooltips_format,
- globals.full_group_names[state->group]);
-
- gkbd_indicator_set_tooltips (gki, buf);
- g_free (buf);
+ gchar *buf =
+ gkbd_configuration_get_current_tooltip (globals.config);
+ if (buf != NULL) {
+ gkbd_indicator_set_tooltips (gki, buf);
+ g_free (buf);
+ }
}
static void
@@ -483,126 +367,45 @@ gkbd_indicator_reinit_ui (GkbdIndicator * gki)
g_signal_emit_by_name (gki, "reinit-ui");
}
-/* Should be called once for all widgets */
-static void
-gkbd_indicator_cfg_changed (GSettings * settings, gchar * key)
-{
- xkl_debug (100,
- "General configuration changed in GConf - reiniting...\n");
- gkbd_desktop_config_load (&globals.cfg);
- gkbd_desktop_config_activate (&globals.cfg);
- ForAllIndicators () {
- gkbd_indicator_reinit_ui (gki);
- } NextIndicator ();
-}
/* Should be called once for all widgets */
static void
-gkbd_indicator_ind_cfg_changed (GSettings * settings, gchar * key)
+gkbd_indicator_kbd_cfg_callback (GkbdConfiguration * configuration)
{
- xkl_debug (100,
- "Applet configuration changed in GConf - reiniting...\n");
- gkbd_indicator_config_load (&globals.ind_cfg);
- gkbd_indicator_update_images ();
- gkbd_indicator_config_activate (&globals.ind_cfg);
-
gkbd_indicator_plugin_manager_toggle_plugins
(&globals.plugin_manager, &globals.plugin_container,
- globals.ind_cfg.enabled_plugins);
+ gkbd_configuration_get_indicator_config (globals.config)->
+ enabled_plugins);
ForAllIndicators () {
gkbd_indicator_reinit_ui (gki);
} NextIndicator ();
}
+/* Should be called once for all applets */
static void
-gkbd_indicator_load_group_names (const gchar ** layout_ids,
- const gchar ** variant_ids)
-{
- if (!gkbd_desktop_config_load_group_descriptions
- (&globals.cfg, globals.registry, layout_ids, variant_ids,
- &globals.short_group_names, &globals.full_group_names)) {
- /* We just populate no short names (remain NULL) -
- * full names are going to be used anyway */
- gint i, total_groups =
- xkl_engine_get_num_groups (globals.engine);
-
- if (xkl_engine_get_features (globals.engine) &
- XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
- globals.full_group_names =
- g_strdupv (globals.kbd_cfg.layouts_variants);
- } else {
- globals.full_group_names =
- g_new0 (gchar *, total_groups + 1);
- for (i = total_groups; --i >= 0;) {
- globals.full_group_names[i] =
- g_strdup_printf ("Group %d", i);
- }
- }
- }
-}
-
-/* Should be called once for all widgets */
-static void
-gkbd_indicator_kbd_cfg_callback (GkbdIndicator * gki)
+gkbd_indicator_state_callback (GkbdConfiguration * configuration,
+ gint group)
{
- XklConfigRec *xklrec = xkl_config_rec_new ();
- xkl_debug (100,
- "XKB configuration changed on X Server - reiniting...\n");
-
- gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
- xklrec);
- gkbd_indicator_update_images ();
-
- g_strfreev (globals.full_group_names);
- globals.full_group_names = NULL;
-
- if (globals.short_group_names != NULL) {
- g_strfreev (globals.short_group_names);
- globals.short_group_names = NULL;
- }
-
- gkbd_indicator_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **)
- xklrec->variants);
-
ForAllIndicators () {
- gkbd_indicator_reinit_ui (gki);
- } NextIndicator ();
- g_object_unref (G_OBJECT (xklrec));
-}
-
-/* Should be called once for all applets */
-static void
-gkbd_indicator_state_callback (XklEngine * engine,
- XklEngineStateChange changeType,
- gint group, gboolean restore)
-{
- xkl_debug (150, "group is now %d, restore: %d\n", group, restore);
-
- if (changeType == GROUP_CHANGED) {
- ForAllIndicators () {
- gkbd_indicator_plugin_manager_group_changed
- (&globals.plugin_manager, GTK_WIDGET (gki),
- group);
- xkl_debug (200, "do repaint\n");
- gkbd_indicator_set_current_page_for_group
- (gki, group);
- }
- NextIndicator ();
+ gkbd_indicator_plugin_manager_group_changed
+ (&globals.plugin_manager, GTK_WIDGET (gki), group);
+ xkl_debug (200, "do repaint\n");
+ gkbd_indicator_set_current_page_for_group (gki, group);
}
+ NextIndicator ();
}
void
gkbd_indicator_set_current_page (GkbdIndicator * gki)
{
- XklState *cur_state;
- cur_state = xkl_engine_get_current_state (globals.engine);
+ XklEngine *engine =
+ gkbd_configuration_get_xkl_engine (globals.config);
+ XklState *cur_state = xkl_engine_get_current_state (engine);
if (cur_state->group >= 0)
gkbd_indicator_set_current_page_for_group (gki,
- cur_state->
- group);
+ cur_state->group);
}
void
@@ -620,8 +423,10 @@ static GdkFilterReturn
gkbd_indicator_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
{
XEvent *xevent = (XEvent *) xev;
+ XklEngine *engine =
+ gkbd_configuration_get_xkl_engine (globals.config);
- xkl_engine_filter_events (globals.engine, xevent);
+ xkl_engine_filter_events (engine, xevent);
switch (xevent->type) {
case ReparentNotify:
{
@@ -637,8 +442,7 @@ gkbd_indicator_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
&& GDK_WINDOW_XID (w) == rne->window) {
/* if so - make it transparent... */
xkl_engine_set_window_transparent
- (globals.engine, rne->window,
- TRUE);
+ (engine, rne->window, TRUE);
}
}
NextIndicator ()
@@ -658,17 +462,12 @@ gkbd_indicator_start_listen (void)
gdk_window_add_filter (gdk_get_default_root_window (),
(GdkFilterFunc)
gkbd_indicator_filter_x_evt, NULL);
-
- xkl_engine_start_listen (globals.engine,
- XKLL_TRACK_KEYBOARD_STATE);
}
/* Should be called once for all widgets */
static void
gkbd_indicator_stop_listen (void)
{
- xkl_engine_stop_listen (globals.engine, XKLL_TRACK_KEYBOARD_STATE);
-
gdk_window_remove_filter (NULL, (GdkFilterFunc)
gkbd_indicator_filter_x_evt, NULL);
gdk_window_remove_filter
@@ -709,7 +508,7 @@ gkbd_indicator_init (GkbdIndicator * gki)
gtk_notebook_append_page (notebook, def_drawing,
gtk_label_new (""));
- if (globals.engine == NULL) {
+ if (gkbd_configuration_get_xkl_engine (globals.config) == NULL) {
gkbd_indicator_set_tooltips (gki,
_
("XKB initialization error"));
@@ -757,25 +556,16 @@ static void
gkbd_indicator_global_term (void)
{
xkl_debug (100, "*** Last GkbdIndicator instance *** \n");
- gkbd_indicator_stop_listen ();
-
- gkbd_desktop_config_stop_listen (&globals.cfg);
- gkbd_indicator_config_stop_listen (&globals.ind_cfg);
gkbd_indicator_plugin_manager_term_initialized_plugins
(&globals.plugin_manager);
gkbd_indicator_plugin_manager_term (&globals.plugin_manager);
-
- gkbd_indicator_config_term (&globals.ind_cfg);
- gkbd_keyboard_config_term (&globals.kbd_cfg);
- gkbd_desktop_config_term (&globals.cfg);
-
gkbd_indicator_plugin_container_term (&globals.plugin_container);
- g_object_unref (G_OBJECT (globals.registry));
- globals.registry = NULL;
- g_object_unref (G_OBJECT (globals.engine));
- globals.engine = NULL;
+ gkbd_indicator_stop_listen ();
+ g_object_unref (globals.config);
+ globals.config = NULL;
+
xkl_debug (100, "*** Terminated globals *** \n");
}
@@ -789,9 +579,6 @@ gkbd_indicator_class_init (GkbdIndicatorClass * klass)
memset (&globals, 0, sizeof (globals));
- /* Initing some global vars */
- globals.tooltips_format = "%s";
-
/* Initing vtable */
object_class->finalize = gkbd_indicator_finalize;
@@ -809,61 +596,25 @@ gkbd_indicator_class_init (GkbdIndicatorClass * klass)
static void
gkbd_indicator_global_init (void)
{
- XklConfigRec *xklrec = xkl_config_rec_new ();
-
- globals.engine =
- xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
- (gdk_display_get_default ()));
- if (globals.engine == NULL) {
- xkl_debug (0, "Libxklavier initialization error");
- return;
- }
+ globals.config = gkbd_configuration_get ();
- g_signal_connect (globals.engine, "X-state-changed",
+ g_signal_connect (globals.config, "group-changed",
G_CALLBACK (gkbd_indicator_state_callback),
NULL);
- g_signal_connect (globals.engine, "X-config-changed",
+ g_signal_connect (globals.config, "changed",
G_CALLBACK (gkbd_indicator_kbd_cfg_callback),
NULL);
gkbd_indicator_plugin_container_init (&globals.plugin_container);
- gkbd_desktop_config_init (&globals.cfg, globals.engine);
- gkbd_keyboard_config_init (&globals.kbd_cfg, globals.engine);
- gkbd_indicator_config_init (&globals.ind_cfg, globals.engine);
-
- gkbd_desktop_config_load (&globals.cfg);
- gkbd_desktop_config_activate (&globals.cfg);
-
- globals.registry =
- xkl_config_registry_get_instance (globals.engine);
- xkl_config_registry_load (globals.registry,
- globals.cfg.load_extra_items);
-
- gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
- xklrec);
-
- gkbd_indicator_config_load (&globals.ind_cfg);
gkbd_indicator_update_images ();
- gkbd_indicator_config_activate (&globals.ind_cfg);
-
- gkbd_indicator_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **)
- xklrec->variants);
- g_object_unref (G_OBJECT (xklrec));
gkbd_indicator_plugin_manager_init (&globals.plugin_manager);
gkbd_indicator_plugin_manager_init_enabled_plugins
(&globals.plugin_manager, &globals.plugin_container,
- globals.ind_cfg.enabled_plugins);
- gkbd_desktop_config_start_listen (&globals.cfg,
- G_CALLBACK
- (gkbd_indicator_cfg_changed),
- NULL);
- gkbd_indicator_config_start_listen (&globals.ind_cfg,
- G_CALLBACK
- (gkbd_indicator_ind_cfg_changed),
- NULL);
+ gkbd_configuration_get_indicator_config (globals.config)->
+ enabled_plugins);
+
gkbd_indicator_start_listen ();
xkl_debug (100, "*** Inited globals *** \n");
@@ -883,19 +634,10 @@ gkbd_indicator_set_parent_tooltips (GkbdIndicator * gki, gboolean spt)
gkbd_indicator_update_tooltips (gki);
}
-void
-gkbd_indicator_set_tooltips_format (const gchar format[])
-{
- globals.tooltips_format = format;
- ForAllIndicators ()
- gkbd_indicator_update_tooltips (gki);
- NextIndicator ()
-}
-
XklEngine *
gkbd_indicator_get_xkl_engine ()
{
- return globals.engine;
+ return gkbd_configuration_get_xkl_engine (globals.config);
}
/**
@@ -905,16 +647,14 @@ gkbd_indicator_get_xkl_engine ()
gchar **
gkbd_indicator_get_group_names ()
{
- return globals.full_group_names;
+ return (gchar **)
+ gkbd_configuration_get_group_names (globals.config);
}
gchar *
gkbd_indicator_get_image_filename (guint group)
{
- if (!globals.ind_cfg.show_flags)
- return NULL;
- return gkbd_indicator_config_get_images_file (&globals.ind_cfg,
- &globals.kbd_cfg,
+ return gkbd_configuration_get_image_filename (globals.config,
group);
}
@@ -923,7 +663,7 @@ gkbd_indicator_get_max_width_height_ratio (void)
{
gdouble rv = 0.0;
GSList *ip = globals.images;
- if (!globals.ind_cfg.show_flags)
+ if (!gkbd_configuration_if_flags_shown (globals.config))
return 0;
while (ip != NULL) {
GdkPixbuf *img = GDK_PIXBUF (ip->data);
@@ -960,5 +700,6 @@ gkbd_indicator_plugin_container_reinit_ui (GkbdIndicatorPluginContainer *
*/
gchar **gkbd_indicator_plugin_load_localized_group_names
(GkbdIndicatorPluginContainer * pc) {
- return globals.full_group_names;
+ return (gchar **)
+ gkbd_configuration_get_group_names (globals.config);
}
diff --git a/libgnomekbd/gkbd-indicator.h b/libgnomekbd/gkbd-indicator.h
index b3feb91..7f69405 100644
--- a/libgnomekbd/gkbd-indicator.h
+++ b/libgnomekbd/gkbd-indicator.h
@@ -24,13 +24,9 @@
#include <libxklavier/xklavier.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- typedef struct _GkbdIndicator GkbdIndicator;
- typedef struct _GkbdIndicatorPrivate GkbdIndicatorPrivate;
- typedef struct _GkbdIndicatorClass GkbdIndicatorClass;
+G_BEGIN_DECLS typedef struct _GkbdIndicator GkbdIndicator;
+typedef struct _GkbdIndicatorPrivate GkbdIndicatorPrivate;
+typedef struct _GkbdIndicatorClass GkbdIndicatorClass;
#define GKBD_TYPE_INDICATOR (gkbd_indicator_get_type ())
#define GKBD_INDICATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKBD_TYPE_INDICATOR, GkbdIndicator))
@@ -39,42 +35,35 @@ extern "C" {
#define GKBD_IS_INDICATOR_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GKBD_TYPE_INDICATOR))
#define GKBD_INDICATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKBD_TYPE_INDICATOR, GkbdIndicatorClass))
- struct _GkbdIndicator {
- GtkNotebook parent;
- GkbdIndicatorPrivate *priv;
- };
+struct _GkbdIndicator {
+ GtkNotebook parent;
+ GkbdIndicatorPrivate *priv;
+};
- struct _GkbdIndicatorClass {
- GtkNotebookClass parent_class;
+struct _GkbdIndicatorClass {
+ GtkNotebookClass parent_class;
- void (*reinit_ui) (GkbdIndicator * gki);
- };
+ void (*reinit_ui) (GkbdIndicator * gki);
+};
- extern GType gkbd_indicator_get_type (void);
+extern GType gkbd_indicator_get_type (void);
- extern GtkWidget *gkbd_indicator_new (void);
+extern GtkWidget *gkbd_indicator_new (void);
- extern void gkbd_indicator_reinit_ui (GkbdIndicator * gki);
+extern void gkbd_indicator_reinit_ui (GkbdIndicator * gki);
- extern void gkbd_indicator_set_angle (GkbdIndicator * gki,
- gdouble angle);
+extern void gkbd_indicator_set_angle (GkbdIndicator * gki, gdouble angle);
- extern XklEngine *gkbd_indicator_get_xkl_engine (void);
+extern XklEngine *gkbd_indicator_get_xkl_engine (void);
- extern gchar **gkbd_indicator_get_group_names (void);
+extern gchar **gkbd_indicator_get_group_names (void);
- extern gchar *gkbd_indicator_get_image_filename (guint group);
+extern gchar *gkbd_indicator_get_image_filename (guint group);
- extern gdouble gkbd_indicator_get_max_width_height_ratio (void);
+extern gdouble gkbd_indicator_get_max_width_height_ratio (void);
- extern void
- gkbd_indicator_set_parent_tooltips (GkbdIndicator *
- gki, gboolean ifset);
+extern void
+ gkbd_indicator_set_parent_tooltips (GkbdIndicator * gki, gboolean ifset);
- extern void
- gkbd_indicator_set_tooltips_format (const gchar str[]);
-
-#ifdef __cplusplus
-}
-#endif
+G_END_DECLS
#endif
diff --git a/libgnomekbd/gkbd-status.c b/libgnomekbd/gkbd-status.c
index 0e0b22c..5bf2467 100644
--- a/libgnomekbd/gkbd-status.c
+++ b/libgnomekbd/gkbd-status.c
@@ -30,18 +30,10 @@
#include <gkbd-desktop-config.h>
#include <gkbd-indicator-config.h>
+#include <gkbd-configuration.h>
typedef struct _gki_globals {
- XklEngine *engine;
- XklConfigRegistry *registry;
-
- GkbdDesktopConfig cfg;
- GkbdIndicatorConfig ind_cfg;
- GkbdKeyboardConfig kbd_cfg;
-
- const gchar *tooltips_format;
- gchar **full_group_names;
- gchar **short_group_names;
+ GkbdConfiguration *config;
gint current_width;
gint current_height;
@@ -49,8 +41,6 @@ typedef struct _gki_globals {
GSList *icons; /* list of GdkPixbuf */
GSList *widget_instances; /* list of GkbdStatus */
- gulong state_changed_handler;
- gulong config_changed_handler;
} gki_globals;
static gchar *settings_signal_names[] = {
@@ -61,7 +51,6 @@ static gchar *settings_signal_names[] = {
};
struct _GkbdStatusPrivate {
- gdouble angle;
gulong settings_signal_handlers[sizeof (settings_signal_names) /
sizeof (settings_signal_names[0])];
};
@@ -119,7 +108,9 @@ void
gkbd_status_global_fill (GkbdStatus * gki)
{
int grp;
- int total_groups = xkl_engine_get_num_groups (globals.engine);
+ int total_groups =
+ xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
+ (globals.config));
for (grp = 0; grp < total_groups; grp++) {
GdkPixbuf *page = gkbd_status_prepare_drawing (gki, grp);
@@ -131,19 +122,9 @@ static void
gkbd_status_activate (GkbdStatus * gki)
{
xkl_debug (150, "Mouse button pressed on applet\n");
- gkbd_desktop_config_lock_next_group (&globals.cfg);
+ gkbd_configuration_lock_next_group (globals.config);
}
-/* hackish xref */
-extern gchar *gkbd_indicator_extract_layout_name (int group,
- XklEngine * engine,
- GkbdKeyboardConfig *
- kbd_cfg,
- gchar **
- short_group_names,
- gchar **
- full_group_names);
-
extern gchar *gkbd_indicator_create_label_title (int group,
GHashTable **
ln2cnt_map,
@@ -161,11 +142,14 @@ gkbd_status_render_cairo (cairo_t * cr, int group)
cairo_font_options_t *fo;
static GHashTable *ln2cnt_map = NULL;
+ GkbdIndicatorConfig *ind_cfg =
+ gkbd_configuration_get_indicator_config (globals.config);
+
xkl_debug (160, "Rendering cairo for group %d\n", group);
- if (globals.ind_cfg.background_color != NULL &&
- globals.ind_cfg.background_color[0] != 0) {
+ if (ind_cfg->background_color != NULL &&
+ ind_cfg->background_color[0] != 0) {
if (sscanf
- (globals.ind_cfg.background_color, "%lg %lg %lg", &r,
+ (ind_cfg->background_color, "%lg %lg %lg", &r,
&g, &b) == 3) {
cairo_set_source_rgb (cr, r, g, b);
cairo_rectangle (cr, 0, 0, globals.current_width,
@@ -174,30 +158,27 @@ gkbd_status_render_cairo (cairo_t * cr, int group)
}
}
- if (globals.ind_cfg.foreground_color != NULL &&
- globals.ind_cfg.foreground_color[0] != 0) {
+ if (ind_cfg->foreground_color != NULL &&
+ ind_cfg->foreground_color[0] != 0) {
if (sscanf
- (globals.ind_cfg.foreground_color, "%lg %lg %lg", &r,
+ (ind_cfg->foreground_color, "%lg %lg %lg", &r,
&g, &b) == 3) {
cairo_set_source_rgb (cr, r, g, b);
}
}
- if (globals.ind_cfg.font_family != NULL &&
- globals.ind_cfg.font_family[0] != 0) {
- cairo_select_font_face (cr, globals.ind_cfg.font_family,
+ if (ind_cfg->font_family != NULL && ind_cfg->font_family[0] != 0) {
+ cairo_select_font_face (cr, ind_cfg->font_family,
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
}
pfd = pango_font_description_new ();
- pango_font_description_set_family (pfd,
- globals.ind_cfg.font_family);
+ pango_font_description_set_family (pfd, ind_cfg->font_family);
pango_font_description_set_style (pfd, PANGO_STYLE_NORMAL);
pango_font_description_set_weight (pfd, PANGO_WEIGHT_NORMAL);
pango_font_description_set_size (pfd,
- globals.ind_cfg.font_size *
- PANGO_SCALE);
+ ind_cfg->font_size * PANGO_SCALE);
pcc = pango_cairo_create_context (cr);
@@ -212,18 +193,15 @@ gkbd_status_render_cairo (cairo_t * cr, int group)
pl = pango_layout_new (pcc);
- layout_name = gkbd_indicator_extract_layout_name (group,
- globals.engine,
- &globals.kbd_cfg,
- globals.
- short_group_names,
- globals.
- full_group_names);
+ layout_name =
+ gkbd_configuration_extract_layout_name (globals.config, group);
lbl_title =
gkbd_indicator_create_label_title (group, &ln2cnt_map,
layout_name);
- if (group + 1 == xkl_engine_get_num_groups (globals.engine)) {
+ if (group + 1 ==
+ xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
+ (globals.config))) {
g_hash_table_destroy (ln2cnt_map);
ln2cnt_map = NULL;
}
@@ -304,11 +282,11 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
if (globals.current_width == 0)
return NULL;
- if (globals.ind_cfg.show_flags) {
+ if (gkbd_configuration_if_flags_shown (globals.config)) {
image_filename =
- (char *) g_slist_nth_data (globals.ind_cfg.
- image_filenames, group);
+ gkbd_configuration_get_image_filename (globals.config,
+ group);
image = gdk_pixbuf_new_from_file_at_size (image_filename,
globals.
@@ -400,17 +378,12 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
static void
gkbd_status_update_tooltips (GkbdStatus * gki)
{
- XklState *state = xkl_engine_get_current_state (globals.engine);
- gchar *buf;
- if (state == NULL || state->group < 0
- || state->group >= g_strv_length (globals.full_group_names))
- return;
-
- buf = g_strdup_printf (globals.tooltips_format,
- globals.full_group_names[state->group]);
-
- gkbd_status_set_tooltips (gki, buf);
- g_free (buf);
+ gchar *buf =
+ gkbd_configuration_get_current_tooltip (globals.config);
+ if (buf != NULL) {
+ gkbd_status_set_tooltips (gki, buf);
+ g_free (buf);
+ }
}
void
@@ -422,123 +395,13 @@ gkbd_status_reinit_ui (GkbdStatus * gki)
gkbd_status_set_current_page (gki);
}
-/* Should be called once for all widgets */
-static void
-gkbd_status_cfg_changed (GSettings * settings, gchar * key)
-{
- xkl_debug (100,
- "General configuration changed in GConf - reiniting...\n");
- gkbd_desktop_config_load (&globals.cfg);
- gkbd_desktop_config_activate (&globals.cfg);
- ForAllIndicators () {
- gkbd_status_reinit_ui (gki);
- } NextIndicator ();
-}
-
-/* Should be called once for all widgets */
-static void
-gkbd_status_ind_cfg_changed (GSettings * settings, gchar * key)
-{
- xkl_debug (100,
- "Applet configuration changed in GConf - reiniting...\n");
- gkbd_indicator_config_load (&globals.ind_cfg);
-
- gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
- gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
- &globals.kbd_cfg);
-
- gkbd_indicator_config_activate (&globals.ind_cfg);
-
- ForAllIndicators () {
- gkbd_status_reinit_ui (gki);
- } NextIndicator ();
-}
-
-static void
-gkbd_status_load_group_names (const gchar ** layout_ids,
- const gchar ** variant_ids)
-{
- if (!gkbd_desktop_config_load_group_descriptions
- (&globals.cfg, globals.registry, layout_ids, variant_ids,
- &globals.short_group_names, &globals.full_group_names)) {
- /* We just populate no short names (remain NULL) -
- * full names are going to be used anyway */
- gint i, total_groups =
- xkl_engine_get_num_groups (globals.engine);
- xkl_debug (150, "group descriptions loaded: %d!\n",
- total_groups);
-
- if (xkl_engine_get_features (globals.engine) &
- XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
- globals.full_group_names =
- g_strdupv (globals.kbd_cfg.layouts_variants);
- } else {
- globals.full_group_names =
- g_new0 (char *, total_groups + 1);
- for (i = total_groups; --i >= 0;) {
- globals.full_group_names[i] =
- g_strdup_printf ("Group %d", i);
- }
- }
- }
-}
-
-/* Should be called once for all widgets */
-static void
-gkbd_status_kbd_cfg_callback (GkbdStatus * gki)
-{
- XklConfigRec *xklrec = xkl_config_rec_new ();
- xkl_debug (100,
- "XKB configuration changed on X Server - reiniting...\n");
-
- gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
- xklrec);
-
- gkbd_indicator_config_free_image_filenames (&globals.ind_cfg);
- gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
- &globals.kbd_cfg);
-
- g_strfreev (globals.full_group_names);
- globals.full_group_names = NULL;
-
- if (globals.short_group_names != NULL) {
- g_strfreev (globals.short_group_names);
- globals.short_group_names = NULL;
- }
-
- gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **) xklrec->variants);
-
- ForAllIndicators () {
- gkbd_status_reinit_ui (gki);
- } NextIndicator ();
- g_object_unref (G_OBJECT (xklrec));
-}
-
-/* Should be called once for all applets */
-static void
-gkbd_status_state_callback (XklEngine * engine,
- XklEngineStateChange changeType,
- gint group, gboolean restore)
-{
- xkl_debug (150, "group is now %d, restore: %d\n", group, restore);
-
- if (changeType == GROUP_CHANGED) {
- ForAllIndicators () {
- xkl_debug (200, "do repaint\n");
- gkbd_status_set_current_page_for_group (gki,
- group);
- }
- NextIndicator ();
- }
-}
-
-
void
gkbd_status_set_current_page (GkbdStatus * gki)
{
XklState *cur_state;
- cur_state = xkl_engine_get_current_state (globals.engine);
+ XklEngine *engine =
+ gkbd_configuration_get_xkl_engine (globals.config);
+ cur_state = xkl_engine_get_current_state (engine);
if (cur_state->group >= 0)
gkbd_status_set_current_page_for_group (gki,
cur_state->group);
@@ -562,8 +425,10 @@ static GdkFilterReturn
gkbd_status_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
{
XEvent *xevent = (XEvent *) xev;
+ XklEngine *engine =
+ gkbd_configuration_get_xkl_engine (globals.config);
- xkl_engine_filter_events (globals.engine, xevent);
+ xkl_engine_filter_events (engine, xevent);
switch (xevent->type) {
case ReparentNotify:
{
@@ -578,8 +443,7 @@ gkbd_status_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
if (xid == rne->window) {
/* if so - make it transparent... */
xkl_engine_set_window_transparent
- (globals.engine, rne->window,
- TRUE);
+ (engine, rne->window, TRUE);
}
}
NextIndicator ()}
@@ -598,17 +462,12 @@ gkbd_status_start_listen (void)
gdk_window_add_filter (gdk_get_default_root_window (),
(GdkFilterFunc) gkbd_status_filter_x_evt,
NULL);
-
- xkl_engine_start_listen (globals.engine,
- XKLL_TRACK_KEYBOARD_STATE);
}
/* Should be called once for all widgets */
static void
gkbd_status_stop_listen (void)
{
- xkl_engine_stop_listen (globals.engine, XKLL_TRACK_KEYBOARD_STATE);
-
gdk_window_remove_filter (NULL, (GdkFilterFunc)
gkbd_status_filter_x_evt, NULL);
gdk_window_remove_filter
@@ -630,7 +489,8 @@ static void
gkbd_status_theme_changed (GtkSettings * settings, GParamSpec * pspec,
GkbdStatus * gki)
{
- gkbd_indicator_config_refresh_style (&globals.ind_cfg);
+ gkbd_indicator_config_refresh_style
+ (gkbd_configuration_get_indicator_config (globals.config));
gkbd_status_reinit_ui (gki);
}
@@ -650,7 +510,7 @@ gkbd_status_init (GkbdStatus * gki)
xkl_debug (100, "Initiating the widget startup process for %p\n",
gki);
- if (globals.engine == NULL) {
+ if (gkbd_configuration_get_xkl_engine (globals.config) == NULL) {
gkbd_status_set_tooltips (gki,
_("XKB initialization error"));
return;
@@ -718,32 +578,9 @@ gkbd_status_global_term (void)
xkl_debug (100, "*** Last GkbdStatus instance *** \n");
gkbd_status_stop_listen ();
- gkbd_desktop_config_stop_listen (&globals.cfg);
- gkbd_indicator_config_stop_listen (&globals.ind_cfg);
-
- gkbd_indicator_config_term (&globals.ind_cfg);
- gkbd_keyboard_config_term (&globals.kbd_cfg);
- gkbd_desktop_config_term (&globals.cfg);
-
- if (g_signal_handler_is_connected
- (globals.engine, globals.state_changed_handler)) {
- g_signal_handler_disconnect (globals.engine,
- globals.
- state_changed_handler);
- globals.state_changed_handler = 0;
- }
- if (g_signal_handler_is_connected
- (globals.engine, globals.config_changed_handler)) {
- g_signal_handler_disconnect (globals.engine,
- globals.
- config_changed_handler);
- globals.config_changed_handler = 0;
- }
+ g_object_unref (globals.config);
+ globals.config = NULL;
- g_object_unref (G_OBJECT (globals.registry));
- globals.registry = NULL;
- g_object_unref (G_OBJECT (globals.engine));
- globals.engine = NULL;
xkl_debug (100, "*** Terminated globals *** \n");
}
@@ -756,70 +593,15 @@ gkbd_status_class_init (GkbdStatusClass * klass)
memset (&globals, 0, sizeof (globals));
- /* Initing some global vars */
- globals.tooltips_format = "%s";
-
/* Initing vtable */
object_class->finalize = gkbd_status_finalize;
-
- /* Signals */
}
static void
gkbd_status_global_init (void)
{
- XklConfigRec *xklrec = xkl_config_rec_new ();
-
- globals.engine =
- xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY
- (gdk_display_get_default ()));
- if (globals.engine == NULL) {
- xkl_debug (0, "Libxklavier initialization error");
- return;
- }
-
- globals.state_changed_handler =
- g_signal_connect (globals.engine, "X-state-changed",
- G_CALLBACK (gkbd_status_state_callback),
- NULL);
- globals.config_changed_handler =
- g_signal_connect (globals.engine, "X-config-changed",
- G_CALLBACK (gkbd_status_kbd_cfg_callback),
- NULL);
-
- gkbd_desktop_config_init (&globals.cfg, globals.engine);
- gkbd_keyboard_config_init (&globals.kbd_cfg, globals.engine);
- gkbd_indicator_config_init (&globals.ind_cfg, globals.engine);
-
- gkbd_desktop_config_load (&globals.cfg);
- gkbd_desktop_config_activate (&globals.cfg);
-
- globals.registry =
- xkl_config_registry_get_instance (globals.engine);
- xkl_config_registry_load (globals.registry,
- globals.cfg.load_extra_items);
+ globals.config = gkbd_configuration_get ();
- gkbd_keyboard_config_load_from_x_current (&globals.kbd_cfg,
- xklrec);
-
- gkbd_indicator_config_load (&globals.ind_cfg);
-
- gkbd_indicator_config_load_image_filenames (&globals.ind_cfg,
- &globals.kbd_cfg);
-
- gkbd_indicator_config_activate (&globals.ind_cfg);
-
- gkbd_status_load_group_names ((const gchar **) xklrec->layouts,
- (const gchar **) xklrec->variants);
- g_object_unref (G_OBJECT (xklrec));
-
- gkbd_desktop_config_start_listen (&globals.cfg,
- G_CALLBACK
- (gkbd_status_cfg_changed), NULL);
- gkbd_indicator_config_start_listen (&globals.ind_cfg,
- G_CALLBACK
- (gkbd_status_ind_cfg_changed),
- NULL);
gkbd_status_start_listen ();
xkl_debug (100, "*** Inited globals *** \n");
@@ -835,7 +617,7 @@ gkbd_status_new (void)
XklEngine *
gkbd_status_get_xkl_engine ()
{
- return globals.engine;
+ return gkbd_configuration_get_xkl_engine (globals.config);
}
/**
@@ -845,21 +627,14 @@ gkbd_status_get_xkl_engine ()
gchar **
gkbd_status_get_group_names ()
{
- return globals.full_group_names;
+ return (gchar **)
+ gkbd_configuration_get_group_names (globals.config);
}
gchar *
gkbd_status_get_image_filename (guint group)
{
- if (!globals.ind_cfg.show_flags)
- return NULL;
- return gkbd_indicator_config_get_images_file (&globals.ind_cfg,
- &globals.kbd_cfg,
+ return gkbd_configuration_get_image_filename (globals.config,
group);
}
-void
-gkbd_status_set_angle (GkbdStatus * gki, gdouble angle)
-{
- gki->priv->angle = angle;
-}
diff --git a/libgnomekbd/gkbd-status.h b/libgnomekbd/gkbd-status.h
index d3647cf..086f8cc 100644
--- a/libgnomekbd/gkbd-status.h
+++ b/libgnomekbd/gkbd-status.h
@@ -24,13 +24,9 @@
#include <libxklavier/xklavier.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- typedef struct _GkbdStatus GkbdStatus;
- typedef struct _GkbdStatusPrivate GkbdStatusPrivate;
- typedef struct _GkbdStatusClass GkbdStatusClass;
+G_BEGIN_DECLS typedef struct _GkbdStatus GkbdStatus;
+typedef struct _GkbdStatusPrivate GkbdStatusPrivate;
+typedef struct _GkbdStatusClass GkbdStatusClass;
#define GKBD_TYPE_STATUS (gkbd_status_get_type ())
#define GKBD_STATUS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GKBD_TYPE_STATUS, GkbdStatus))
@@ -39,34 +35,26 @@ extern "C" {
#define GKBD_IS_STATUS_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GKBD_TYPE_STATUS))
#define GKBD_STATUS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKBD_TYPE_STATUS, GkbdStatusClass))
- struct _GkbdStatus {
- GtkStatusIcon parent;
- GkbdStatusPrivate *priv;
- };
-
- struct _GkbdStatusClass {
- GtkNotebookClass parent_class;
- };
+struct _GkbdStatus {
+ GtkStatusIcon parent;
+ GkbdStatusPrivate *priv;
+};
- extern GType gkbd_status_get_type (void);
+struct _GkbdStatusClass {
+ GtkNotebookClass parent_class;
+};
- extern GtkStatusIcon *gkbd_status_new (void);
+extern GType gkbd_status_get_type (void);
- extern void gkbd_status_reinit_ui (GkbdStatus * gki);
+extern GtkStatusIcon *gkbd_status_new (void);
- extern void gkbd_status_set_angle (GkbdStatus * gki,
- gdouble angle);
+extern void gkbd_status_reinit_ui (GkbdStatus * gki);
- extern XklEngine *gkbd_status_get_xkl_engine (void);
+extern XklEngine *gkbd_status_get_xkl_engine (void);
- extern gchar **gkbd_status_get_group_names (void);
+extern gchar **gkbd_status_get_group_names (void);
- extern gchar *gkbd_status_get_image_filename (guint group);
+extern gchar *gkbd_status_get_image_filename (guint group);
- extern void
- gkbd_status_set_tooltips_format (const gchar str[]);
-
-#ifdef __cplusplus
-}
-#endif
+G_END_DECLS
#endif
diff --git a/test/gkbd-indicator-test.c b/test/gkbd-indicator-test.c
index f902e80..7051d2b 100644
--- a/test/gkbd-indicator-test.c
+++ b/test/gkbd-indicator-test.c
@@ -53,8 +53,7 @@ main (int argc, char **argv)
mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gki = gkbd_indicator_new ();
- gkbd_indicator_set_tooltips_format (_
- ("Keyboard Indicator Test (%s)"));
+
gkbd_indicator_set_parent_tooltips (GKBD_INDICATOR (gki), TRUE);
gtk_window_resize (GTK_WINDOW (mainwin), 250, 250);