[gnome-flashback] input-sources: add gf_input_source_get_layout



commit 2a8ba606283d13d213a7c616b7d0c52d4a6c8918
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Jan 2 05:03:29 2020 +0200

    input-sources: add gf_input_source_get_layout

 .../libinput-sources/gf-input-source-ibus.c        | 24 ++++++++++
 .../libinput-sources/gf-input-source-xkb.c         | 18 +++++++
 gnome-flashback/libinput-sources/gf-input-source.c | 10 ++++
 gnome-flashback/libinput-sources/gf-input-source.h | 38 +++++++++------
 .../libinput-sources/gf-input-sources.c            | 55 +++-------------------
 5 files changed, 81 insertions(+), 64 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/gf-input-source-ibus.c 
b/gnome-flashback/libinput-sources/gf-input-source-ibus.c
index 10831f1..224d9a8 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-ibus.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-ibus.c
@@ -227,6 +227,29 @@ gf_input_source_ibus_set_short_name (GfInputSource *input_source,
   return TRUE;
 }
 
+static gboolean
+gf_input_source_ibus_get_layout (GfInputSource  *input_source,
+                                 const char    **layout,
+                                 const char    **variant)
+{
+  GfInputSourceIBus *self;
+  const char *id;
+  IBusEngineDesc *engine_desc;
+
+  self = GF_INPUT_SOURCE_IBUS (input_source);
+
+  id = gf_input_source_get_id (input_source);
+  engine_desc = gf_ibus_manager_get_engine_desc (self->ibus_manager, id);
+
+  if (engine_desc == NULL)
+    return FALSE;
+
+  *layout = ibus_engine_desc_get_layout (engine_desc);
+  *variant = ibus_engine_desc_get_layout_variant (engine_desc);
+
+  return TRUE;
+}
+
 static const char *
 gf_input_source_ibus_get_xkb_id (GfInputSource *input_source)
 {
@@ -269,6 +292,7 @@ gf_input_source_ibus_class_init (GfInputSourceIBusClass *self_class)
   input_source_class->get_display_name = gf_input_source_ibus_get_display_name;
   input_source_class->get_short_name = gf_input_source_ibus_get_short_name;
   input_source_class->set_short_name = gf_input_source_ibus_set_short_name;
+  input_source_class->get_layout = gf_input_source_ibus_get_layout;
   input_source_class->get_xkb_id = gf_input_source_ibus_get_xkb_id;
 
   install_properties (object_class);
diff --git a/gnome-flashback/libinput-sources/gf-input-source-xkb.c 
b/gnome-flashback/libinput-sources/gf-input-source-xkb.c
index afadd85..ec6994a 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-xkb.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-xkb.c
@@ -152,6 +152,23 @@ gf_input_source_xkb_set_short_name (GfInputSource *input_source,
   return TRUE;
 }
 
+static gboolean
+gf_input_source_xkb_get_layout (GfInputSource  *input_source,
+                                const char    **layout,
+                                const char    **variant)
+{
+  GfInputSourceXkb *self;
+
+  self = GF_INPUT_SOURCE_XKB (input_source);
+
+  return gnome_xkb_info_get_layout_info (self->xkb_info,
+                                         gf_input_source_get_id (input_source),
+                                         NULL,
+                                         NULL,
+                                         layout,
+                                         variant);
+}
+
 static const char *
 gf_input_source_xkb_get_xkb_id (GfInputSource *input_source)
 {
@@ -190,6 +207,7 @@ gf_input_source_xkb_class_init (GfInputSourceXkbClass *self_class)
   input_source_class->get_display_name = gf_input_source_xkb_get_display_name;
   input_source_class->get_short_name = gf_input_source_xkb_get_short_name;
   input_source_class->set_short_name = gf_input_source_xkb_set_short_name;
+  input_source_class->get_layout = gf_input_source_xkb_get_layout;
   input_source_class->get_xkb_id = gf_input_source_xkb_get_xkb_id;
 
   install_properties (object_class);
diff --git a/gnome-flashback/libinput-sources/gf-input-source.c 
b/gnome-flashback/libinput-sources/gf-input-source.c
index 1772582..8c32717 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.c
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -228,6 +228,16 @@ gf_input_source_get_index (GfInputSource *source)
   return priv->index;
 }
 
+gboolean
+gf_input_source_get_layout (GfInputSource  *source,
+                            const char    **layout,
+                            const char    **variant)
+{
+  return GF_INPUT_SOURCE_GET_CLASS (source)->get_layout (source,
+                                                         layout,
+                                                         variant);
+}
+
 const gchar *
 gf_input_source_get_xkb_id (GfInputSource *source)
 {
diff --git a/gnome-flashback/libinput-sources/gf-input-source.h 
b/gnome-flashback/libinput-sources/gf-input-source.h
index 1cf7114..186be49 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.h
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -31,33 +31,41 @@ struct _GfInputSourceClass
 {
   GObjectClass parent_class;
 
-  const char * (* get_display_name) (GfInputSource *self);
+  const char * (* get_display_name) (GfInputSource  *self);
 
-  const char * (* get_short_name)   (GfInputSource *self);
+  const char * (* get_short_name)   (GfInputSource  *self);
 
-  gboolean     (* set_short_name)   (GfInputSource *self,
-                                     const char    *short_name);
+  gboolean     (* set_short_name)   (GfInputSource  *self,
+                                     const char     *short_name);
 
-  const char * (* get_xkb_id)       (GfInputSource *self);
+  gboolean     (* get_layout)       (GfInputSource  *self,
+                                     const char    **layout,
+                                     const char    **variant);
+
+  const char * (* get_xkb_id)       (GfInputSource  *self);
 };
 
-const gchar   *gf_input_source_get_source_type  (GfInputSource *source);
+const gchar *gf_input_source_get_source_type  (GfInputSource  *source);
+
+const gchar *gf_input_source_get_id           (GfInputSource  *source);
 
-const gchar   *gf_input_source_get_id           (GfInputSource *source);
+const gchar *gf_input_source_get_display_name (GfInputSource  *source);
 
-const gchar   *gf_input_source_get_display_name (GfInputSource *source);
+const gchar *gf_input_source_get_short_name   (GfInputSource  *source);
 
-const gchar   *gf_input_source_get_short_name   (GfInputSource *source);
+void         gf_input_source_set_short_name   (GfInputSource  *source,
+                                               const gchar    *short_name);
 
-void           gf_input_source_set_short_name   (GfInputSource *source,
-                                                 const gchar   *short_name);
+guint        gf_input_source_get_index        (GfInputSource  *source);
 
-guint          gf_input_source_get_index        (GfInputSource *source);
+gboolean     gf_input_source_get_layout       (GfInputSource  *source,
+                                               const char    **layout,
+                                               const char    **variant);
 
-const gchar   *gf_input_source_get_xkb_id       (GfInputSource *source);
+const gchar *gf_input_source_get_xkb_id       (GfInputSource  *source);
 
-void           gf_input_source_activate         (GfInputSource *source,
-                                                 gboolean       interactive);
+void         gf_input_source_activate         (GfInputSource  *source,
+                                               gboolean        interactive);
 
 G_END_DECLS
 
diff --git a/gnome-flashback/libinput-sources/gf-input-sources.c 
b/gnome-flashback/libinput-sources/gf-input-sources.c
index 20ca245..bd5a328 100644
--- a/gnome-flashback/libinput-sources/gf-input-sources.c
+++ b/gnome-flashback/libinput-sources/gf-input-sources.c
@@ -19,7 +19,6 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libgnome-desktop/gnome-xkb-info.h>
 #include <locale.h>
 #include <utime.h>
 
@@ -275,56 +274,17 @@ static void
 append_layout_info (GVariantBuilder *builder,
                     GfInputSources  *self)
 {
-  char *layout;
-  char *layout_variant;
-  const char *type;
-  const char *id;
+  const char *layout;
+  const char *layout_variant;
   GVariant *variant;
 
   layout = NULL;
   layout_variant = NULL;
 
-  type = gf_input_source_get_source_type (self->current_source);
-  id = gf_input_source_get_id (self->current_source);
-
-  if (g_strcmp0 (type, INPUT_SOURCE_TYPE_XKB) == 0)
-    {
-      GnomeXkbInfo *info;
-      const char *xkb_layout;
-      const char *xkb_variant;
-
-      info = gnome_xkb_info_new ();
-
-      gnome_xkb_info_get_layout_info (info,
-                                      id,
-                                      NULL,
-                                      NULL,
-                                      &xkb_layout,
-                                      &xkb_variant);
-
-      layout = g_strdup (xkb_layout);
-      layout_variant = g_strdup (xkb_variant);
-
-      g_clear_object (&info);
-    }
-  else if (g_strcmp0 (type, INPUT_SOURCE_TYPE_IBUS) == 0)
-    {
-      IBusEngineDesc *engine_desc;
-
-      engine_desc = gf_ibus_manager_get_engine_desc (self->ibus_manager, id);
-
-      if (engine_desc)
-        {
-          const char *ibus_layout;
-          const char *ibus_variant;
-
-          ibus_layout = ibus_engine_desc_get_layout (engine_desc);
-          ibus_variant = ibus_engine_desc_get_layout_variant (engine_desc);
-
-          layout = g_strdup (ibus_layout);
-          layout_variant = g_strdup (ibus_variant);
-        }
-    }
+  if (!gf_input_source_get_layout (self->current_source,
+                                   &layout,
+                                   &layout_variant))
+    return;
 
   if (layout != NULL)
     {
@@ -337,9 +297,6 @@ append_layout_info (GVariantBuilder *builder,
       variant = g_variant_new_string (layout_variant);
       g_variant_builder_add (builder, "{sv}", "layout-variant", variant);
     }
-
-  g_free (layout_variant);
-  g_free (layout);
 }
 
 static GVariant *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]