From ce0a5c849081e8d6f54a28f771dce0136a4e4b93 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Sat, 19 Jun 2010 09:32:56 -0400 Subject: support gtk3 version of libdbusmenu-gtk --- libdbusmenu-gtk/Makefile.am | 47 ++++++++++++++++++++++++++++++++----- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 14 +++++++++++ libdbusmenu-gtk/menu.c | 4 ++-- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk3.pc.in (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 2be63b7..4f38b63 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -2,17 +2,21 @@ CLEANFILES = EXTRA_DIST = \ - dbusmenu-gtk.pc.in + dbusmenu-gtk.pc.in \ + dbusmenu-gtk3.pc.in lib_LTLIBRARIES = \ - libdbusmenu-gtk.la + libdbusmenu-gtk.la \ + libdbusmenu-gtk3.la libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ +libdbusmenu_gtk3includedir=$(includedir)/libdbusmenu3-0.1/libdbusmenu-gtk/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ menuitem.h +libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -23,20 +27,27 @@ libdbusmenu_gtk_la_SOURCES = \ menu.c \ menuitem.h \ menuitem.c +libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -no-undefined \ -export-symbols-regex "^[^_].*" +libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk_la_CFLAGS = \ $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" +libdbusmenu_gtk3_la_CFLAGS = \ + $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" libdbusmenu_gtk_la_LIBADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ $(DBUSMENUGTK_LIBS) +libdbusmenu_gtk3_la_LIBADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUGTK3_LIBS) -pkgconfig_DATA = dbusmenu-gtk.pc +pkgconfig_DATA = dbusmenu-gtk.pc dbusmenu-gtk3.pc pkgconfigdir = $(libdir)/pkgconfig ######################### @@ -64,7 +75,16 @@ DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir +DbusmenuGtk3-0.2.gir: libdbusmenu-gtk3.la +DbusmenuGtk3_0_2_gir_INCLUDES = \ + GObject-2.0 \ + Gtk-3.0 \ + Dbusmenu-Glib-0.2 +DbusmenuGtk3_0_2_gir_CFLAGS = $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) +DbusmenuGtk3_0_2_gir_LIBS = libdbusmenu-gtk3.la +DbusmenuGtk3_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) + +INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir DbusmenuGtk3-0.2.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -83,7 +103,7 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi +vapi_DATA = DbusmenuGtk-0.2.vapi DbusmenuGtk3-0.2.vapi DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ @@ -94,13 +114,28 @@ DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am --vapidir=$(top_builddir)/libdbusmenu-glib \ $< +DbusmenuGtk3-0.2.vapi: DbusmenuGtk3-0.2.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk3-0.2 \ + --pkg gdk-pixbuf-3.0 \ + --pkg gtk+-3.0 \ + --pkg atk \ + --pkg Dbusmenu-Glib-0.2 \ + --vapidir=$(top_builddir)/libdbusmenu-glib \ + $< + DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir +DbusmenuGtk3-0.2.tmp.gir: DbusmenuGtk3-0.2.gir + $(SED) \ + -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ + -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ + $< > $@ + +CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir DbusmenuGtk3-0.2.tmp.gir endif diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in new file mode 100644 index 0000000..e2c4cc3 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-3.1 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk3 + +Name: libdbusmenu-gtk3 +Description: libdbusmenu-gtk3. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 4fa546b..3e6f2dd 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -237,7 +237,7 @@ root_child_added (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint posit GtkMenuItem * mi = dbusmenu_gtkclient_menuitem_get(priv->client, child); if (mi != NULL) { GtkWidget * item = GTK_WIDGET(mi); - gtk_menu_insert(GTK_MENU(menu), item, dbusmenu_menuitem_get_position_realized(child, root)); + gtk_menu_shell_insert(GTK_MENU_SHELL(menu), item, dbusmenu_menuitem_get_position_realized(child, root)); #ifdef MASSIVEDEBUGGING menu_pos_t menu_pos; menu_pos.mi = mi; @@ -299,7 +299,7 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) GtkWidget * child_widget = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); if (child_widget != NULL) { - gtk_menu_append(menu, child_widget); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), child_widget); gtk_menu_reorder_child(GTK_MENU(menu), child_widget, dbusmenu_menuitem_get_position_realized(child, dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client)))); } else { g_warning("Child is realized, but doesn't have a GTK Widget!"); -- cgit v1.2.3 From 46cf6414f55a027f0eaf3b85701479fb5fe12441 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 24 Sep 2010 14:38:24 -0500 Subject: Making sure to reference the accel group --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 6970d59..0f8592c 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -249,6 +249,7 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * } priv->agroup = agroup; + g_object_ref(priv->agroup); return; } -- cgit v1.2.3 From 682fd63278c0306437d43c827d7873403d3575af Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 6 Oct 2010 10:13:09 -0400 Subject: instead of always building gtk2 and gtk3, add a --with-gtk= flag to configure to specify which to build with --- libdbusmenu-gtk/Makefile.am | 91 +++++++++++++++++-------------------- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 2 +- libdbusmenu-gtk/genericmenuitem.c | 40 +++++++++++----- 3 files changed, 70 insertions(+), 63 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 4f38b63..cfa4230 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -1,22 +1,27 @@ CLEANFILES = -EXTRA_DIST = \ - dbusmenu-gtk.pc.in \ - dbusmenu-gtk3.pc.in +if USE_GTK3 +VER=3 +GTKGIR=Gtk-3.0 +GTKVALA=gtk+-3.0 +lib_LTLIBRARIES = libdbusmenu-gtk3.la +else +VER= +GTKGIR=Gtk-2.0 +GTKVALA=gtk+-2.0 +lib_LTLIBRARIES = libdbusmenu-gtk.la +endif -lib_LTLIBRARIES = \ - libdbusmenu-gtk.la \ - libdbusmenu-gtk3.la +EXTRA_DIST = \ + dbusmenu-gtk$(VER).pc.in -libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ -libdbusmenu_gtk3includedir=$(includedir)/libdbusmenu3-0.1/libdbusmenu-gtk/ +libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ menuitem.h -libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -27,27 +32,31 @@ libdbusmenu_gtk_la_SOURCES = \ menu.c \ menuitem.h \ menuitem.c -libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -no-undefined \ -export-symbols-regex "^[^_].*" -libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk_la_CFLAGS = \ $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" -libdbusmenu_gtk3_la_CFLAGS = \ - $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" libdbusmenu_gtk_la_LIBADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ $(DBUSMENUGTK_LIBS) -libdbusmenu_gtk3_la_LIBADD = \ - ../libdbusmenu-glib/libdbusmenu-glib.la \ - $(DBUSMENUGTK3_LIBS) -pkgconfig_DATA = dbusmenu-gtk.pc dbusmenu-gtk3.pc +# We duplicate these here because Automake won't let us use $(VER) on the left hand side. +# Since we carefully use $(VER) in the right hand side above, we can assign the same values. +# Only one version of the library is every compiled at the same time, so it is safe to reuse +# the right hand sides like this. +libdbusmenu_gtk3includedir = $(libdbusmenu_gtkincludedir) +libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) +libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) +libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) +libdbusmenu_gtk3_la_CFLAGS = $(libdbusmenu_gtk_la_CFLAGS) +libdbusmenu_gtk3_la_LIBADD = $(libdbusmenu_gtk_la_LIBADD) + +pkgconfig_DATA = dbusmenu-gtk$(VER).pc pkgconfigdir = $(libdir)/pkgconfig ######################### @@ -66,25 +75,22 @@ if HAVE_INTROSPECTION introspection_sources = $(libdbusmenu_gtkinclude_HEADERS) -DbusmenuGtk-0.2.gir: libdbusmenu-gtk.la +DbusmenuGtk$(VER)-0.2.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_INCLUDES = \ GObject-2.0 \ - Gtk-2.0 \ + $(GTKGIR) \ Dbusmenu-Glib-0.2 DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la +DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -DbusmenuGtk3-0.2.gir: libdbusmenu-gtk3.la -DbusmenuGtk3_0_2_gir_INCLUDES = \ - GObject-2.0 \ - Gtk-3.0 \ - Dbusmenu-Glib-0.2 -DbusmenuGtk3_0_2_gir_CFLAGS = $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -DbusmenuGtk3_0_2_gir_LIBS = libdbusmenu-gtk3.la -DbusmenuGtk3_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) +# We duplicate these for the same reason as libdbusmenu_gtk3includedir above +DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) +DbusmenuGtk3_0_2_gir_CFLAGS = $(DbusmenuGtk_0_2_gir_CFLAGS) +DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) +DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir DbusmenuGtk3-0.2.gir +INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -103,39 +109,24 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi DbusmenuGtk3-0.2.vapi +vapi_DATA = DbusmenuGtk$(VER)-0.2.vapi -DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ +DbusmenuGtk$(VER)-0.2.vapi: DbusmenuGtk$(VER)-0.2.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk$(VER)-0.2 \ --pkg gdk-pixbuf-2.0 \ - --pkg gtk+-2.0 \ - --pkg atk \ - --pkg Dbusmenu-Glib-0.2 \ - --vapidir=$(top_builddir)/libdbusmenu-glib \ - $< - -DbusmenuGtk3-0.2.vapi: DbusmenuGtk3-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk3-0.2 \ - --pkg gdk-pixbuf-3.0 \ - --pkg gtk+-3.0 \ + --pkg $(GTKVALA) \ --pkg atk \ --pkg Dbusmenu-Glib-0.2 \ --vapidir=$(top_builddir)/libdbusmenu-glib \ $< -DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir - $(SED) \ - -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ - -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ - $< > $@ - -DbusmenuGtk3-0.2.tmp.gir: DbusmenuGtk3-0.2.gir +DbusmenuGtk$(VER)-0.2.tmp.gir: DbusmenuGtk$(VER)-0.2.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir DbusmenuGtk3-0.2.tmp.gir +CLEANFILES += $(vapi_DATA) DbusmenuGtk$(VER)-0.2.tmp.gir endif diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in index e2c4cc3..1a3410e 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-3.1 +Cflags: -I${includedir}/libdbusmenu-0.1 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk3 diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 8f40d93..b357d82 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -51,7 +51,6 @@ static void genericmenuitem_class_init (GenericmenuitemClass *klass); static void genericmenuitem_init (Genericmenuitem *self); static void genericmenuitem_dispose (GObject *object); static void genericmenuitem_finalize (GObject *object); -static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void set_label (GtkMenuItem * menu_item, const gchar * label); static const gchar * get_label (GtkMenuItem * menu_item); static void activate (GtkMenuItem * menu_item); @@ -59,8 +58,13 @@ static void activate (GtkMenuItem * menu_item); /* GObject stuff */ G_DEFINE_TYPE (Genericmenuitem, genericmenuitem, GTK_TYPE_CHECK_MENU_ITEM); -/* Globals */ +#if HAVE_GTK3 +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 +static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) = NULL; +#endif /* Initializing all of the classes. Most notably we're disabling the drawing of the check early. */ @@ -121,6 +125,17 @@ 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 +static void +draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) +{ + Genericmenuitem * self = GENERICMENUITEM(check_menu_item); + if (self->priv->check_type != GENERICMENUITEM_CHECK_TYPE_NONE) { + parent_draw_indicator(check_menu_item, cr); + } + return; +} +#else static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) { @@ -130,6 +145,7 @@ draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) } return; } +#endif /* A small helper to look through the widgets in the box and find the one that is the label. */ @@ -320,32 +336,32 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) GtkCheckMenuItem * check = GTK_CHECK_MENU_ITEM(item); - gboolean old_active = check->active; - gboolean old_inconsist = check->inconsistent; + gboolean old_active = gtk_check_menu_item_get_active (check); + gboolean old_inconsist = gtk_check_menu_item_get_inconsistent (check); switch (item->priv->state) { case GENERICMENUITEM_STATE_UNCHECKED: - check->active = FALSE; - check->inconsistent = FALSE; + gtk_check_menu_item_set_active (check, FALSE); + gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_CHECKED: - check->active = TRUE; - check->inconsistent = FALSE; + gtk_check_menu_item_set_active (check, TRUE); + gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_INDETERMINATE: - check->active = TRUE; - check->inconsistent = TRUE; + gtk_check_menu_item_set_active (check, TRUE); + gtk_check_menu_item_set_inconsistent (check, TRUE); break; default: g_warning("Generic Menuitem invalid check state: %d", state); return; } - if (old_active != check->active) { + if (old_active != gtk_check_menu_item_get_active (check)) { g_object_notify(G_OBJECT(item), "active"); } - if (old_inconsist != check->inconsistent) { + if (old_inconsist != gtk_check_menu_item_get_inconsistent (check)) { g_object_notify(G_OBJECT(item), "inconsistent"); } -- cgit v1.2.3 From 650d606580a1cf5842470ecf9dd97b166eed55d4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:07:22 -0500 Subject: Going to 6 privates like others --- libdbusmenu-gtk/client.h | 6 +++++- libdbusmenu-gtk/menu.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index a7c96ee..2793faf 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -50,6 +50,8 @@ G_BEGIN_DECLS @reserved2: Reserved for future use. @reserved3: Reserved for future use. @reserved4: Reserved for future use. + @reserved5: Reserved for future use. + @reserved6: Reserved for future use. */ typedef struct _DbusmenuGtkClientClass DbusmenuGtkClientClass; struct _DbusmenuGtkClientClass { @@ -58,11 +60,13 @@ struct _DbusmenuGtkClientClass { /* Signals */ void (*root_changed) (DbusmenuMenuitem * newroot); - /* Reserved */ + /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); }; /** diff --git a/libdbusmenu-gtk/menu.h b/libdbusmenu-gtk/menu.h index 5147d30..0601d0a 100644 --- a/libdbusmenu-gtk/menu.h +++ b/libdbusmenu-gtk/menu.h @@ -49,16 +49,20 @@ G_BEGIN_DECLS @reserved2: Reserved for future use. @reserved3: Reserved for future use. @reserved4: Reserved for future use. + @reserved5: Reserved for future use. + @reserved6: Reserved for future use. */ typedef struct _DbusmenuGtkMenuClass DbusmenuGtkMenuClass; struct _DbusmenuGtkMenuClass { GtkMenuClass parent_class; - /* Reserved */ + /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); }; /** -- cgit v1.2.3 From 176f561e6959611b96e4c1525958fce757a6fb46 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:16:55 -0500 Subject: Private pointers in instance structs --- libdbusmenu-gtk/client.c | 1 - libdbusmenu-gtk/client.h | 5 +++++ libdbusmenu-gtk/menu.c | 1 - libdbusmenu-gtk/menu.h | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 6970d59..7de93e1 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -37,7 +37,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "genericmenuitem.h" /* Private */ -typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate; struct _DbusmenuGtkClientPrivate { GtkAccelGroup * agroup; }; diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index 2793faf..c986a5d 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -43,6 +43,8 @@ G_BEGIN_DECLS #define DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED +typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate; + /** DbusmenuGtkClientClass: @parent_class: #GtkMenuClass @@ -76,6 +78,9 @@ struct _DbusmenuGtkClientClass { typedef struct _DbusmenuGtkClient DbusmenuGtkClient; struct _DbusmenuGtkClient { DbusmenuClient parent; + + /*< Private >*/ + DbusmenuGtkClientPrivate * priv; }; GType dbusmenu_gtkclient_get_type (void); diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 4fa546b..14dcb89 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -44,7 +44,6 @@ enum { }; /* Private */ -typedef struct _DbusmenuGtkMenuPrivate DbusmenuGtkMenuPrivate; struct _DbusmenuGtkMenuPrivate { DbusmenuGtkClient * client; diff --git a/libdbusmenu-gtk/menu.h b/libdbusmenu-gtk/menu.h index 0601d0a..896e466 100644 --- a/libdbusmenu-gtk/menu.h +++ b/libdbusmenu-gtk/menu.h @@ -42,6 +42,8 @@ G_BEGIN_DECLS #define DBUSMENU_IS_GTKMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_GTKMENU_TYPE)) #define DBUSMENU_GTKMENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuClass)) +typedef struct _DbusmenuGtkMenuPrivate DbusmenuGtkMenuPrivate; + /** DbusmenuGtkMenuClass: @parent_class: #GtkMenuClass @@ -72,6 +74,9 @@ struct _DbusmenuGtkMenuClass { typedef struct _DbusmenuGtkMenu DbusmenuGtkMenu; struct _DbusmenuGtkMenu { GtkMenu parent; + + /*< Private >*/ + DbusmenuGtkMenuPrivate * priv; }; GType dbusmenu_gtkmenu_get_type (void); -- cgit v1.2.3 From f8d472db4415096f7a5e99e14aa3b1af290d2098 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:29:26 -0500 Subject: Switching to using the pointer in the instance --- libdbusmenu-gtk/client.c | 5 +++-- libdbusmenu-gtk/menu.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 7de93e1..487971f 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -41,8 +41,7 @@ struct _DbusmenuGtkClientPrivate { GtkAccelGroup * agroup; }; -#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate)) +#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); @@ -84,6 +83,8 @@ dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass) static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate); + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(self); priv->agroup = NULL; diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 14dcb89..ace8e8a 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -51,8 +51,7 @@ struct _DbusmenuGtkMenuPrivate { gchar * dbus_name; }; -#define DBUSMENU_GTKMENU_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuPrivate)) +#define DBUSMENU_GTKMENU_GET_PRIVATE(o) (DBUSMENU_GTKMENU(o)->priv) /* Prototypes */ static void dbusmenu_gtkmenu_class_init (DbusmenuGtkMenuClass *klass); @@ -109,6 +108,8 @@ menu_focus_cb(DbusmenuGtkMenu * menu, gpointer userdata) static void dbusmenu_gtkmenu_init (DbusmenuGtkMenu *self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuPrivate); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(self); priv->client = NULL; -- cgit v1.2.3 From 7ba22007311d5ed891a8dbb29e76873c74ea4ea6 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 13 Oct 2010 08:42:42 -0400 Subject: ship both .pc files in EXTRA_DIST --- libdbusmenu-gtk/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index cfa4230..b30cac9 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -14,7 +14,8 @@ lib_LTLIBRARIES = libdbusmenu-gtk.la endif EXTRA_DIST = \ - dbusmenu-gtk$(VER).pc.in + dbusmenu-gtk.pc.in \ + dbusmenu-gtk3.pc.in libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk$(VER)/ -- cgit v1.2.3 From 726e8b11f2938a229b5ff75979031aafdbacf60d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Nov 2010 16:27:53 -0600 Subject: Redoing the handling of shortcuts to use GVariants rather than GValues --- libdbusmenu-gtk/menuitem.c | 128 +++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 87 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 5846aa7..9c1cfd2 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -29,7 +29,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "menuitem.h" #include #include -#include /** dbusmenu_menuitem_property_set_image: @@ -201,25 +200,16 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, const gchar * keyname = gdk_keyval_name(key); g_array_append_val(array, keyname); - GType type = dbus_g_type_get_collection("GPtrArray", G_TYPE_STRV); - GPtrArray * wrapper = (GPtrArray *)dbus_g_type_specialized_construct(type); + GVariant * inside = g_variant_new("as", array->data); + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("av")); + g_variant_builder_add_value(&builder, inside); + GVariant * outsidevariant = g_variant_builder_end(&builder); - GValue value = {0,}; - g_value_init(&value, type); - g_value_take_boxed(&value, wrapper); + dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); - DBusGTypeSpecializedAppendContext ctx; - dbus_g_type_specialized_init_append(&value, &ctx); - - GValue strval = {0,}; - g_value_init(&strval, G_TYPE_STRV); - g_value_take_boxed(&strval, array->data); - g_array_free(array, FALSE); - - dbus_g_type_specialized_collection_append(&ctx, &strval); - dbus_g_type_specialized_collection_end_append(&ctx); - - dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); + g_variant_unref(outsidevariant); + g_variant_unref(inside); return TRUE; } @@ -279,68 +269,6 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } -/* A set of typed data for the interator */ -typedef struct _iter_data_t iter_data_t; -struct _iter_data_t { - guint * key; - GdkModifierType * modifier; -}; - -/* Goes through the wrapper items. In reality we only support one - so it checks to see if a key is set first. But, we could possibly, - support more in the future. */ -static void -_wrapper_iterator (const GValue * value, gpointer user_data) -{ - iter_data_t * iter_data = (iter_data_t *)user_data; - - if (*iter_data->key != 0) { - g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); - return; - } - - if (!G_VALUE_HOLDS(value, G_TYPE_STRV)) { - g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); - return; - } - - gchar ** stringarray = (gchar **)g_value_get_boxed(value); - if (stringarray == NULL) { - return; - } - - const gchar * last_string = NULL; - int i; - - for (i = 0; stringarray[i] != NULL; i++) { - last_string = stringarray[i]; - - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *iter_data->modifier |= GDK_CONTROL_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *iter_data->modifier |= GDK_MOD1_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *iter_data->modifier |= GDK_SHIFT_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *iter_data->modifier |= GDK_SUPER_MASK; - continue; - } - } - - if (last_string != NULL) { - GdkModifierType tempmod; - gtk_accelerator_parse(last_string, iter_data->key, &tempmod); - } - - return; -} - /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -358,20 +286,46 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); - const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); + GVariant * wrapper = dbusmenu_menuitem_property_get_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); if (wrapper == NULL) { return; } - if (!dbus_g_type_is_collection(G_VALUE_TYPE(wrapper))) { - g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); + + if (g_variant_n_children(wrapper) != 1) { + g_warning("Unable to parse shortcut, too many keys"); + g_variant_unref(wrapper); return; } - iter_data_t iter_data; - iter_data.key = key; - iter_data.modifier = modifier; + GVariantIter outsideiter; + GVariant * inside; + g_variant_iter_init(&outsideiter, wrapper); + + while(g_variant_iter_next(&outsideiter, "v", &inside)) { + GVariantIter insideiter; + g_variant_iter_init(&insideiter, inside); + gchar * string; + + while(g_variant_iter_next(&insideiter, "s", &string)) { + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *modifier |= GDK_CONTROL_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *modifier |= GDK_MOD1_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *modifier |= GDK_SHIFT_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *modifier |= GDK_SUPER_MASK; + } else { + GdkModifierType tempmod; + gtk_accelerator_parse(string, key, &tempmod); + } + + g_free(string); + } - dbus_g_type_collection_value_iterate(wrapper, _wrapper_iterator, &iter_data); + g_variant_unref(inside); + } + g_variant_unref(wrapper); return; } -- cgit v1.2.3 From 153a249f1029171cfcf40cf34ccc5157ba791c20 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 20:37:01 -0600 Subject: Switching everything to start using variants... even ahead of GLib --- libdbusmenu-gtk/client.c | 71 ++++++++++++++++----------------------- libdbusmenu-gtk/genericmenuitem.c | 2 ++ 2 files changed, 31 insertions(+), 42 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 487971f..9dd18df 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -57,9 +57,9 @@ static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value); -static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value); -static void image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GValue * invalue, gpointer userdata); +static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); +static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); +static void image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant * invalue, gpointer userdata); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkClient, dbusmenu_gtkclient, DBUSMENU_TYPE_CLIENT); @@ -283,10 +283,8 @@ static gboolean menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) { if (gtk_menu_item_get_submenu(gmi) == NULL) { - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); - g_value_set_int(&value, 0); - dbusmenu_menuitem_handle_event(mi, "clicked", &value, gtk_get_current_event_time()); + GVariant * variant = g_variant_new("i", 0); + dbusmenu_menuitem_handle_event(mi, "clicked", variant, gtk_get_current_event_time()); } else { /* TODO: We need to stop the display of the submenu until this callback returns. */ @@ -297,7 +295,7 @@ menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) /* Process the visible property */ static void -process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value) { gboolean val = TRUE; if (value != NULL) { @@ -314,7 +312,7 @@ process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) /* Process the sensitive property */ static void -process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value) { gboolean val = TRUE; if (value != NULL) { @@ -326,26 +324,21 @@ process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * valu /* Process the sensitive property */ static void -process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant) { if (!IS_GENERICMENUITEM(gmi)) return; - if (value == NULL) return; + if (variant == NULL) return; GenericmenuitemCheckType type = GENERICMENUITEM_CHECK_TYPE_NONE; - GValue strvalue = {0}; - g_value_init(&strvalue, G_TYPE_STRING); - - if (value != NULL && g_value_transform(value, &strvalue)) { - const gchar * strval = g_value_get_string(&strvalue); + if (variant != NULL) { + const gchar * strval = g_variant_get_string(variant, NULL); if (!g_strcmp0(strval, DBUSMENU_MENUITEM_TOGGLE_CHECK)) { type = GENERICMENUITEM_CHECK_TYPE_CHECKBOX; } else if (!g_strcmp0(strval, DBUSMENU_MENUITEM_TOGGLE_RADIO)) { type = GENERICMENUITEM_CHECK_TYPE_RADIO; } - - g_value_unset(&strvalue); } genericmenuitem_set_check_type(GENERICMENUITEM(gmi), type); @@ -355,17 +348,14 @@ process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * va /* Process the sensitive property */ static void -process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant) { if (!IS_GENERICMENUITEM(gmi)) return; GenericmenuitemState state = GENERICMENUITEM_STATE_UNCHECKED; - GValue intvalue = {0}; - g_value_init(&intvalue, G_TYPE_INT); - - if (value != NULL && g_value_transform(value, &intvalue)) { - int val = g_value_get_int(&intvalue); + if (variant != NULL) { + int val = g_variant_get_int32(variant); if (val == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED) { state = GENERICMENUITEM_STATE_CHECKED; @@ -381,18 +371,18 @@ process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * v /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void -menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkMenuItem * gmi) +menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, GtkMenuItem * gmi) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) { - gtk_menu_item_set_label(gmi, g_value_get_string(value)); + gtk_menu_item_set_label(gmi, g_variant_get_string(variant, NULL)); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) { - process_visible(mi, gmi, value); + process_visible(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ENABLED)) { - process_sensitive(mi, gmi, value); + process_sensitive(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)) { - process_toggle_type(mi, gmi, value); + process_toggle_type(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)) { - process_toggle_state(mi, gmi, value); + process_toggle_state(mi, gmi, variant); } return; @@ -401,7 +391,7 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkMen /* Special handler for the shortcut changing as we need to have the client for that one to get the accel group. */ static void -menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, DbusmenuGtkClient * client) +menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * value, DbusmenuGtkClient * client) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { refresh_shortcut(client, mi); @@ -537,10 +527,10 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * g_object_weak_ref(G_OBJECT(item), destoryed_dbusmenuitem_cb, gmi); /* Check our set of props to see if any are set already */ - process_visible(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_VISIBLE)); - process_sensitive(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_ENABLED)); - process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); - process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); + process_visible(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_VISIBLE)); + process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED)); + process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); + process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); refresh_shortcut(client, item); /* Oh, we're a child, let's deal with that */ @@ -705,11 +695,11 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu image_property_handle(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - dbusmenu_menuitem_property_get_value(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME), + dbusmenu_menuitem_property_get_variant(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME), client); image_property_handle(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA, - dbusmenu_menuitem_property_get_value(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA), + dbusmenu_menuitem_property_get_variant(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA), client); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, @@ -743,7 +733,7 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm /* This handler looks at property changes for items that are image menu items. */ static void -image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GValue * invalue, gpointer userdata) +image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer userdata) { /* We're only looking at these two properties here */ if (g_strcmp0(property, DBUSMENU_MENUITEM_PROP_ICON_NAME) != 0 && @@ -752,11 +742,8 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GV } const gchar * value = NULL; + value = g_variant_get_string(variant, NULL); - if (invalue != NULL && G_VALUE_TYPE(invalue) == G_TYPE_STRING) { - value = g_value_get_string(invalue); - } - if (value == NULL || value[0] == '\0') { /* This means that we're unsetting a value. */ /* Try to use the other one */ diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 30b072f..cb76964 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -298,6 +298,8 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType return; } + g_value_unset(&value); + gtk_widget_queue_draw(GTK_WIDGET(item)); return; -- cgit v1.2.3 From a7a7326946d7dd13c0ef5027d460662dfd04b1e7 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 23 Nov 2010 15:53:10 -0500 Subject: Set more scanner flags to get the namespace right --- libdbusmenu-gtk/Makefile.am | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index b30cac9..bb3890e 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -66,10 +66,12 @@ pkgconfigdir = $(libdir)/pkgconfig -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = \ - --add-include-path=$(srcdir) \ +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ - $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) + $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ + --symbol-prefix=dbusmenu \ + --identifier-prefix=DbusmenuGtk \ + --pkg-export=dbusmenu-gtk$(VER) INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION @@ -80,16 +82,20 @@ DbusmenuGtk$(VER)-0.2.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_INCLUDES = \ GObject-2.0 \ $(GTKGIR) \ - Dbusmenu-Glib-0.2 + Dbusmenu-Glib-0.2 DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) +DbusmenuGtk_0_2_gir_NAMESPACE = DbusmenuGtk$(VER) +DbusmenuGtk_0_2_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) DbusmenuGtk3_0_2_gir_CFLAGS = $(DbusmenuGtk_0_2_gir_CFLAGS) DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) +DbusmenuGtk3_0_2_gir_NAMESPACE = $(DbusmenuGtk_0_2_gir_NAMESPACE) +DbusmenuGtk3_0_2_gir_SCANNERFLAGS = $(DbusmenuGtk_0_2_gir_SCANNERFLAGS) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir -- cgit v1.2.3 From d9d3f22c4240b7b1479299167e8ce184fd0c5f3a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 23 Nov 2010 16:06:30 -0500 Subject: Cleaned up the scanner flags some --- libdbusmenu-gtk/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index bb3890e..e539aa6 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -70,8 +70,7 @@ INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ - --identifier-prefix=DbusmenuGtk \ - --pkg-export=dbusmenu-gtk$(VER) + --identifier-prefix=DbusmenuGtk INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION @@ -88,6 +87,7 @@ DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_2_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_2_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) +DbusmenuGtk_0_2_gir_PACKAGES = dbusmenu-gtk$(VER) # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) @@ -96,6 +96,7 @@ DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) DbusmenuGtk3_0_2_gir_NAMESPACE = $(DbusmenuGtk_0_2_gir_NAMESPACE) DbusmenuGtk3_0_2_gir_SCANNERFLAGS = $(DbusmenuGtk_0_2_gir_SCANNERFLAGS) +DbusmenuGtk3_0_2_gir_PACKAGES = $(DbusmenuGtk_0_2_gir_PACKAGES) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir -- cgit v1.2.3 From 02be403c32b2228b33d3cb122750889f165419d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 23 Nov 2010 17:00:14 -0600 Subject: Fixing up variant usage --- libdbusmenu-gtk/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 9c1cfd2..64913be 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -200,9 +200,9 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, const gchar * keyname = gdk_keyval_name(key); g_array_append_val(array, keyname); - GVariant * inside = g_variant_new("as", array->data); + GVariant * inside = g_variant_new_strv((const gchar * const *)array->data, -1); GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("av")); + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); -- cgit v1.2.3 From 938856dbb01aa4e583ce637a0cd34846f8a940fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 12:32:35 -0600 Subject: Switching shortcut parsing code to more directly use the variant iterator --- libdbusmenu-gtk/menuitem.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 64913be..872142b 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -297,35 +297,28 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } - GVariantIter outsideiter; - GVariant * inside; - g_variant_iter_init(&outsideiter, wrapper); - - while(g_variant_iter_next(&outsideiter, "v", &inside)) { - GVariantIter insideiter; - g_variant_iter_init(&insideiter, inside); - gchar * string; - - while(g_variant_iter_next(&insideiter, "s", &string)) { - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *modifier |= GDK_CONTROL_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *modifier |= GDK_MOD1_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *modifier |= GDK_SHIFT_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *modifier |= GDK_SUPER_MASK; - } else { - GdkModifierType tempmod; - gtk_accelerator_parse(string, key, &tempmod); - } - - g_free(string); + g_debug("Data: %s", g_variant_print(wrapper, TRUE)); + + GVariantIter iter; + g_variant_iter_init(&iter, g_variant_get_child_value(wrapper, 0)); + gchar * string; + + while(g_variant_iter_next(&iter, "s", &string)) { + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *modifier |= GDK_CONTROL_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *modifier |= GDK_MOD1_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *modifier |= GDK_SHIFT_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *modifier |= GDK_SUPER_MASK; + } else { + GdkModifierType tempmod; + gtk_accelerator_parse(string, key, &tempmod); } - g_variant_unref(inside); + g_free(string); } - g_variant_unref(wrapper); return; } -- cgit v1.2.3 From 611103533121afca614b2e531c5e113a1a6122f4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 14:21:03 -0600 Subject: Protect against NULL variants to remove warnings --- libdbusmenu-gtk/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 9dd18df..77935c5 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -374,7 +374,7 @@ static void menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, GtkMenuItem * gmi) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) { - gtk_menu_item_set_label(gmi, g_variant_get_string(variant, NULL)); + gtk_menu_item_set_label(gmi, variant == NULL ? NULL : g_variant_get_string(variant, NULL)); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) { process_visible(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ENABLED)) { @@ -742,7 +742,9 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant } const gchar * value = NULL; - value = g_variant_get_string(variant, NULL); + if (variant != NULL) { + value = g_variant_get_string(variant, NULL); + } if (value == NULL || value[0] == '\0') { /* This means that we're unsetting a value. */ -- cgit v1.2.3 From e3097b569710d3cb8466f229571dc632decd1671 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:38:21 -0600 Subject: Switching to use the builder all the way for the strings instead of the GArray --- libdbusmenu-gtk/menuitem.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 872142b..1b8cab1 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -177,31 +177,26 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE); - GArray * array = g_array_sized_new(TRUE, TRUE, sizeof(gchar *), 4); /* Four seems like the max we'd need, plus it's still small */ - - const gchar * control_val = DBUSMENU_MENUITEM_SHORTCUT_CONTROL; - const gchar * alt_val = DBUSMENU_MENUITEM_SHORTCUT_ALT; - const gchar * shift_val = DBUSMENU_MENUITEM_SHORTCUT_SHIFT; - const gchar * super_val = DBUSMENU_MENUITEM_SHORTCUT_SUPER; + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); if (modifier & GDK_CONTROL_MASK) { - g_array_append_val(array, control_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_CONTROL); } if (modifier & GDK_MOD1_MASK) { - g_array_append_val(array, alt_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_ALT); } if (modifier & GDK_SHIFT_MASK) { - g_array_append_val(array, shift_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SHIFT); } if (modifier & GDK_SUPER_MASK) { - g_array_append_val(array, super_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SUPER); } const gchar * keyname = gdk_keyval_name(key); - g_array_append_val(array, keyname); + g_variant_builder_add(&builder, "s", keyname); - GVariant * inside = g_variant_new_strv((const gchar * const *)array->data, -1); - GVariantBuilder builder; + GVariant * inside = g_variant_builder_end(&builder); g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); -- cgit v1.2.3 From 675693fe90c242c4dc9d54d7d3ed34be49d931cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:50:38 -0600 Subject: Ah, oops, we shouldn't unref these variants as they're kept in the hashtable, we have them as floating. --- libdbusmenu-gtk/menuitem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 1b8cab1..2251efc 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -201,12 +201,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); - dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); - - g_variant_unref(outsidevariant); - g_variant_unref(inside); - - return TRUE; + return dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); } /* Look at the closures in an accel group and find -- cgit v1.2.3 From 9231081151c71846010c1be75277a4cc0afc29e3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:51:57 -0600 Subject: oops, forgot a debug message --- libdbusmenu-gtk/menuitem.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 2251efc..e27e6ff 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -287,8 +287,6 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } - g_debug("Data: %s", g_variant_print(wrapper, TRUE)); - GVariantIter iter; g_variant_iter_init(&iter, g_variant_get_child_value(wrapper, 0)); gchar * string; -- cgit v1.2.3 From 0ac0a85f42be1aa1c93cfc42a0b4d455f594ba2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 15:53:09 -0600 Subject: Changing API to 0.4 --- libdbusmenu-gtk/Makefile.am | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 2be63b7..3a65b03 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ lib_LTLIBRARIES = \ libdbusmenu-gtk.la -libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ +libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ @@ -55,16 +55,16 @@ if HAVE_INTROSPECTION introspection_sources = $(libdbusmenu_gtkinclude_HEADERS) -DbusmenuGtk-0.2.gir: libdbusmenu-gtk.la -DbusmenuGtk_0_2_gir_INCLUDES = \ +DbusmenuGtk-0.4.gir: libdbusmenu-gtk.la +DbusmenuGtk_0_4_gir_INCLUDES = \ GObject-2.0 \ Gtk-2.0 \ - Dbusmenu-Glib-0.2 -DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la -DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) + Dbusmenu-Glib-0.4 +DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) +DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk.la +DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir +INTROSPECTION_GIRS += DbusmenuGtk-0.4.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -83,24 +83,24 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi +vapi_DATA = DbusmenuGtk-0.4.vapi -DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ +DbusmenuGtk-0.4.vapi: DbusmenuGtk-0.4.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk-0.4 \ --pkg gdk-pixbuf-2.0 \ --pkg gtk+-2.0 \ --pkg atk \ - --pkg Dbusmenu-Glib-0.2 \ + --pkg Dbusmenu-Glib-0.4 \ --vapidir=$(top_builddir)/libdbusmenu-glib \ $< -DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir +DbusmenuGtk-0.4.tmp.gir: DbusmenuGtk-0.4.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir +CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.4.tmp.gir endif -- cgit v1.2.3 From 2a3d4ac52d20ea99e77b44749aaccb07a135fe25 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 20:42:13 -0600 Subject: Changing the include directory to be the correct changed one. --- libdbusmenu-gtk/dbusmenu-gtk.pc.in | 2 +- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk.pc.in b/libdbusmenu-gtk/dbusmenu-gtk.pc.in index df4cb36..f35c621 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-0.1 +Cflags: -I${includedir}/libdbusmenu-0.4 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in index 1a3410e..033c390 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-0.1 +Cflags: -I${includedir}/libdbusmenu-0.4 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk3 -- cgit v1.2.3 From 7c45578e1fbaa08088d4f2d43bc3533e6b9112e1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 20:46:40 -0600 Subject: Moving the pc files to be parallel installable. --- libdbusmenu-gtk/Makefile.am | 6 +++--- libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in | 14 ++++++++++++++ libdbusmenu-gtk/dbusmenu-gtk.pc.in | 14 -------------- libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in | 14 ++++++++++++++ libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 14 -------------- 5 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in delete mode 100644 libdbusmenu-gtk/dbusmenu-gtk.pc.in create mode 100644 libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in delete mode 100644 libdbusmenu-gtk/dbusmenu-gtk3.pc.in (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e512c4d..7eb725a 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -14,8 +14,8 @@ lib_LTLIBRARIES = libdbusmenu-gtk.la endif EXTRA_DIST = \ - dbusmenu-gtk.pc.in \ - dbusmenu-gtk3.pc.in + dbusmenu-gtk-0.4.pc.in \ + dbusmenu-gtk3-0.4.pc.in libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ @@ -57,7 +57,7 @@ libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk3_la_CFLAGS = $(libdbusmenu_gtk_la_CFLAGS) libdbusmenu_gtk3_la_LIBADD = $(libdbusmenu_gtk_la_LIBADD) -pkgconfig_DATA = dbusmenu-gtk$(VER).pc +pkgconfig_DATA = dbusmenu-gtk$(VER)-0.4.pc pkgconfigdir = $(libdir)/pkgconfig ######################### diff --git a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in new file mode 100644 index 0000000..f35c621 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-0.4 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk + +Name: libdbusmenu-gtk +Description: libdbusmenu-gtk. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/dbusmenu-gtk.pc.in b/libdbusmenu-gtk/dbusmenu-gtk.pc.in deleted file mode 100644 index f35c621..0000000 --- a/libdbusmenu-gtk/dbusmenu-gtk.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -bindir=@bindir@ -includedir=@includedir@ - -Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib -Libs: -L${libdir} -ldbusmenu-gtk - -Name: libdbusmenu-gtk -Description: libdbusmenu-gtk. -Version: @VERSION@ - diff --git a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in new file mode 100644 index 0000000..033c390 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-0.4 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk3 + +Name: libdbusmenu-gtk3 +Description: libdbusmenu-gtk3. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in deleted file mode 100644 index 033c390..0000000 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -bindir=@bindir@ -includedir=@includedir@ - -Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib -Libs: -L${libdir} -ldbusmenu-gtk3 - -Name: libdbusmenu-gtk3 -Description: libdbusmenu-gtk3. -Version: @VERSION@ - -- cgit v1.2.3 From 9dba82584abf181777b7bed4cca8202cf6652ff6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 2 Dec 2010 13:52:54 -0600 Subject: Removing a GValue to use the direct functions --- libdbusmenu-gtk/genericmenuitem.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 990ca82..61881ef 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -291,7 +291,6 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType } item->priv->check_type = check_type; - GValue value = {0}; switch (item->priv->check_type) { case GENERICMENUITEM_CHECK_TYPE_NONE: @@ -300,22 +299,16 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType check on the item. */ break; case GENERICMENUITEM_CHECK_TYPE_CHECKBOX: - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_set_boolean(&value, FALSE); - g_object_set_property(G_OBJECT(item), "draw-as-radio", &value); + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), FALSE); break; case GENERICMENUITEM_CHECK_TYPE_RADIO: - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_set_boolean(&value, TRUE); - g_object_set_property(G_OBJECT(item), "draw-as-radio", &value); + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE); break; default: g_warning("Generic Menuitem invalid check type: %d", check_type); return; } - g_value_unset(&value); - gtk_widget_queue_draw(GTK_WIDGET(item)); return; -- cgit v1.2.3 From 5f1c15b654a09bf8d5ad04b8d8ff046cdf7068fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 6 Dec 2010 10:50:24 -0600 Subject: Add a check for GIR version less that 10 --- libdbusmenu-gtk/Makefile.am | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e539aa6..19765d5 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -66,11 +66,19 @@ pkgconfigdir = $(libdir)/pkgconfig -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = + +if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=DbusmenuGtk +else +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --add-include-path=$(top_builddir)/libdbusmenu-glib \ + $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) +endif + INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION -- cgit v1.2.3 From 1a73825600508b5d7f027641b05a682a8ac81f5e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 8 Dec 2010 09:27:48 -0600 Subject: Fixing the requires in the pc files --- libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in | 2 +- libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in index f35c621..8784556 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib +Requires: dbusmenu-glib-0.4 Libs: -L${libdir} -ldbusmenu-gtk Name: libdbusmenu-gtk diff --git a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in index 033c390..804b13e 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib +Requires: dbusmenu-glib-0.4 Libs: -L${libdir} -ldbusmenu-gtk3 Name: libdbusmenu-gtk3 -- cgit v1.2.3 From 1574d58e111bd80cbeb770ab3f603dca88a90341 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Dec 2010 16:36:48 -0600 Subject: Switching away from using set_activate as that doesn't actually set the value, it just signals, but we're sucking up that signal already so we need to manually create it if we need it, which is the only way to set the active property. Goofy. --- libdbusmenu-gtk/genericmenuitem.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index d507487..d3023ad 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -65,6 +65,7 @@ static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, cairo_t static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) = NULL; #endif +static void (*parent_menuitem_activate) (GtkMenuItem * mi) = NULL; /* Initializing all of the classes. Most notably we're disabling the drawing of the check early. */ @@ -86,6 +87,7 @@ genericmenuitem_class_init (GenericmenuitemClass *klass) GtkMenuItemClass * menuitem_class = GTK_MENU_ITEM_CLASS (klass); menuitem_class->set_label = set_label; menuitem_class->get_label = get_label; + parent_menuitem_activate = menuitem_class->activate; menuitem_class->activate = activate; return; @@ -338,21 +340,19 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) item->priv->state = state; GtkCheckMenuItem * check = GTK_CHECK_MENU_ITEM(item); - - gboolean old_active = gtk_check_menu_item_get_active (check); - gboolean old_inconsist = gtk_check_menu_item_get_inconsistent (check); + gboolean goal_active = FALSE; switch (item->priv->state) { case GENERICMENUITEM_STATE_UNCHECKED: - gtk_check_menu_item_set_active (check, FALSE); + goal_active = FALSE; gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_CHECKED: - gtk_check_menu_item_set_active (check, TRUE); + goal_active = TRUE; gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_INDETERMINATE: - gtk_check_menu_item_set_active (check, TRUE); + goal_active = TRUE; gtk_check_menu_item_set_inconsistent (check, TRUE); break; default: @@ -360,16 +360,12 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) return; } - if (old_active != gtk_check_menu_item_get_active (check)) { - g_object_notify(G_OBJECT(item), "active"); - } - - if (old_inconsist != gtk_check_menu_item_get_inconsistent (check)) { - g_object_notify(G_OBJECT(item), "inconsistent"); + if (goal_active != gtk_check_menu_item_get_active(check)) { + if (parent_menuitem_activate != NULL) { + parent_menuitem_activate(GTK_MENU_ITEM(check)); + } } - gtk_widget_queue_draw(GTK_WIDGET(item)); - return; } -- cgit v1.2.3 From 9ca2114ba780c0d7976e66fbc6e4ae750a7522c4 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Mon, 13 Dec 2010 13:40:01 +0000 Subject: Bracked public libdbusmenu-gtk/menuitem.h header with G_{BEGIN/END}_DECLS, so it can be used from C++ consumers --- libdbusmenu-gtk/menuitem.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index 6960f76..a2b6652 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -35,6 +35,8 @@ License version 3 and version 2.1 along with this program. If not, see #include #include +G_BEGIN_DECLS + gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data); GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property); @@ -43,4 +45,6 @@ gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menu gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi); void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers); +G_END_DECLS + #endif -- cgit v1.2.3 From 86337748c5683bc8f5f953e9baa85fe485d8ff26 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Jan 2011 09:57:37 -0600 Subject: Fixing packages names for the gir scanner --- libdbusmenu-gtk/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index ac2eee9..1957820 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -95,7 +95,7 @@ DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_4_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_4_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) -DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER) +DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER)-0.4 # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES) -- cgit v1.2.3 From 66cfbe695f21345bb0cf84824f4b2d9183067a25 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 18 Jan 2011 10:02:47 -0500 Subject: Use EXPORT_PACKAGES instead of PACKAGES to prevent circular build depends --- libdbusmenu-gtk/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 1957820..0b939c0 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -95,7 +95,7 @@ DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_4_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_4_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) -DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER)-0.4 +DbusmenuGtk_0_4_gir_EXPORT_PACKAGES = dbusmenu-gtk$(VER)-0.4 # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES) @@ -104,7 +104,7 @@ DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS) DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES) DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE) DbusmenuGtk3_0_4_gir_SCANNERFLAGS = $(DbusmenuGtk_0_4_gir_SCANNERFLAGS) -DbusmenuGtk3_0_4_gir_PACKAGES = $(DbusmenuGtk_0_4_gir_PACKAGES) +DbusmenuGtk3_0_4_gir_EXPORT_PACKAGES = $(DbusmenuGtk_0_4_gir_EXPORT_PACKAGES) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.4.gir -- cgit v1.2.3 From cedc4584f11e6fa90ae73db5ecc3019868a6323e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 15:59:36 -0600 Subject: Set the use-fallback property to TRUE on all our Images --- libdbusmenu-gtk/client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b01156f..18a2cdd 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -789,6 +789,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtkimage = NULL; } else if (g_strcmp0(iconname, DBUSMENU_MENUITEM_ICON_NAME_BLANK) == 0) { gtkimage = gtk_image_new(); + g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); } else { /* Look to see if we want to have an icon with the 'ltr' or 'rtl' depending on what we're doing. */ @@ -807,6 +808,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant can just convert it to this name. */ if (gtkimage == NULL) { gtkimage = gtk_image_new_from_icon_name(finaliconname, GTK_ICON_SIZE_MENU); + g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); } else { gtk_image_set_from_icon_name(GTK_IMAGE(gtkimage), finaliconname, GTK_ICON_SIZE_MENU); } -- cgit v1.2.3 From e319b07fba9a47a15aae9ef7c85da464b75874ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:02:48 -0600 Subject: Steal the serializable menuitem from IDO --- libdbusmenu-gtk/serializablemenuitem.c | 99 ++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 58 ++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 libdbusmenu-gtk/serializablemenuitem.c create mode 100644 libdbusmenu-gtk/serializablemenuitem.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c new file mode 100644 index 0000000..2c166d8 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -0,0 +1,99 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "idoserializablemenuitem.h" + +struct _IdoSerializableMenuItemPrivate { + int dummy; +}; + +#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) + +static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); +static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); +static void ido_serializable_menu_item_dispose (GObject *object); +static void ido_serializable_menu_item_finalize (GObject *object); + +G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); + +static void +ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + + object_class->dispose = ido_serializable_menu_item_dispose; + object_class->finalize = ido_serializable_menu_item_finalize; + + return; +} + +static void +ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +{ + self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + + self->priv->dummy = 5; + + return; +} + +static void +ido_serializable_menu_item_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + return; +} + +static void +ido_serializable_menu_item_finalize (GObject *object) +{ + + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + return; +} + +DbusmenuMenuitem * +ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +{ + g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + + IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + if (klass->get_dbusmenu_menuitem != NULL) { + return klass->get_dbusmenu_menuitem(smi); + } + + return NULL; +} + +void +ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +{ + g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + + gpointer type_class = g_type_class_ref(item_type); + g_return_if_fail(type_class != NULL); + + IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + + if (class->get_type_string == NULL) { + g_type_class_unref(type_class); + g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + return; + } + + /* Register type */ + + + /* Register defaults */ + + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h new file mode 100644 index 0000000..48fdb49 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -0,0 +1,58 @@ +#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ +#define __IDO_SERIALIZABLE_MENU_ITEM_H__ + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) +#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) +#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) + +typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; +typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; +typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; + +struct _IdoSerializableMenuItemClass { + GtkMenuItemClass parent_class; + + /* Subclassable functions */ + const gchar * (*get_type_string) (void); + GHashTable * (*get_default_properties) (void); + + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + + /* Signals */ + + + + /* Empty Space */ + void (*_ido_serializable_menu_item_reserved1) (void); + void (*_ido_serializable_menu_item_reserved2) (void); + void (*_ido_serializable_menu_item_reserved3) (void); + void (*_ido_serializable_menu_item_reserved4) (void); + void (*_ido_serializable_menu_item_reserved5) (void); + void (*_ido_serializable_menu_item_reserved6) (void); +}; + +struct _IdoSerializableMenuItem { + GtkMenuItem parent; + + IdoSerializableMenuItemPrivate * priv; +}; + +GType ido_serializable_menu_item_get_type (void); + +DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); +void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); + +G_END_DECLS + +#endif -- cgit v1.2.3 From d43d544702665d2653f7dbb9c73493733ff2fae6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:27:12 -0600 Subject: Adding the files to the build --- libdbusmenu-gtk/Makefile.am | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 0b939c0..a424d4a 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -22,7 +22,8 @@ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + serializablemenuitem.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -32,7 +33,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + serializablemenuitem.h \ + serializablemenuitem.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -- cgit v1.2.3 From 8122074a5e67cf69f147a8b10b31c1fefaf64486 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:32:02 -0600 Subject: Changing namespace from IDO to DBusMenu GTK --- libdbusmenu-gtk/serializablemenuitem.c | 52 +++++++++++++++++----------------- libdbusmenu-gtk/serializablemenuitem.h | 48 +++++++++++++++---------------- 2 files changed, 50 insertions(+), 50 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 2c166d8..c9eb416 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -2,39 +2,39 @@ #include "config.h" #endif -#include "idoserializablemenuitem.h" +#include "serializablemenuitem.h" -struct _IdoSerializableMenuItemPrivate { +struct _DbusmenuGtkSerializableMenuItemPrivate { int dummy; }; -#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) -static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); -static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); -static void ido_serializable_menu_item_dispose (GObject *object); -static void ido_serializable_menu_item_finalize (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); +static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); +static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); -G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); static void -ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + g_type_class_add_private (klass, sizeof (DbusmenuGtkSerializableMenuItemPrivate)); - object_class->dispose = ido_serializable_menu_item_dispose; - object_class->finalize = ido_serializable_menu_item_finalize; + object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; + object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; return; } static void -ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { - self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); self->priv->dummy = 5; @@ -42,30 +42,30 @@ ido_serializable_menu_item_init (IdoSerializableMenuItem *self) } static void -ido_serializable_menu_item_dispose (GObject *object) +dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); return; } static void -ido_serializable_menu_item_finalize (GObject *object) +dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->finalize (object); return; } DbusmenuMenuitem * -ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { - g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); - IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); if (klass->get_dbusmenu_menuitem != NULL) { return klass->get_dbusmenu_menuitem(smi); } @@ -74,18 +74,18 @@ ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) } void -ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { - g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + g_return_if_fail(g_type_is_a(item_type, DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)); gpointer type_class = g_type_class_ref(item_type); g_return_if_fail(type_class != NULL); - IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + DbusmenuGtkSerializableMenuItemClass * class = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(type_class); if (class->get_type_string == NULL) { g_type_class_unref(type_class); - g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + g_error("No 'get_type_string' in subclass of DbusmenuGtkSerializableMenuItem"); return; } diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 48fdb49..e99d329 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,5 +1,5 @@ -#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ -#define __IDO_SERIALIZABLE_MENU_ITEM_H__ +#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #include #include @@ -9,49 +9,49 @@ G_BEGIN_DECLS -#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) -#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) -#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM (dbusmenu_gtk_serializable_menu_item_get_type ()) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItem)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) -typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; -typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; -typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; +typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; +typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; +typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -struct _IdoSerializableMenuItemClass { +struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; /* Subclassable functions */ const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ /* Empty Space */ - void (*_ido_serializable_menu_item_reserved1) (void); - void (*_ido_serializable_menu_item_reserved2) (void); - void (*_ido_serializable_menu_item_reserved3) (void); - void (*_ido_serializable_menu_item_reserved4) (void); - void (*_ido_serializable_menu_item_reserved5) (void); - void (*_ido_serializable_menu_item_reserved6) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved4) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved5) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; -struct _IdoSerializableMenuItem { +struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; - IdoSerializableMenuItemPrivate * priv; + DbusmenuGtkSerializableMenuItemPrivate * priv; }; -GType ido_serializable_menu_item_get_type (void); +GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); -void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); G_END_DECLS -- cgit v1.2.3 From 6ec53854067f149492c18d35d680c2dad01d0a41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:45:44 -0600 Subject: Setting up the type handler, need more API --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index c9eb416..4d23635 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,14 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +/* Handle the type with this item. */ +static gboolean +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return TRUE; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -90,10 +98,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - + dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ /* Register defaults */ - + /* TODO: Need API on another branch */ return; } -- cgit v1.2.3 From 3d8ec9ae0b07cbe287aaeda633621ac8c81b5925 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:59:57 -0600 Subject: Fixing callback prototypes --- libdbusmenu-gtk/client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b01156f..af7768a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -54,8 +54,8 @@ static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, Dbusm static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); @@ -684,7 +684,7 @@ dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMen /* The base type handler that builds a plain ol' GtkMenuItem to represent, well, the GtkMenuItem */ static gboolean -new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); @@ -719,7 +719,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu /* Type handler for the seperators where it builds a GtkSeparator to act as the GtkMenuItem */ static gboolean -new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); -- cgit v1.2.3 From 61fd5050b6319de6b948cdb0cd36e1b985d7b2a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:02:00 -0600 Subject: Setup to the use the full type handler --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 4d23635..42d79b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -75,12 +75,20 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab /* Handle the type with this item. */ static gboolean -type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { return TRUE; } +/* Destruction is inevitable */ +static void +type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) +{ + + return; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -98,7 +106,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 5d6f408aad06b27f8d29b52df9bd8d76155eabe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:05:31 -0600 Subject: Build a type handler structure to handle the class struct --- libdbusmenu-gtk/serializablemenuitem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 42d79b2..16b3910 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,12 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +typedef struct _type_handler_t type_handler_t; +struct _type_handler_t { + DbusmenuGtkSerializableMenuItemClass * class; + GType type; +}; + /* Handle the type with this item. */ static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) @@ -85,7 +91,10 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli static void type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) { - + g_return_if_fail(user_data != NULL); + type_handler_t * th = (type_handler_t *)user_data; + g_type_class_unref(th->class); + g_free(user_data); return; } @@ -106,7 +115,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ + type_handler_t * th = g_new0(type_handler_t, 1); + th->class = class; + th->type = item_type; + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 43b377b84c868f652e8ea0db989b985cf20a3304 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:06:28 -0600 Subject: Clean up on failure --- libdbusmenu-gtk/serializablemenuitem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 16b3910..1d4703f 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -118,7 +118,9 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, type_handler_t * th = g_new0(type_handler_t, 1); th->class = class; th->type = item_type; - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ + if (!dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler)) { + type_destroy_handler(client, class->get_type_string(), th); + } /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 4d6b2a232814fc61e7652199a142d5af39c4f78f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 10:52:33 -0600 Subject: License headers --- libdbusmenu-gtk/serializablemenuitem.c | 28 ++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 1d4703f..e8ad22b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index e99d329..bb67192 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -- cgit v1.2.3 From c0990d9fa4889042ae255ed1358c0686d5dec241 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 16:50:34 -0600 Subject: Filling out the type handler --- libdbusmenu-gtk/serializablemenuitem.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index e8ad22b..de7bb04 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include "client.h" #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { @@ -111,6 +112,13 @@ struct _type_handler_t { static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { + type_handler_t * th = (type_handler_t *)user_data; + + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); + g_return_val_if_fail(smi != NULL, FALSE); + + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; } -- cgit v1.2.3 From 5dc7f70d50ba5cf9cdc86693e7b759f567fb862c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 17:00:50 -0600 Subject: Adding a function to tell the menu item about where it's properties are coming from. --- libdbusmenu-gtk/serializablemenuitem.c | 7 +++++++ libdbusmenu-gtk/serializablemenuitem.h | 1 + 2 files changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index de7bb04..74e0bec 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -163,3 +163,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } + +void +dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +{ + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index bb67192..487b08b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -80,6 +80,7 @@ GType dbusmenu_gtk_serializable_menu_item_get_type (void); DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From 58677931dde065b11f7010ad1443c6d4d1b20d7d Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 19 Jan 2011 22:50:25 -0500 Subject: added --warn-all to scanner flags so the build log will warn us about missing annotations --- libdbusmenu-gtk/Makefile.am | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 0b939c0..b8e1170 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -69,12 +69,14 @@ INTROSPECTION_GIRS = if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=DbusmenuGtk else INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) endif -- cgit v1.2.3 From abe1a8b281bf08217367666fbac41eb812708d33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 19:56:14 -0600 Subject: Switching the name to build so that we realize what's going on there. --- libdbusmenu-gtk/serializablemenuitem.c | 6 +++--- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 74e0bec..32be773 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -90,13 +90,13 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) } DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); - if (klass->get_dbusmenu_menuitem != NULL) { - return klass->get_dbusmenu_menuitem(smi); + if (klass->build_dbusmenu_menuitem != NULL) { + return klass->build_dbusmenu_menuitem(smi); } return NULL; diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 487b08b..30e1157 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -55,7 +55,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); + DbusmenuMenuitem * (*build_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ @@ -78,7 +78,7 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); -- cgit v1.2.3 From aea42d14c645517cc32611ab0e8580223948aad3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 20:09:39 -0600 Subject: Installing a property for the menuitem in the super-class --- libdbusmenu-gtk/serializablemenuitem.c | 23 +++++++++++++++++++++-- libdbusmenu-gtk/serializablemenuitem.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 32be773..5089af0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -34,7 +34,13 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { - int dummy; + DbusmenuMenuitem * mi; +}; + +/* Properties */ +enum { + PROP_0, + PROP_MENUITEM }; #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ @@ -57,6 +63,12 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + g_object_class_install_property (object_class, PROP_MENUITEM, + g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", + "A menuitem who's properties are being watched and where changes should be watched for updates. It is the responsibility of subclasses to set up the signal handlers for those property changes.", + DBUSMENU_TYPE_MENUITEM, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + return; } @@ -65,7 +77,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); - self->priv->dummy = 5; + self->priv->mi = NULL; return; } @@ -73,6 +85,13 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(object); + g_return_if_fail(smi != NULL); + + if (smi->priv->mi != NULL) { + g_object_unref(G_OBJECT(smi->priv->mi)); + smi->priv->mi = NULL; + } G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 30e1157..0dc92e0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -44,6 +44,8 @@ G_BEGIN_DECLS #define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM "dbusmenu-menuitem" + typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -- cgit v1.2.3 From 1a4efa01c312cf8c54d7d158385b5208f1cdb841 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 10:35:55 -0600 Subject: Add a single include for dbusmenu-gtk --- libdbusmenu-gtk/Makefile.am | 1 + libdbusmenu-gtk/dbusmenu-gtk.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index b8e1170..e5df6b1 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ + dbusmenu-gtk.h \ client.h \ menu.h \ menuitem.h diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h new file mode 100644 index 0000000..de63c61 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -0,0 +1,40 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef __DBUSMENU_GTK_H__ +#define __DBUSMENU_GTK_H__ + +/* Start with the glib stuff */ +#include + +/* Now get the GTK stuff */ +#include +#include +#include + +#endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From 0ea5e726b97d9080b4300d007f002da247dbf0b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 11:59:06 -0600 Subject: Add serializable menuitem to the single include --- libdbusmenu-gtk/dbusmenu-gtk.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h index de63c61..f2fe5be 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.h +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -36,5 +36,6 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include +#include #endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From ffce14168e30c5b34d24ee7ee5199a61bb4a30f3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 12:02:57 -0600 Subject: Add some documentation of the class and object structures. --- libdbusmenu-gtk/serializablemenuitem.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 0dc92e0..aae2f96 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -50,6 +50,19 @@ typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMe typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; +/** + DbusmenuGtkSerializableMenuItemClass: + @parent_class: Inherit from GtkMenuItem + @get_type_string: Static function to get a string describing this type + @get_default_properties: Return a hashtable of defaults for the menu item type + @build_dbusmenu_menuitem: Build a menuitem that can be sent over dbus + @_dbusmenu_gtk_serializable_menu_item_reserved1: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved2: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved3: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved4: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved5: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved6: Reserved for future use. +*/ struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; @@ -64,6 +77,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { /* Empty Space */ + /*< Private >*/ void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); @@ -72,6 +86,11 @@ struct _DbusmenuGtkSerializableMenuItemClass { void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; +/** + DbusmenuGtkSerializableMenuItem: + @parent: Inherit from GtkMenuItem + @priv: Blind structure of private variables +*/ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From efd5c63d09eed1230bb0bb822f3040f55d30638d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:01:20 -0600 Subject: More documentation --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 5089af0..01b20b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -33,6 +33,10 @@ License version 3 and version 2.1 along with this program. If not, see #include "client.h" #include "serializablemenuitem.h" +/** + DbusmenuGtkSerializableMenuItemPrivate: + @mi: Menuitem to watch the property changes from +*/ struct _DbusmenuGtkSerializableMenuItemPrivate { DbusmenuMenuitem * mi; }; @@ -43,16 +47,20 @@ enum { PROP_MENUITEM }; +/* Private macro, only used in object init */ #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) +/* Function prototypes */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +/* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); +/* Initialize the stuff in the class structure */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { @@ -72,6 +80,7 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC return; } +/* Initialize the object structures and private structure */ static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { @@ -82,6 +91,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) return; } +/* Free all references to objects */ static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { @@ -98,6 +108,7 @@ dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) return; } +/* Free memory */ static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { @@ -121,6 +132,7 @@ dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializ return NULL; } +/* Callback to the generic type handler */ typedef struct _type_handler_t type_handler_t; struct _type_handler_t { DbusmenuGtkSerializableMenuItemClass * class; -- cgit v1.2.3 From 91544bb4a5ae2bc6eea3e930da6c7ebbb32216d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:37:44 -0600 Subject: gtk-doc documentation for public API functions --- libdbusmenu-gtk/serializablemenuitem.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 01b20b2..06dfa59 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -119,6 +119,19 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/** + dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring + + This function is for menu items that are instanciated from + GTK and have their properites set using GTK functions. This + builds a #DbusmenuMenuitem that then has the properties that + should be sent over the bus to create a new item of this + type on the other side. + + Return value: A #DbusmenuMenuitem who's values will be set by + this object. +*/ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { @@ -165,6 +178,16 @@ type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user return; } +/** + dbusmenu_gtk_serializable_menu_item_register_to_client: + @client: #DbusmenuClient that we should register a type at. + @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem + + Registers a generic handler for dealing with all subclasses of + #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, + creates a new object and attaches it to the appropriate #DbusmenuMenuitem + object. +*/ void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -195,6 +218,17 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } +/** + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of + @mi: Menuitem to get the properties from + + This function is used on the server side to signal to the object + that it should get its' property change events from @mi instead + of expecting calls to its' API. A call to this function sets the + property and subclasses should listen to the notify signal to + pick up this property being set. +*/ void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { -- cgit v1.2.3 From 97083dc0b396d91c68fe9f439024cc048333e87b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:43:44 -0600 Subject: Adding in set and get property functions. --- libdbusmenu-gtk/serializablemenuitem.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 06dfa59..99bc585 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -56,6 +56,14 @@ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializa static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +static void set_property (GObject * obj, + guint id, + const GValue * value, + GParamSpec * pspec); +static void get_property (GObject * obj, + guint id, + GValue * value, + GParamSpec * pspec); /* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); @@ -70,6 +78,8 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + object_class->set_property = set_property; + object_class->get_property = get_property; g_object_class_install_property (object_class, PROP_MENUITEM, g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", @@ -119,6 +129,42 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/* Set an object property */ +static void +set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + smi->priv->mi = g_value_get_object(value); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + +/* Get an object property */ +static void +get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + g_value_set_object(value, smi->priv->mi); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + /** dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring -- cgit v1.2.3 From 555f085168fac50cf55c910c746363f8ce268823 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:46:27 -0600 Subject: Fleshing out setting the property --- libdbusmenu-gtk/serializablemenuitem.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 99bc585..6bc3695 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -278,6 +278,11 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); + g_return_if_fail(mi != NULL); + + smi->priv->mi = mi; + g_object_notify(G_OBJECT(smi), DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM); return; } -- cgit v1.2.3 From 539290124d737754b20dd69e6d3033175ca37e12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:48:41 -0600 Subject: Ensuring our double include protectors make g-ir-scanner happy. --- libdbusmenu-gtk/menuitem.h | 4 ++-- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index a2b6652..4fc42f9 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTKMENUITEM_H__ -#define __DBUSMENU_GTKMENUITEM_H__ 1 +#ifndef DBUSMENU_GTK_MENUITEM_H__ +#define DBUSMENU_GTK_MENUITEM_H__ 1 #include #include diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index aae2f96..1ca3ef8 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#ifndef DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ 1 #include #include -- cgit v1.2.3 From edef8613dd3e78e5d11a2754e6175dd8e55ff87e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:59:35 -0600 Subject: Adding a transfer annotation --- libdbusmenu-gtk/serializablemenuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 6bc3695..f67434e 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -175,8 +175,8 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) should be sent over the bus to create a new item of this type on the other side. - Return value: A #DbusmenuMenuitem who's values will be set by - this object. + Return value: (transfer full) A #DbusmenuMenuitem who's values will be + set by this object. */ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) -- cgit v1.2.3 From c644e10c9da09e443a00422df00a6ba9df7a7e83 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 12:45:05 -0600 Subject: Adding the base files for the parser --- libdbusmenu-gtk/Makefile.am | 7 +++++-- libdbusmenu-gtk/parser.c | 9 +++++++++ libdbusmenu-gtk/parser.h | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 libdbusmenu-gtk/parser.c create mode 100644 libdbusmenu-gtk/parser.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e5df6b1..201a631 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -23,7 +23,8 @@ libdbusmenu_gtkinclude_HEADERS = \ dbusmenu-gtk.h \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + parser.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -33,7 +34,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + parser.h \ + parser.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c new file mode 100644 index 0000000..98b3f7d --- /dev/null +++ b/libdbusmenu-gtk/parser.c @@ -0,0 +1,9 @@ + +#include "parser.h" + +DbusmenuMenuitem * +dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +{ + + return NULL; +} diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h new file mode 100644 index 0000000..222d9f4 --- /dev/null +++ b/libdbusmenu-gtk/parser.h @@ -0,0 +1,6 @@ + +#include +#include + +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); + -- cgit v1.2.3 From b39a625defde44aa345253237d4f186abedf7196 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Sun, 23 Jan 2011 13:05:28 -0600 Subject: Taking the menu parsing code from appmenu-gtk --- libdbusmenu-gtk/parser.c | 426 ++++++++++++++++++++++++++++++++++++++++++++++- libdbusmenu-gtk/parser.h | 2 +- 2 files changed, 426 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 98b3f7d..8fd0d12 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,9 +1,433 @@ #include "parser.h" +#include "menuitem.h" + +static void accel_changed (GtkWidget *widget, gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); +static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static GtkWidget * find_menu_label (GtkWidget *widget); +static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); +static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); +static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static gboolean should_show_image (GtkImage *image); DbusmenuMenuitem * -dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + + if (GTK_IS_MENU_ITEM (widget)) + { + gboolean visible = FALSE; + gboolean sensitive = FALSE; + if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + "type", + "separator"); + + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + else + { + gboolean label_set = FALSE; + + g_signal_connect (widget, + "accel-closures-changed", + G_CALLBACK (accel_changed), + mi); + + if (GTK_IS_CHECK_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, + gtk_check_menu_item_get_draw_as_radio (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_RADIO : DBUSMENU_MENUITEM_TOGGLE_CHECK); + + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); + + g_signal_connect (widget, + "activate", + G_CALLBACK (checkbox_toggled), + mi); + } + + if (GTK_IS_IMAGE_MENU_ITEM (widget)) + { + GtkWidget *image; + GtkImageType image_type; + + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); + + if (GTK_IS_IMAGE (image)) + { + image_type = gtk_image_get_storage_type (GTK_IMAGE (image)); + + if (image_type == GTK_IMAGE_STOCK) + { + label_set = update_stock_item (mi, image); + } + else if (image_type == GTK_IMAGE_ICON_NAME) + { + update_icon_name (mi, image); + } + else if (image_type == GTK_IMAGE_PIXBUF) + { + dbusmenu_menuitem_property_set_image (mi, + DBUSMENU_MENUITEM_PROP_ICON_DATA, + gtk_image_get_pixbuf (GTK_IMAGE (image))); + } + } + } + + GtkWidget *label = find_menu_label (widget); + + dbusmenu_menuitem_property_set (mi, + "label", + label ? gtk_label_get_text (GTK_LABEL (label)) : NULL); + + if (label) + { + // Sometimes, an app will directly find and modify the label + // (like empathy), so watch the label especially for that. + g_signal_connect (G_OBJECT (label), + "notify", + G_CALLBACK (label_notify_cb), + mi); + } + + if (GTK_IS_ACTIVATABLE (widget)) + { + GtkActivatable *activatable = GTK_ACTIVATABLE (widget); + + if (gtk_activatable_get_use_action_appearance (activatable)) + { + GtkAction *action = gtk_activatable_get_related_action (activatable); + + if (action) + { + visible = gtk_action_is_visible (action); + sensitive = gtk_action_is_sensitive (action); + + g_signal_connect_object (action, "notify", + G_CALLBACK (action_notify_cb), + mi, + G_CONNECT_AFTER); + } + } + } + + if (!g_object_get_data (G_OBJECT (widget), "gtk-empty-menu-item") && !GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (item_activated), + widget); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, + G_CALLBACK (item_about_to_show), + widget); + } + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + visible); + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + sensitive); + + g_signal_connect (widget, + "notify", + G_CALLBACK (widget_notify_cb), + mi); + } + + return mi; return NULL; } + +static void +accel_changed (GtkWidget *widget, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); +} + +static gboolean +update_stock_item (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkStockItem stock; + GtkImage *image; + + g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) + return FALSE; + + gtk_stock_lookup (image->data.stock.stock_id, &stock); + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.stock.stock_id); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); + + const gchar *label = dbusmenu_menuitem_property_get (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL); + + if (stock.label != NULL && label != NULL) + { + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + stock.label); + + return TRUE; + } + + return FALSE; +} + +static void +checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi) +{ + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); +} + +static void +update_icon_name (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkImage *image; + + g_return_if_fail (GTK_IS_IMAGE (widget)); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) + return; + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.name.icon_name); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); +} + +static GtkWidget * +find_menu_label (GtkWidget *widget) +{ + GtkWidget *label = NULL; + + if (GTK_IS_LABEL (widget)) + return widget; + + if (GTK_IS_CONTAINER (widget)) + { + GList *children; + GList *l; + + children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (l = children; l; l = l->next) + { + label = find_menu_label (l->data); + + if (label) + break; + } + + g_list_free (children); + } + + return label; +} + +static void +label_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_label_get_text (GTK_LABEL (widget))); + } +} + +static void +action_notify_cb (GtkAction *action, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_action_is_sensitive (action)); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_action_is_visible (action)); + } + else if (pspec->name == g_intern_static_string ("active")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_action_get_label (action)); + } +} + +static void +item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } +} + +static gboolean +item_about_to_show (DbusmenuMenuitem *item, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + // Only called for items with submens. So we activate it here in + // case the program dynamically creates menus (like empathy does) + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } + + return TRUE; +} + +static void +widget_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_widget_get_sensitive (widget)); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_menu_item_get_label (GTK_MENU_ITEM (widget))); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_widget_get_visible (widget)); + } + else if (pspec->name == g_intern_static_string ("stock")) + { + update_stock_item (child, widget); + } + else if (pspec->name == g_intern_static_string ("icon-name")) + { + update_icon_name (child, widget); + } + else if (pspec->name == g_intern_static_string ("parent")) + { + /* + * We probably should have added a 'remove' method to the + * UbuntuMenuProxy early on, but it's late in the cycle now. + */ + if (gtk_widget_get_parent (widget) == NULL) + { + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (widget_notify_cb), + child); + + DbusmenuMenuitem *parent = g_object_get_data (G_OBJECT (child), "dbusmenu-parent"); + + if (DBUSMENU_IS_MENUITEM (parent) && DBUSMENU_IS_MENUITEM (child)) + { + dbusmenu_menuitem_child_delete (parent, child); + } + } + } +} + +static gboolean +should_show_image (GtkImage *image) +{ + GtkWidget *item; + + item = gtk_widget_get_ancestor (GTK_WIDGET (image), + GTK_TYPE_IMAGE_MENU_ITEM); + + if (item) + { + GtkSettings *settings; + gboolean gtk_menu_images; + + settings = gtk_widget_get_settings (item); + + g_object_get (settings, "gtk-menu-images", >k_menu_images, NULL); + + if (gtk_menu_images) + return TRUE; + + return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item)); + } + + return FALSE; +} + diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 222d9f4..3cffb9c 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -2,5 +2,5 @@ #include #include -DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); -- cgit v1.2.3 From 708ccab44c2c88b43ad35048dc0aee81023e61f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:11:46 -0600 Subject: Reformating prototypes because it makes the code run faster. --- libdbusmenu-gtk/parser.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8fd0d12..f0c22be 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -2,17 +2,30 @@ #include "parser.h" #include "menuitem.h" -static void accel_changed (GtkWidget *widget, gpointer data); -static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); -static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static GtkWidget * find_menu_label (GtkWidget *widget); -static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); -static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); -static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); -static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static gboolean should_show_image (GtkImage *image); +static void accel_changed (GtkWidget * widget, + gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static void checkbox_toggled (GtkWidget * widget, + DbusmenuMenuitem * mi); +static void update_icon_name (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static GtkWidget * find_menu_label (GtkWidget * widget); +static void label_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static void action_notify_cb (GtkAction * action, + GParamSpec * pspec, + gpointer data); +static void item_activated (DbusmenuMenuitem * item, + guint timestamp, + gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem * item, + gpointer user_data); +static void widget_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) -- cgit v1.2.3 From 401bc7c326c518ad01c1edd38155d89d9e35fd49 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:16:20 -0600 Subject: Adding copyright headers --- libdbusmenu-gtk/parser.c | 27 +++++++++++++++++++++++++++ libdbusmenu-gtk/parser.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f0c22be..cba6b42 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,3 +1,30 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Numerous (check Bazaar) + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ #include "parser.h" #include "menuitem.h" diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 3cffb9c..a40d709 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -1,6 +1,37 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef DBUSMENU_GTK_PARSER_H__ +#define DBUSMENU_GTK_PARSER_H__ #include #include DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); +#endif /* DBUSMENU_GTK_PARSER_H__ */ -- cgit v1.2.3 From 32a7eb938893bcc1bc5644aa95c63041e9d4db01 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:09:51 -0600 Subject: Needed to go up a level to get recursion code. --- libdbusmenu-gtk/parser.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cba6b42..08613ac 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +typedef struct _RecurseContext +{ + gint count; + DbusmenuMenuitem *stack[30]; +} RecurseContext; + +static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); +static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget); static void accel_changed (GtkWidget * widget, gpointer data); static gboolean update_stock_item (DbusmenuMenuitem * menuitem, @@ -56,6 +64,156 @@ static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) +{ + RecurseContext recurse = {0}; + recurse.count = -1; + + parse_menu_structure_helper(widget, &recurse); + + if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { + return recurse.stack[0]; + } + + return NULL; +} + +static void +parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) +{ + if (GTK_IS_CONTAINER (widget)) + { + gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + + if (increment) + recurse->count++; + + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) + { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) + { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + } + + if (recurse->count > -1 && increment) + { + DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + if (dmi != NULL) + { + if (increment) + recurse->count--; + + return; + } + else + { + recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); + //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + } + + if (!gtk_widget_get_visible (widget)) + { + /*g_signal_connect (G_OBJECT (widget), + "notify", + G_CALLBACK (menuitem_notify_cb), + recurse->context); */ + } + + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + } + + if (recurse->count > 0) + { + GList *children = NULL; + GList *peek = NULL; + + if (recurse->stack[recurse->count - 1]) + { + children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + /* Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], + recurse->stack[recurse->count]); + } + } + else + { + DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, + gtk_widget_get_parent (widget)); */ + + if (item) + { + children = dbusmenu_menuitem_get_children (item); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + + dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); + } + } + } + } + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + + if (GTK_IS_MENU_ITEM (widget)) + { + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + + if (menu != NULL) + { + parse_menu_structure_helper (menu, recurse); + } + } + + if (increment) + recurse->count--; + } +} + +static DbusmenuMenuitem * +construct_dbusmenu_for_widget (GtkWidget * widget) { DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); -- cgit v1.2.3 From 65b9cda89a5bef2c541f5ed2624e6e199f136435 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:40:26 -0600 Subject: Trying to put back in the visibility notifier to force the rebuild, but I'm not quite sure how to do that yet. --- libdbusmenu-gtk/parser.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 08613ac..9d0f9b4 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { + GtkWidget * toplevel; gint count; DbusmenuMenuitem *stack[30]; } RecurseContext; @@ -61,12 +62,17 @@ static void widget_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); static gboolean should_show_image (GtkImage * image); +static void menuitem_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; + recurse.count = -1; + recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); @@ -129,10 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (!gtk_widget_get_visible (widget)) { - /*g_signal_connect (G_OBJECT (widget), - "notify", + g_signal_connect (G_OBJECT (widget), + "notify::visible", G_CALLBACK (menuitem_notify_cb), - recurse->context); */ + recurse->toplevel); } if (GTK_IS_TEAROFF_MENU_ITEM (widget)) @@ -358,6 +364,27 @@ construct_dbusmenu_for_widget (GtkWidget * widget) return NULL; } +static void +menuitem_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + if (pspec->name == g_intern_static_string ("visible")) + { + GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget); + GtkWidget * old_toplevel = GTK_WIDGET(data); + + if (new_toplevel == old_toplevel) { + /* TODO: Figure this out -> rebuild (context->bridge, window); */ + } + + /* We only care about this once, so let's disconnect now. */ + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (menuitem_notify_cb), + data); + } +} + static void accel_changed (GtkWidget *widget, gpointer data) -- cgit v1.2.3 From a439aeb8fd08d9858055bbb2ae1326a1335600d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:53:27 -0600 Subject: Reimplementing the cache based on object data with signals to cleanup --- libdbusmenu-gtk/parser.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 9d0f9b4..f1c46ba 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,8 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" + typedef struct _RecurseContext { GtkWidget * toplevel; @@ -83,6 +85,20 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +static void +dbusmenu_cache_freed (gpointer data, GObject * obj) +{ + g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + return; +} + +static void +object_cache_freed (gpointer data) +{ + g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); + return; +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -119,7 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (recurse->count > -1 && increment) { - DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + DbusmenuMenuitem *dmi = NULL; + if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); + if (dmi != NULL) { if (increment) @@ -130,7 +149,8 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) else { recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); + g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); } if (!gtk_widget_get_visible (widget)) -- cgit v1.2.3 From fc096ca12b152461dfddbfdf74720b98691448ce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 16:08:39 -0600 Subject: Stop using the data field in gtk image for GTK3 --- libdbusmenu-gtk/parser.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f1c46ba..cfce42a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -427,12 +427,15 @@ update_stock_item (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) return FALSE; - gtk_stock_lookup (image->data.stock.stock_id, &stock); + gchar * stock_id = NULL; + gtk_image_get_stock(image, &stock_id, NULL); + + gtk_stock_lookup (stock_id, &stock); if (should_show_image (image)) dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.stock.stock_id); + stock_id); else dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); @@ -473,13 +476,16 @@ update_icon_name (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) return; - if (should_show_image (image)) + if (should_show_image (image)) { + const gchar * icon_name = NULL; + gtk_image_get_icon_name(image, &icon_name, NULL); dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.name.icon_name); - else + icon_name); + } else { dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); + } } static GtkWidget * -- cgit v1.2.3 From 25ab785826d59d8ca7860b0d0bc39d6187a3a1ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Jan 2011 14:56:07 -0600 Subject: Fixing referencing warnings on destruction. --- libdbusmenu-gtk/parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cfce42a..52bd8a8 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -88,7 +88,9 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) static void dbusmenu_cache_freed (gpointer data, GObject * obj) { - g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + /* If the dbusmenu item is killed we don't need to remove + the weak ref as well. */ + g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); return; } -- cgit v1.2.3 From 32def89e3191d994a43d222c1e81c746922b688d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 11:50:46 -0600 Subject: Moving one up the stack so GtkMenu works as well --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 52bd8a8..d26f8fb 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -106,7 +106,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { if (GTK_IS_CONTAINER (widget)) { - gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); if (increment) recurse->count++; -- cgit v1.2.3 From 275bd0eec2e28b708ff6cda14531f63a8aa16e8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 16:51:31 -0600 Subject: Looking for the serializable menu item and using it's build function if it is one. --- libdbusmenu-gtk/parser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..6d95f10 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -28,6 +28,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#include "serializablemenuitem.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" @@ -240,13 +241,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) } } +/* Turn a widget into a dbusmenu item depending on the type of GTK + object that it is. */ static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget) { - DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); - + /* If it's a subclass of our serializable menu item then we can + use its own build function */ + if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); + return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + } + + /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + gboolean visible = FALSE; gboolean sensitive = FALSE; if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) @@ -379,11 +390,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) "notify", G_CALLBACK (widget_notify_cb), mi); + return mi; } - return mi; - - return NULL; + /* If it's none of those we're going to just create a + generic menuitem as a place holder for it. */ + return dbusmenu_menuitem_new(); } static void -- cgit v1.2.3 From d5a160e04dfd351cefb70ac5f6955cb2913e2ad5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 17:04:23 -0600 Subject: Adding a little helper to reduce the number of warnings if the property is missing. --- libdbusmenu-gtk/client.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 18a2cdd..ff2b3a7 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -42,6 +42,7 @@ struct _DbusmenuGtkClientPrivate { }; #define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) +#define USE_FALLBACK_PROP "use-fallback" /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); @@ -737,6 +738,28 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } +/* A little helper so we don't generate a bunch of warnings + about being able to set use-fallback */ +static void +set_use_fallback (GtkWidget * widget) +{ + static gboolean checked = FALSE; + static gboolean available = FALSE; + + if (!checked) { + available = (g_object_class_find_property(G_OBJECT_CLASS(GTK_IMAGE_GET_CLASS(widget)), USE_FALLBACK_PROP) != NULL); + if (!available) { + g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); + } + } + + if (available) { + g_object_set(G_OBJECT(widget), USE_FALLBACK_PROP, TRUE, NULL); + } + + return; +} + /* This handler looks at property changes for items that are image menu items. */ static void @@ -789,7 +812,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtkimage = NULL; } else if (g_strcmp0(iconname, DBUSMENU_MENUITEM_ICON_NAME_BLANK) == 0) { gtkimage = gtk_image_new(); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { /* Look to see if we want to have an icon with the 'ltr' or 'rtl' depending on what we're doing. */ @@ -808,7 +831,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant can just convert it to this name. */ if (gtkimage == NULL) { gtkimage = gtk_image_new_from_icon_name(finaliconname, GTK_ICON_SIZE_MENU); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { gtk_image_set_from_icon_name(GTK_IMAGE(gtkimage), finaliconname, GTK_ICON_SIZE_MENU); } -- cgit v1.2.3 From 1039a4dd88243938e8871c307c20841c375b78d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 15:11:16 -0600 Subject: Adding comments and a check to ensure the item is valid. --- libdbusmenu-gtk/parser.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..1936d2d 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -85,6 +85,8 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +/* Called when the dbusmenu item that we're keeping around + is finalized */ static void dbusmenu_cache_freed (gpointer data, GObject * obj) { @@ -94,9 +96,12 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) return; } +/* Called if we replace the cache on the object with a new + dbusmenu menuitem */ static void object_cache_freed (gpointer data) { + if (!G_IS_OBJECT(data)) return; g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); return; } -- cgit v1.2.3 From 81032fae461250e5e73aaa49896fd92dd58ad674 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:09:41 -0600 Subject: Factoring out the stack and just tracking the parent as that's all we were using it for really. --- libdbusmenu-gtk/parser.c | 236 ++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 137 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 1936d2d..5f0ef48 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -34,8 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { GtkWidget * toplevel; - gint count; - DbusmenuMenuitem *stack[30]; + DbusmenuMenuitem * parent; } RecurseContext; static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); @@ -68,21 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); + DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; - recurse.count = -1; recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); - if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { - return recurse.stack[0]; - } - - return NULL; + return recurse.parent; } /* Called when the dbusmenu item that we're keeping around @@ -93,6 +88,7 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) /* If the dbusmenu item is killed we don't need to remove the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); + g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); return; } @@ -109,140 +105,106 @@ object_cache_freed (gpointer data) static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { - if (GTK_IS_CONTAINER (widget)) - { - gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); - - if (increment) - recurse->count++; - - /* Okay, this is a little janky and all.. but some applications update some - * menuitem properties such as sensitivity on the activate callback. This - * seems a little weird, but it's not our place to judge when all this code - * is so crazy. So we're going to get ever crazier and activate all the - * menus that are directly below the menubar and force the applications to - * update their sensitivity. The menus won't actually popup in the app - * window due to our gtk+ patches. - * - * Note that this will not force menuitems in submenus to be updated as well. - */ - if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) - { - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - - for (; children != NULL; children = children->next) - { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } - - g_list_free (children); - } - - if (recurse->count > -1 && increment) - { - gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); - DbusmenuMenuitem *dmi = NULL; - if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); - if (dmi != NULL) - { - if (increment) - recurse->count--; - - return; - } - else - { - recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); - g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); + /* If this is a shell, then let's handle the items in it. */ + if (GTK_IS_MENU_SHELL (widget)) { + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + + if (recurse->parent == NULL) { + recurse->parent = dbusmenu_menuitem_new(); + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + return; + } + + if (GTK_IS_MENU_ITEM(widget)) { + DbusmenuMenuitem * thisitem = NULL; + + /* Check to see if we're cached already */ + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + if (pmi != NULL) { + thisitem = DBUSMENU_MENUITEM(pmi); + g_object_ref(G_OBJECT(thisitem)); + } + + /* We don't have one, so we'll need to build it */ + if (thisitem == NULL) { + thisitem = construct_dbusmenu_for_widget (widget); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, thisitem, object_cache_freed); + g_object_weak_ref(G_OBJECT(thisitem), dbusmenu_cache_freed, widget); + + if (!gtk_widget_get_visible (widget)) { + g_signal_connect (G_OBJECT (widget), + "notify::visible", + G_CALLBACK (menuitem_notify_cb), + recurse->toplevel); } - if (!gtk_widget_get_visible (widget)) - { - g_signal_connect (G_OBJECT (widget), - "notify::visible", - G_CALLBACK (menuitem_notify_cb), - recurse->toplevel); + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) { + dbusmenu_menuitem_property_set_bool (thisitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); } + } + + /* Check to see if we're in our parents list of children, if we have + a parent. */ + if (recurse->parent != NULL) { + GList * children = dbusmenu_menuitem_get_children (recurse->parent); + GList * peek = NULL; + + if (children != NULL) { + peek = g_list_find (children, thisitem); + } + + /* Oops, let's tell our parents about us */ + if (peek == NULL) { + /* TODO: Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (thisitem), + "dbusmenu-parent", + recurse->parent); + dbusmenu_menuitem_child_append (recurse->parent, + thisitem); + } + } + + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + if (menu != NULL) { + DbusmenuMenuitem * parent_save = recurse->parent; + recurse->parent = thisitem; + parse_menu_structure_helper (menu, recurse); + recurse->parent = parent_save; + } + + if (recurse->parent == NULL) { + recurse->parent = thisitem; + } else { + g_object_unref(thisitem); + } + } - if (GTK_IS_TEAROFF_MENU_ITEM (widget)) - { - dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], - DBUSMENU_MENUITEM_PROP_VISIBLE, - FALSE); - } - - if (recurse->count > 0) - { - GList *children = NULL; - GList *peek = NULL; - - if (recurse->stack[recurse->count - 1]) - { - children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - /* Should we set a weak ref on the parent? */ - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], - recurse->stack[recurse->count]); - } - } - else - { - DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, - gtk_widget_get_parent (widget)); */ - - if (item) - { - children = dbusmenu_menuitem_get_children (item); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - - dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); - } - } - } - } - } - - gtk_container_foreach (GTK_CONTAINER (widget), - (GtkCallback)parse_menu_structure_helper, - recurse); - - if (GTK_IS_MENU_ITEM (widget)) - { - GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); - - if (menu != NULL) - { - parse_menu_structure_helper (menu, recurse); - } - } - - if (increment) - recurse->count--; - } + return; } static DbusmenuMenuitem * -- cgit v1.2.3 From fe464dc002ed3e2e713f64145e689f66ad51f275 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 26 Jan 2011 16:13:56 -0600 Subject: Fix to the type of toggle-state to int --- libdbusmenu-gtk/parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5f0ef48..b1e7e01 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -522,9 +522,9 @@ action_notify_cb (GtkAction *action, } else if (pspec->name == g_intern_static_string ("active")) { - dbusmenu_menuitem_property_set_bool (mi, - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, - gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); } else if (pspec->name == g_intern_static_string ("label")) { -- cgit v1.2.3 From e5078ed1027e8c466d081183eeee6888b10ef510 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:27:50 -0600 Subject: No really, read the comment and make sure that only happens on the highest level --- libdbusmenu-gtk/parser.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index b1e7e01..27ac926 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,15 +118,17 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + if (recurse->parent == NULL) { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - for (; children != NULL; children = children->next) { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } - g_list_free (children); + g_list_free (children); + } if (recurse->parent == NULL) { recurse->parent = dbusmenu_menuitem_new(); -- cgit v1.2.3 From c6da3667cae61d1606eb66e6b7be01c2cbf9cbff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:53:54 -0600 Subject: Only activating on menu bars. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 27ac926..5dea9de 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,7 +118,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - if (recurse->parent == NULL) { + if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); for (; children != NULL; children = children->next) { -- cgit v1.2.3 From 1555d242f4e0214dd39dbd56e5cc6ddcf426e19b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 22:42:30 -0600 Subject: Actually setting the 'checked' value --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index ff2b3a7..00b2b90 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -751,6 +751,7 @@ set_use_fallback (GtkWidget * widget) if (!available) { g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); } + checked = TRUE; } if (available) { -- cgit v1.2.3 From 7e55758aa584a9e4080411cbd663d1fa30725a57 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:48:37 -0600 Subject: Adding documentation of the public API. --- libdbusmenu-gtk/parser.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5dea9de..8537a07 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -67,7 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); +/** + dbusmenu_gtk_parse_menu_structure: + @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem + Goes through the GTK structures and turns them into the appropraite + Dbusmenu structures along with setting up all the relationships + between the objects. It also stores the dbusmenu items as a cache + on the GTK items so that they'll be reused if necissary. + + Return value: A dbusmenu item representing the menu structure +*/ DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { -- cgit v1.2.3 From 321935e1678923454a97bcb41f9ddc6714e4ac88 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:50:24 -0600 Subject: Adding an early check on the type of widget coming into the function. --- libdbusmenu-gtk/parser.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8537a07..ead653a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -81,6 +81,8 @@ static void menuitem_notify_cb (GtkWidget * widget, DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + g_return_val_if_fail(GTK_IS_MENU_ITEM(widget) || GTK_IS_MENU_SHELL(widget), NULL); + RecurseContext recurse = {0}; recurse.toplevel = gtk_widget_get_toplevel(widget); -- cgit v1.2.3 From 49ecfc8c84d543491031aecbe64037e3fd76d366 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:28:44 -0600 Subject: Shortening function names to be more reasonable. --- libdbusmenu-gtk/serializablemenuitem.c | 10 +++++----- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index f67434e..cfd864d 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -166,7 +166,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } /** - dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_build_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring This function is for menu items that are instanciated from @@ -179,7 +179,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) set by this object. */ DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); @@ -207,7 +207,7 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); g_return_val_if_fail(smi != NULL, FALSE); - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtk_serializable_menu_item_set_menuitem(smi, newitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; @@ -265,7 +265,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /** - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_set_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of @mi: Menuitem to get the properties from @@ -276,7 +276,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, pick up this property being set. */ void -dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); g_return_if_fail(mi != NULL); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1ca3ef8..1d12dd4 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -99,9 +99,9 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); -void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); +void dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From 717e9a319cd430428c297d0777b45c64e4d7f5fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:40:30 -0600 Subject: Adding some naritive text describing the purpose --- libdbusmenu-gtk/serializablemenuitem.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1d12dd4..db28a24 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -90,6 +90,13 @@ struct _DbusmenuGtkSerializableMenuItemClass { DbusmenuGtkSerializableMenuItem: @parent: Inherit from GtkMenuItem @priv: Blind structure of private variables + + The Serializable Menuitem provides a way for menu items to be created + that can easily be picked up by the Dbusmenu GTK Parser. This way + you can create custom items, and transport them across dbusmenu to + your menus or the appmenu on the other side of the bus. By providing + these function the parser has enough information to both serialize, and + deserialize on the other side, the menuitem you've so carefully created. */ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From 07666d7543bfce7fe925c15d3350519fd711a8f0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:44:11 -0600 Subject: Fix changing prototypes. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 6d95f10..cdbc001 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -250,7 +250,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) use its own build function */ if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); - return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + return dbusmenu_gtk_serializable_menu_item_build_menuitem(smi); } /* If it's a standard GTK Menu Item we need to do some of our own work */ -- cgit v1.2.3 From 7be86c5778e58bbe231655ed58b7597ad61f5310 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 28 Jan 2011 14:35:36 -0500 Subject: notice new submenus --- libdbusmenu-gtk/parser.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5d71585..5f42ed5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -649,6 +649,27 @@ widget_notify_cb (GtkWidget *widget, } } } + else if (pspec->name == g_intern_static_string ("submenu")) + { + /* The underlying submenu got swapped out. Let's see what it is now. */ + /* First, delete any children that may exist currently. */ + DbusmenuMenuitem * item = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM)); + if (item != NULL) + { + GList * children = dbusmenu_menuitem_get_children (item); + while (children != NULL) { + dbusmenu_menuitem_child_delete (item, DBUSMENU_MENUITEM(children->data)); + children = children->next; + } + } + + /* Now parse new submenu. */ + GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + RecurseContext recurse = {0}; + recurse.toplevel = gtk_widget_get_toplevel(widget); + recurse.parent = item; + parse_menu_structure_helper(menu, &recurse); + } } static gboolean -- cgit v1.2.3 From db2d419d34f98cf8067bc97cda27b8687ce1be6c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 10:01:59 -0600 Subject: Disconnect realized handler when we don't care about the item anymore. --- libdbusmenu-gtk/menu.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 9c4f7f8..5231d0f 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -271,6 +271,10 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt #ifdef MASSIVEDEBUGGING g_debug("Root child deleted"); #endif + + /* Remove signal for realized */ + g_signal_handlers_disconnect_by_func(G_OBJECT(child), child_realized, menu); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); GtkWidget * item = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); if (item != NULL) { -- cgit v1.2.3 From d9b81a0645e15f03c89cae3466a3928d2b75c4ef Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 10:12:20 -0600 Subject: Keeping the root so that we can remove the signal handlers. --- libdbusmenu-gtk/menu.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 5231d0f..2a27fe2 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -46,6 +46,7 @@ enum { /* Private */ struct _DbusmenuGtkMenuPrivate { DbusmenuGtkClient * client; + DbusmenuMenuitem * root; gchar * dbus_object; gchar * dbus_name; @@ -63,6 +64,8 @@ static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * /* Internal */ static void build_client (DbusmenuGtkMenu * self); static void child_realized (DbusmenuMenuitem * child, gpointer userdata); +static void remove_child_signals (gpointer data, gpointer user_data); +static void root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGtkMenu * menu); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkMenu, dbusmenu_gtkmenu, GTK_TYPE_MENU); @@ -127,6 +130,12 @@ dbusmenu_gtkmenu_dispose (GObject *object) { DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(object); + /* Remove signals from the root */ + if (priv->root != NULL) { + /* This will clear the root */ + root_changed(priv->client, NULL, DBUSMENU_GTKMENU(object)); + } + if (priv->client != NULL) { g_object_unref(G_OBJECT(priv->client)); priv->client = NULL; @@ -273,7 +282,7 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt #endif /* Remove signal for realized */ - g_signal_handlers_disconnect_by_func(G_OBJECT(child), child_realized, menu); + remove_child_signals(child, menu); DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); GtkWidget * item = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); @@ -312,15 +321,41 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) return; } +/* Remove any signals we attached to children -- just realized right now */ +static void +remove_child_signals (gpointer data, gpointer user_data) +{ + g_signal_handlers_disconnect_by_func(G_OBJECT(data), child_realized, user_data); + return; +} + /* When the root menuitem changes we need to resetup things so that we're back in the game. */ static void root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGtkMenu * menu) { + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); + + /* Clear out our interest in the old root */ + if (priv->root != NULL) { + GList * children = dbusmenu_menuitem_get_children(priv->root); + g_list_foreach(children, remove_child_signals, menu); + + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_added, menu); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_moved, menu); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_delete, menu); + + g_object_unref(priv->root); + priv->root = NULL; + } + if (newroot == NULL) { gtk_widget_hide(GTK_WIDGET(menu)); return; } + priv->root = newroot; + g_object_ref(priv->root); + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(root_child_added), menu); g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(root_child_moved), menu); g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(root_child_delete), menu); -- cgit v1.2.3 From 591583b6e602b93399fd125da1f658146e5d717d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 11:55:39 -0600 Subject: Switching to take_children() so that we can ensure all the data remains valid --- libdbusmenu-gtk/parser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5f42ed5..4941bf4 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -656,11 +656,13 @@ widget_notify_cb (GtkWidget *widget, DbusmenuMenuitem * item = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM)); if (item != NULL) { - GList * children = dbusmenu_menuitem_get_children (item); - while (children != NULL) { - dbusmenu_menuitem_child_delete (item, DBUSMENU_MENUITEM(children->data)); - children = children->next; + GList * children = dbusmenu_menuitem_take_children (item); + GList * child = children; + while (child != NULL) { + g_object_unref (G_OBJECT(child->data)); + child = child->next; } + g_list_free(children); } /* Now parse new submenu. */ -- cgit v1.2.3 From 74a0afebe8d3c1fa28d969739ea5c718f00e8c0d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 12:08:57 -0600 Subject: Handle the case where we don't have a cached item. Not sure how that'd be, but we shouldn't let it drop. --- libdbusmenu-gtk/parser.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4941bf4..7e5e7e1 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -666,11 +666,19 @@ widget_notify_cb (GtkWidget *widget, } /* Now parse new submenu. */ - GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); RecurseContext recurse = {0}; recurse.toplevel = gtk_widget_get_toplevel(widget); recurse.parent = item; - parse_menu_structure_helper(menu, &recurse); + + if (item != NULL) { + GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + parse_menu_structure_helper(menu, &recurse); + } else { + /* Note: it would be really odd that we wouldn't have a cached + item, but we should handle that appropriately. */ + parse_menu_structure_helper(widget, &recurse); + g_object_unref(G_OBJECT(recurse.parent)); + } } } -- cgit v1.2.3 From a3da704b473f3ab75786501a6ec20d7b735fe8d9 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 2 Feb 2011 13:44:53 -0500 Subject: disconnect signals when done with menuitem --- libdbusmenu-gtk/parser.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 7e5e7e1..317dba2 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -102,6 +102,21 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); + + GtkWidget *widget = GTK_WIDGET(data); + GtkWidget *label = find_menu_label (widget); + if (label != NULL) { + g_signal_handlers_disconnect_by_func(label, G_CALLBACK(label_notify_cb), obj); + } + + if (GTK_IS_ACTIVATABLE (widget)) { + GtkAction *action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget)); + + if (action) { + g_signal_handlers_disconnect_by_func(action, G_CALLBACK(action_notify_cb), obj); + } + } + return; } -- cgit v1.2.3 From 51e68e1efe0eff4de283d2a0095357115ae514f4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 3 Feb 2011 08:43:56 -0500 Subject: keep track of objects that we set notifies for --- libdbusmenu-gtk/parser.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 317dba2..db1d8dd 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -31,6 +31,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" +#define PARSER_DATA "dbusmenu-gtk-parser-data" + +typedef struct _ParserData +{ + GtkWidget *label; + GtkAction *action; + GtkWidget *widget; +} ParserData; typedef struct _RecurseContext { @@ -103,18 +111,21 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); - GtkWidget *widget = GTK_WIDGET(data); - GtkWidget *label = find_menu_label (widget); - if (label != NULL) { - g_signal_handlers_disconnect_by_func(label, G_CALLBACK(label_notify_cb), obj); + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA); + + if (pdata != NULL && pdata->label != NULL) { + g_signal_handlers_disconnect_by_func(pdata->label, G_CALLBACK(label_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->label), (gpointer*)&pdata->label); } - if (GTK_IS_ACTIVATABLE (widget)) { - GtkAction *action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget)); + if (pdata != NULL && pdata->action != NULL) { + g_signal_handlers_disconnect_by_func(pdata->action, G_CALLBACK(action_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->action), (gpointer*)&pdata->action); + } - if (action) { - g_signal_handlers_disconnect_by_func(action, G_CALLBACK(action_notify_cb), obj); - } + if (pdata != NULL && pdata->widget != NULL) { + g_signal_handlers_disconnect_by_func(pdata->widget, G_CALLBACK(widget_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->widget), (gpointer*)&pdata->widget); } return; @@ -125,8 +136,10 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) static void object_cache_freed (gpointer data) { - if (!G_IS_OBJECT(data)) return; - g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); + // TODO: make this have access to both data and obj so we can call these + //if (!G_IS_OBJECT(obj)) return; + //g_object_weak_unref(G_OBJECT(obj), dbusmenu_cache_freed, data); + //dbusmenu_cache_freed(data, obj); return; } @@ -254,6 +267,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + ParserData *pdata = g_new0 (ParserData, 1); + g_object_set_data_full (G_OBJECT (mi), PARSER_DATA, pdata, g_free); + gboolean visible = FALSE; gboolean sensitive = FALSE; if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) @@ -328,10 +344,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. + pdata->label = label; g_signal_connect (G_OBJECT (label), "notify", G_CALLBACK (label_notify_cb), mi); + g_object_add_weak_pointer(G_OBJECT (label), (gpointer*)&pdata->label); } if (GTK_IS_ACTIVATABLE (widget)) @@ -347,10 +365,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) visible = gtk_action_is_visible (action); sensitive = gtk_action_is_sensitive (action); + pdata->action = action; g_signal_connect_object (action, "notify", G_CALLBACK (action_notify_cb), mi, G_CONNECT_AFTER); + g_object_add_weak_pointer(G_OBJECT (action), (gpointer*)&pdata->action); } } } @@ -382,10 +402,13 @@ construct_dbusmenu_for_widget (GtkWidget * widget) DBUSMENU_MENUITEM_PROP_ENABLED, sensitive); + pdata->widget = widget; g_signal_connect (widget, "notify", G_CALLBACK (widget_notify_cb), mi); + g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); + return mi; } -- cgit v1.2.3 From 4da7e99010b1dbf2a6f28660570e9ad79f538136 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 4 Feb 2011 14:05:52 -0500 Subject: watch for new menu items being added to existing menu shells --- libdbusmenu-gtk/parser.c | 97 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index db1d8dd..96418b3 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -38,6 +38,7 @@ typedef struct _ParserData GtkWidget *label; GtkAction *action; GtkWidget *widget; + GtkWidget *shell; } ParserData; typedef struct _RecurseContext @@ -63,6 +64,9 @@ static void label_notify_cb (GtkWidget * widget, static void action_notify_cb (GtkAction * action, GParamSpec * pspec, gpointer data); +static void child_added_cb (GtkContainer * menu, + GtkWidget * widget, + gpointer data); static void item_activated (DbusmenuMenuitem * item, guint timestamp, gpointer user_data); @@ -109,7 +113,6 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) /* If the dbusmenu item is killed we don't need to remove the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); - g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA); @@ -128,6 +131,11 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) g_object_remove_weak_pointer(G_OBJECT(pdata->widget), (gpointer*)&pdata->widget); } + if (pdata != NULL && pdata->shell != NULL) { + g_signal_handlers_disconnect_by_func(pdata->shell, G_CALLBACK(child_added_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->shell), (gpointer*)&pdata->shell); + } + return; } @@ -143,6 +151,45 @@ object_cache_freed (gpointer data) return; } +static gint +get_child_position (GtkWidget * child) +{ + GtkWidget * parent = gtk_widget_get_parent (child); + if (parent == NULL || !GTK_IS_CONTAINER (parent)) + return -1; + + GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); + GList * iter; + gint position = 0; + + for (iter = children; iter != NULL; iter = iter->next) { + if (iter->data == child) + break; + ++position; + } + + g_list_free (children); + + if (iter == NULL) + return -1; + else + return position; +} + +static DbusmenuMenuitem * +new_menuitem (GtkWidget * widget) +{ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + ParserData *pdata = g_new0 (ParserData, 1); + g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, g_free); + + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, item, object_cache_freed); + g_object_weak_ref(G_OBJECT(item), dbusmenu_cache_freed, widget); + + return item; +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -161,10 +208,11 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) */ if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + GList *iter; - for (; children != NULL; children = children->next) { + for (iter = children; iter != NULL; iter = iter->next) { gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, + iter->data, TRUE); } @@ -172,9 +220,18 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) } if (recurse->parent == NULL) { - recurse->parent = dbusmenu_menuitem_new(); + recurse->parent = new_menuitem(widget); } + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(recurse->parent), PARSER_DATA); + + pdata->shell = widget; + g_signal_connect (G_OBJECT (widget), + "child-added", + G_CALLBACK (child_added_cb), + recurse->parent); + g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->shell); + gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback)parse_menu_structure_helper, recurse); @@ -194,8 +251,6 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) /* We don't have one, so we'll need to build it */ if (thisitem == NULL) { thisitem = construct_dbusmenu_for_widget (widget); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, thisitem, object_cache_freed); - g_object_weak_ref(G_OBJECT(thisitem), dbusmenu_cache_freed, widget); if (!gtk_widget_get_visible (widget)) { g_signal_connect (G_OBJECT (widget), @@ -227,8 +282,14 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) g_object_set_data (G_OBJECT (thisitem), "dbusmenu-parent", recurse->parent); - dbusmenu_menuitem_child_append (recurse->parent, - thisitem); + gint pos = get_child_position (widget); + if (pos >= 0) + dbusmenu_menuitem_child_add_position (recurse->parent, + thisitem, + pos); + else + dbusmenu_menuitem_child_append (recurse->parent, + thisitem); } } @@ -265,10 +326,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { - DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + DbusmenuMenuitem *mi = new_menuitem(widget); - ParserData *pdata = g_new0 (ParserData, 1); - g_object_set_data_full (G_OBJECT (mi), PARSER_DATA, pdata, g_free); + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA); gboolean visible = FALSE; gboolean sensitive = FALSE; @@ -414,7 +474,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) /* If it's none of those we're going to just create a generic menuitem as a place holder for it. */ - return dbusmenu_menuitem_new(); + return new_menuitem(widget); } static void @@ -720,6 +780,19 @@ widget_notify_cb (GtkWidget *widget, } } +/* A child item was added to a menu we're watching. Let's try to integrate it. */ +static void +child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) +{ + DbusmenuMenuitem *menuitem = (DbusmenuMenuitem *)data; + + RecurseContext recurse = {0}; + recurse.toplevel = gtk_widget_get_toplevel(GTK_WIDGET(menu)); + recurse.parent = menuitem; + + parse_menu_structure_helper(widget, &recurse); +} + static gboolean should_show_image (GtkImage *image) { -- cgit v1.2.3