[gnome-panel/wip/status-notifier: 13/14] snh: create as items as menu bar
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/status-notifier: 13/14] snh: create as items as menu bar
- Date: Wed, 22 Jul 2015 20:27:09 +0000 (UTC)
commit 804ea6fbf6efba8807080069fa5a3f3126b4045c
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Jul 21 01:49:59 2015 +0300
snh: create as items as menu bar
applets/snh/snh-applet.c | 35 ++++++++++++++++++++++-------------
applets/snh/snh-item.c | 33 ++++++++++++++++-----------------
applets/snh/snh-item.h | 2 +-
gnome-panel/Adwaita.css | 8 ++++++++
gnome-panel/HighContrast.css | 8 ++++++++
5 files changed, 55 insertions(+), 31 deletions(-)
---
diff --git a/applets/snh/snh-applet.c b/applets/snh/snh-applet.c
index 69ef262..443beee 100644
--- a/applets/snh/snh-applet.c
+++ b/applets/snh/snh-applet.c
@@ -26,7 +26,7 @@ struct _SnhApplet
SnHost *host;
- GtkWidget *box;
+ GtkWidget *menu_bar;
};
G_DEFINE_TYPE (SnhApplet, snh_applet, PANEL_TYPE_APPLET)
@@ -50,7 +50,7 @@ items_changed_cb (SnHost *host,
list = sn_host_get_items (host);
- gtk_container_foreach (GTK_CONTAINER (applet->box),
+ gtk_container_foreach (GTK_CONTAINER (applet->menu_bar),
(GtkCallback) item_remove, NULL);
for (l = list; l; l = l->next)
@@ -61,10 +61,7 @@ items_changed_cb (SnHost *host,
item_client = SN_ITEM_CLIENT (l->data);
item = snh_item_new (item_client);
- g_object_bind_property (applet->box, "orientation", item, "orientation",
- G_BINDING_DEFAULT);
-
- gtk_box_pack_start (GTK_BOX (applet->box), item, FALSE, FALSE, 0);
+ gtk_menu_shell_append (GTK_MENU_SHELL (applet->menu_bar), item);
gtk_widget_show (item);
}
@@ -109,6 +106,19 @@ snh_applet_finalize (GObject *object)
}
static void
+change_orientation (GtkWidget *widget,
+ gpointer data)
+{
+ SnhItem *item;
+ GtkOrientation orientation;
+
+ item = SNH_ITEM (widget);
+ orientation = GPOINTER_TO_INT (data);
+
+ g_object_set (item, "orientation", orientation, NULL);
+}
+
+static void
snh_applet_change_orient (PanelApplet *applet,
PanelAppletOrient orient)
{
@@ -118,8 +128,9 @@ snh_applet_change_orient (PanelApplet *applet,
snh_applet = SNH_APPLET (applet);
orientation = panel_applet_get_gtk_orientation (applet);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (snh_applet->box),
- orientation);
+ gtk_container_foreach (GTK_CONTAINER (snh_applet->menu_bar),
+ (GtkCallback) change_orientation,
+ GINT_TO_POINTER (orientation));
}
static void
@@ -141,10 +152,8 @@ static void
snh_applet_init (SnhApplet *applet)
{
PanelApplet *panel_applet;
- GtkOrientation orientation;
panel_applet = PANEL_APPLET (applet);
- orientation = panel_applet_get_gtk_orientation (panel_applet);
panel_applet_set_flags (panel_applet, PANEL_APPLET_HAS_HANDLE |
PANEL_APPLET_EXPAND_MINOR);
@@ -153,9 +162,9 @@ snh_applet_init (SnhApplet *applet)
g_signal_connect (applet->host, "items-changed",
G_CALLBACK (items_changed_cb), applet);
- applet->box = gtk_box_new (orientation, 6);
- gtk_container_add (GTK_CONTAINER (applet), applet->box);
- gtk_widget_show (applet->box);
+ applet->menu_bar = gtk_menu_bar_new ();
+ gtk_container_add (GTK_CONTAINER (applet), applet->menu_bar);
+ gtk_widget_show (applet->menu_bar);
}
PANEL_APPLET_IN_PROCESS_FACTORY ("SnhAppletFactory", SNH_TYPE_APPLET,
diff --git a/applets/snh/snh-item.c b/applets/snh/snh-item.c
index be5cd48..8ebb338 100644
--- a/applets/snh/snh-item.c
+++ b/applets/snh/snh-item.c
@@ -24,7 +24,7 @@
struct _SnhItem
{
- GtkEventBox parent;
+ GtkMenuItem parent;
SnItemClient *item;
@@ -63,7 +63,7 @@ enum
static GParamSpec *properties[LAST_PROP] = { NULL };
-G_DEFINE_TYPE (SnhItem, snh_item, GTK_TYPE_EVENT_BOX)
+G_DEFINE_TYPE (SnhItem, snh_item, GTK_TYPE_MENU_ITEM)
static gboolean
update_cb (gpointer user_data)
@@ -300,6 +300,7 @@ snh_item_constructed (GObject *object)
{
SnhItem *item;
SnItemStatus status;
+ GtkMenu *menu;
item = SNH_ITEM (object);
@@ -325,6 +326,9 @@ snh_item_constructed (GObject *object)
status = sn_item_client_get_status (item->item);
snh_item_update_status (item, status);
+
+ menu = sn_item_client_get_menu (item->item);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), GTK_WIDGET (menu));
}
static void
@@ -408,16 +412,23 @@ snh_item_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
SnhItem *item;
+ GtkStyleContext *context;
+ GtkStateFlags flags;
+ GtkBorder padding;
gint size;
item = SNH_ITEM (widget);
+ context = gtk_widget_get_style_context (widget);
+ flags = gtk_widget_get_state_flags (widget);
GTK_WIDGET_CLASS (snh_item_parent_class)->size_allocate (widget, allocation);
+ gtk_style_context_get_padding (context, flags, &padding);
+
if (item->orientation == GTK_ORIENTATION_HORIZONTAL)
- size = allocation->height;
+ size = allocation->height - padding.top - padding.bottom;
else
- size = allocation->width;
+ size = allocation->width - padding.left - padding.right;
if (item->size == size)
return;
@@ -438,19 +449,7 @@ snh_item_button_press_event (GtkWidget *widget,
menu = sn_item_client_get_menu (item->item);
- if (menu)
- {
- GtkWidget *widget;
-
- widget = GTK_WIDGET (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
+ if (menu == NULL)
{
gint x;
gint y;
diff --git a/applets/snh/snh-item.h b/applets/snh/snh-item.h
index 5a7ce44..feb59bc 100644
--- a/applets/snh/snh-item.h
+++ b/applets/snh/snh-item.h
@@ -24,7 +24,7 @@
G_BEGIN_DECLS
#define SNH_TYPE_ITEM snh_item_get_type ()
-G_DECLARE_FINAL_TYPE (SnhItem, snh_item, SNH, ITEM, GtkEventBox)
+G_DECLARE_FINAL_TYPE (SnhItem, snh_item, SNH, ITEM, GtkMenuItem)
GtkWidget *snh_item_new (SnItemClient *item);
diff --git a/gnome-panel/Adwaita.css b/gnome-panel/Adwaita.css
index 404e039..83d6f98 100644
--- a/gnome-panel/Adwaita.css
+++ b/gnome-panel/Adwaita.css
@@ -43,3 +43,11 @@ NaTrayApplet {
-NaTrayApplet-icon-padding: 2;
-NaTrayApplet-icon-size: 16;
}
+
+SnhApplet {
+ outline: none;
+}
+
+SnhItem {
+ padding: 2px 4px;
+}
diff --git a/gnome-panel/HighContrast.css b/gnome-panel/HighContrast.css
index 404e039..83d6f98 100644
--- a/gnome-panel/HighContrast.css
+++ b/gnome-panel/HighContrast.css
@@ -43,3 +43,11 @@ NaTrayApplet {
-NaTrayApplet-icon-padding: 2;
-NaTrayApplet-icon-size: 16;
}
+
+SnhApplet {
+ outline: none;
+}
+
+SnhItem {
+ padding: 2px 4px;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]