From 62b0fccd725b4e3c7b01e39258fd64dfa1d6064d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 10:54:48 -0500 Subject: Changing from using a transform to getting the contents --- tools/dbusmenu-dumper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 55d631e..68a21d9 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -36,11 +36,10 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * properties = dbusmenu_menuitem_properties_list(item); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { - GValue value = {0}; - g_value_init(&value, G_TYPE_STRING); - g_value_transform(dbusmenu_menuitem_property_get_value(item, (gchar *)property->data), &value); - g_print(",\n%s\"%s\": \"%s\"", space, (gchar *)property->data, g_value_get_string(&value)); - g_value_unset(&value); + const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); + gchar * str = g_strdup_value_contents(value); + g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str); + g_free(str); } g_list_free(properties); -- cgit v1.2.3 From e7ef77f7498d95f1f752aaca73f2dfdd935a0f44 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:07:31 -0500 Subject: Splitting out the collection printing. --- tools/dbusmenu-dumper.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 68a21d9..38284b1 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -25,8 +25,16 @@ with this program. If not, see . #include #include +#include + static GMainLoop * mainloop = NULL; +static gchar * +collection_dumper (const GValue * value) +{ + return g_strdup(""); +} + static void print_menuitem (DbusmenuMenuitem * item, int depth) { @@ -37,7 +45,12 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); - gchar * str = g_strdup_value_contents(value); + gchar * str = NULL; + if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { + str = collection_dumper(value); + } else { + str = g_strdup_value_contents(value); + } g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str); g_free(str); } -- cgit v1.2.3 From b13fe82d9d489e0c77cd4e8a9e09fce934d40865 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:14:28 -0500 Subject: Giving the depth as well so this can look nice. --- tools/dbusmenu-dumper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 38284b1..5790828 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -30,7 +30,7 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; static gchar * -collection_dumper (const GValue * value) +collection_dumper (const GValue * value, int depth) { return g_strdup(""); } @@ -47,7 +47,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth) const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); gchar * str = NULL; if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - str = collection_dumper(value); + str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2); } else { str = g_strdup_value_contents(value); } -- cgit v1.2.3 From 84e7a884a2f3c6bd480060235478beb50a38841e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:22:07 -0500 Subject: Printing more like we'd want a collection to print. --- tools/dbusmenu-dumper.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 5790828..1bf6e43 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -32,7 +32,19 @@ static GMainLoop * mainloop = NULL; static gchar * collection_dumper (const GValue * value, int depth) { - return g_strdup(""); + gchar * space = g_strnfill(depth, ' '); + GPtrArray * array = g_ptr_array_new_with_free_func(g_free); + + g_ptr_array_add(array, g_strdup("[\n")); + g_ptr_array_add(array, g_strdup_printf("%s\n", space)); + g_ptr_array_add(array, g_strdup_printf("%s]", space)); + + g_free(space); + + gchar * retstr = g_strjoinv(NULL, (gchar **)array->pdata); + g_ptr_array_free(array, TRUE); + + return retstr; } static void @@ -47,7 +59,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth) const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); gchar * str = NULL; if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2); + str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */); } else { str = g_strdup_value_contents(value); } -- cgit v1.2.3 From a359a31ffc36630c385ac9ebdf06b6f20e8401f6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:36:35 -0500 Subject: Now iterating through the collection and printing those entries out. --- tools/dbusmenu-dumper.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 1bf6e43..724ee25 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -29,15 +29,50 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; +typedef struct _collection_iterator_t collection_iterator_t; +struct _collection_iterator_t { + gchar * space; + GPtrArray * array; + gboolean first; +}; + +static void +collection_iterate (const GValue * value, gpointer user_data) +{ + collection_iterator_t * iter = (collection_iterator_t *)user_data; + + gchar * str = g_strdup_value_contents(value); + gchar * retval = NULL; + + if (iter->first) { + iter->first = FALSE; + retval = g_strdup_printf("\n%s%s", iter->space, str); + } else { + retval = g_strdup_printf(",\n%s%s", iter->space, str); + } + + g_ptr_array_add(iter->array, retval); + g_free(str); + + return; +} + static gchar * collection_dumper (const GValue * value, int depth) { gchar * space = g_strnfill(depth, ' '); GPtrArray * array = g_ptr_array_new_with_free_func(g_free); - g_ptr_array_add(array, g_strdup("[\n")); - g_ptr_array_add(array, g_strdup_printf("%s\n", space)); - g_ptr_array_add(array, g_strdup_printf("%s]", space)); + g_ptr_array_add(array, g_strdup("[")); + + collection_iterator_t iter; + iter.space = space; + iter.array = array; + iter.first = TRUE; + + dbus_g_type_collection_value_iterate(value, collection_iterate, &iter); + + g_ptr_array_add(array, g_strdup_printf("\n%s]", space)); g_free(space); -- cgit v1.2.3 From 84437fefcfda6157063210bbd9677298d62899b8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:45:56 -0500 Subject: Handling the printing of strv's as well. --- tools/dbusmenu-dumper.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 724ee25..4ce1374 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -29,6 +29,17 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; +static gchar * +strv_dumper(const GValue * value) +{ + gchar ** strv = (gchar **)g_value_get_boxed(value); + + gchar * joined = g_strjoinv("\", \"", strv); + gchar * retval = g_strdup_printf("[\"%s\"]", joined); + g_free(joined); + return retval; +} + typedef struct _collection_iterator_t collection_iterator_t; struct _collection_iterator_t { gchar * space; @@ -41,7 +52,13 @@ collection_iterate (const GValue * value, gpointer user_data) { collection_iterator_t * iter = (collection_iterator_t *)user_data; - gchar * str = g_strdup_value_contents(value); + gchar * str; + if (G_VALUE_TYPE(value) == G_TYPE_STRV) { + str = strv_dumper(value); + } else { + str = g_strdup_value_contents(value); + } + gchar * retval = NULL; if (iter->first) { -- cgit v1.2.3 From 057503a47f2dff7ea4863ffc1df939556cc1753f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:51:19 -0500 Subject: Abstracting out the choosing of how to dump the value. --- tools/dbusmenu-dumper.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 4ce1374..6af344d 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -29,6 +29,8 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; +static gchar * value2string (const GValue * value, int depth); + static gchar * strv_dumper(const GValue * value) { @@ -45,6 +47,7 @@ struct _collection_iterator_t { gchar * space; GPtrArray * array; gboolean first; + int depth; }; static void @@ -52,13 +55,7 @@ collection_iterate (const GValue * value, gpointer user_data) { collection_iterator_t * iter = (collection_iterator_t *)user_data; - gchar * str; - if (G_VALUE_TYPE(value) == G_TYPE_STRV) { - str = strv_dumper(value); - } else { - str = g_strdup_value_contents(value); - } - + gchar * str = value2string(value, iter->depth); gchar * retval = NULL; if (iter->first) { @@ -86,6 +83,7 @@ collection_dumper (const GValue * value, int depth) iter.space = space; iter.array = array; iter.first = TRUE; + iter.depth = depth + 2; dbus_g_type_collection_value_iterate(value, collection_iterate, &iter); @@ -99,6 +97,22 @@ collection_dumper (const GValue * value, int depth) return retstr; } +static gchar * +value2string (const GValue * value, int depth) +{ + gchar * str = NULL; + + if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { + str = collection_dumper(value, depth); + } else if (G_VALUE_TYPE(value) == G_TYPE_STRV) { + str = strv_dumper(value); + } else { + str = g_strdup_value_contents(value); + } + + return str; +} + static void print_menuitem (DbusmenuMenuitem * item, int depth) { @@ -109,12 +123,7 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); - gchar * str = NULL; - if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - str = collection_dumper(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */); - } else { - str = g_strdup_value_contents(value); - } + gchar * str = value2string(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */); g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str); g_free(str); } -- cgit v1.2.3 From aea8d2664195b8d5b6b77817a70c5955f9f32a8c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:55:22 -0500 Subject: Optimizing the one item in the collection case (common for shortcuts) --- tools/dbusmenu-dumper.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 6af344d..f0f4ba0 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -90,8 +90,14 @@ collection_dumper (const GValue * value, int depth) g_ptr_array_add(array, g_strdup_printf("\n%s]", space)); g_free(space); - - gchar * retstr = g_strjoinv(NULL, (gchar **)array->pdata); + + gchar * retstr = NULL; + if (array->len == 3) { + retstr = g_strdup_printf("[%s]", ((gchar *)array->pdata[1]) + depth + 1/*for newline*/); + } else { + retstr = g_strjoinv(NULL, (gchar **)array->pdata); + } + g_ptr_array_free(array, TRUE); return retstr; -- cgit v1.2.3 From a2d820e83b57e71a0b1305b52b1aff8162d6930d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 12:55:51 -0500 Subject: Adding an explicit null check. --- tools/dbusmenu-dumper.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index f0f4ba0..f2e2bec 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -108,6 +108,10 @@ value2string (const GValue * value, int depth) { gchar * str = NULL; + if (value == NULL) { + return g_strdup("(null)"); + } + if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { str = collection_dumper(value, depth); } else if (G_VALUE_TYPE(value) == G_TYPE_STRV) { -- cgit v1.2.3 From 3d291c9bd937b20511efbebb938b3a6b059e8b14 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 18:04:06 -0500 Subject: Have the proper case for booleans --- tools/dbusmenu-dumper.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index f2e2bec..6ce9655 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -116,6 +116,12 @@ value2string (const GValue * value, int depth) str = collection_dumper(value, depth); } else if (G_VALUE_TYPE(value) == G_TYPE_STRV) { str = strv_dumper(value); + } else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) { + if (g_value_get_boolean(value)) { + str = g_strdup("true"); + } else { + str = g_strdup("false"); + } } else { str = g_strdup_value_contents(value); } -- cgit v1.2.3 From 9f4213d9d59c84c9c4811a69ee50d4baaab6dc58 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Mon, 19 Jul 2010 12:53:38 +0200 Subject: Started to implement click-to-dump --- tools/Makefile.am | 4 +- tools/dbusmenu-dumper.c | 129 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 122 insertions(+), 11 deletions(-) (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index 77d6eef..a36d224 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -10,11 +10,11 @@ dbusmenu_dumper_SOURCES = \ dbusmenu_dumper_CFLAGS = \ -I $(srcdir)/.. \ - $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + $(DBUSMENUGLIB_CFLAGS) -I/usr/include/dbus-1.0 -Wall -Werror dbusmenu_dumper_LDADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ - $(DBUSMENUGLIB_LIBS) + $(DBUSMENUGLIB_LIBS) -lX11 -ldbus-glib-1 doc_DATA = README.dbusmenu-bench diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 55d631e..4a0dd03 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -21,10 +21,13 @@ with this program. If not, see . */ #include +#include #include #include +#include + static GMainLoop * mainloop = NULL; static void @@ -90,10 +93,104 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) return; } +static Window +find_real_window(Display * display, Window w, int depth) +{ + if (depth > 5) { + return None; + } + /*static*/ Atom wm_state = XInternAtom(display, "WM_STATE", False); + Atom type; + int format; + unsigned long nitems, after; + unsigned char* prop; + if (XGetWindowProperty(display, w, wm_state, 0, 0, False, AnyPropertyType, + &type, &format, &nitems, &after, &prop) == Success) { + if (prop != NULL) { + XFree(prop); + } + if (type != None) { + return w; + } + } + Window root, parent; + Window* children; + unsigned int nchildren; + Window ret = None; + if (XQueryTree(display, w, &root, &parent, &children, &nchildren) != 0) { + unsigned int i; + for(i = 0; i < nchildren && ret == None; ++i) { + ret = find_real_window(display, children[ i ], depth + 1); + } + if (children != NULL) { + XFree(children); + } + } + return ret; +} + +static Window +get_window_under_cursor() +{ + Display * display = XOpenDisplay(NULL); + g_return_val_if_fail(display != NULL, None); + + Window root; + Window child; + uint mask; + int rootX, rootY, winX, winY; + XGrabServer(display); + Window root_window = DefaultRootWindow(display); + XQueryPointer(display, root_window, &root, &child, &rootX, &rootY, &winX, &winY, &mask); + if (child == None) { + return None; + } + return find_real_window(display, child, 0); +} static gchar * dbusname = NULL; static gchar * dbusobject = NULL; +static gboolean +init_dbus_vars_from_window(Window window) +{ + DBusGConnection *connection; + GError *error; + DBusGProxy *proxy; + + error = NULL; + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (connection == NULL) { + g_printerr("Failed to open connection to bus: %s\n", error->message); + g_error_free(error); + return FALSE; + } + + proxy = dbus_g_proxy_new_for_name (connection, + "org.ayatana.AppMenu.Registrar", + "/org/ayatana/AppMenu/Registrar", + "org.ayatana.AppMenu.Registrar"); + + error = NULL; + if (!dbus_g_proxy_call (proxy, "GetMenuForWindow", &error, + G_TYPE_UINT, window, G_TYPE_INVALID, + G_TYPE_STRING, &dbusname, DBUS_TYPE_G_OBJECT_PATH, &dbusobject, G_TYPE_INVALID)) + { + g_printerr("ERROR: %s\n", error->message); + g_error_free(error); + g_object_unref(proxy); + return FALSE; + } + + if (!g_strcmp0(dbusobject, "/")) { + return FALSE; + } + + g_object_unref (proxy); + + return TRUE; +} + static gboolean option_dbusname (const gchar * arg, const gchar * value, gpointer data, GError ** error) { @@ -147,16 +244,30 @@ main (int argc, char ** argv) return 1; } - if (dbusname == NULL) { - g_printerr("ERROR: dbus-name not specified\n"); - usage(); - return 1; - } + if (dbusname == NULL && dbusobject == NULL) { + Window window = get_window_under_cursor(); + if (window == None) { + g_printerr("ERROR: could not get the id for the pointed window\n"); + return 1; + } + g_debug("window: %u", (unsigned int)window); + if (!init_dbus_vars_from_window(window)) { + g_printerr("ERROR: could not find a menu for the pointed window\n"); + return 1; + } + g_debug("dbusname: %s, dbusobject: %s", dbusname, dbusobject); + } else { + if (dbusname == NULL) { + g_printerr("ERROR: dbus-name not specified\n"); + usage(); + return 1; + } - if (dbusobject == NULL) { - g_printerr("ERROR: dbus-object not specified\n"); - usage(); - return 1; + if (dbusobject == NULL) { + g_printerr("ERROR: dbus-object not specified\n"); + usage(); + return 1; + } } DbusmenuClient * client = dbusmenu_client_new (dbusname, dbusobject); -- cgit v1.2.3 From 6da7a3341f028d913fd3ad01d47a59f436b5e780 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Mon, 19 Jul 2010 17:21:38 +0200 Subject: Use pkgconfig to find libx11 --- tools/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index a36d224..3cd5538 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -10,11 +10,11 @@ dbusmenu_dumper_SOURCES = \ dbusmenu_dumper_CFLAGS = \ -I $(srcdir)/.. \ - $(DBUSMENUGLIB_CFLAGS) -I/usr/include/dbus-1.0 -Wall -Werror + $(DBUSMENUGLIB_CFLAGS) $(DBUSMENUTOOLS_CFLAGS) -Wall -Werror dbusmenu_dumper_LDADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ - $(DBUSMENUGLIB_LIBS) -lX11 -ldbus-glib-1 + $(DBUSMENUGLIB_LIBS) $(DBUSMENUTOOLS_LIBS) doc_DATA = README.dbusmenu-bench -- cgit v1.2.3 From 646c74694e86d6e5d479028a7dbd8cf9a1aca37a Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 20 Jul 2010 14:51:23 +0200 Subject: Ripped some code from wnckprop to do proper click-to-dump --- tools/Makefile.am | 4 +- tools/dbusmenu-dumper.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index 3cd5538..ab7a598 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -10,11 +10,11 @@ dbusmenu_dumper_SOURCES = \ dbusmenu_dumper_CFLAGS = \ -I $(srcdir)/.. \ - $(DBUSMENUGLIB_CFLAGS) $(DBUSMENUTOOLS_CFLAGS) -Wall -Werror + $(DBUSMENUGLIB_CFLAGS) $(DBUSMENUDUMPER_CFLAGS) -Wall -Werror dbusmenu_dumper_LDADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ - $(DBUSMENUGLIB_LIBS) $(DBUSMENUTOOLS_LIBS) + $(DBUSMENUGLIB_LIBS) $(DBUSMENUDUMPER_LIBS) doc_DATA = README.dbusmenu-bench diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 4a0dd03..3a47f21 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -23,6 +23,10 @@ with this program. If not, see . #include #include +#include +#include +#include + #include #include @@ -93,6 +97,12 @@ new_root_cb (DbusmenuClient * client, DbusmenuMenuitem * newroot) return; } +/* Window clicking ***************************************************/ +static GdkFilterReturn +click_filter (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data); + static Window find_real_window(Display * display, Window w, int depth) { @@ -148,6 +158,91 @@ get_window_under_cursor() return find_real_window(display, child, 0); } +static void +uninstall_click_filter (void) +{ + GdkWindow *root; + + root = gdk_get_default_root_window (); + gdk_window_remove_filter (root, (GdkFilterFunc) click_filter, NULL); + + gdk_pointer_ungrab (GDK_CURRENT_TIME); + gdk_keyboard_ungrab (GDK_CURRENT_TIME); + + gtk_main_quit (); +} + +static GdkFilterReturn +click_filter (GdkXEvent *gdk_xevent, + GdkEvent *event, + gpointer data) + +{ + XEvent *xevent = (XEvent *) gdk_xevent; + gboolean *success = (gboolean *)data; + + switch (xevent->type) { + case ButtonPress: + uninstall_click_filter(); + *success = TRUE; + return GDK_FILTER_REMOVE; + case KeyPress: + if (xevent->xkey.keycode == XKeysymToKeycode(gdk_display, XK_Escape)) { + uninstall_click_filter(); + *success = FALSE; + return GDK_FILTER_REMOVE; + } + break; + default: + break; + } + + return GDK_FILTER_CONTINUE; +} + +static gboolean +install_click_filter (gpointer data) +{ + GdkGrabStatus status; + GdkCursor *cross; + GdkWindow *root; + + root = gdk_get_default_root_window(); + + gdk_window_add_filter(root, (GdkFilterFunc) click_filter, data); + + cross = gdk_cursor_new(GDK_CROSS); + status = gdk_pointer_grab(root, FALSE, GDK_BUTTON_PRESS_MASK, + NULL, cross, GDK_CURRENT_TIME); + gdk_cursor_unref(cross); + + if (status != GDK_GRAB_SUCCESS) { + g_warning("Pointer grab failed.\n"); + uninstall_click_filter(); + return FALSE; + } + + status = gdk_keyboard_grab(root, FALSE, GDK_CURRENT_TIME); + if (status != GDK_GRAB_SUCCESS) { + g_warning("Keyboard grab failed.\n"); + uninstall_click_filter(); + return FALSE; + } + + gdk_flush(); + return FALSE; +} + +static gboolean +wait_for_click (int argc, char **argv) +{ + gtk_init(&argc, &argv); + gboolean success; + g_idle_add (install_click_filter, (gpointer)(&success)); + gtk_main (); + return success; +} + static gchar * dbusname = NULL; static gchar * dbusobject = NULL; @@ -191,6 +286,7 @@ init_dbus_vars_from_window(Window window) return TRUE; } +/* Option parser *****************************************************/ static gboolean option_dbusname (const gchar * arg, const gchar * value, gpointer data, GError ** error) { @@ -245,6 +341,9 @@ main (int argc, char ** argv) } if (dbusname == NULL && dbusobject == NULL) { + if (!wait_for_click(argc, argv)) { + return 1; + } Window window = get_window_under_cursor(); if (window == None) { g_printerr("ERROR: could not get the id for the pointed window\n"); @@ -256,6 +355,7 @@ main (int argc, char ** argv) return 1; } g_debug("dbusname: %s, dbusobject: %s", dbusname, dbusobject); + return 1; } else { if (dbusname == NULL) { g_printerr("ERROR: dbus-name not specified\n"); -- cgit v1.2.3 From 463b05a77a8e21e60ffe197f58461b0fb02ed930 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 20 Jul 2010 14:58:16 +0200 Subject: Clean up --- tools/dbusmenu-dumper.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 3a47f21..4ddb057 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -104,17 +104,17 @@ click_filter (GdkXEvent *gdk_xevent, gpointer data); static Window -find_real_window(Display * display, Window w, int depth) +find_real_window (Window w, int depth) { if (depth > 5) { return None; } - /*static*/ Atom wm_state = XInternAtom(display, "WM_STATE", False); + /*static*/ Atom wm_state = XInternAtom(gdk_display, "WM_STATE", False); Atom type; int format; unsigned long nitems, after; unsigned char* prop; - if (XGetWindowProperty(display, w, wm_state, 0, 0, False, AnyPropertyType, + if (XGetWindowProperty(gdk_display, w, wm_state, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &prop) == Success) { if (prop != NULL) { XFree(prop); @@ -127,10 +127,10 @@ find_real_window(Display * display, Window w, int depth) Window* children; unsigned int nchildren; Window ret = None; - if (XQueryTree(display, w, &root, &parent, &children, &nchildren) != 0) { + if (XQueryTree(gdk_display, w, &root, &parent, &children, &nchildren) != 0) { unsigned int i; for(i = 0; i < nchildren && ret == None; ++i) { - ret = find_real_window(display, children[ i ], depth + 1); + ret = find_real_window(children[ i ], depth + 1); } if (children != NULL) { XFree(children); @@ -140,22 +140,17 @@ find_real_window(Display * display, Window w, int depth) } static Window -get_window_under_cursor() +get_window_under_cursor (void) { - Display * display = XOpenDisplay(NULL); - g_return_val_if_fail(display != NULL, None); - Window root; Window child; uint mask; int rootX, rootY, winX, winY; - XGrabServer(display); - Window root_window = DefaultRootWindow(display); - XQueryPointer(display, root_window, &root, &child, &rootX, &rootY, &winX, &winY, &mask); + XQueryPointer(gdk_display, gdk_x11_get_default_root_xwindow(), &root, &child, &rootX, &rootY, &winX, &winY, &mask); if (child == None) { return None; } - return find_real_window(display, child, 0); + return find_real_window(child, 0); } static void @@ -234,9 +229,8 @@ install_click_filter (gpointer data) } static gboolean -wait_for_click (int argc, char **argv) +wait_for_click (void) { - gtk_init(&argc, &argv); gboolean success; g_idle_add (install_click_filter, (gpointer)(&success)); gtk_main (); @@ -341,7 +335,8 @@ main (int argc, char ** argv) } if (dbusname == NULL && dbusobject == NULL) { - if (!wait_for_click(argc, argv)) { + gtk_init(&argc, &argv); + if (!wait_for_click()) { return 1; } Window window = get_window_under_cursor(); -- cgit v1.2.3 From 70961ba202ced579d434e19f185f442684814722 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Tue, 20 Jul 2010 15:03:39 +0200 Subject: Unbreak command line parser --- tools/dbusmenu-dumper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 4ddb057..82ca5c1 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -314,7 +314,8 @@ usage (void) static GOptionEntry general_options[] = { {"dbus-name", 'd', 0, G_OPTION_ARG_CALLBACK, option_dbusname, "The name of the program to connect to (i.e. org.test.bob", "dbusname"}, - {"dbus-object", 'o', 0, G_OPTION_ARG_CALLBACK, option_dbusobject, "The path to the Dbus object (i.e /org/test/bob/alvin)", "dbusobject"} + {"dbus-object", 'o', 0, G_OPTION_ARG_CALLBACK, option_dbusobject, "The path to the Dbus object (i.e /org/test/bob/alvin)", "dbusobject"}, + {NULL} }; int @@ -350,7 +351,6 @@ main (int argc, char ** argv) return 1; } g_debug("dbusname: %s, dbusobject: %s", dbusname, dbusobject); - return 1; } else { if (dbusname == NULL) { g_printerr("ERROR: dbus-name not specified\n"); -- cgit v1.2.3 From a68fa500006320df74beb336c5daf2f2f0950560 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Thu, 5 Aug 2010 19:05:51 +0200 Subject: debug-- --- tools/dbusmenu-dumper.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 40ab1e1..9e66236 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -445,12 +445,10 @@ main (int argc, char ** argv) g_printerr("ERROR: could not get the id for the pointed window\n"); return 1; } - g_debug("window: %u", (unsigned int)window); if (!init_dbus_vars_from_window(window)) { g_printerr("ERROR: could not find a menu for the pointed window\n"); return 1; } - g_debug("dbusname: %s, dbusobject: %s", dbusname, dbusobject); } else { if (dbusname == NULL) { g_printerr("ERROR: dbus-name not specified\n"); -- cgit v1.2.3 From e22b44483407aac56d6b50705bed890038e469a2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 12 Aug 2010 11:11:13 -0500 Subject: Making the dumper sort the properties to make it more predictable. --- tools/dbusmenu-dumper.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 9e66236..3256f7e 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -135,13 +135,20 @@ value2string (const GValue * value, int depth) return str; } +static gint +list_str_cmp (gconstpointer a, gconstpointer b) +{ + return g_strcmp0((gchar *)a, (gchar *)b); +} + static void print_menuitem (DbusmenuMenuitem * item, int depth) { gchar * space = g_strnfill(depth, ' '); g_print("%s\"id\": %d", space, dbusmenu_menuitem_get_id(item)); - GList * properties = dbusmenu_menuitem_properties_list(item); + GList * properties_raw = dbusmenu_menuitem_properties_list(item); + GList * properties = g_list_sort(properties_raw, list_str_cmp); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); -- 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 --- tools/testapp/Makefile.am | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/testapp/Makefile.am b/tools/testapp/Makefile.am index a8b42dd..39de532 100644 --- a/tools/testapp/Makefile.am +++ b/tools/testapp/Makefile.am @@ -1,4 +1,10 @@ +if USE_GTK3 +VER=3 +else +VER= +endif + libexec_PROGRAMS = dbusmenu-testapp dbusmenu_testapp_SOURCES = \ @@ -12,6 +18,6 @@ dbusmenu_testapp_CFLAGS = \ dbusmenu_testapp_LDADD = \ $(builddir)/../../libdbusmenu-glib/libdbusmenu-glib.la \ - $(builddir)/../../libdbusmenu-gtk/libdbusmenu-gtk.la \ + $(builddir)/../../libdbusmenu-gtk/libdbusmenu-gtk$(VER).la \ $(DBUSMENUGTK_LIBS) \ $(DBUSMENUTESTS_LIBS) -- cgit v1.2.3 From b856f7cd47db470f4369aa28ad87dc1925bf68a5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Nov 2010 16:31:51 -0600 Subject: Switching to getting the name with GDBus --- tools/testapp/main.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'tools') diff --git a/tools/testapp/main.c b/tools/testapp/main.c index f489407..67e962d 100644 --- a/tools/testapp/main.c +++ b/tools/testapp/main.c @@ -26,9 +26,7 @@ License version 3 and version 2.1 along with this program. If not, see */ #include - -#include -#include +#include #include @@ -117,6 +115,24 @@ void init_menu(DbusmenuMenuitem *root, const char *filename) } } +static void +on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data) +{ + DbusmenuServer *server = dbusmenu_server_new("/MenuBar"); + DbusmenuMenuitem *root = dbusmenu_menuitem_new_with_id(0); + init_menu(root, (gchar *)user_data); + dbusmenu_server_set_root(server, root); + + return; +} + +static void +name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data) +{ + g_error("Unable to get name '%s' on DBus", name); + return; +} + int main (int argc, char ** argv) { g_type_init(); @@ -127,25 +143,14 @@ int main (int argc, char ** argv) } const char *filename = argv[1]; - GError * error = NULL; - DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); - guint nameret = 0; - - if (!org_freedesktop_DBus_request_name(bus_proxy, "org.dbusmenu.test", 0, &nameret, &error)) { - g_error("Unable to call to request name"); - return 1; - } - - if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { - g_error("Unable to get name"); - return 1; - } - - DbusmenuServer *server = dbusmenu_server_new("/MenuBar"); - DbusmenuMenuitem *root = dbusmenu_menuitem_new_with_id(0); - init_menu(root, filename); - dbusmenu_server_set_root(server, root); + g_bus_own_name(G_BUS_TYPE_SESSION, + "org.dbusmenu.test", + G_BUS_NAME_OWNER_FLAGS_NONE, + on_bus, + NULL, + name_lost, + (gpointer)filename, + NULL); g_main_loop_run(g_main_loop_new(NULL, FALSE)); -- cgit v1.2.3 From e9e8e1c31e0a32e23e2526622d2435f60c24a084 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 11:12:28 -0600 Subject: Porting the dumper to GDBus --- tools/dbusmenu-dumper.c | 154 ++++++++++-------------------------------------- 1 file changed, 30 insertions(+), 124 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 3256f7e..4580e4c 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -21,7 +21,6 @@ with this program. If not, see . */ #include -#include #include #include @@ -30,111 +29,10 @@ with this program. If not, see . #include #include -#include #include static GMainLoop * mainloop = NULL; -static gchar * value2string (const GValue * value, int depth); - -static gchar * -strv_dumper(const GValue * value) -{ - gchar ** strv = (gchar **)g_value_get_boxed(value); - - gchar * joined = g_strjoinv("\", \"", strv); - gchar * retval = g_strdup_printf("[\"%s\"]", joined); - g_free(joined); - return retval; -} - -typedef struct _collection_iterator_t collection_iterator_t; -struct _collection_iterator_t { - gchar * space; - GPtrArray * array; - gboolean first; - int depth; -}; - -static void -collection_iterate (const GValue * value, gpointer user_data) -{ - collection_iterator_t * iter = (collection_iterator_t *)user_data; - - gchar * str = value2string(value, iter->depth); - gchar * retval = NULL; - - if (iter->first) { - iter->first = FALSE; - retval = g_strdup_printf("\n%s%s", iter->space, str); - } else { - retval = g_strdup_printf(",\n%s%s", iter->space, str); - } - - g_ptr_array_add(iter->array, retval); - g_free(str); - - return; -} - -static gchar * -collection_dumper (const GValue * value, int depth) -{ - gchar * space = g_strnfill(depth, ' '); - GPtrArray * array = g_ptr_array_new_with_free_func(g_free); - - g_ptr_array_add(array, g_strdup("[")); - - collection_iterator_t iter; - iter.space = space; - iter.array = array; - iter.first = TRUE; - iter.depth = depth + 2; - - dbus_g_type_collection_value_iterate(value, collection_iterate, &iter); - - g_ptr_array_add(array, g_strdup_printf("\n%s]", space)); - - g_free(space); - - gchar * retstr = NULL; - if (array->len == 3) { - retstr = g_strdup_printf("[%s]", ((gchar *)array->pdata[1]) + depth + 1/*for newline*/); - } else { - retstr = g_strjoinv(NULL, (gchar **)array->pdata); - } - - g_ptr_array_free(array, TRUE); - - return retstr; -} - -static gchar * -value2string (const GValue * value, int depth) -{ - gchar * str = NULL; - - if (value == NULL) { - return g_strdup("(null)"); - } - - if (dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - str = collection_dumper(value, depth); - } else if (G_VALUE_TYPE(value) == G_TYPE_STRV) { - str = strv_dumper(value); - } else if (G_VALUE_TYPE(value) == G_TYPE_BOOLEAN) { - if (g_value_get_boolean(value)) { - str = g_strdup("true"); - } else { - str = g_strdup("false"); - } - } else { - str = g_strdup_value_contents(value); - } - - return str; -} - static gint list_str_cmp (gconstpointer a, gconstpointer b) { @@ -151,10 +49,11 @@ print_menuitem (DbusmenuMenuitem * item, int depth) GList * properties = g_list_sort(properties_raw, list_str_cmp); GList * property; for (property = properties; property != NULL; property = g_list_next(property)) { - const GValue * value = dbusmenu_menuitem_property_get_value(item, (gchar *)property->data); - gchar * str = value2string(value, depth + g_utf8_strlen((gchar *)property->data, -1) + 2 /*quotes*/ + 2 /*: */); + GVariant * variant = dbusmenu_menuitem_property_get_variant(item, (gchar *)property->data); + gchar * str = g_variant_print(variant, FALSE); g_print(",\n%s\"%s\": %s", space, (gchar *)property->data, str); g_free(str); + g_variant_unref(variant); } g_list_free(properties); @@ -350,39 +249,46 @@ static gchar * dbusobject = NULL; static gboolean init_dbus_vars_from_window(Window window) { - DBusGConnection *connection; GError *error; - DBusGProxy *proxy; + GDBusProxy *proxy; error = NULL; - connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (connection == NULL) { - g_printerr("Failed to open connection to bus: %s\n", error->message); + + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.ayatana.AppMenu.Registrar", + "/org/ayatana/AppMenu/Registrar", + "org.ayatana.AppMenu.Registrar", + NULL, + &error); + if (error != NULL) { + g_warning("Unable to get registrar proxy: %s", error->message); g_error_free(error); return FALSE; } - proxy = dbus_g_proxy_new_for_name (connection, - "org.ayatana.AppMenu.Registrar", - "/org/ayatana/AppMenu/Registrar", - "org.ayatana.AppMenu.Registrar"); - error = NULL; - if (!dbus_g_proxy_call (proxy, "GetMenuForWindow", &error, - G_TYPE_UINT, window, G_TYPE_INVALID, - G_TYPE_STRING, &dbusname, DBUS_TYPE_G_OBJECT_PATH, &dbusobject, G_TYPE_INVALID)) - { - g_printerr("ERROR: %s\n", error->message); + GVariant * retval; + + retval = g_dbus_proxy_call_sync(proxy, + "GetMenuForWindow", + g_variant_new("u", window), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + + if (error != NULL) { + g_warning("Unable to call 'GetMenuForWindow' on registrar: %s", error->message); g_error_free(error); - g_object_unref(proxy); return FALSE; } - if (!g_strcmp0(dbusobject, "/")) { - return FALSE; - } + g_variant_get(retval, "so", &dbusname, &dbusobject); - g_object_unref (proxy); + g_variant_unref(retval); + g_object_unref(proxy); return TRUE; } -- cgit v1.2.3 From a8b425c5868c73739f60997ebc2013df3b3d6d4b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Jan 2011 09:53:15 -0600 Subject: Ayatana purge --- tools/dbusmenu-bench | 2 +- tools/dbusmenu-dumper.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-bench b/tools/dbusmenu-bench index 4b58da8..dcf5f6f 100755 --- a/tools/dbusmenu-bench +++ b/tools/dbusmenu-bench @@ -35,7 +35,7 @@ from xml.etree import ElementTree as ET import dbus -DBUS_INTERFACE = "org.ayatana.dbusmenu" +DBUS_INTERFACE = "com.canonical.dbusmenu" DBUS_SERVICE = "org.dbusmenu.test" DBUS_PATH = "/MenuBar" diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 4580e4c..bd986e8 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -257,9 +257,9 @@ init_dbus_vars_from_window(Window window) proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, - "org.ayatana.AppMenu.Registrar", - "/org/ayatana/AppMenu/Registrar", - "org.ayatana.AppMenu.Registrar", + "com.canonical.AppMenu.Registrar", + "/com/canonical/AppMenu/Registrar", + "com.canonical.AppMenu.Registrar", NULL, &error); if (error != NULL) { -- cgit v1.2.3 From 273fd4ea8fb0376256d773914786ebc433399c6f Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 16 Feb 2011 16:59:17 +0100 Subject: tools/dbusmenu-dumper: Proper GVariant handling of gdbus call to make this actually work --- tools/dbusmenu-dumper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index bd986e8..2db437d 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -270,10 +270,12 @@ init_dbus_vars_from_window(Window window) error = NULL; GVariant * retval; + GVariant * args[1]; + args[0] = g_variant_new("u", window); retval = g_dbus_proxy_call_sync(proxy, "GetMenuForWindow", - g_variant_new("u", window), + g_variant_new_tuple(args, 1), G_DBUS_CALL_FLAGS_NONE, -1, NULL, @@ -285,7 +287,7 @@ init_dbus_vars_from_window(Window window) return FALSE; } - g_variant_get(retval, "so", &dbusname, &dbusobject); + g_variant_get(retval, "(so)", &dbusname, &dbusobject); g_variant_unref(retval); g_object_unref(proxy); -- cgit v1.2.3