diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | libdbusmenu-gtk/client.c | 7 | ||||
-rw-r--r-- | libdbusmenu-gtk/genericmenuitem.c | 25 | ||||
-rw-r--r-- | libdbusmenu-gtk/parser.c | 55 |
4 files changed, 57 insertions, 31 deletions
diff --git a/configure.ac b/configure.ac index 81cbb99..ff12a43 100644 --- a/configure.ac +++ b/configure.ac @@ -67,7 +67,6 @@ AS_IF([test "x$with_gtk" = x3], glib-2.0 >= $GLIB_REQUIRED_VERSION, [have_gtk=yes] ) - AC_DEFINE(HAVE_GTK3, 1, [whether gtk3 is available]) ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index d345313..7e1ea36 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -842,7 +842,7 @@ activate_helper (GtkMenuShell * shell) doesn't expose the right variables. We need to figure this out as menus won't get grabs properly. TODO FIXME HELP ARGHHHHHHHH */ -#if (HAVE_GTK3 == 0) +#if !GTK_CHECK_VERSION(3,0,0) if (!GTK_MENU_SHELL (parent)->active) { gtk_grab_add (parent); GTK_MENU_SHELL (parent)->have_grab = TRUE; @@ -1278,7 +1278,12 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); gtk_widget_set_size_request(GTK_WIDGET(gtkimage), width, height); +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_set_halign(GTK_WIDGET(gtkimage), GTK_ALIGN_START); + gtk_widget_set_valign(GTK_WIDGET(gtkimage), GTK_ALIGN_CENTER); +#else gtk_misc_set_alignment(GTK_MISC(gtkimage), 0.0, 0.5); +#endif } genericmenuitem_set_image(GENERICMENUITEM(gimi), gtkimage); diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 9707ba3..fbd0416 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -62,7 +62,7 @@ static void activate (GtkMenuItem * menu_item); /* GObject stuff */ G_DEFINE_TYPE (Genericmenuitem, genericmenuitem, GTK_TYPE_CHECK_MENU_ITEM); -#if HAVE_GTK3 +#if GTK_CHECK_VERSION(3,0,0) static void draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr); static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, cairo_t *cr) = NULL; #else @@ -83,7 +83,7 @@ genericmenuitem_class_init (GenericmenuitemClass *klass) object_class->dispose = genericmenuitem_dispose; object_class->finalize = genericmenuitem_finalize; -#ifdef HAVE_GTK3 +#if GTK_CHECK_VERSION(3,2,0) GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); gtk_widget_class_set_accessible_role(widget_class, ATK_ROLE_MENU_ITEM); @@ -115,7 +115,7 @@ genericmenuitem_init (Genericmenuitem *self) self->priv->disposition = GENERICMENUITEM_DISPOSITION_NORMAL; self->priv->label_text = NULL; -#ifndef HAVE_GTK3 +#if !GTK_CHECK_VERSION(3,0,0) AtkObject * aobj = gtk_widget_get_accessible(GTK_WIDGET(self)); if (aobj != NULL) { atk_object_set_role(aobj, ATK_ROLE_MENU_ITEM); @@ -148,7 +148,7 @@ genericmenuitem_finalize (GObject *object) /* Checks to see if we should be drawing a little box at all. If we should be, let's do that, otherwise we're going suppress the box drawing. */ -#if HAVE_GTK3 +#if GTK_CHECK_VERSION(3,0,0) static void draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) { @@ -310,12 +310,12 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) /* We need to put the child into a new box and make the box the child of the menu item. Basically we're inserting a box in the middle. */ - #ifdef HAVE_GTK3 +#if GTK_CHECK_VERSION(3,0,0) GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, get_toggle_space(GTK_WIDGET(menu_item))); - #else +#else GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item))); - #endif +#endif g_object_ref(child); gtk_container_remove(GTK_CONTAINER(menu_item), child); gtk_box_pack_start(GTK_BOX(hbox), child, FALSE, FALSE, 0); @@ -334,7 +334,12 @@ set_label (GtkMenuItem * menu_item, const gchar * in_label) /* Build it */ labelw = GTK_LABEL(gtk_accel_label_new(local_label)); gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE); +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_set_halign(GTK_WIDGET(labelw), GTK_ALIGN_START); + gtk_widget_set_valign(GTK_WIDGET(labelw), GTK_ALIGN_CENTER); +#else gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); +#endif gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item)); if (has_mnemonic(in_label, FALSE)) { @@ -541,12 +546,12 @@ genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image) /* We need to put the child into a new box and make the box the child of the menu item. Basically we're inserting a box in the middle. */ - #ifdef HAVE_GTK3 +#if GTK_CHECK_VERSION(3,0,0) GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, get_toggle_space(GTK_WIDGET(menu_item))); - #else +#else GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item))); - #endif +#endif g_object_ref(child); gtk_container_remove(GTK_CONTAINER(menu_item), child); gtk_box_pack_end(GTK_BOX(hbox), child, TRUE, TRUE, 0); diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d23fb75..bd62b15 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -82,7 +82,8 @@ static void checkbox_toggled (GtkWidget * widget, static void update_icon (DbusmenuMenuitem * menuitem, ParserData * pdata, GtkImage * image); -static GtkWidget * find_menu_label (GtkWidget * widget); +static GtkWidget * find_menu_child (GtkWidget * widget, + GType child_type); static void label_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); @@ -648,7 +649,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) gboolean visible = FALSE; gboolean sensitive = FALSE; - if (GTK_IS_SEPARATOR_MENU_ITEM (widget) || !find_menu_label (widget)) + if (GTK_IS_SEPARATOR_MENU_ITEM (widget) || !find_menu_child (widget, GTK_TYPE_LABEL)) { dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_TYPE, @@ -659,6 +660,8 @@ construct_dbusmenu_for_widget (GtkWidget * widget) } else { + GtkWidget *image = NULL; + pdata->widget_accel_handler_id = g_signal_connect (widget, "accel-closures-changed", G_CALLBACK (accel_changed), mi); @@ -674,20 +677,26 @@ construct_dbusmenu_for_widget (GtkWidget * widget) pdata->widget_toggle_handler_id = g_signal_connect (widget, "activate", G_CALLBACK (checkbox_toggled), mi); } - - if (GTK_IS_IMAGE_MENU_ITEM (widget)) + else if (GTK_IS_IMAGE_MENU_ITEM (widget)) { - GtkWidget *image; image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); - if (GTK_IS_IMAGE (image)) - { - update_icon (mi, pdata, GTK_IMAGE (image)); - } } + else + { + // GtkImageMenuItem is deprecated, so check regular GtkMenuItems + // for an image child too + image = find_menu_child (widget, GTK_TYPE_IMAGE); + } + + if (GTK_IS_IMAGE (image)) + { + update_icon (mi, pdata, GTK_IMAGE (image)); + } + - GtkWidget *label = find_menu_label (widget); + GtkWidget *label = find_menu_child (widget, GTK_TYPE_LABEL); // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. @@ -907,7 +916,11 @@ update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImage *image) GTK_ICON_LOOKUP_FORCE_SIZE); if (info != NULL) { pixbuf = gtk_icon_info_load_icon (info, NULL); +#if GTK_CHECK_VERSION(3,8,0) + g_object_unref (info); +#else gtk_icon_info_free (info); +#endif } break; @@ -944,11 +957,11 @@ update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImage *image) } static GtkWidget * -find_menu_label (GtkWidget *widget) +find_menu_child (GtkWidget *widget, GType child_type) { - GtkWidget *label = NULL; + GtkWidget *child = NULL; - if (GTK_IS_LABEL (widget)) + if (G_TYPE_CHECK_INSTANCE_TYPE (widget, child_type)) return widget; if (GTK_IS_CONTAINER (widget)) @@ -960,16 +973,16 @@ find_menu_label (GtkWidget *widget) for (l = children; l; l = l->next) { - label = find_menu_label (l->data); + child = find_menu_child (l->data, child_type); - if (label) + if (child) break; } g_list_free (children); } - return label; + return child; } static void @@ -1121,7 +1134,7 @@ a11y_name_notify_cb (AtkObject * accessible, GParamSpec * pspec, gpointer data) { DbusmenuMenuitem * item = DBUSMENU_MENUITEM(data); GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); - GtkWidget *label = find_menu_label (widget); + GtkWidget *label = find_menu_child (widget, GTK_TYPE_LABEL); const gchar *label_text = gtk_label_get_text (GTK_LABEL (label)); const gchar *name = atk_object_get_name (accessible); @@ -1335,7 +1348,7 @@ widget_add_cb (GtkWidget *widget, GtkWidget *child, gpointer data) { - if (find_menu_label (child) != NULL) + if (find_menu_child (widget, GTK_TYPE_LABEL) != NULL) handle_first_label (data); } @@ -1433,6 +1446,9 @@ should_show_image (GtkImage *image) item = gtk_widget_get_ancestor (GTK_WIDGET (image), GTK_TYPE_IMAGE_MENU_ITEM); + if (!item) + item = gtk_widget_get_ancestor (GTK_WIDGET (image), + GTK_TYPE_MENU_ITEM); if (item) { @@ -1446,7 +1462,8 @@ should_show_image (GtkImage *image) if (gtk_menu_images) return TRUE; - return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item)); + if (GTK_IS_IMAGE_MENU_ITEM (item)) + return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item)); } return FALSE; |