[gnome-flashback] input-sources: port GtkStatusIcon to SnItem
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] input-sources: port GtkStatusIcon to SnItem
- Date: Wed, 23 Nov 2016 12:04:54 +0000 (UTC)
commit 8c6db97fe5afc820682903257cc5cb28e2c5fbbd
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Nov 23 14:04:17 2016 +0200
input-sources: port GtkStatusIcon to SnItem
gnome-flashback/libinput-sources/Makefile.am | 1 +
.../libinput-sources/gf-input-sources.c | 63 ++++++++++---------
2 files changed, 34 insertions(+), 30 deletions(-)
---
diff --git a/gnome-flashback/libinput-sources/Makefile.am b/gnome-flashback/libinput-sources/Makefile.am
index ec1c77a..fb35f69 100644
--- a/gnome-flashback/libinput-sources/Makefile.am
+++ b/gnome-flashback/libinput-sources/Makefile.am
@@ -48,6 +48,7 @@ libinput_sources_la_LDFLAGS = \
$(NULL)
libinput_sources_la_LIBADD = \
+ $(top_builddir)/libstatus-notifier/libstatus-notifier.la \
$(top_builddir)/gnome-flashback/libcommon/libcommon.la \
$(INPUT_SOURCES_LIBS) \
$(LIBM) \
diff --git a/gnome-flashback/libinput-sources/gf-input-sources.c
b/gnome-flashback/libinput-sources/gf-input-sources.c
index 15546c1..ec940de 100644
--- a/gnome-flashback/libinput-sources/gf-input-sources.c
+++ b/gnome-flashback/libinput-sources/gf-input-sources.c
@@ -18,6 +18,7 @@
#include "config.h"
#include <glib/gi18n.h>
+#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <libgnome-desktop/gnome-xkb-info.h>
#include <locale.h>
@@ -27,6 +28,7 @@
#include "gf-input-sources.h"
#include "gf-input-source-manager.h"
#include "gf-input-source.h"
+#include "libstatus-notifier/sn-item.h"
#define STATUS_ICON_SCHEMA "org.gnome.gnome-flashback.input-sources.status-icon"
@@ -42,7 +44,7 @@ struct _GfInputSources
gchar *icon_theme_path;
GfInputSource *current_source;
- GtkStatusIcon *status_icon;
+ SnItem *status_item;
};
G_DEFINE_TYPE (GfInputSources, gf_input_sources, G_TYPE_OBJECT)
@@ -481,18 +483,19 @@ show_layout_cb (GtkMenuItem *menuitem,
}
static void
-status_icon_activate_cb (GtkStatusIcon *status_icon,
- gpointer user_data)
+context_menu_cb (SnItem *object,
+ gint x,
+ gint y,
+ GfInputSources *sources)
{
- GfInputSources *sources;
GtkWidget *menu;
GfInputSourceManager *manager;
GList *input_sources;
GList *is;
GtkWidget *item;
GtkWidget *separator;
-
- sources = GF_INPUT_SOURCES (user_data);
+ GdkScreen *screen;
+ GdkWindow *root;
menu = gtk_menu_new ();
@@ -542,14 +545,12 @@ status_icon_activate_cb (GtkStatusIcon *status_icon,
g_signal_connect (item, "activate", G_CALLBACK (show_layout_cb), sources);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ screen = gdk_screen_get_default ();
+ root = gdk_screen_get_root_window (screen);
gtk_widget_show_all (menu);
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- gtk_status_icon_position_menu, status_icon,
- 0, gtk_get_current_event_time ());
-
- G_GNUC_END_IGNORE_DEPRECATIONS
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
+ 0, gdk_x11_get_server_time (root));
}
static void
@@ -569,7 +570,7 @@ update_status_icon (GfInputSources *sources)
if (source == NULL)
{
- g_clear_object (&sources->status_icon);
+ g_clear_object (&sources->status_item);
return;
}
@@ -588,27 +589,29 @@ update_status_icon (GfInputSources *sources)
sources->current_source = g_object_ref (source);
- if (sources->status_icon == NULL)
+ if (sources->status_item == NULL)
{
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- sources->status_icon = gtk_status_icon_new ();
- G_GNUC_END_IGNORE_DEPRECATIONS
-
- g_signal_connect_swapped (sources->status_icon, "size-changed",
- G_CALLBACK (update_status_icon), sources);
- g_signal_connect (sources->status_icon, "activate",
- G_CALLBACK (status_icon_activate_cb), sources);
+ sources->status_item = g_object_new (SN_TYPE_ITEM,
+ "version", 0,
+ "category", SN_ITEM_CATEGORY_SYSTEM_SERVICES,
+ "id", "gf-input-sources",
+ "title", _("Keyboard"),
+ NULL);
+
+ sn_item_set_icon_theme_path (sources->status_item,
+ sources->icon_theme_path);
+
+ g_signal_connect (sources->status_item, "context-menu",
+ G_CALLBACK (context_menu_cb), sources);
+
+ sn_item_register (sources->status_item);
}
display_name = gf_input_source_get_display_name (source);
- icon_name = get_icon_name (sources);
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_status_icon_set_title (sources->status_icon, _("Keyboard"));
- gtk_status_icon_set_tooltip_text (sources->status_icon, display_name);
- gtk_status_icon_set_from_icon_name (sources->status_icon, icon_name);
- G_GNUC_END_IGNORE_DEPRECATIONS
+ sn_item_set_tooltip (sources->status_item, NULL, NULL, NULL, display_name);
+ icon_name = get_icon_name (sources);
+ sn_item_set_icon_name (sources->status_item, icon_name);
g_free (icon_name);
}
@@ -648,7 +651,7 @@ gf_input_sources_dispose (GObject *object)
g_clear_object (&sources->status_icon_settings);
g_clear_object (&sources->current_source);
- g_clear_object (&sources->status_icon);
+ g_clear_object (&sources->status_item);
G_OBJECT_CLASS (gf_input_sources_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]