[gnome-flashback] input-sources: create list of user's input sources
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] input-sources: create list of user's input sources
- Date: Tue, 22 Sep 2015 03:40:23 +0000 (UTC)
commit def37c5843b7caa3dc6f9b7a00d88914d126714c
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Sep 22 06:39:10 2015 +0300
input-sources: create list of user's input sources
gnome-flashback/libinput-sources/gf-ibus-manager.c | 7 +
gnome-flashback/libinput-sources/gf-ibus-manager.h | 6 +-
.../libinput-sources/gf-input-source-manager.c | 197 +++++++++++++++++++-
.../libinput-sources/gf-input-sources.c | 2 +
.../libinput-sources/gf-keyboard-manager.c | 10 +
.../libinput-sources/gf-keyboard-manager.h | 28 ++--
6 files changed, 234 insertions(+), 16 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-ibus-manager.c
b/gnome-flashback/libinput-sources/gf-ibus-manager.c
index 8011318..9b9151c 100644
--- a/gnome-flashback/libinput-sources/gf-ibus-manager.c
+++ b/gnome-flashback/libinput-sources/gf-ibus-manager.c
@@ -62,3 +62,10 @@ gf_ibus_manager_new (void)
{
return g_object_new (GF_TYPE_IBUS_MANAGER, NULL);
}
+
+IBusEngineDesc *
+gf_ibus_manager_get_engine_desc (GfIBusManager *manager,
+ const gchar *id)
+{
+ return NULL;
+}
diff --git a/gnome-flashback/libinput-sources/gf-ibus-manager.h
b/gnome-flashback/libinput-sources/gf-ibus-manager.h
index 7886eb5..aa2201d 100644
--- a/gnome-flashback/libinput-sources/gf-ibus-manager.h
+++ b/gnome-flashback/libinput-sources/gf-ibus-manager.h
@@ -19,11 +19,15 @@
#define GF_IBUS_MANAGER_H
#include <glib-object.h>
+#include <ibus-1.0/ibus.h>
#define GF_TYPE_IBUS_MANAGER gf_ibus_manager_get_type ()
G_DECLARE_FINAL_TYPE (GfIBusManager, gf_ibus_manager,
GF, IBUS_MANAGER, GObject)
-GfIBusManager *gf_ibus_manager_new (void);
+GfIBusManager *gf_ibus_manager_new (void);
+
+IBusEngineDesc *gf_ibus_manager_get_engine_desc (GfIBusManager *manager,
+ const gchar *id);
#endif
diff --git a/gnome-flashback/libinput-sources/gf-input-source-manager.c
b/gnome-flashback/libinput-sources/gf-input-source-manager.c
index 5c956a9..e070c8d 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-manager.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-manager.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2015 Alberts Muktupāvels
* Copyright (C) 2015 Sebastian Geiger
*
* This program is free software: you can redistribute it and/or modify
@@ -18,6 +19,7 @@
#include "config.h"
#include <gio/gio.h>
+#include <glib/gi18n.h>
#include <libcommon/gf-keybindings.h>
#include "gf-input-source-manager.h"
@@ -30,6 +32,20 @@
#define KEY_SWITCH_INPUT_SOURCE "switch-input-source"
#define KEY_SWITCH_INPUT_SOURCE_BACKWARD "switch-input-source-backward"
+#define INPUT_SOURCE_TYPE_XKB "xkb"
+#define INPUT_SOURCE_TYPE_IBUS "ibus"
+
+typedef struct _SourceInfo SourceInfo;
+struct _SourceInfo
+{
+ gchar *type;
+
+ gchar *id;
+
+ gchar *display_name;
+ gchar *short_name;
+};
+
struct _GfInputSourceManager
{
GObject parent;
@@ -44,10 +60,9 @@ struct _GfInputSourceManager
GfKeyboardManager *keyboard_manager;
GfIBusManager *ibus_manager;
+ gboolean disable_ibus;
};
-G_DEFINE_TYPE (GfInputSourceManager, gf_input_source_manager, G_TYPE_OBJECT)
-
enum
{
PROP_0,
@@ -59,6 +74,41 @@ enum
static GParamSpec *properties[LAST_PROP] = { NULL };
+G_DEFINE_TYPE (GfInputSourceManager, gf_input_source_manager, G_TYPE_OBJECT)
+
+static SourceInfo *
+source_info_new (const gchar *type,
+ const gchar *id,
+ const gchar *display_name,
+ const gchar *short_name)
+{
+ SourceInfo *info;
+
+ info = g_new0 (SourceInfo, 1);
+
+ info->type = g_strdup (type);
+ info->id = g_strdup (id);
+ info->display_name = g_strdup (display_name);
+ info->short_name = g_strdup (short_name);
+
+ return info;
+}
+
+static void
+source_info_free (gpointer data)
+{
+ SourceInfo *info;
+
+ info = (SourceInfo *) data;
+
+ g_free (info->type);
+ g_free (info->id);
+ g_free (info->display_name);
+ g_free (info->short_name);
+
+ g_free (info);
+}
+
static void
switch_input_changed_cb (GSettings *settings,
gchar *key,
@@ -160,10 +210,153 @@ keybindings_init (GfInputSourceManager *manager)
switch_input_backward_changed_cb (manager->wm_keybindings, NULL, manager);
}
+static gchar *
+make_engine_short_name (IBusEngineDesc *engine_desc)
+{
+ const gchar *symbol;
+ const gchar *language_code;
+ gchar **codes;
+
+ symbol = ibus_engine_desc_get_symbol (engine_desc);
+
+ if (symbol != NULL && symbol[0] != '\0')
+ return g_strdup (symbol);
+
+ language_code = ibus_engine_desc_get_language (engine_desc);
+ codes = g_strsplit (language_code, "_", 2);
+
+ if (strlen (codes[0]) == 2 || strlen (codes[0]) == 3)
+ {
+ gchar *short_name;
+
+ short_name = g_ascii_strdown (codes[0], -1);
+ g_strfreev (codes);
+
+ return short_name;
+ }
+
+ g_strfreev (codes);
+
+ return g_strdup_printf ("\u2328");
+}
+
+static GList *
+get_source_info_list (GfInputSourceManager *manager)
+{
+ GVariant *sources;
+ GnomeXkbInfo *xkb_info;
+ GList *list;
+ gsize size;
+ gsize i;
+
+ sources = gf_input_source_settings_get_sources (manager->settings);
+ xkb_info = gf_keyboard_manager_get_xkb_info (manager->keyboard_manager);
+
+ list = NULL;
+ size = g_variant_n_children (sources);
+
+ for (i = 0; i < size; i++)
+ {
+ const gchar *type;
+ const gchar *id;
+ SourceInfo *info;
+
+ g_variant_get_child (sources, i, "(&s&s)", &type, &id);
+ info = NULL;
+
+ if (g_strcmp0 (type, INPUT_SOURCE_TYPE_XKB) == 0)
+ {
+ gboolean exists;
+ const gchar *display_name;
+ const gchar *short_name;
+
+ exists = gnome_xkb_info_get_layout_info (xkb_info, id, &display_name,
+ &short_name, NULL, NULL);
+
+ if (exists)
+ info = source_info_new (type, id, display_name, short_name);
+ }
+ else if (g_strcmp0 (type, INPUT_SOURCE_TYPE_IBUS) == 0)
+ {
+ IBusEngineDesc *engine_desc;
+ const gchar *language_code;
+ const gchar *language;
+ const gchar *longname;
+ const gchar *textdomain;
+ gchar *display_name;
+ gchar *short_name;
+
+ if (manager->disable_ibus)
+ continue;
+
+ engine_desc = gf_ibus_manager_get_engine_desc (manager->ibus_manager,
+ id);
+
+ if (engine_desc == NULL)
+ continue;
+
+ language_code = ibus_engine_desc_get_language (engine_desc);
+ language = ibus_get_language_name (language_code);
+ longname = ibus_engine_desc_get_longname (engine_desc);
+ textdomain = ibus_engine_desc_get_textdomain (engine_desc);
+
+ if (*textdomain != '\0' && *longname != '\0')
+ longname = g_dgettext (textdomain, longname);
+
+ display_name = g_strdup_printf ("%s (%s)", language, longname);
+ short_name = make_engine_short_name (engine_desc);
+
+ info = source_info_new (type, id, display_name, short_name);
+
+ g_free (display_name);
+ g_free (short_name);
+ }
+
+ if (info != NULL)
+ list = g_list_append (list, info);
+ }
+
+ g_variant_unref (sources);
+
+ if (list == NULL)
+ {
+ const gchar *type;
+ const gchar *id;
+ const gchar *display_name;
+ const gchar *short_name;
+ SourceInfo *info;
+
+ type = INPUT_SOURCE_TYPE_XKB;
+ id = gf_keyboard_manager_get_default_layout (manager->keyboard_manager);
+
+ gnome_xkb_info_get_layout_info (xkb_info, id, &display_name,
+ &short_name, NULL, NULL);
+
+ info = source_info_new (type, id, display_name, short_name);
+ list = g_list_append (list, info);
+ }
+
+ g_object_unref (xkb_info);
+
+ return list;
+}
+
static void
sources_changed_cb (GfInputSourceSettings *settings,
gpointer user_data)
{
+ GfInputSourceManager *manager;
+ GList *source_infos;
+ GList *l;
+
+ manager = GF_INPUT_SOURCE_MANAGER (user_data);
+ source_infos = get_source_info_list (manager);
+
+ for (l = source_infos; l != NULL; l = g_list_next (l))
+ {
+ }
+
+ g_list_free_full (source_infos, source_info_free);
}
static void
diff --git a/gnome-flashback/libinput-sources/gf-input-sources.c
b/gnome-flashback/libinput-sources/gf-input-sources.c
index 66e68e6..9e47de2 100644
--- a/gnome-flashback/libinput-sources/gf-input-sources.c
+++ b/gnome-flashback/libinput-sources/gf-input-sources.c
@@ -59,6 +59,8 @@ gf_input_sources_init (GfInputSources *sources)
{
sources->ibus_manager = gf_ibus_manager_new ();
sources->input_source_manager = gf_input_source_manager_new (sources->ibus_manager);
+
+ gf_input_source_manager_reload (sources->input_source_manager);
}
GfInputSources *
diff --git a/gnome-flashback/libinput-sources/gf-keyboard-manager.c
b/gnome-flashback/libinput-sources/gf-keyboard-manager.c
index 66faf49..c59049c 100644
--- a/gnome-flashback/libinput-sources/gf-keyboard-manager.c
+++ b/gnome-flashback/libinput-sources/gf-keyboard-manager.c
@@ -680,3 +680,13 @@ gf_keyboard_manager_ungrab (GfKeyboardManager *manager,
gdk_device_ungrab (manager->keyboard, timestamp);
}
+
+/**
+ * gf_keyboard_manager_get_default_layout:
+ * @manager: a #GfKeyboardManager
+ */
+const gchar *
+gf_keyboard_manager_get_default_layout (GfKeyboardManager *manager)
+{
+ return DEFAULT_LAYOUT;
+}
diff --git a/gnome-flashback/libinput-sources/gf-keyboard-manager.h
b/gnome-flashback/libinput-sources/gf-keyboard-manager.h
index 31fc96c..f850efb 100644
--- a/gnome-flashback/libinput-sources/gf-keyboard-manager.h
+++ b/gnome-flashback/libinput-sources/gf-keyboard-manager.h
@@ -27,26 +27,28 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GfKeyboardManager, gf_keyboard_manager,
GF, KEYBOARD_MANAGER, GObject)
-GfKeyboardManager *gf_keyboard_manager_new (void);
+GfKeyboardManager *gf_keyboard_manager_new (void);
-GnomeXkbInfo *gf_keyboard_manager_get_xkb_info (GfKeyboardManager *manager);
+GnomeXkbInfo *gf_keyboard_manager_get_xkb_info (GfKeyboardManager *manager);
-void gf_keyboard_manager_set_xkb_options (GfKeyboardManager *manager,
- gchar **options);
+void gf_keyboard_manager_set_xkb_options (GfKeyboardManager *manager,
+ gchar **options);
-void gf_keyboard_manager_set_user_layouts (GfKeyboardManager *manager,
- gchar **ids);
+void gf_keyboard_manager_set_user_layouts (GfKeyboardManager *manager,
+ gchar **ids);
-void gf_keyboard_manager_apply (GfKeyboardManager *manager,
- const gchar *id);
+void gf_keyboard_manager_apply (GfKeyboardManager *manager,
+ const gchar *id);
-void gf_keyboard_manager_reapply (GfKeyboardManager *manager);
+void gf_keyboard_manager_reapply (GfKeyboardManager *manager);
-void gf_keyboard_manager_grab (GfKeyboardManager *manager,
- guint32 timestamp);
+void gf_keyboard_manager_grab (GfKeyboardManager *manager,
+ guint32 timestamp);
-void gf_keyboard_manager_ungrab (GfKeyboardManager *manager,
- guint32 timestamp);
+void gf_keyboard_manager_ungrab (GfKeyboardManager *manager,
+ guint32 timestamp);
+
+const gchar *gf_keyboard_manager_get_default_layout (GfKeyboardManager *manager);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]