[gnome-flashback] system-indicators: add setting to use IBus icon
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] system-indicators: add setting to use IBus icon
- Date: Mon, 23 Dec 2019 01:06:19 +0000 (UTC)
commit cd96c92dcdbb444af6ac6cb9b6bb673b1e407905
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Dec 23 02:55:19 2019 +0200
system-indicators: add setting to use IBus icon
https://bugzilla.gnome.org/show_bug.cgi?id=779990
...back.system-indicators.input-source.gschema.xml | 5 +++
.../libinput-sources/gf-input-source-manager.c | 8 +++++
gnome-flashback/libinput-sources/gf-input-source.c | 17 ++++++++++
gnome-flashback/libinput-sources/gf-input-source.h | 5 +++
.../libinput-sources/gf-input-sources.c | 8 +++++
system-indicators/si-input-source.c | 38 ++++++++++++++++------
6 files changed, 71 insertions(+), 10 deletions(-)
---
diff --git a/data/schemas/org.gnome.gnome-flashback.system-indicators.input-source.gschema.xml
b/data/schemas/org.gnome.gnome-flashback.system-indicators.input-source.gschema.xml
index 3783930..57f78e5 100644
--- a/data/schemas/org.gnome.gnome-flashback.system-indicators.input-source.gschema.xml
+++ b/data/schemas/org.gnome.gnome-flashback.system-indicators.input-source.gschema.xml
@@ -6,6 +6,11 @@
<summary>Generate symbolic icon</summary>
</key>
+ <key name="use-ibus-icon-if-available" type="b">
+ <default>false</default>
+ <summary>Use IBus icon if available</summary>
+ </key>
+
<key name="icon-bg-color" type="s">
<default>'#FFFFFF'</default>
<summary>Icon background color</summary>
diff --git a/gnome-flashback/libinput-sources/gf-input-source-manager.c
b/gnome-flashback/libinput-sources/gf-input-source-manager.c
index 35e3477..3e1b44d 100644
--- a/gnome-flashback/libinput-sources/gf-input-source-manager.c
+++ b/gnome-flashback/libinput-sources/gf-input-source-manager.c
@@ -46,6 +46,8 @@ struct _SourceInfo
gchar *display_name;
gchar *short_name;
+
+ char *icon_file;
};
typedef struct
@@ -422,6 +424,7 @@ source_info_free (gpointer data)
g_free (info->id);
g_free (info->display_name);
g_free (info->short_name);
+ g_free (info->icon_file);
g_free (info);
}
@@ -746,6 +749,7 @@ get_source_info_list (GfInputSourceManager *manager)
const gchar *language;
const gchar *longname;
const gchar *textdomain;
+ const char *icon;
gchar *display_name;
gchar *short_name;
@@ -762,6 +766,7 @@ get_source_info_list (GfInputSourceManager *manager)
language = ibus_get_language_name (language_code);
longname = ibus_engine_desc_get_longname (engine_desc);
textdomain = ibus_engine_desc_get_textdomain (engine_desc);
+ icon = ibus_engine_desc_get_icon (engine_desc);
if (*textdomain != '\0' && *longname != '\0')
longname = g_dgettext (textdomain, longname);
@@ -770,6 +775,7 @@ get_source_info_list (GfInputSourceManager *manager)
short_name = make_engine_short_name (engine_desc);
info = source_info_new (type, id, display_name, short_name);
+ info->icon_file = g_strdup (icon);
g_free (display_name);
g_free (short_name);
@@ -1193,6 +1199,8 @@ sources_changed_cb (GfInputSourceSettings *settings,
info->id, info->display_name,
info->short_name, position);
+ gf_input_source_set_icon_file (source, info->icon_file);
+
g_signal_connect (source, "activate",
G_CALLBACK (activate_cb), manager);
diff --git a/gnome-flashback/libinput-sources/gf-input-source.c
b/gnome-flashback/libinput-sources/gf-input-source.c
index 8ed404d..0e34c4e 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.c
+++ b/gnome-flashback/libinput-sources/gf-input-source.c
@@ -37,6 +37,8 @@ struct _GfInputSource
gchar *xkb_id;
IBusPropList *prop_list;
+
+ char *icon_file;
};
enum
@@ -198,6 +200,7 @@ gf_input_source_finalize (GObject *object)
g_free (source->display_name);
g_free (source->short_name);
g_free (source->xkb_id);
+ g_free (source->icon_file);
G_OBJECT_CLASS (gf_input_source_parent_class)->finalize (object);
}
@@ -368,3 +371,17 @@ gf_input_source_set_properties (GfInputSource *source,
if (prop_list != NULL)
source->prop_list = g_object_ref (prop_list);
}
+
+const char *
+gf_input_source_get_icon_file (GfInputSource *self)
+{
+ return self->icon_file;
+}
+
+void
+gf_input_source_set_icon_file (GfInputSource *self,
+ const char *icon_file)
+{
+ g_clear_pointer (&self->icon_file, g_free);
+ self->icon_file = g_strdup (icon_file);
+}
diff --git a/gnome-flashback/libinput-sources/gf-input-source.h
b/gnome-flashback/libinput-sources/gf-input-source.h
index 6388d11..fe0a166 100644
--- a/gnome-flashback/libinput-sources/gf-input-source.h
+++ b/gnome-flashback/libinput-sources/gf-input-source.h
@@ -57,4 +57,9 @@ IBusPropList *gf_input_source_get_properties (GfInputSource *source);
void gf_input_source_set_properties (GfInputSource *source,
IBusPropList *prop_list);
+const char *gf_input_source_get_icon_file (GfInputSource *self);
+
+void gf_input_source_set_icon_file (GfInputSource *self,
+ const char *icon_file);
+
#endif
diff --git a/gnome-flashback/libinput-sources/gf-input-sources.c
b/gnome-flashback/libinput-sources/gf-input-sources.c
index 9942914..8dae608 100644
--- a/gnome-flashback/libinput-sources/gf-input-sources.c
+++ b/gnome-flashback/libinput-sources/gf-input-sources.c
@@ -66,10 +66,12 @@ append_icon_info (GVariantBuilder *builder,
{
const char *display_name;
const char *icon_text;
+ const char *icon_file;
IBusPropList *prop_list;
display_name = gf_input_source_get_display_name (self->current_source);
icon_text = gf_input_source_get_short_name (self->current_source);
+ icon_file = gf_input_source_get_icon_file (self->current_source);
prop_list = gf_input_source_get_properties (self->current_source);
if (prop_list != NULL)
@@ -111,6 +113,12 @@ append_icon_info (GVariantBuilder *builder,
g_variant_builder_add (builder, "{sv}", "icon-text",
g_variant_new_string (icon_text));
+
+ if (icon_file != NULL)
+ {
+ g_variant_builder_add (builder, "{sv}", "icon-file",
+ g_variant_new_string (icon_file));
+ }
}
static const char *
diff --git a/system-indicators/si-input-source.c b/system-indicators/si-input-source.c
index 915820a..f8fc288 100644
--- a/system-indicators/si-input-source.c
+++ b/system-indicators/si-input-source.c
@@ -42,6 +42,7 @@ struct _SiInputSource
GfInputSourcesGen *input_sources;
char *icon_text;
+ char *icon_file;
};
G_DEFINE_TYPE (SiInputSource, si_input_source, SI_TYPE_INDICATOR)
@@ -406,12 +407,24 @@ get_icon_name (SiInputSource *self)
static void
update_icon (SiInputSource *self)
{
- char *icon_name;
+ gboolean use_ibus_icon;
+
+ use_ibus_icon = g_settings_get_boolean (self->settings,
+ "use-ibus-icon-if-available");
+
+ if (use_ibus_icon && self->icon_file != NULL)
+ {
+ si_indicator_set_icon_filename (SI_INDICATOR (self), self->icon_file);
+ }
+ else
+ {
+ char *icon_name;
- icon_name = get_icon_name (self);
+ icon_name = get_icon_name (self);
- si_indicator_set_icon_name (SI_INDICATOR (self), icon_name);
- g_free (icon_name);
+ si_indicator_set_icon_name (SI_INDICATOR (self), icon_name);
+ g_free (icon_name);
+ }
}
static void
@@ -420,6 +433,7 @@ update_indicator_icon (SiInputSource *self,
{
GVariantDict dict;
const char *icon_text;
+ const char *icon_file;
const char *tooltip;
GtkWidget *item;
@@ -428,19 +442,22 @@ update_indicator_icon (SiInputSource *self,
if (!g_variant_dict_lookup (&dict, "icon-text", "&s", &icon_text))
icon_text = NULL;
+ if (!g_variant_dict_lookup (&dict, "icon-file", "&s", &icon_file))
+ icon_file = NULL;
+
if (!g_variant_dict_lookup (&dict, "tooltip", "&s", &tooltip))
tooltip = NULL;
- if (g_strcmp0 (self->icon_text, icon_text) != 0)
- {
- g_clear_pointer (&self->icon_text, g_free);
- self->icon_text = g_strdup (icon_text);
+ g_clear_pointer (&self->icon_text, g_free);
+ self->icon_text = g_strdup (icon_text);
- update_icon (self);
- }
+ g_clear_pointer (&self->icon_file, g_free);
+ self->icon_file = g_strdup (icon_file);
item = si_indicator_get_menu_item (SI_INDICATOR (self));
gtk_widget_set_tooltip_text (item , tooltip);
+
+ update_icon (self);
}
static void
@@ -1064,6 +1081,7 @@ si_input_source_finalize (GObject *object)
g_clear_pointer (&self->icon_theme_path, g_free);
g_clear_pointer (&self->icon_text, g_free);
+ g_clear_pointer (&self->icon_file, g_free);
G_OBJECT_CLASS (si_input_source_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]