From b1d66f9d77fa960d7e59353e1e33250060493ec6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 13:16:32 -0600 Subject: Refactoring so the menu is created in init. --- src/indicator-session.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index dda8c76..2017fff 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -51,6 +51,8 @@ struct _IndicatorSessionClass { struct _IndicatorSession { IndicatorObject parent; IndicatorServiceManager * service; + GtkImage * status_image; + GtkMenu * menu; }; GType indicator_session_get_type (void); @@ -96,6 +98,9 @@ indicator_session_init (IndicatorSession *self) /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); + self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); + self->menu = GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); + return; } @@ -130,9 +135,8 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - GtkImage * status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); - gtk_widget_show(GTK_WIDGET(status_image)); - return status_image; + gtk_widget_show(GTK_WIDGET(INDICATOR_SESSION(io)->status_image)); + return INDICATOR_SESSION(io)->status_image; } /* Indicator based function to get the menu for the whole @@ -141,7 +145,7 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - return GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); + return INDICATOR_SESSION(io)->menu; } -- cgit v1.2.3 From 70d29699c60a2507e457357a72eb484644f67dfd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 13:18:17 -0600 Subject: Woot, a dbusmenu, much better. --- src/indicator-session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 2017fff..840965e 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -52,7 +52,7 @@ struct _IndicatorSession { IndicatorObject parent; IndicatorServiceManager * service; GtkImage * status_image; - GtkMenu * menu; + DbusmenuGtkMenu * menu; }; GType indicator_session_get_type (void); @@ -99,7 +99,7 @@ indicator_session_init (IndicatorSession *self) self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); - self->menu = GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); + self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); return; } @@ -145,7 +145,7 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - return INDICATOR_SESSION(io)->menu; + return GTK_MENU(INDICATOR_SESSION(io)->menu); } -- cgit v1.2.3 From a36272659c9dbcff0c083a2083417ac65d876c3b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 14:53:20 -0600 Subject: Setting up the type handler --- src/indicator-session.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 840965e..a1f83d1 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -33,6 +33,7 @@ with this program. If not, see . #include #include "dbus-shared-names.h" +#include "dbusmenu-shared.h" #define INDICATOR_SESSION_TYPE (indicator_session_get_type ()) #define INDICATOR_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SESSION_TYPE, IndicatorSession)) @@ -65,6 +66,7 @@ INDICATOR_SET_TYPE(INDICATOR_SESSION_TYPE) static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); +static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -101,6 +103,9 @@ indicator_session_init (IndicatorSession *self) self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); + DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); + dbusmenu_client_add_type_handler(client, MENU_SWITCH_TYPE, build_menu_switch); + return; } @@ -148,4 +153,13 @@ get_menu (IndicatorObject * io) return GTK_MENU(INDICATOR_SESSION(io)->menu); } +/* This function checks to see if the user name is short enough + to not need ellipsing itself, or if, it will get ellipsed by + the standard label processor. */ +static gboolean +build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return FALSE; +} -- cgit v1.2.3 From 2398976ff0152f8cdbd1c2ec84663b33598abd7d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 16:08:36 -0600 Subject: Fleshing out the menu_switch function with a function that looks at the length of the label and sees if we need to ellipsize it or not. --- src/indicator-session.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a1f83d1..7e9bb45 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -22,6 +22,7 @@ with this program. If not, see . #include #include +#include #include #include @@ -153,13 +154,81 @@ get_menu (IndicatorObject * io) return GTK_MENU(INDICATOR_SESSION(io)->menu); } +static void +switch_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data) +{ + if (g_strcmp0(property, MENU_SWITCH_USER) != 0) { + return; + } + + gchar * finalstring = NULL; + gboolean set_ellipsize = FALSE; + + /* If there's a NULL string of some type, then we want to + go back to our old 'Switch User' which isn't great but + eh, this error condition should never happen. */ + if (value == NULL || g_value_get_string(value) == NULL || g_value_get_string(value)[0] == '\0') { + finalstring = _("Switch User..."); + set_ellipsize = FALSE; + } + + if (finalstring == NULL) { + const gchar * username = g_value_get_string(value); + GtkWidget * off = gtk_offscreen_window_new(); + GtkWidget * label = gtk_label_new(username); + gtk_container_add(GTK_CONTAINER(off), label); + GdkPixmap * pixmap = gtk_offscreen_window_get_pixmap(GTK_OFFSCREEN_WINDOW(off)); + + gint width, height; + gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &width, &height); + + GtkStyle * style = gtk_widget_get_style(label); /* TODO: Switch to menuitem label */ + gint point = pango_font_description_get_size(style->font_desc); + + gdouble dpi = gdk_screen_get_resolution(gdk_screen_get_default()); + + gdouble pixels_per_em = point * dpi / 72.0f; + gdouble ems = width / pixels_per_em; + + /* TODO: We need some way to remove the elipsis from appearing + twice in the label. Not sure how to do that yet. */ + finalstring = g_strdup_printf(_("Switch from %s..."), username); + if (ems >= 20.0f) { + set_ellipsize = TRUE; + } else { + set_ellipsize = FALSE; + } + } + + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(DBUSMENU_GTKCLIENT(user_data), item); + gtk_menu_item_set_label(gmi, finalstring); + + GtkLabel * label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(gmi))); + if (label != NULL) { + if (set_ellipsize) { + gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_NONE); + } else { + gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END); + } + } + + return; +} + + /* This function checks to see if the user name is short enough to not need ellipsing itself, or if, it will get ellipsed by the standard label processor. */ static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + /* TODO: Setup style update */ + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(switch_property_change), client); + switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(newitem, MENU_SWITCH_USER), client); return FALSE; } -- cgit v1.2.3 From 54cd89f665c38244b811508d5995010c9a9d08e0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 16:17:54 -0600 Subject: Get returns in better shape --- src/indicator-session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 7e9bb45..f0ec5a4 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -223,6 +223,9 @@ static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + if (gmi == NULL) { + return FALSE; + } /* TODO: Setup style update */ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); @@ -230,5 +233,5 @@ build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusme g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(switch_property_change), client); switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(newitem, MENU_SWITCH_USER), client); - return FALSE; + return TRUE; } -- cgit v1.2.3 From d2bc464709c47d37d110179c291a914fc989f148 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 16:22:51 -0600 Subject: Make sure to realize the offscreen window --- src/indicator-session.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index f0ec5a4..81453f2 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -177,6 +177,7 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G GtkWidget * off = gtk_offscreen_window_new(); GtkWidget * label = gtk_label_new(username); gtk_container_add(GTK_CONTAINER(off), label); + gtk_widget_realize(off); GdkPixmap * pixmap = gtk_offscreen_window_get_pixmap(GTK_OFFSCREEN_WINDOW(off)); gint width, height; -- cgit v1.2.3 From 5540e6c1c6321ec9c9d10060dc5917d842bcf08a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 20:37:28 -0600 Subject: Switching to using Pango to get the width --- src/indicator-session.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 81453f2..c685203 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -161,6 +161,7 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G return; } + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(DBUSMENU_GTKCLIENT(user_data), item); gchar * finalstring = NULL; gboolean set_ellipsize = FALSE; @@ -174,22 +175,25 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G if (finalstring == NULL) { const gchar * username = g_value_get_string(value); - GtkWidget * off = gtk_offscreen_window_new(); - GtkWidget * label = gtk_label_new(username); - gtk_container_add(GTK_CONTAINER(off), label); - gtk_widget_realize(off); - GdkPixmap * pixmap = gtk_offscreen_window_get_pixmap(GTK_OFFSCREEN_WINDOW(off)); + GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi)); /* TODO: Switch to menuitem label */ + + PangoLayout * layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(gmi))); + pango_layout_set_text(layout, username, -1); + pango_layout_set_font_description(layout, style->font_desc); gint width, height; - gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &width, &height); + pango_layout_get_pixel_size(layout, &width, &height); + g_debug("Username width %dpx", width); - GtkStyle * style = gtk_widget_get_style(label); /* TODO: Switch to menuitem label */ gint point = pango_font_description_get_size(style->font_desc); + g_debug("Font size %d pt", point); gdouble dpi = gdk_screen_get_resolution(gdk_screen_get_default()); + g_debug("Screen DPI %f", dpi); gdouble pixels_per_em = point * dpi / 72.0f; gdouble ems = width / pixels_per_em; + g_debug("Username width %fem", ems); /* TODO: We need some way to remove the elipsis from appearing twice in the label. Not sure how to do that yet. */ @@ -201,7 +205,6 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G } } - GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(DBUSMENU_GTKCLIENT(user_data), item); gtk_menu_item_set_label(gmi, finalstring); GtkLabel * label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(gmi))); -- cgit v1.2.3 From 78fa67257e72eb43d2a4f4d82d51f881af8ad91c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 20:44:35 -0600 Subject: Calculating font size with PANGO_SCALE getting involved --- src/indicator-session.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index c685203..f0232c6 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -181,17 +181,17 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G pango_layout_set_text(layout, username, -1); pango_layout_set_font_description(layout, style->font_desc); - gint width, height; - pango_layout_get_pixel_size(layout, &width, &height); + gint width; + pango_layout_get_pixel_size(layout, &width, NULL); g_debug("Username width %dpx", width); gint point = pango_font_description_get_size(style->font_desc); - g_debug("Font size %d pt", point); + g_debug("Font size %f pt", (gfloat)point / PANGO_SCALE); gdouble dpi = gdk_screen_get_resolution(gdk_screen_get_default()); g_debug("Screen DPI %f", dpi); - gdouble pixels_per_em = point * dpi / 72.0f; + gdouble pixels_per_em = ((point * dpi) / 72.0f) / PANGO_SCALE; gdouble ems = width / pixels_per_em; g_debug("Username width %fem", ems); -- cgit v1.2.3 From 93c4617240197202846fd9305f2154f885d17224 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 20:45:09 -0600 Subject: Fixing a value --- src/indicator-session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index f0232c6..9a5385e 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -210,9 +210,9 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G GtkLabel * label = GTK_LABEL(gtk_bin_get_child(GTK_BIN(gmi))); if (label != NULL) { if (set_ellipsize) { - gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_NONE); - } else { gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_END); + } else { + gtk_label_set_ellipsize(label, PANGO_ELLIPSIZE_NONE); } } -- cgit v1.2.3 From a2cf14bc54d903dbc51557ff6d06e38f92714010 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 22:48:04 -0600 Subject: Adding in the ability to monitor style changes and re-evaluate. --- src/indicator-session.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 9a5385e..4dc3d11 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -219,6 +219,20 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G return; } +static const gchar * dbusmenu_item_data = "dbusmenu-item"; + +/* Callback for when the style changes so we can reevaluate the + size of the user name with the potentially new font. */ +static void +switch_style_set (GtkWidget * widget, GtkStyle * prev_style, gpointer user_data) +{ + DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data); + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), dbusmenu_item_data)); + + switch_property_change(mi, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(mi, MENU_SWITCH_USER), client); + return; +} + /* This function checks to see if the user name is short enough to not need ellipsing itself, or if, it will get ellipsed by @@ -230,11 +244,12 @@ build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusme if (gmi == NULL) { return FALSE; } - /* TODO: Setup style update */ + g_object_set_data(G_OBJECT(gmi), dbusmenu_item_data, newitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(switch_property_change), client); + g_signal_connect(G_OBJECT(gmi), "style-set", G_CALLBACK(switch_style_set), client); switch_property_change(newitem, MENU_SWITCH_USER, dbusmenu_menuitem_property_get_value(newitem, MENU_SWITCH_USER), client); return TRUE; -- cgit v1.2.3 From c6661b02cfede0afff6102d7ebff656a166e0b29 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 11 Feb 2010 22:48:43 -0600 Subject: Removing comment. --- src/indicator-session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 4dc3d11..1b9629b 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -175,7 +175,7 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G if (finalstring == NULL) { const gchar * username = g_value_get_string(value); - GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi)); /* TODO: Switch to menuitem label */ + GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(gmi)); PangoLayout * layout = pango_layout_new(gtk_widget_get_pango_context(GTK_WIDGET(gmi))); pango_layout_set_text(layout, username, -1); -- cgit v1.2.3 From 765a3b87d9812680615dcb7278e16fea8f0fa1d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 23:24:09 -0600 Subject: Registering a handler for our new type --- src/indicator-session.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index dda8c76..d931bcd 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -135,13 +135,25 @@ get_icon (IndicatorObject * io) return status_image; } +static gboolean +new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return FALSE; +} + /* Indicator based function to get the menu for the whole applet. This starts up asking for the parts of the menu from the various services. */ static GtkMenu * get_menu (IndicatorObject * io) { - return GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT)); + DbusmenuGtkMenu * menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); + DbusmenuGtkClient * client = dbusmenu_gtkmenu_get_client(menu); + + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), USER_ITEM_TYPE, new_user_item); + + return GTK_MENU(menu); } -- cgit v1.2.3 From 7723397ac8f8f5875ffac86f007b9321a503a846 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Feb 2010 23:36:13 -0600 Subject: Fleshing out the building of the user item --- src/indicator-session.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index d931bcd..a39e4a0 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -135,11 +135,33 @@ get_icon (IndicatorObject * io) return status_image; } +/* Builds an item with a hip little logged in icon. */ static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + GtkWidget * hbox = gtk_hbox_new(FALSE, 0); + + GtkWidget * label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, USER_ITEM_PROP_NAME)); + gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + GtkWidget * icon = gtk_image_new_from_icon_name("account-logged-in", GTK_ICON_SIZE_MENU); + gtk_misc_set_alignment(GTK_MISC(icon), 1.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); + if (dbusmenu_menuitem_property_get_bool(newitem, USER_ITEM_PROP_LOGGED_IN)) { + gtk_widget_show(icon); + } else { + gtk_widget_hide(icon); + } + + gtk_container_add(GTK_CONTAINER(gmi), hbox); + gtk_widget_show(hbox); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); - return FALSE; + return TRUE; } /* Indicator based function to get the menu for the whole -- cgit v1.2.3 From db48c78c85af5ba8380ad147ba8576fd4d878c6f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 18 Feb 2010 09:39:20 -0600 Subject: adding prototype for new user item --- src/indicator-session.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index ee7d76c..a97eb95 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -68,6 +68,7 @@ static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); -- cgit v1.2.3 From 7e8f0d662bd911cf8c9e79b24446449d31464b8b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 1 Mar 2010 20:45:16 -0600 Subject: Unreffing the layout that we allocated --- src/indicator-session.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a97eb95..a815e40 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -214,6 +214,7 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G gint width; pango_layout_get_pixel_size(layout, &width, NULL); + g_object_unref(layout); g_debug("Username width %dpx", width); gint point = pango_font_description_get_size(style->font_desc); -- cgit v1.2.3 From fb8754f048176039d268157a22da3745773bd15b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 12:25:58 -0600 Subject: Adding in a handler and renderer for the restart required item --- src/indicator-session.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a815e40..fab3463 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -69,6 +69,7 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -108,6 +109,7 @@ indicator_session_init (IndicatorSession *self) DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); dbusmenu_client_add_type_handler(client, MENU_SWITCH_TYPE, build_menu_switch); dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item); + dbusmenu_client_add_type_handler(client, RESTART_ITEM_TYPE, build_restart_item); return; } @@ -253,6 +255,60 @@ switch_property_change (DbusmenuMenuitem * item, const gchar * property, const G static const gchar * dbusmenu_item_data = "dbusmenu-item"; +/* IF the label or icon changes we need to grab that and update + the menu item */ +static void +restart_property_change (DbusmenuMenuitem * item, const gchar * property, const GValue * value, gpointer user_data) +{ + DbusmenuGtkClient * client = DBUSMENU_GTKCLIENT(user_data); + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, item); + + if (g_strcmp0(property, RESTART_ITEM_LABEL) == 0) { + gtk_menu_item_set_label(gmi, g_value_get_string(value)); + } else if (g_strcmp0(property, RESTART_ITEM_ICON) == 0) { + GtkWidget * image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(gmi)); + + if (image == NULL) { + image = gtk_image_new_from_icon_name(g_value_get_string(value), GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gmi), image); + } else { + gtk_image_set_from_icon_name(GTK_IMAGE(image), g_value_get_string(value), GTK_ICON_SIZE_MENU); + } + } + + return; +} + +/* Builds the restart item which is a more traditional GTK image + menu item that puts the graphic into the gutter. */ +static gboolean +build_restart_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_image_menu_item_new()); + if (gmi == NULL) { + return FALSE; + } + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + + g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(restart_property_change), client); + + /* Grab the inital values and put them into the item */ + const GValue * value; + value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_LABEL); + if (value != NULL) { + restart_property_change(newitem, RESTART_ITEM_LABEL, value, client); + } + + value = dbusmenu_menuitem_property_get_value(newitem, RESTART_ITEM_ICON); + if (value != NULL) { + restart_property_change(newitem, RESTART_ITEM_ICON, value, client); + } + + return TRUE; +} + + /* Callback for when the style changes so we can reevaluate the size of the user name with the potentially new font. */ static void @@ -265,7 +321,6 @@ switch_style_set (GtkWidget * widget, GtkStyle * prev_style, gpointer user_data) return; } - /* This function checks to see if the user name is short enough to not need ellipsing itself, or if, it will get ellipsed by the standard label processor. */ -- cgit v1.2.3 From 535a2e63fd4e605ef63c933797abedcc28a55861 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 13:04:22 -0600 Subject: Setting up the indicator to use library translations so they'll be grabbed from the right domain. --- src/indicator-session.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a815e40..54431ee 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -20,9 +20,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include -#include +#include #include #include -- cgit v1.2.3 From fced2aaae755846922b46fa55a6444f0e0406c8d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 15:08:25 -0600 Subject: Building us a proxy! Now we are dangerous. --- src/indicator-session.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a815e40..0b8d77e 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -55,6 +55,7 @@ struct _IndicatorSession { IndicatorServiceManager * service; GtkImage * status_image; DbusmenuGtkMenu * menu; + DBusGProxy * service_proxy; }; GType indicator_session_get_type (void); @@ -109,6 +110,12 @@ indicator_session_init (IndicatorSession *self) dbusmenu_client_add_type_handler(client, MENU_SWITCH_TYPE, build_menu_switch); dbusmenu_client_add_type_handler(client, USER_ITEM_TYPE, new_user_item); + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + self->service_proxy = dbus_g_proxy_new_for_name(session_bus, + INDICATOR_SESSION_DBUS_NAME, + INDICATOR_SESSION_SERVICE_DBUS_OBJECT, + INDICATOR_SESSION_SERVICE_DBUS_IFACE); + return; } @@ -122,6 +129,11 @@ indicator_session_dispose (GObject *object) self->service = NULL; } + if (self->service_proxy != NULL) { + g_object_unref(self->service_proxy); + self->service_proxy = NULL; + } + G_OBJECT_CLASS (indicator_session_parent_class)->dispose (object); return; } -- cgit v1.2.3 From 10ab858ea1a244f92b57d3e8c96c76045e02e93b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 15:26:50 -0600 Subject: Icon name changing signal for updating the image. --- src/indicator-session.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index 0b8d77e..c23cd0b 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -70,6 +70,7 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static void icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -116,6 +117,14 @@ indicator_session_init (IndicatorSession *self) INDICATOR_SESSION_SERVICE_DBUS_OBJECT, INDICATOR_SESSION_SERVICE_DBUS_IFACE); + dbus_g_proxy_add_signal(self->service_proxy, "IconUpdated", + G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(self->service_proxy, + "IconUpdated", + G_CALLBACK(icon_changed), + self, + NULL); + return; } @@ -152,6 +161,14 @@ get_label (IndicatorObject * io) return NULL; } +static void +icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data) +{ + IndicatorSession * session = INDICATOR_SESSION(user_data); + gtk_image_set_from_icon_name(session->status_image, icon_name, GTK_ICON_SIZE_MENU); + return; +} + static GtkImage * get_icon (IndicatorObject * io) { -- cgit v1.2.3 From 746636765323cb223ef84af13920a9620176eb4f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 15:47:33 -0600 Subject: Getting the icon, but only when we're connected. --- src/indicator-session.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index c23cd0b..6e259dc 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -35,6 +35,7 @@ with this program. If not, see . #include "dbus-shared-names.h" #include "dbusmenu-shared.h" +#include "session-dbus-client.h" #define INDICATOR_SESSION_TYPE (indicator_session_get_type ()) #define INDICATOR_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SESSION_TYPE, IndicatorSession)) @@ -71,6 +72,7 @@ static GtkMenu * get_menu (IndicatorObject * io); static gboolean build_menu_switch (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_user_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data); +static void service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data); static void indicator_session_class_init (IndicatorSessionClass *klass); static void indicator_session_init (IndicatorSession *self); @@ -103,6 +105,7 @@ indicator_session_init (IndicatorSession *self) /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); + g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(service_connection_cb), self); self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); @@ -155,6 +158,28 @@ indicator_session_finalize (GObject *object) return; } +static void +icon_name_get_cb (DBusGProxy *proxy, char * OUT_name, GError *error, gpointer userdata) +{ + IndicatorSession * self = INDICATOR_SESSION(userdata); + gtk_image_set_from_icon_name(self->status_image, OUT_name, GTK_ICON_SIZE_MENU); + return; +} + +static void +service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) +{ + IndicatorSession * self = INDICATOR_SESSION(user_data); + + if (connected) { + org_ayatana_indicator_session_service_get_icon_async(self->service_proxy, icon_name_get_cb, user_data); + } else { + gtk_image_set_from_icon_name(self->status_image, "system-shutdown-panel", GTK_ICON_SIZE_MENU); + } + + return; +} + static GtkLabel * get_label (IndicatorObject * io) { -- cgit v1.2.3 From 2dd05e216cdc0e7ab9318a410758eade2d3e68a4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 15:49:52 -0600 Subject: Moving the icon names into the shared header files --- src/dbus-shared-names.h | 3 +++ src/indicator-session.c | 4 ++-- src/session-dbus.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 2c30b36..8cbb488 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -45,4 +45,7 @@ with this program. If not, see . #define USER_ITEM_PROP_NAME "user-item-name" #define USER_ITEM_PROP_LOGGED_IN "user-item-logged-in" +#define ICON_DEFAULT "system-shutdown-panel" +#define ICON_RESTART "system-shutdown-restart-panel" + #endif /* __DBUS_SHARED_NAMES_H__ */ diff --git a/src/indicator-session.c b/src/indicator-session.c index 6e259dc..de18bb3 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -107,7 +107,7 @@ indicator_session_init (IndicatorSession *self) self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(service_connection_cb), self); - self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name("system-shutdown-panel", GTK_ICON_SIZE_MENU)); + self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name(ICON_DEFAULT, GTK_ICON_SIZE_MENU)); self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); @@ -174,7 +174,7 @@ service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointe if (connected) { org_ayatana_indicator_session_service_get_icon_async(self->service_proxy, icon_name_get_cb, user_data); } else { - gtk_image_set_from_icon_name(self->status_image, "system-shutdown-panel", GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name(self->status_image, ICON_DEFAULT, GTK_ICON_SIZE_MENU); } return; diff --git a/src/session-dbus.c b/src/session-dbus.c index 7159d7f..1413916 100644 --- a/src/session-dbus.c +++ b/src/session-dbus.c @@ -63,7 +63,7 @@ session_dbus_init (SessionDbus *self) SessionDbusPrivate * priv = SESSION_DBUS_GET_PRIVATE(self); - priv->name = g_strdup("system-shutdown-panel"); + priv->name = g_strdup(ICON_DEFAULT); return; } -- cgit v1.2.3 From b419d049e7fe398e52739183f26cd486b7d9c421 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 12 Mar 2010 16:33:33 -0600 Subject: Using the libindicator helpers so we get things like fallbacks! \o/ --- src/indicator-session.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index de18bb3..0282616 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -32,6 +32,7 @@ with this program. If not, see . #include #include #include +#include #include "dbus-shared-names.h" #include "dbusmenu-shared.h" @@ -107,7 +108,7 @@ indicator_session_init (IndicatorSession *self) self->service = indicator_service_manager_new_version(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_VERSION); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(service_connection_cb), self); - self->status_image = GTK_IMAGE(gtk_image_new_from_icon_name(ICON_DEFAULT, GTK_ICON_SIZE_MENU)); + self->status_image = indicator_image_helper(ICON_DEFAULT); self->menu = dbusmenu_gtkmenu_new(INDICATOR_SESSION_DBUS_NAME, INDICATOR_SESSION_DBUS_OBJECT); DbusmenuClient * client = DBUSMENU_CLIENT(dbusmenu_gtkmenu_get_client(self->menu)); @@ -162,7 +163,7 @@ static void icon_name_get_cb (DBusGProxy *proxy, char * OUT_name, GError *error, gpointer userdata) { IndicatorSession * self = INDICATOR_SESSION(userdata); - gtk_image_set_from_icon_name(self->status_image, OUT_name, GTK_ICON_SIZE_MENU); + indicator_image_helper_update(self->status_image, OUT_name); return; } @@ -174,7 +175,7 @@ service_connection_cb (IndicatorServiceManager * sm, gboolean connected, gpointe if (connected) { org_ayatana_indicator_session_service_get_icon_async(self->service_proxy, icon_name_get_cb, user_data); } else { - gtk_image_set_from_icon_name(self->status_image, ICON_DEFAULT, GTK_ICON_SIZE_MENU); + indicator_image_helper_update(self->status_image, ICON_DEFAULT); } return; @@ -190,7 +191,7 @@ static void icon_changed (DBusGProxy * proxy, gchar * icon_name, gpointer user_data) { IndicatorSession * session = INDICATOR_SESSION(user_data); - gtk_image_set_from_icon_name(session->status_image, icon_name, GTK_ICON_SIZE_MENU); + indicator_image_helper_update(session->status_image, icon_name); return; } -- cgit v1.2.3