[gnome-panel/wip/status-notifier: 8/14] snh: make it possible to open item menu



commit 4d3d27d772fc5a406132bd7a0f4c19d3e1ac8568
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Jul 4 23:55:08 2015 +0300

    snh: make it possible to open item menu

 applets/snh/snh-applet.c |    2 +-
 applets/snh/snh-item.c   |  115 ++++++++++++++++++++++++++++++++++++++-------
 configure.ac             |    2 +-
 3 files changed, 99 insertions(+), 20 deletions(-)
---
diff --git a/applets/snh/snh-applet.c b/applets/snh/snh-applet.c
index 1870cbf..69ef262 100644
--- a/applets/snh/snh-applet.c
+++ b/applets/snh/snh-applet.c
@@ -153,7 +153,7 @@ snh_applet_init (SnhApplet *applet)
   g_signal_connect (applet->host, "items-changed",
                     G_CALLBACK (items_changed_cb), applet);
 
-  applet->box = gtk_box_new (orientation, 0);
+  applet->box = gtk_box_new (orientation, 6);
   gtk_container_add (GTK_CONTAINER (applet), applet->box);
   gtk_widget_show (applet->box);
 }
diff --git a/applets/snh/snh-item.c b/applets/snh/snh-item.c
index 645d32e..1011f2e 100644
--- a/applets/snh/snh-item.c
+++ b/applets/snh/snh-item.c
@@ -17,6 +17,8 @@
 
 #include "config.h"
 
+#include <libdbusmenu-gtk/menu.h>
+
 #include "snh-item.h"
 
 #define UPDATE_TIMEOUT 100
@@ -24,31 +26,33 @@
 
 struct _SnhItem
 {
-  GtkEventBox     parent;
+  GtkEventBox      parent;
+
+  SnItemClient    *item;
 
-  SnItemClient   *item;
+  GtkOrientation   orientation;
+  gint             size;
 
-  GtkOrientation  orientation;
-  gint            size;
+  guint            update_id;
+  guint            update_icons_id;
 
-  guint           update_id;
-  guint           update_icons_id;
+  gchar           *title;
+  gchar           *tooltip_title;
+  gchar           *tooltip_text;
+  gchar           *icon_theme_path;
 
-  gchar          *title;
-  gchar          *tooltip_title;
-  gchar          *tooltip_text;
-  gchar          *icon_theme_path;
+  GdkPixbuf       *icon;
+  GdkPixbuf       *overlay_icon;
+  GdkPixbuf       *attention_icon;
+  GdkPixbuf       *tooltip_icon;
 
-  GdkPixbuf      *icon;
-  GdkPixbuf      *overlay_icon;
-  GdkPixbuf      *attention_icon;
-  GdkPixbuf      *tooltip_icon;
+  SnItemStatus     status;
 
-  SnItemStatus    status;
+  GtkWidget       *box;
+  GtkWidget       *image;
+  GtkWidget       *label;
 
-  GtkWidget      *box;
-  GtkWidget      *image;
-  GtkWidget      *label;
+  DbusmenuGtkMenu *gtk_menu;
 };
 
 enum
@@ -427,6 +431,76 @@ snh_item_size_allocate (GtkWidget     *widget,
   snh_item_update_icons (item);
 }
 
+static gboolean
+snh_item_button_press_event (GtkWidget      *widget,
+                             GdkEventButton *event)
+{
+  SnhItem *item;
+
+  item = SNH_ITEM (widget);
+
+  if (item->gtk_menu == NULL)
+    {
+      const gchar *name;
+      const gchar *menu;
+
+      g_object_get (item->item, "service", &name, NULL);
+      menu = sn_item_client_get_menu (item->item);
+
+      if (menu != NULL)
+        item->gtk_menu = dbusmenu_gtkmenu_new ((gchar *) name, (gchar *) menu);
+    }
+
+  if (item->gtk_menu)
+    {
+      GtkWidget *widget;
+
+      widget = GTK_WIDGET (item->gtk_menu);
+
+      if (gtk_widget_is_visible (widget) == FALSE)
+        gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL,
+                        0, event->time);
+      else
+        gtk_widget_hide (widget);
+    }
+  else
+    {
+      gint x;
+      gint y;
+
+      x = 0;
+      y = 0;
+
+      if (event->button == GDK_BUTTON_PRIMARY)
+        sn_item_client_activate (item->item, x, y);
+      else if (event->button == GDK_BUTTON_MIDDLE)
+        sn_item_client_secondary_activate (item->item, x, y);
+      else if (event->button == GDK_BUTTON_SECONDARY)
+        sn_item_client_context_menu (item->item, x, y);
+    }
+
+  return GTK_WIDGET_CLASS (snh_item_parent_class)->button_press_event (widget,
+                                                                       event);
+}
+
+static gboolean
+snh_item_scroll_event (GtkWidget      *widget,
+                       GdkEventScroll *event)
+{
+  SnhItem *item;
+  gint delta;
+  SnItemScrollOrientation orientation;
+
+  item = SNH_ITEM (widget);
+
+  delta = 0;
+  orientation = SN_ITEM_SCROLL_ORIENTATION_HORIZONTAL;
+
+  sn_item_client_scroll (item->item, delta, orientation);
+
+  return FALSE;
+}
+
 static void
 snh_item_class_init (SnhItemClass *item_class)
 {
@@ -442,6 +516,8 @@ snh_item_class_init (SnhItemClass *item_class)
   object_class->finalize = snh_item_finalize;
 
   widget_class->size_allocate = snh_item_size_allocate;
+  widget_class->button_press_event = snh_item_button_press_event;
+  widget_class->scroll_event = snh_item_scroll_event;
 
   properties[PROP_ITEM] =
     g_param_spec_object ("item", "item", "item", SN_TYPE_ITEM_CLIENT,
@@ -467,6 +543,9 @@ snh_item_init (SnhItem *item)
 
   item->label = gtk_label_new (NULL);
   gtk_box_pack_start (GTK_BOX (item->box), item->label, FALSE, FALSE, 0);
+
+  gtk_widget_add_events (GTK_WIDGET (item), GDK_BUTTON_RELEASE_MASK |
+                         GDK_SCROLL_MASK);
 }
 
 GtkWidget *
diff --git a/configure.ac b/configure.ac
index 64bc78d..f61d566 100644
--- a/configure.ac
+++ b/configure.ac
@@ -119,7 +119,7 @@ PKG_CHECK_MODULES(NOTIFICATION_AREA, gtk+-3.0 >= $GTK_REQUIRED)
 AC_SUBST(NOTIFICATION_AREA_CFLAGS)
 AC_SUBST(NOTIFICATION_AREA_LIBS)
 
-PKG_CHECK_MODULES(SNH, gtk+-3.0 >= $GTK_REQUIRED libstatus-notifier-3.0 >= $LIBSTATUS_NOTIFIER_REQUIRED)
+PKG_CHECK_MODULES(SNH, gtk+-3.0 >= $GTK_REQUIRED libstatus-notifier-3.0 >= $LIBSTATUS_NOTIFIER_REQUIRED 
dbusmenu-gtk3-0.4)
 AC_SUBST(SNH_CFLAGS)
 AC_SUBST(SNH_LIBS)
 


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