File show-input-mode-icon.patch of Package ibus.openSUSE_13.1_Update

From 8dcad73926dfed30b1aae6bcb6c0ecae35d13777 Mon Sep 17 00:00:00 2001
From: Fuminobu TAKEYAMA <ftake@geeko.jp>
Date: Sun, 6 Oct 2013 15:29:43 +0900
Subject: [PATCH] If icons for input modes are available, use those icons
 instead of engine's icons.

---
 ui/gtk3/panel.vala | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/ui/gtk3/panel.vala b/ui/gtk3/panel.vala
index 9c1fef5..1d38bfe 100644
--- a/ui/gtk3/panel.vala
+++ b/ui/gtk3/panel.vala
@@ -1098,10 +1098,51 @@ class Panel : IBus.PanelService {
 
     public override void register_properties(IBus.PropList props) {
         m_property_manager.set_properties(props);
+        int i = 0;
+        while (true) {
+            IBus.Property prop = props.get(i);
+            if (prop == null)
+                break;
+            if (prop.key == "InputMode") {
+                update_input_mode_icon(prop.icon);
+                break;
+            }
+            i++;
+        }
     }
 
     public override void update_property(IBus.Property prop) {
         m_property_manager.update_property(prop);
+        if (prop.key == "InputMode") {
+            update_input_mode_icon(prop.icon);
+        }
+    }
+
+    // If InputMode has an icon, use it instead of engine's icon.
+    public void update_input_mode_icon(string icon) {
+        var icon_name = icon;
+        if (icon == "") {
+            var engine = m_bus.get_global_engine();
+            icon_name = engine.get_icon();
+        }
+
+        if (icon_name[0] == '/') {
+            try {
+                // resize icon because icons were desinged for ibus tool bar of 1.4.x
+                // use 24 px because icons are wrongly cropped on KDE
+                var icon_img = new Gdk.Pixbuf.from_file_at_size(icon_name, 24, 24);
+                m_status_icon.set_from_pixbuf(icon_img);
+            } catch (Error e) {
+                warning("could not load icon: %s", icon_name);
+            }
+        } else {
+            var theme = Gtk.IconTheme.get_default();
+            if (theme.lookup_icon(icon_name, 48, 0) != null) {
+                m_status_icon.set_from_icon_name(icon_name);
+            } else {
+                m_status_icon.set_from_icon_name("ibus-engine");
+            }
+        }
     }
 
     public override void update_preedit_text(IBus.Text text,
-- 
1.8.4

openSUSE Build Service is sponsored by