Blob Blame History Raw
From 8375f391e1b9bfc048ff14fd458f689d853064ac Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Thu, 28 Feb 2019 15:26:11 +0900
Subject: [PATCH] ui/gtk3: Do not add emojis in compose category to emoji
 variants

Any emojis in compose category have variants and should be shown by default.
---
 bindings/vala/IBus-1.0-custom.vala |  4 ++
 ui/gtk3/emojier.vala               | 74 ++++++++++++++++++++++++++----
 2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/bindings/vala/IBus-1.0-custom.vala b/bindings/vala/IBus-1.0-custom.vala
index 7d34a8bd..ec46fc90 100644
--- a/bindings/vala/IBus-1.0-custom.vala
+++ b/bindings/vala/IBus-1.0-custom.vala
@@ -17,4 +17,8 @@ namespace IBus {
 	public class PanelService : IBus.Service {
                 public void panel_extension_register_keys(string first_property_name, ...);
 	}
+        public class EmojiData : IBus.Serializable {
+		[CCode (cname = "ibus_emoji_data_new", has_construct_function = true)]
+		public EmojiData (string first_property_name, ...);
+	}
 }
diff --git a/ui/gtk3/emojier.vala b/ui/gtk3/emojier.vala
index aedeb4cb..fc15cffe 100644
--- a/ui/gtk3/emojier.vala
+++ b/ui/gtk3/emojier.vala
@@ -389,6 +389,14 @@ public class IBusEmojier : Gtk.ApplicationWindow {
             }
             make_emoji_dict(m_current_lang_id);
         }
+        add_variants_to_component();
+
+        GLib.List<unowned string> annotations =
+                m_annotation_to_emojis_dict.get_keys();
+        foreach (unowned string annotation in annotations) {
+            if (m_emoji_max_seq_len < annotation.length)
+                m_emoji_max_seq_len = annotation.length;
+        }
         update_favorite_emoji_dict();
     }
 
@@ -430,11 +438,54 @@ public class IBusEmojier : Gtk.ApplicationWindow {
             update_annotation_to_emojis_dict(data);
             update_category_to_emojis_dict(data, lang);
         }
-        GLib.List<unowned string> annotations =
-                m_annotation_to_emojis_dict.get_keys();
-        foreach (unowned string annotation in annotations) {
-            if (m_emoji_max_seq_len < annotation.length)
-                m_emoji_max_seq_len = annotation.length;
+    }
+
+
+    private static void add_variants_to_component() {
+        string category = "Component";
+        unowned GLib.SList<string> hits =
+                m_category_to_emojis_dict.lookup(category);
+        if (hits == null) {
+            category = "component";
+            hits = m_category_to_emojis_dict.lookup(category);
+        }
+        if (hits == null)
+            return;
+        GLib.SList<IBus.EmojiData> emoji_list =
+                new GLib.SList<IBus.EmojiData>();
+        GLib.SList<string> annotations = new GLib.SList<string>();
+        annotations.append("zero");
+        IBus.EmojiData _data;
+        _data = new IBus.EmojiData("emoji", "\u200d",
+                                   "annotations", annotations,
+                                   "description",
+                                   "ZERO WIDTH JOINER",
+                                   "category", category);
+        emoji_list.append(_data);
+        annotations = null;
+        annotations.append("text");
+        annotations.append("variation");
+        annotations.append("selector");
+        _data = new IBus.EmojiData("emoji", "\ufe0e",
+                                   "annotations", annotations,
+                                   "description",
+                                   "VARIATION SELECTOR-15",
+                                   "category", category);
+        emoji_list.append(_data);
+        annotations = null;
+        annotations.append("emoji");
+        annotations.append("variation");
+        annotations.append("selector");
+        _data = new IBus.EmojiData("emoji", "\ufe0f",
+                                   "annotations", annotations,
+                                   "description",
+                                   "VARIATION SELECTOR-16",
+                                   "category", category);
+        emoji_list.append(_data);
+        foreach (IBus.EmojiData data in emoji_list) {
+            update_emoji_to_data_dict(data, "en");
+            update_annotation_to_emojis_dict(data);
+            update_category_to_emojis_dict(data, "en");
         }
     }
 
@@ -583,10 +634,12 @@ public class IBusEmojier : Gtk.ApplicationWindow {
             category = EMOJI_CATEGORY_OTHERS;
         if (lang == "en") {
             bool has_variant = false;
-            foreach (unichar ch in EMOJI_VARIANT_LIST) {
-                if (emoji.index_of_char(ch) >= 0) {
-                    has_variant = true;
-                    break;
+            if (category.ascii_casecmp("component") != 0) {
+                foreach (unichar ch in EMOJI_VARIANT_LIST) {
+                    if (emoji.index_of_char(ch) >= 0) {
+                        has_variant = true;
+                        break;
+                    }
                 }
             }
             // If emoji includes variants (skin colors and items),
@@ -606,7 +659,8 @@ public class IBusEmojier : Gtk.ApplicationWindow {
                 if (variants.find_custom(emoji, GLib.strcmp) == null) {
                     if (variants == null)
                         variants.append(base_emoji);
-                    variants.append(emoji);
+                    if (base_emoji != emoji)
+                        variants.append(emoji);
                     m_emoji_to_emoji_variants_dict.replace(
                             base_emoji,
                             variants.copy_deep(GLib.strdup));
-- 
2.21.0