./0000755000004100000410000000000012772465331011255 5ustar www-datawww-data./Makefile.am.marshal0000644000004100000410000000223612772465331014742 0ustar www-datawww-data# Rules for generating marshal files using glib-genmarshal # # Define: # glib_marshal_list = marshal list file # glib_marshal_prefix = prefix for marshal functions # # before including Makefile.am.marshal. You will also need to have # the following targets already defined: # # CLEANFILES # DISTCLEANFILES # BUILT_SOURCES # EXTRA_DIST # # Author: Emmanuele Bassi marshal_h = $(glib_marshal_list:.list=.h) marshal_c = $(glib_marshal_list:.list=.c) CLEANFILES += stamp-marshal DISTCLEANFILES += $(marshal_h) $(marshal_c) BUILT_SOURCES += $(marshal_h) $(marshal_c) EXTRA_DIST += $(glib_marshal_list) stamp-marshal: $(glib_marshal_list) $(QUIET_GEN)$(GLIB_GENMARSHAL) \ --prefix=$(glib_marshal_prefix) \ --header \ $(srcdir)/$(glib_marshal_list) > xgen-mh \ && (cmp -s xgen-mh $(marshal_h) || cp -f xgen-mh $(marshal_h)) \ && rm -f xgen-mh \ && echo timestamp > $(@F) $(marshal_h): stamp-marshal @true $(marshal_c): $(marshal_h) $(QUIET_GEN)(echo "#include \"$(marshal_h)\"" ; \ $(GLIB_GENMARSHAL) \ --prefix=$(glib_marshal_prefix) \ --body \ $(srcdir)/$(glib_marshal_list)) > xgen-mc \ && cp xgen-mc $(marshal_c) \ && rm -f xgen-mc ./NEWS0000644000004100000410000000113212772465331011751 0ustar www-datawww-data12.10.3 - add the hud awareness protocol, an efficient way to notify applications that the HUD will open - fix hud match highlighting (lp #961000) 12.10.2 - support indicators based on gmenumodel (lp #1042824) - fix crash (lp #913324) 12.10.1 - add webapp support - port appmenu indicator to gtk_widget_insert_action_group() 12.10.0 - merge lp:~desrt/indicator-appmenu/no-zero-indicator-penalty to improve HUD's scoring algorithm - merge lp:~allanlesage/indicator-appmenu/TDD-fixes for gcov fixes, including docs fixes which broke linking. - raise GTK minimum to 3.0 ./configure.ac0000644000004100000410000001431412772465331013546 0ustar www-datawww-dataAC_INIT([indicator-appmenu], [15.02.0], [http://bugs.launchpad.net/indicator-appmenu], [indicator-appmenu], [http://launchpad.net/indicator-appmenu]) AC_COPYRIGHT([Copyright 2010 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([1.11 -Wall foreign subdir-objects]) AM_MAINTAINER_MODE([enable]) AM_SILENT_RULES([yes]) # Check for programs AC_PROG_CC AM_PROG_CC_C_O AM_PROG_VALAC([]) # Initialize libtool LT_PREREQ([2.2.6]) LT_INIT AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums]) AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal]) PKG_PROG_PKG_CONFIG AC_ARG_ENABLE([deprecations], [AS_HELP_STRING([--enable-deprecations], [allow deprecated API usage @<:@default=yes@:>@])], [], [enable_deprecations=yes]) AS_IF([test "x$enable_deprecations" = xno], [CFLAGS="$CFLAGS -DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE -DGTK_DISABLE_SINGLE_INCLUDES"] ) ########################### # GTK Doc ########################### GTK_DOC_CHECK([1.9], [--flavour=no-tmpl]) ########################### # GLib GSettings ########################### GLIB_GSETTINGS ########################### # Dependencies ########################### GLIB_REQUIRED_VERSION=2.35.4 GIO_REQUIRED_VERSION=2.26 GTK_REQUIRED_VERSION=3.0 INDICATOR_REQUIRED_VERSION=0.3.90 DBUSMENUGTK_REQUIRED_VERSION=0.5.90 BAMF_REQUIRED_VERSION=0.5.2 PKG_CHECK_MODULES(gtk, gtk+-3.0 >= $GTK_REQUIRED_VERSION) PKG_CHECK_MODULES(INDICATOR, glib-2.0 >= $GLIB_REQUIRED_VERSION gio-2.0 >= $GIO_REQUIRED_VERSION gtk+-3.0 >= $GTK_REQUIRED_VERSION indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libbamf3 >= $BAMF_REQUIRED_VERSION) AC_SUBST(INDICATOR_CFLAGS) AC_SUBST(INDICATOR_LIBS) ########################### # CLI Dependencies ########################### AC_CHECK_HEADER("readline/readline.h", [has_readline_h="yes"]) AC_CHECK_HEADER("readline/history.h", [has_history_h="yes"]) AC_CHECK_HEADER("curses.h", [has_curses_h="yes"]) AM_CONDITIONAL([BUILD_CLI], [test "x$has_readline_h" == "xyes" && test "x$has_history_h" == "xyes" && test "x$has_curses_h" == "xyes"]), ########################### # Test Dependencies ########################### DBUSMENU_JSONLOADER_REQUIRED_VERSION=0.3.3 LIBAPPINDICATOR_REQUIRED_VERSION=0.0.0 AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], [Disable test scripts and tools]),, [enable_tests=auto]) if test x"$enable_tests" != x"no" ; then PKG_CHECK_MODULES(INDICATORTEST, dbusmenu-jsonloader-0.4 >= $DBUSMENU_JSONLOADER_REQUIRED_VERSION appindicator3-0.1 >= $LIBAPPINDICATOR_REQUIRED_VERSION, [have_dbusmenu_jsonloader=yes], [have_dbusmenu_jsonloader=no] ) if test x${enable_tests} = xyes && test x${have_dbusmenu_jsonloader} = xno; then AC_MSG_ERROR([Test scripts and tools configured but dbusmenu-jsonloader not found]) fi else have_dbusmenu-jsonloader=no fi AM_CONDITIONAL(BUILD_TESTS, test x${have_dbusmenu_jsonloader} = xyes) AC_SUBST(INDICATORTEST_CFLAGS) AC_SUBST(INDICATORTEST_LIBS) ########################### # gcov coverage reporting ########################### m4_include([m4/gcov.m4]) AC_TDD_GCOV AM_CONDITIONAL([HAVE_GCOV], [test "x$ac_cv_check_gcov" = xyes]) AM_CONDITIONAL([HAVE_LCOV], [test "x$ac_cv_check_lcov" = xyes]) AM_CONDITIONAL([HAVE_GCOVR], [test "x$ac_cv_check_gcovr" = xyes]) AC_SUBST(COVERAGE_CFLAGS) AC_SUBST(COVERAGE_CXXFLAGS) AC_SUBST(COVERAGE_LDFLAGS) ########################### # XSLT Processor ########################### AC_PATH_PROG([XSLT_PROC], [xsltproc]) ########################### # Check to see if we're local ########################### with_localinstall="no" AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall], [install all of the files localy instead of system directories (for distcheck)]), with_localinstall=$enableval, with_localinstall=no) ########################### # Indicator Info ########################### if test "x$with_localinstall" = "xyes"; then INDICATORDIR="${libdir}/indicators/3/" INDICATORICONSDIR="${datadir}/libindicate/icons/" elif test "x$with_gtk" = x2; then INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator-0.4` INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator-0.4` else INDICATORDIR=`$PKG_CONFIG --variable=indicatordir indicator3-0.4` INDICATORICONSDIR=`$PKG_CONFIG --variable=iconsdir indicator3-0.4` fi AC_SUBST(INDICATORDIR) AC_SUBST(INDICATORICONSDIR) ########################### # DBus Service Info ########################### if test "x$with_localinstall" = "xyes"; then DBUSSERVICEDIR="${datadir}/dbus-1/services/" else DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1` fi AC_SUBST(DBUSSERVICEDIR) ############################## # Custom Junk ############################## AC_DEFUN([AC_DEFINE_PATH], [ test "x$prefix" = xNONE && prefix="$ac_default_prefix" test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' ac_define_path=`eval echo [$]$2` ac_define_path=`eval echo [$]ac_define_path` $1="$ac_define_path" AC_SUBST($1) ifelse($3, , AC_DEFINE_UNQUOTED($1, "$ac_define_path"), AC_DEFINE_UNQUOTED($1, "$ac_define_path", $3)) ]) ########################### # Internationalization ########################### GETTEXT_PACKAGE=indicator-appmenu IT_PROG_INTLTOOL([0.50.2]) AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Define to the gettext package name.]) AC_DEFINE_PATH(GNOMELOCALEDIR, "${datadir}/locale", [locale directory]) ########################### # Files ########################### AC_OUTPUT([ Makefile src/Makefile scripts/Makefile data/Makefile tools/Makefile po/Makefile.in tests/Makefile tests/manual/Makefile ]) ########################### # Results ########################### AC_MSG_NOTICE([ App Menu Indicator Configuration: Prefix: $prefix Indicator Dir: $INDICATORDIR gcov: $use_gcov Local Install: $with_localinstall Test tools: $have_dbusmenu_jsonloader ]) ./README0000644000004100000410000000000012772465331012123 0ustar www-datawww-data./scripts/0000755000004100000410000000000012772465331012744 5ustar www-datawww-data./scripts/menu-pusher.c0000644000004100000410000000647212772465331015371 0ustar www-datawww-data/* A test menu pusher to the appmenu. Copyright 2010 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include "../src/dbus-shared.h" int main (int argv, char ** argc) { gtk_init(&argv, &argc); DbusmenuMenuitem * root = dbusmenu_menuitem_new(); DbusmenuMenuitem * firstlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(firstlevel, DBUSMENU_MENUITEM_PROP_LABEL, "File"); dbusmenu_menuitem_child_append(root, firstlevel); DbusmenuMenuitem * secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Open"); dbusmenu_menuitem_property_set_shortcut_string(secondlevel, "O"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Save"); dbusmenu_menuitem_property_set_shortcut_string(secondlevel, "S"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Exit"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); firstlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(firstlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Edit"); dbusmenu_menuitem_child_append(root, firstlevel); secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Copy"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Paste"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); secondlevel = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(secondlevel, DBUSMENU_MENUITEM_PROP_LABEL, "Cut"); dbusmenu_menuitem_child_append(firstlevel, secondlevel); DbusmenuServer * server = dbusmenu_server_new("/this/is/a/long/object/path"); dbusmenu_server_set_root(server, root); GDBusProxy * proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, DBUS_NAME, REG_OBJECT, REG_IFACE, NULL, NULL); g_return_val_if_fail(proxy != NULL, 1); g_dbus_proxy_call_sync(proxy, "RegisterWindow", g_variant_new("(uo)", 0, "/this/is/a/long/object/path"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); gtk_main(); return 0; } ./scripts/Makefile.am0000644000004100000410000000032412772465331014777 0ustar www-datawww-data libexec_PROGRAMS = menu-pusher menu_pusher_SOURCES = \ menu-pusher.c menu_pusher_CFLAGS = \ $(INDICATOR_CFLAGS) \ -Wall \ -Werror -Wno-error=deprecated-declarations menu_pusher_LDADD = \ $(INDICATOR_LIBS) ./COPYING0000644000004100000410000010437412772465331012321 0ustar www-datawww-data GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ./src/0000755000004100000410000000000012772465331012044 5ustar www-datawww-data./src/window-menu-model.h0000644000004100000410000000403212772465331015563 0ustar www-datawww-data/* * Copyright © 2012 Canonical Limited * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the licence, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * * Author: Ted Gould */ #ifndef __WINDOW_MENU_MODEL_H__ #define __WINDOW_MENU_MODEL_H__ #include #include #include #include "window-menu.h" G_BEGIN_DECLS #define WINDOW_MENU_MODEL_TYPE (window_menu_model_get_type ()) #define WINDOW_MENU_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModel)) #define WINDOW_MENU_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass)) #define IS_WINDOW_MENU_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINDOW_MENU_MODEL_TYPE)) #define IS_WINDOW_MENU_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINDOW_MENU_MODEL_TYPE)) #define WINDOW_MENU_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINDOW_MENU_MODEL_TYPE, WindowMenuModelClass)) typedef struct _WindowMenuModel WindowMenuModel; typedef struct _WindowMenuModelClass WindowMenuModelClass; typedef struct _WindowMenuModelPrivate WindowMenuModelPrivate; struct _WindowMenuModelClass { WindowMenuClass parent_class; }; struct _WindowMenuModel { WindowMenu parent; WindowMenuModelPrivate * priv; }; GType window_menu_model_get_type (void); WindowMenuModel * window_menu_model_new (BamfApplication * app, BamfWindow * window); G_END_DECLS #endif ./src/application-menu-registrar.xml0000644000004100000410000000733212772465331020040 0ustar www-datawww-data An interface to register a menu from an application's window to be displayed in another window.  This manages that association between XWindow Window IDs and the dbus address and object that provides the menu using the dbusmenu dbus interface. The XWindow ID of the window The object on the dbus interface implementing the dbusmenu interface A method to allow removing a window from the database. Windows will also be removed when the client drops off DBus so this is not required. It is polite though. And important for testing. The XWindow ID of the window Gets the registered menu for a given window ID. The XWindow ID of the window to get The address of the connection on DBus (e.g. :1.23 or org.example.service) The path to the object which implements the com.canonical.dbusmenu interface. Gets the information on all menus that the registrar knows about. This is useful for debugging or bringing up a new renderer. An array of structures containing the same parameters as @GetMenuForWindow. Window ID, Service and ObjectPath. Signals when the registrar gets a new menu registered The XWindow ID of the window The address of the connection on DBus (e.g. :1.23 or org.example.service) The path to the object which implements the com.canonical.dbusmenu interface. Signals when the registrar removes a menu registration The XWindow ID of the window ./src/gdk-get-func.h0000644000004100000410000000011212772465331014462 0ustar www-datawww-datagboolean egg_xid_get_functions (Window window, GdkWMFunction *functions); ./src/window-menu.c0000644000004100000410000001553112772465331014466 0ustar www-datawww-data/* * Copyright © 2012 Canonical Limited * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the licence, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * * Author: Ted Gould */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "window-menu.h" #include "indicator-appmenu-marshal.h" #define WINDOW_MENU_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), WINDOW_MENU_TYPE, WindowMenuPrivate)) /* Signals */ enum { ENTRY_ADDED, ENTRY_REMOVED, ERROR_STATE, STATUS_CHANGED, SHOW_MENU, A11Y_UPDATE, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; /* Prototypes */ static void window_menu_class_init (WindowMenuClass *klass); static void window_menu_init (WindowMenu *self); static void window_menu_dispose (GObject *object); static void window_menu_finalize (GObject *object); G_DEFINE_TYPE (WindowMenu, window_menu, G_TYPE_OBJECT); static void window_menu_class_init (WindowMenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = window_menu_dispose; object_class->finalize = window_menu_finalize; /* Signals */ signals[ENTRY_ADDED] = g_signal_new(WINDOW_MENU_SIGNAL_ENTRY_ADDED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, entry_added), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); signals[ENTRY_REMOVED] = g_signal_new(WINDOW_MENU_SIGNAL_ENTRY_REMOVED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, entry_removed), NULL, NULL, g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER); signals[ERROR_STATE] = g_signal_new(WINDOW_MENU_SIGNAL_ERROR_STATE, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, error_state), NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN, G_TYPE_NONE); signals[STATUS_CHANGED] = g_signal_new(WINDOW_MENU_SIGNAL_STATUS_CHANGED, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, status_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT, G_TYPE_NONE); signals[SHOW_MENU] = g_signal_new(WINDOW_MENU_SIGNAL_SHOW_MENU, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, show_menu), NULL, NULL, _indicator_appmenu_marshal_VOID__POINTER_UINT, G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_NONE); signals[A11Y_UPDATE] = g_signal_new(WINDOW_MENU_SIGNAL_A11Y_UPDATE, G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (WindowMenuClass, a11y_update), NULL, NULL, _indicator_appmenu_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER, G_TYPE_NONE); return; } static void window_menu_init (WindowMenu *self) { return; } static void window_menu_dispose (GObject *object) { G_OBJECT_CLASS (window_menu_parent_class)->dispose (object); return; } static void window_menu_finalize (GObject *object) { G_OBJECT_CLASS (window_menu_parent_class)->finalize (object); return; } /************************** API **************************/ GList * window_menu_get_entries (WindowMenu * wm) { g_return_val_if_fail (IS_WINDOW_MENU(wm), NULL); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->get_entries != NULL) { return class->get_entries(wm); } else { return NULL; } } guint window_menu_get_location (WindowMenu * wm, IndicatorObjectEntry * entry) { g_return_val_if_fail (IS_WINDOW_MENU(wm), G_MAXUINT); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->get_location != NULL) { return class->get_location(wm, entry); } else { return G_MAXUINT; } } guint window_menu_get_xid (WindowMenu * wm) { g_return_val_if_fail (IS_WINDOW_MENU(wm), 0); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->get_xid != NULL) { return class->get_xid(wm); } else { return 0; } } gboolean window_menu_get_error_state (WindowMenu * wm) { g_return_val_if_fail (IS_WINDOW_MENU(wm), FALSE); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->get_error_state != NULL) { return class->get_error_state(wm); } else { return TRUE; } } WindowMenuStatus window_menu_get_status (WindowMenu * wm) { g_return_val_if_fail (IS_WINDOW_MENU(wm), WINDOW_MENU_STATUS_NORMAL); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->get_status != NULL) { return class->get_status(wm); } else { return WINDOW_MENU_STATUS_NORMAL; } } void window_menu_entry_restore (WindowMenu * wm, IndicatorObjectEntry * entry) { g_return_if_fail (IS_WINDOW_MENU(wm)); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->entry_restore != NULL) { return class->entry_restore(wm, entry); } else { return; } } void window_menu_entry_activate (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp) { g_return_if_fail (IS_WINDOW_MENU(wm)); WindowMenuClass * class = WINDOW_MENU_GET_CLASS(wm); if (class->entry_activate != NULL) { return class->entry_activate(wm, entry, timestamp); } else { return; } } ./src/window-menu-model.c0000644000004100000410000004404312772465331015564 0ustar www-datawww-data/* * Copyright © 2012 Canonical Limited * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the licence, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * * Author: Ted Gould */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include "window-menu-model.h" struct _WindowMenuModelPrivate { guint xid; GtkAccelGroup * accel_group; GActionGroup * app_actions; GActionGroup * win_actions; GActionGroup * unity_actions; /* Application Menu */ GDBusMenuModel * app_menu_model; IndicatorObjectEntry application_menu; gboolean has_application_menu; /* Window Menus */ GDBusMenuModel * win_menu_model; GtkMenuBar * win_menu; }; #define WINDOW_MENU_MODEL_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), WINDOW_MENU_MODEL_TYPE, WindowMenuModelPrivate)) /* Base class stuff */ static void window_menu_model_class_init (WindowMenuModelClass *klass); static void window_menu_model_init (WindowMenuModel *self); static void window_menu_model_dispose (GObject *object); /* Window Menu subclassin' */ static GList * get_entries (WindowMenu * wm); static guint get_location (WindowMenu * wm, IndicatorObjectEntry * entry); static WindowMenuStatus get_status (WindowMenu * wm); static gboolean get_error_state (WindowMenu * wm); static guint get_xid (WindowMenu * wm); /* GLib boilerplate */ G_DEFINE_TYPE (WindowMenuModel, window_menu_model, WINDOW_MENU_TYPE); /* Prefixes to the action muxer */ #define ACTION_MUX_PREFIX_APP "app" #define ACTION_MUX_PREFIX_WIN "win" #define ACTION_MUX_PREFIX_UNITY "unity" /* Entry data on the menuitem */ #define ENTRY_DATA "window-menu-model-menuitem-entry" static void window_menu_model_class_init (WindowMenuModelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (WindowMenuModelPrivate)); object_class->dispose = window_menu_model_dispose; WindowMenuClass * wm_class = WINDOW_MENU_CLASS(klass); wm_class->get_entries = get_entries; wm_class->get_location = get_location; wm_class->get_status = get_status; wm_class->get_error_state = get_error_state; wm_class->get_xid = get_xid; return; } static void window_menu_model_init (WindowMenuModel *self) { self->priv = WINDOW_MENU_MODEL_GET_PRIVATE(self); self->priv->accel_group = gtk_accel_group_new(); return; } static void window_menu_model_dispose (GObject *object) { WindowMenuModel * menu = WINDOW_MENU_MODEL(object); if (menu->priv->has_application_menu) { g_signal_emit_by_name(menu, WINDOW_MENU_SIGNAL_ENTRY_REMOVED, &menu->priv->application_menu); menu->priv->has_application_menu = FALSE; } g_clear_object(&menu->priv->accel_group); /* Application Menu */ g_clear_object(&menu->priv->app_menu_model); g_clear_object(&menu->priv->application_menu.label); g_clear_object(&menu->priv->application_menu.menu); /* Window Menus */ g_clear_object(&menu->priv->win_menu_model); if (menu->priv->win_menu) { g_signal_handlers_disconnect_by_data(menu->priv->win_menu, menu); gtk_widget_destroy (GTK_WIDGET (menu->priv->win_menu)); g_object_unref (menu->priv->win_menu); menu->priv->win_menu = NULL; } g_clear_object(&menu->priv->unity_actions); g_clear_object(&menu->priv->win_actions); g_clear_object(&menu->priv->app_actions); G_OBJECT_CLASS (window_menu_model_parent_class)->dispose (object); return; } /* Adds the application menu and turns the whole thing into an object entry that can be used elsewhere */ static void add_application_menu (WindowMenuModel * menu, const gchar * appname, GMenuModel * model) { g_return_if_fail(G_IS_MENU_MODEL(model)); menu->priv->app_menu_model = g_object_ref(model); menu->priv->application_menu.parent_window = menu->priv->xid; if (appname != NULL) { menu->priv->application_menu.label = GTK_LABEL(gtk_label_new(appname)); } else { menu->priv->application_menu.label = GTK_LABEL(gtk_label_new(_("Unknown Application Name"))); } g_object_ref_sink(menu->priv->application_menu.label); gtk_widget_show(GTK_WIDGET(menu->priv->application_menu.label)); menu->priv->application_menu.menu = GTK_MENU(gtk_menu_new_from_model(model)); if (menu->priv->app_actions) { gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->application_menu.menu), ACTION_MUX_PREFIX_APP, menu->priv->app_actions); } if (menu->priv->win_actions) { gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->application_menu.menu), ACTION_MUX_PREFIX_WIN, menu->priv->win_actions); } if (menu->priv->unity_actions) { gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->application_menu.menu), ACTION_MUX_PREFIX_UNITY, menu->priv->unity_actions); } gtk_widget_show(GTK_WIDGET(menu->priv->application_menu.menu)); g_object_ref_sink(menu->priv->application_menu.menu); menu->priv->has_application_menu = TRUE; g_signal_emit_by_name(menu, WINDOW_MENU_SIGNAL_ENTRY_ADDED, &menu->priv->application_menu); } /* Find the label in a GTK MenuItem */ GtkLabel * mi_find_label (GtkWidget * mi) { if (GTK_IS_LABEL(mi)) { return GTK_LABEL(mi); } GtkLabel * retval = NULL; if (GTK_IS_CONTAINER(mi)) { GList * children = gtk_container_get_children(GTK_CONTAINER(mi)); GList * child = children; while (child != NULL && retval == NULL) { if (GTK_IS_WIDGET(child->data)) { retval = mi_find_label(GTK_WIDGET(child->data)); } child = g_list_next(child); } g_list_free(children); } return retval; } /* Find the icon in a GTK MenuItem */ GtkImage * mi_find_icon (GtkWidget * mi) { if (GTK_IS_IMAGE(mi)) { return GTK_IMAGE(mi); } GtkImage * retval = NULL; if (GTK_IS_CONTAINER(mi)) { GList * children = gtk_container_get_children(GTK_CONTAINER(mi)); GList * child = children; while (child != NULL && retval == NULL) { if (GTK_IS_WIDGET(child->data)) { retval = mi_find_icon(GTK_WIDGET(child->data)); } child = g_list_next(child); } g_list_free(children); } return retval; } /* Check the menu and make sure we return it if it's a menu all proper like that */ GtkMenu * mi_find_menu (GtkMenuItem * mi) { GtkWidget * retval = gtk_menu_item_get_submenu(mi); if (GTK_IS_MENU(retval)) { return GTK_MENU(retval); } else { return NULL; } } typedef struct _WindowMenuEntry WindowMenuEntry; struct _WindowMenuEntry { IndicatorObjectEntry entry; GtkMenuItem * gmi; }; /* Sync the menu label changing to the label object */ static void entry_label_notify (GObject * obj, GParamSpec * pspec, gpointer user_data) { g_return_if_fail(GTK_IS_MENU_ITEM(obj)); GtkMenuItem * gmi = GTK_MENU_ITEM(obj); WindowMenuEntry * entry = (WindowMenuEntry *)user_data; if (entry->entry.label != NULL) { const gchar * label = gtk_menu_item_get_label(gmi); gtk_label_set_label(entry->entry.label, label); } return; } /* Watch for visible changes and ensure they can be picked up by the indicator object host */ static void entry_visible_notify (GObject * obj, GParamSpec * pspec, gpointer user_data) { g_return_if_fail(GTK_IS_WIDGET(obj)); GtkWidget * widget = GTK_WIDGET(obj); WindowMenuEntry * entry = (WindowMenuEntry *)user_data; gboolean visible = gtk_widget_get_visible(widget); if (entry->entry.label != NULL) { gtk_widget_set_visible(GTK_WIDGET(entry->entry.label), visible); } if (entry->entry.image != NULL) { gtk_widget_set_visible(GTK_WIDGET(entry->entry.image), visible); } return; } /* Watch for sensitive changes and ensure they can be picked up by the indicator object host */ static void entry_sensitive_notify (GObject * obj, GParamSpec * pspec, gpointer user_data) { g_return_if_fail(GTK_IS_WIDGET(obj)); GtkWidget * widget = GTK_WIDGET(obj); WindowMenuEntry * entry = (WindowMenuEntry *)user_data; gboolean sensitive = gtk_widget_get_sensitive(widget); if (entry->entry.label != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->entry.label), sensitive); } if (entry->entry.image != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->entry.image), sensitive); } return; } /* Destroy and unref the items of the object entry */ static void entry_object_free (gpointer inentry) { WindowMenuEntry * entry = (WindowMenuEntry *)inentry; g_signal_handlers_disconnect_by_data(entry->gmi, entry); g_clear_object(&entry->entry.label); g_clear_object(&entry->entry.image); g_clear_object(&entry->entry.menu); g_free(entry); return; } /* Put an entry on a menu item */ static void entry_on_menuitem (WindowMenuModel * menu, GtkMenuItem * gmi) { WindowMenuEntry * entry = g_new0(WindowMenuEntry, 1); entry->gmi = gmi; entry->entry.parent_window = menu->priv->xid; entry->entry.label = mi_find_label(GTK_WIDGET(gmi)); entry->entry.image = mi_find_icon(GTK_WIDGET(gmi)); entry->entry.menu = mi_find_menu(gmi); if (entry->entry.label == NULL && entry->entry.image == NULL) { const gchar * label = gtk_menu_item_get_label(gmi); if (label == NULL) { g_warning("Item doesn't have a label or an image, aborting"); return; } entry->entry.label = GTK_LABEL(gtk_label_new(label)); gtk_widget_show(GTK_WIDGET(entry->entry.label)); g_signal_connect(G_OBJECT(gmi), "notify::label", G_CALLBACK(entry_label_notify), entry); } if (entry->entry.label != NULL) { g_object_ref_sink(entry->entry.label); } if (entry->entry.image != NULL) { g_object_ref_sink(entry->entry.image); } if (entry->entry.menu != NULL) { g_object_ref_sink(entry->entry.menu); } g_signal_connect(G_OBJECT(gmi), "notify::sensitive", G_CALLBACK(entry_sensitive_notify), entry); g_signal_connect(G_OBJECT(gmi), "notify::visible", G_CALLBACK(entry_visible_notify), entry); g_object_set_data_full(G_OBJECT(gmi), ENTRY_DATA, entry, entry_object_free); return; } /* A child item was added to a menu we're watching. Let's try to integrate it. */ static void item_inserted_cb (GtkContainer *menu, GtkWidget *widget, gint position, gpointer data) { if (g_object_get_data(G_OBJECT(widget), ENTRY_DATA) == NULL) { entry_on_menuitem(WINDOW_MENU_MODEL(data), GTK_MENU_ITEM(widget)); } if (g_object_get_data(G_OBJECT(widget), ENTRY_DATA) != NULL) { g_signal_emit_by_name(data, WINDOW_MENU_SIGNAL_ENTRY_ADDED, g_object_get_data(G_OBJECT(widget), ENTRY_DATA)); } return; } /* A child item was removed from a menu we're watching. */ static void item_removed_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) { g_signal_emit_by_name(data, WINDOW_MENU_SIGNAL_ENTRY_REMOVED, g_object_get_data(G_OBJECT(widget), ENTRY_DATA)); } /* Adds the window menu and turns it into a set of IndicatorObjectEntries that can be used elsewhere */ static void add_window_menu (WindowMenuModel * menu, GMenuModel * model) { menu->priv->win_menu_model = g_object_ref(model); menu->priv->win_menu = GTK_MENU_BAR(gtk_menu_bar_new_from_model(model)); g_assert(menu->priv->win_menu != NULL); g_object_ref_sink(menu->priv->win_menu); if (menu->priv->app_actions) gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->win_menu), ACTION_MUX_PREFIX_APP, menu->priv->app_actions); if (menu->priv->win_actions) gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->win_menu), ACTION_MUX_PREFIX_WIN, menu->priv->win_actions); if (menu->priv->unity_actions) gtk_widget_insert_action_group(GTK_WIDGET(menu->priv->win_menu), ACTION_MUX_PREFIX_UNITY, menu->priv->unity_actions); g_signal_connect(G_OBJECT(menu->priv->win_menu), "insert", G_CALLBACK (item_inserted_cb), menu); g_signal_connect(G_OBJECT(menu->priv->win_menu), "remove", G_CALLBACK (item_removed_cb), menu); GList * children = gtk_container_get_children(GTK_CONTAINER(menu->priv->win_menu)); GList * child; for (child = children; child != NULL; child = g_list_next(child)) { GtkMenuItem * gmi = GTK_MENU_ITEM(child->data); if (gmi == NULL) { continue; } entry_on_menuitem(menu, gmi); } g_list_free(children); return; } /* Builds the menu model from the window for the application */ WindowMenuModel * window_menu_model_new (BamfApplication * app, BamfWindow * window) { g_return_val_if_fail(BAMF_IS_APPLICATION(app), NULL); g_return_val_if_fail(BAMF_IS_WINDOW(window), NULL); WindowMenuModel * menu = g_object_new(WINDOW_MENU_MODEL_TYPE, NULL); menu->priv->xid = bamf_window_get_xid(window); gchar *unique_bus_name; gchar *app_menu_object_path; gchar *menubar_object_path; gchar *application_object_path; gchar *window_object_path; gchar *unity_object_path; GDBusConnection *session; unique_bus_name = bamf_window_get_utf8_prop (window, "_GTK_UNIQUE_BUS_NAME"); if (unique_bus_name == NULL) { /* If this isn't set, we won't get very far... */ return NULL; } app_menu_object_path = bamf_window_get_utf8_prop (window, "_GTK_APP_MENU_OBJECT_PATH"); menubar_object_path = bamf_window_get_utf8_prop (window, "_GTK_MENUBAR_OBJECT_PATH"); application_object_path = bamf_window_get_utf8_prop (window, "_GTK_APPLICATION_OBJECT_PATH"); window_object_path = bamf_window_get_utf8_prop (window, "_GTK_WINDOW_OBJECT_PATH"); unity_object_path = bamf_window_get_utf8_prop (window, "_UNITY_OBJECT_PATH"); session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); /* Setup actions */ if (application_object_path != NULL) { menu->priv->app_actions = G_ACTION_GROUP(g_dbus_action_group_get (session, unique_bus_name, application_object_path)); } if (window_object_path != NULL) { menu->priv->win_actions = G_ACTION_GROUP(g_dbus_action_group_get (session, unique_bus_name, window_object_path)); } if (unity_object_path != NULL) { menu->priv->unity_actions = G_ACTION_GROUP(g_dbus_action_group_get (session, unique_bus_name, unity_object_path)); } /* Build us some menus */ if (app_menu_object_path != NULL) { const gchar * desktop_path = bamf_application_get_desktop_file(app); gchar * app_name = NULL; if (desktop_path != NULL) { GDesktopAppInfo * desktop = g_desktop_app_info_new_from_filename(desktop_path); if (desktop != NULL) { app_name = g_strdup(g_app_info_get_name(G_APP_INFO(desktop))); g_object_unref(desktop); } } GMenuModel * model = G_MENU_MODEL(g_dbus_menu_model_get (session, unique_bus_name, app_menu_object_path)); add_application_menu(menu, app_name, model); g_object_unref(model); g_free(app_name); } if (menubar_object_path != NULL) { GMenuModel * model = G_MENU_MODEL(g_dbus_menu_model_get (session, unique_bus_name, menubar_object_path)); add_window_menu(menu, model); g_object_unref(model); } /* when the action groups change, we could end up having items * enabled/disabled. how to deal with that? */ g_free (unique_bus_name); g_free (app_menu_object_path); g_free (menubar_object_path); g_free (application_object_path); g_free (window_object_path); g_free (unity_object_path); g_object_unref (session); return menu; } /* Get the list of entries */ static GList * get_entries (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_MODEL(wm), NULL); WindowMenuModel * menu = WINDOW_MENU_MODEL(wm); GList * ret = NULL; if (menu->priv->has_application_menu) { ret = g_list_append(ret, &menu->priv->application_menu); } if (menu->priv->win_menu != NULL) { GList * children = gtk_container_get_children(GTK_CONTAINER(menu->priv->win_menu)); GList * child; for (child = children; child != NULL; child = g_list_next(child)) { gpointer entry = g_object_get_data(child->data, ENTRY_DATA); if (entry == NULL) { /* Try to build the entry, it is possible (but unlikely) that we could beat the signal that this isn't created. So we'll just handle that race here */ entry_on_menuitem(menu, GTK_MENU_ITEM(child->data)); entry = g_object_get_data(child->data, ENTRY_DATA); } if (entry != NULL) { ret = g_list_append(ret, entry); } } g_list_free(children); } return ret; } /* Find the location of an entry */ static guint get_location (WindowMenu * wm, IndicatorObjectEntry * entry) { g_return_val_if_fail(IS_WINDOW_MENU_MODEL(wm), 0); WindowMenuModel * menu = WINDOW_MENU_MODEL(wm); gboolean found = FALSE; guint pos = 0; if (menu->priv->has_application_menu) { if (entry == &menu->priv->application_menu) { pos = 0; found = TRUE; } else { /* We need to put a shift in if there is an application menu and we're not looking for that one */ pos = 1; } } if (menu->priv->win_menu != NULL) { GList * children = gtk_container_get_children(GTK_CONTAINER(menu->priv->win_menu)); GList * child; for (child = children; child != NULL; child = g_list_next(child), pos++) { gpointer lentry = g_object_get_data(child->data, ENTRY_DATA); if (entry == lentry) { found = TRUE; break; } } g_list_free(children); } if (!found) { /* NOTE: Not printing any of the values here because there's a pretty good chance that they're not valid. Let's not crash things here. */ pos = G_MAXUINT; g_warning("Unable to find entry: %p", entry); } return pos; } /* Get's the status of the application to whether underlines should be shown to the application. GMenuModel doesn't give us this info. */ static WindowMenuStatus get_status (WindowMenu * wm) { return WINDOW_MENU_STATUS_NORMAL; } /* Says whether the application is in error, GMenuModel doesn't give us this information on the app */ static gboolean get_error_state (WindowMenu * wm) { return FALSE; } /* Get the XID of this guy */ static guint get_xid (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_MODEL(wm), 0); return WINDOW_MENU_MODEL(wm)->priv->xid; } ./src/clean-namespaces.xslt0000644000004100000410000000067612772465331016170 0ustar www-datawww-data ./src/indicator-appmenu-marshal.list0000644000004100000410000000010712772465331020003 0ustar www-datawww-dataVOID: UINT, STRING, BOXED VOID: UINT VOID: POINTER, UINT VOID: POINTER ./src/dbus-shared.h0000644000004100000410000000177012772465331014423 0ustar www-datawww-data/* An implementation of indicator object showing menus from applications. Copyright 2010 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define DBUS_NAME "com.canonical.AppMenu.Registrar" #define REG_IFACE "com.canonical.AppMenu.Registrar" #define REG_OBJECT "/com/canonical/AppMenu/Registrar" #define DEBUG_IFACE "com.canonical.AppMenu.Renderer" #define DEBUG_OBJECT "/com/canonical/AppMenu/Renderer" ./src/MwmUtil.h0000644000004100000410000000730012772465331013613 0ustar www-datawww-data/* * * $Id$ * * Copyright (C) 1995 Free Software Foundation, Inc. * * This file is part of the GNU LessTif Library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * * * Feb 21 1999 - George Lebl (jirka@5z.com) * Owen Taylor (otaylor@redhat.com) * * Modified so that the MotifWmHints structure defined here * is suitable for client side use on 64-bit architectures. * X expects fields with a format of 32 to be longs, even * when sizeof(long) == 8. */ #ifndef MWMUTIL_H_INCLUDED #define MWMUTIL_H_INCLUDED #include G_BEGIN_DECLS typedef struct { unsigned long flags; unsigned long functions; unsigned long decorations; long input_mode; unsigned long status; } MotifWmHints, MwmHints; #define MWM_HINTS_FUNCTIONS (1L << 0) #define MWM_HINTS_DECORATIONS (1L << 1) #define MWM_HINTS_INPUT_MODE (1L << 2) #define MWM_HINTS_STATUS (1L << 3) #define MWM_FUNC_ALL (1L << 0) #define MWM_FUNC_RESIZE (1L << 1) #define MWM_FUNC_MOVE (1L << 2) #define MWM_FUNC_MINIMIZE (1L << 3) #define MWM_FUNC_MAXIMIZE (1L << 4) #define MWM_FUNC_CLOSE (1L << 5) #define MWM_DECOR_ALL (1L << 0) #define MWM_DECOR_BORDER (1L << 1) #define MWM_DECOR_RESIZEH (1L << 2) #define MWM_DECOR_TITLE (1L << 3) #define MWM_DECOR_MENU (1L << 4) #define MWM_DECOR_MINIMIZE (1L << 5) #define MWM_DECOR_MAXIMIZE (1L << 6) #define MWM_INPUT_MODELESS 0 #define MWM_INPUT_PRIMARY_APPLICATION_MODAL 1 #define MWM_INPUT_SYSTEM_MODAL 2 #define MWM_INPUT_FULL_APPLICATION_MODAL 3 #define MWM_INPUT_APPLICATION_MODAL MWM_INPUT_PRIMARY_APPLICATION_MODAL #define MWM_TEAROFF_WINDOW (1L<<0) /* * atoms */ #define _XA_MOTIF_BINDINGS "_MOTIF_BINDINGS" #define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS" #define _XA_MOTIF_WM_MESSAGES "_MOTIF_WM_MESSAGES" #define _XA_MOTIF_WM_OFFSET "_MOTIF_WM_OFFSET" #define _XA_MOTIF_WM_MENU "_MOTIF_WM_MENU" #define _XA_MOTIF_WM_INFO "_MOTIF_WM_INFO" #define _XA_MWM_HINTS _XA_MOTIF_WM_HINTS #define _XA_MWM_MESSAGES _XA_MOTIF_WM_MESSAGES #define _XA_MWM_MENU _XA_MOTIF_WM_MENU #define _XA_MWM_INFO _XA_MOTIF_WM_INFO /* * _MWM_INFO property */ typedef struct { long flags; Window wm_window; } MotifWmInfo; typedef MotifWmInfo MwmInfo; #define MWM_INFO_STARTUP_STANDARD (1L<<0) #define MWM_INFO_STARTUP_CUSTOM (1L<<1) /* * _MWM_HINTS property */ typedef struct { unsigned long flags; unsigned long functions; unsigned long decorations; long inputMode; unsigned long status; } PropMotifWmHints; typedef PropMotifWmHints PropMwmHints; #define PROP_MOTIF_WM_HINTS_ELEMENTS 5 #define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS /* * _MWM_INFO property, slight return */ typedef struct { unsigned long flags; unsigned long wmWindow; } PropMotifWmInfo; typedef PropMotifWmInfo PropMwmInfo; #define PROP_MOTIF_WM_INFO_ELEMENTS 2 #define PROP_MWM_INFO_ELEMENTS PROP_MOTIF_WM_INFO_ELEMENTS G_END_DECLS #endif /* MWMUTIL_H_INCLUDED */ ./src/window-menu.h0000644000004100000410000000723512772465331014475 0ustar www-datawww-data/* An implementation of indicator object showing menus from applications. Copyright 2012 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef __WINDOW_MENU_H__ #define __WINDOW_MENU_H__ #include #include G_BEGIN_DECLS #define WINDOW_MENU_TYPE (window_menu_get_type ()) #define WINDOW_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINDOW_MENU_TYPE, WindowMenu)) #define WINDOW_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINDOW_MENU_TYPE, WindowMenuClass)) #define IS_WINDOW_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINDOW_MENU_TYPE)) #define IS_WINDOW_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINDOW_MENU_TYPE)) #define WINDOW_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINDOW_MENU_TYPE, WindowMenuClass)) #define WINDOW_MENU_SIGNAL_ENTRY_ADDED "entry-added" #define WINDOW_MENU_SIGNAL_ENTRY_REMOVED "entry-removed" #define WINDOW_MENU_SIGNAL_ERROR_STATE "error-state" #define WINDOW_MENU_SIGNAL_STATUS_CHANGED "status-changed" #define WINDOW_MENU_SIGNAL_SHOW_MENU "show-menu" #define WINDOW_MENU_SIGNAL_A11Y_UPDATE "a11y-update" typedef enum _WindowMenuStatus WindowMenuStatus; enum _WindowMenuStatus { WINDOW_MENU_STATUS_NORMAL, WINDOW_MENU_STATUS_ACTIVE }; typedef struct _WindowMenu WindowMenu; typedef struct _WindowMenuClass WindowMenuClass; struct _WindowMenuClass { GObjectClass parent_class; /* Virtual Funcs */ GList * (*get_entries) (WindowMenu * wm); guint (*get_location) (WindowMenu * wm, IndicatorObjectEntry * entry); guint (*get_xid) (WindowMenu * wm); gboolean (*get_error_state) (WindowMenu * wm); WindowMenuStatus (*get_status) (WindowMenu * wm); void (*entry_restore) (WindowMenu * wm, IndicatorObjectEntry * entry); void (*entry_activate) (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp); /* Signals */ void (*entry_added) (WindowMenu * wm, IndicatorObjectEntry * entry, gpointer user_data); void (*entry_removed) (WindowMenu * wm, IndicatorObjectEntry * entry, gpointer user_data); void (*error_state) (WindowMenu * wm, gboolean state, gpointer user_data); void (*status_changed) (WindowMenu * wm, WindowMenuStatus status, gpointer user_data); void (*show_menu) (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data); void (*a11y_update) (WindowMenu * wm, IndicatorObjectEntry * entry, gpointer user_data); }; struct _WindowMenu { GObject parent; }; GType window_menu_get_type (void); GList * window_menu_get_entries (WindowMenu * wm); guint window_menu_get_location (WindowMenu * wm, IndicatorObjectEntry * entry); guint window_menu_get_xid (WindowMenu * wm); gboolean window_menu_get_error_state (WindowMenu * wm); WindowMenuStatus window_menu_get_status (WindowMenu * wm); void window_menu_entry_restore (WindowMenu * wm, IndicatorObjectEntry * entry); void window_menu_entry_activate (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp); G_END_DECLS #endif ./src/indicator-appmenu.c0000644000004100000410000013115312772465331015633 0ustar www-datawww-data/* An implementation of indicator object showing menus from applications. Copyright 2010-2013 Canonical Ltd. Authors: Ted Gould Marco Trevisan This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include /* exit() */ #include #include #include #include #include #include #include #include #include "gen-application-menu-registrar.xml.h" #include "gen-application-menu-renderer.xml.h" #include "indicator-appmenu-marshal.h" #include "window-menu.h" #include "window-menu-dbusmenu.h" #include "window-menu-model.h" #include "dbus-shared.h" #include "gdk-get-func.h" /********************** Indicator Object **********************/ #define INDICATOR_APPMENU_TYPE (indicator_appmenu_get_type ()) #define INDICATOR_APPMENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_APPMENU_TYPE, IndicatorAppmenu)) #define INDICATOR_APPMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_APPMENU_TYPE, IndicatorAppmenuClass)) #define IS_INDICATOR_APPMENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_APPMENU_TYPE)) #define IS_INDICATOR_APPMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_APPMENU_TYPE)) #define INDICATOR_APPMENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_APPMENU_TYPE, IndicatorAppmenuClass)) GType indicator_appmenu_get_type (void); INDICATOR_SET_VERSION INDICATOR_SET_TYPE(INDICATOR_APPMENU_TYPE) typedef struct _IndicatorAppmenu IndicatorAppmenu; typedef struct _IndicatorAppmenuClass IndicatorAppmenuClass; typedef struct _IndicatorAppmenuDebug IndicatorAppmenuDebug; typedef struct _IndicatorAppmenuDebugClass IndicatorAppmenuDebugClass; typedef enum _ActiveStubsState ActiveStubsState; enum _ActiveStubsState { STUBS_UNKNOWN, STUBS_SHOW, STUBS_HIDE }; typedef enum _AppmenuMode AppmenuMode; enum _AppmenuMode { MODE_STANDARD, MODE_UNITY, MODE_UNITY_ALL_MENUS }; struct _IndicatorAppmenuClass { IndicatorObjectClass parent_class; }; struct _IndicatorAppmenu { IndicatorObject parent; AppmenuMode mode; WindowMenu * default_app; GHashTable * apps; BamfMatcher * matcher; BamfWindow * active_window; ActiveStubsState active_stubs; GtkMenuItem * close_item; GArray * window_menus; GHashTable * desktop_windows; WindowMenu * desktop_menu; GDBusConnection * bus; guint owner_id; guint dbus_registration; }; /********************** Debug Proxy **********************/ #define INDICATOR_APPMENU_DEBUG_TYPE (indicator_appmenu_debug_get_type ()) #define INDICATOR_APPMENU_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_APPMENU_DEBUG_TYPE, IndicatorAppmenuDebug)) #define INDICATOR_APPMENU_DEBUG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_APPMENU_DEBUG_TYPE, IndicatorAppmenuDebugClass)) #define IS_INDICATOR_APPMENU_DEBUG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_APPMENU_DEBUG_TYPE)) #define IS_INDICATOR_APPMENU_DEBUG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_APPMENU_DEBUG_TYPE)) #define INDICATOR_APPMENU_DEBUG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_APPMENU_DEBUG_TYPE, IndicatorAppmenuDebugClass)) GType indicator_appmenu_debug_get_type (void); struct _IndicatorAppmenuDebugClass { GObjectClass parent_class; }; struct _IndicatorAppmenuDebug { GObject parent; IndicatorAppmenu * appmenu; GCancellable * bus_cancel; GDBusConnection * bus; guint dbus_registration; }; /********************** Prototypes **********************/ static gboolean indicator_appmenu_delayed_init (IndicatorAppmenu * iapp); static void indicator_appmenu_dispose (GObject *object); static void indicator_appmenu_finalize (GObject *object); static void build_window_menus (IndicatorAppmenu * iapp); static GList * get_entries (IndicatorObject * io); static guint get_location (IndicatorObject * io, IndicatorObjectEntry * entry); static void entry_activate (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp); static void entry_activate_window (IndicatorObject * io, IndicatorObjectEntry * entry, guint windowid, guint timestamp); static void switch_default_app (IndicatorAppmenu * iapp, WindowMenu * newdef, BamfWindow * active_window); static void find_relevant_windows (IndicatorAppmenu * iapp); static void new_window (BamfMatcher * matcher, BamfView * view, gpointer user_data); static void old_window (BamfMatcher * matcher, BamfView * view, gpointer user_data); static void window_entry_added (WindowMenu * mw, IndicatorObjectEntry * entry, IndicatorAppmenu * iapp); static void window_entry_removed (WindowMenu * mw, IndicatorObjectEntry * entry, IndicatorAppmenu * iapp); static void window_status_changed (WindowMenu * mw, DbusmenuStatus status, IndicatorAppmenu * iapp); static void window_show_menu (WindowMenu * mw, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data); static void window_a11y_update (WindowMenu * mw, IndicatorObjectEntry * entry, gpointer user_data); static void active_window_changed (BamfMatcher * matcher, BamfView * oldview, BamfView * newview, gpointer user_data); static WindowMenu * update_active_window (IndicatorAppmenu * appmenu, BamfWindow *window); static GQuark error_quark (void); static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data); static void on_bus_acquired (GDBusConnection * connection, const gchar * name, gpointer user_data); static void on_name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data); static WindowMenu * ensure_menus (IndicatorAppmenu * iapp, BamfWindow * window); static GVariant * unregister_window (IndicatorAppmenu * iapp, guint windowid); static void connect_to_menu_signals (IndicatorAppmenu * iapp, WindowMenu * menus); /* Unique error codes for debug interface */ enum { ERROR_NO_APPLICATIONS, ERROR_NO_DEFAULT_APP, ERROR_WINDOW_NOT_FOUND }; /********************** DBus Interfaces **********************/ static GDBusNodeInfo * node_info = NULL; static GDBusInterfaceInfo * interface_info = NULL; static GDBusInterfaceVTable interface_table = { method_call: bus_method_call, get_property: NULL, /* No properties */ set_property: NULL /* No properties */ }; G_DEFINE_TYPE (IndicatorAppmenu, indicator_appmenu, INDICATOR_OBJECT_TYPE); /* One time init */ static void indicator_appmenu_class_init (IndicatorAppmenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = indicator_appmenu_dispose; object_class->finalize = indicator_appmenu_finalize; IndicatorObjectClass * ioclass = INDICATOR_OBJECT_CLASS(klass); ioclass->get_entries = get_entries; ioclass->get_location = get_location; ioclass->entry_activate = entry_activate; ioclass->entry_activate_window = entry_activate_window; /* Setting up the DBus interfaces */ if (node_info == NULL) { GError * error = NULL; node_info = g_dbus_node_info_new_for_xml(_application_menu_registrar, &error); if (error != NULL) { g_critical("Unable to parse Application Menu Interface description: %s", error->message); g_error_free(error); } } if (interface_info == NULL) { interface_info = g_dbus_node_info_lookup_interface(node_info, REG_IFACE); if (interface_info == NULL) { g_critical("Unable to find interface '" REG_IFACE "'"); } } return; } /* Per instance Init */ static void indicator_appmenu_init (IndicatorAppmenu *self) { self->apps = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref); self->mode = MODE_STANDARD; self->active_stubs = STUBS_UNKNOWN; /* Setup the cache of windows with possible desktop entries */ self->desktop_windows = g_hash_table_new(g_direct_hash, g_direct_equal); g_idle_add((GSourceFunc) indicator_appmenu_delayed_init, self); } /* Delayed Init, this is done so it can happen after that the mode has been set */ static gboolean indicator_appmenu_delayed_init (IndicatorAppmenu *self) { if (indicator_object_check_environment(INDICATOR_OBJECT(self), "unity-all-menus")) { self->mode = MODE_UNITY_ALL_MENUS; } else if (indicator_object_check_environment(INDICATOR_OBJECT(self), "unity")) { self->mode = MODE_UNITY; } if (self->mode != MODE_STANDARD) self->active_stubs = STUBS_HIDE; if (self->active_stubs != STUBS_HIDE) build_window_menus(self); /* Get the default BAMF matcher */ self->matcher = bamf_matcher_get_default(); if (self->matcher == NULL) { /* we don't want to exit out of Unity -- but this should really never happen */ g_warning("Unable to get BAMF matcher, can not watch applications switch!"); } else { g_signal_connect(G_OBJECT(self->matcher), "active-window-changed", G_CALLBACK(active_window_changed), self); /* Desktop window tracking */ g_signal_connect(G_OBJECT(self->matcher), "view-opened", G_CALLBACK(new_window), self); g_signal_connect(G_OBJECT(self->matcher), "view-closed", G_CALLBACK(old_window), self); } find_relevant_windows(self); /* Request a name so others can find us */ self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, on_name_lost, self, NULL); return G_SOURCE_REMOVE; } static void on_bus_acquired (GDBusConnection * connection, const gchar * name, gpointer user_data) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); GError * error = NULL; if (connection == NULL) { g_critical ("Unable to get session bus."); exit (0); } iapp->bus = connection; /* Now register our object on our new connection */ iapp->dbus_registration = g_dbus_connection_register_object(connection, REG_OBJECT, interface_info, &interface_table, user_data, NULL, &error); if (error != NULL) { g_critical("Unable to register the object to DBus: %s", error->message); g_error_free(error); } } static void on_name_lost (GDBusConnection * connection, const gchar * name, gpointer user_data) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); if (connection == NULL) { g_critical("OMG! Unable to get a connection to DBus"); } else { g_critical("Unable to claim the name %s", DBUS_NAME); } /* We can rest assured no one will register with us, but let's just ensure we're not showing anything. */ switch_default_app(iapp, NULL, NULL); } /* Object refs decrement */ static void indicator_appmenu_dispose (GObject *object) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(object); if (iapp->dbus_registration != 0) { g_dbus_connection_unregister_object(iapp->bus, iapp->dbus_registration); /* Don't care if it fails, there's nothing we can do */ iapp->dbus_registration = 0; } g_clear_object(&iapp->bus); if (iapp->owner_id != 0) { g_bus_unown_name(iapp->owner_id); iapp->owner_id = 0; } /* bring down the matcher before resetting to no menu so we don't get match signals */ g_clear_object(&iapp->matcher); /* No specific ref */ switch_default_app(iapp, NULL, NULL); g_clear_pointer(&iapp->apps, g_hash_table_destroy); g_clear_pointer(&iapp->desktop_windows, g_hash_table_destroy); if (iapp->desktop_menu != NULL) { /* Wait, nothing here? Yup. We're not referencing the menus here they're already attached to the window ID. We're just keeping an efficient pointer to them. */ iapp->desktop_menu = NULL; } G_OBJECT_CLASS (indicator_appmenu_parent_class)->dispose (object); return; } /* Free memory */ static void indicator_appmenu_finalize (GObject *object) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(object); if (iapp->window_menus != NULL) { g_signal_handlers_disconnect_by_data(iapp->close_item, iapp); gint i; for (i = 0; i < iapp->window_menus->len; ++i) { IndicatorObjectEntry *entry = &g_array_index(iapp->window_menus, IndicatorObjectEntry, i); g_clear_object(&(entry->label)); g_clear_object(&(entry->menu)); } g_array_free(iapp->window_menus, TRUE); } g_signal_handlers_disconnect_by_data(iapp->matcher, iapp); G_OBJECT_CLASS (indicator_appmenu_parent_class)->finalize (object); return; } static void emit_signal (IndicatorAppmenu * iapp, const gchar * name, GVariant * variant) { GError * error = NULL; g_dbus_connection_emit_signal (iapp->bus, NULL, REG_OBJECT, REG_IFACE, name, variant, &error); if (error != NULL) { g_critical("Unable to send %s signal: %s", name, error->message); g_error_free(error); return; } return; } /* Close the current application using magic */ static void close_current (GtkMenuItem * mi, gpointer user_data) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); if (!BAMF_IS_WINDOW (iapp->active_window) || bamf_view_is_closed (BAMF_VIEW (iapp->active_window))) { g_warning("Can't close a window we don't have. Window is either non-existent or recently closed."); return; } guint32 xid = bamf_window_get_xid(iapp->active_window); guint timestamp = gdk_event_get_time(NULL); XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = gdk_x11_get_default_xdisplay (); xev.xclient.window = xid; xev.xclient.message_type = gdk_x11_atom_to_xatom (gdk_atom_intern ("_NET_CLOSE_WINDOW", TRUE)); xev.xclient.format = 32; xev.xclient.data.l[0] = timestamp; xev.xclient.data.l[1] = 2; /* Client type pager, so it listens to us */ xev.xclient.data.l[2] = 0; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; gdk_error_trap_push (); XSendEvent (gdk_x11_get_default_xdisplay (), gdk_x11_get_default_root_xwindow (), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); gdk_flush (); gdk_error_trap_pop_ignored (); return; } /* Create the default window menus */ static void build_window_menus (IndicatorAppmenu * iapp) { IndicatorObjectEntry entries[1] = {{0}}; GtkAccelGroup * agroup = gtk_accel_group_new(); GtkMenuItem * mi = NULL; GtkStockItem stockitem; /* Setup the entries for the fallbacks */ iapp->window_menus = g_array_sized_new(FALSE, FALSE, sizeof(IndicatorObjectEntry), 2); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* File Menu */ if (!gtk_stock_lookup(GTK_STOCK_FILE, &stockitem)) { g_warning("Unable to find the file menu stock item"); stockitem.label = "_File"; } G_GNUC_END_IGNORE_DEPRECATIONS entries[0].label = GTK_LABEL(gtk_label_new_with_mnemonic(stockitem.label)); g_object_ref(G_OBJECT(entries[0].label)); gtk_widget_show(GTK_WIDGET(entries[0].label)); entries[0].menu = GTK_MENU(gtk_menu_new()); g_object_ref(G_OBJECT(entries[0].menu)); G_GNUC_BEGIN_IGNORE_DEPRECATIONS mi = GTK_MENU_ITEM(gtk_image_menu_item_new_from_stock(GTK_STOCK_CLOSE, agroup)); G_GNUC_END_IGNORE_DEPRECATIONS gtk_widget_set_sensitive(GTK_WIDGET(mi), FALSE); g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(close_current), iapp); gtk_widget_show(GTK_WIDGET(mi)); gtk_menu_shell_append(GTK_MENU_SHELL(entries[0].menu), GTK_WIDGET(mi)); iapp->close_item = mi; gtk_widget_show(GTK_WIDGET(entries[0].menu)); /* Copy the entries on the stack into the array */ g_array_insert_vals(iapp->window_menus, 0, entries, 1); } /* Determine which windows should be used as the desktop menus. */ static void determine_new_desktop (IndicatorAppmenu * iapp) { GList * keys = g_hash_table_get_keys(iapp->desktop_windows); GList * key; for (key = keys; key != NULL; key = g_list_next(key)) { guint xid = GPOINTER_TO_UINT(key->data); gpointer pwm = g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(xid)); if (pwm != NULL) { g_debug("Setting Desktop Menus to: %X", xid); iapp->desktop_menu = WINDOW_MENU(pwm); break; } } g_list_free(keys); return; } /* Puts all the windows we care about into the hash table so that we can have a nice list of them. */ static void find_relevant_windows (IndicatorAppmenu * iapp) { GList * windows = bamf_matcher_get_windows(iapp->matcher); GList * lwindow; for (lwindow = windows; lwindow != NULL; lwindow = g_list_next(lwindow)) { BamfView * view = BAMF_VIEW(lwindow->data); new_window(iapp->matcher, view, iapp); } g_list_free(windows); return; } /* When new windows are born, we check to see if they're desktop windows. */ static void new_window (BamfMatcher * matcher, BamfView * view, gpointer user_data) { if (!BAMF_IS_WINDOW(view)) { return; } BamfWindow * window = BAMF_WINDOW(view); IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); guint32 xid = bamf_window_get_xid(window); if (iapp->mode == MODE_UNITY_ALL_MENUS) { ensure_menus(iapp, window); return; } if (bamf_window_get_window_type(window) != BAMF_WINDOW_DESKTOP) { return; } g_hash_table_insert(iapp->desktop_windows, GUINT_TO_POINTER(xid), GINT_TO_POINTER(TRUE)); g_debug("New Desktop Window: %X", xid); gpointer pwm = g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(xid)); if (pwm != NULL) { WindowMenu * wm = WINDOW_MENU(pwm); iapp->desktop_menu = wm; g_debug("Setting Desktop Menus to: %X", xid); if (iapp->active_window == NULL && iapp->default_app == NULL) { switch_default_app(iapp, NULL, NULL); } } } /* When windows leave us, this function gets called */ static void old_window (BamfMatcher * matcher, BamfView * view, gpointer user_data) { if (!BAMF_IS_WINDOW(view)) { return; } IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); BamfWindow * window = BAMF_WINDOW(view); guint32 xid = bamf_window_get_xid(window); unregister_window(iapp, xid); return; } /* List of desktop files that shouldn't have menu stubs. */ const static gchar * stubs_blacklist[] = { /* Firefox */ "/firefox.desktop", /* Thunderbird */ "/thunderbird.desktop", /* Open Office */ "/openoffice.org-base.desktop", "/openoffice.org-impress.desktop", "/openoffice.org-calc.desktop", "/openoffice.org-math.desktop", "/openoffice.org-draw.desktop", "/openoffice.org-writer.desktop", /* Blender */ "/blender-fullscreen.desktop", "/blender-windowed.desktop", /* Eclipse */ "/eclipse.desktop", NULL }; /* Check with BAMF, and then check the blacklist of desktop files to see if any are there. Otherwise, show the stubs. */ gboolean show_menu_stubs (BamfApplication * app) { if (bamf_application_get_show_menu_stubs(app) == FALSE) { return FALSE; } const gchar * desktop_file = bamf_application_get_desktop_file(app); if (desktop_file == NULL || desktop_file[0] == '\0') { return TRUE; } int i; for (i = 0; stubs_blacklist[i] != NULL; i++) { if (g_str_has_suffix(desktop_file, stubs_blacklist[i]) == 0) { return FALSE; } } return TRUE; } /* Get the current set of entries */ static GList * get_entries (IndicatorObject * io) { g_return_val_if_fail(IS_INDICATOR_APPMENU(io), NULL); IndicatorAppmenu * iapp = INDICATOR_APPMENU(io); GHashTableIter iter; gpointer value; GList* entries = NULL; if (iapp->mode == MODE_UNITY_ALL_MENUS) { g_hash_table_iter_init(&iter, iapp->apps); while (g_hash_table_iter_next(&iter, NULL, &value)) { GList *app_entries = window_menu_get_entries(WINDOW_MENU (value)); entries = g_list_concat(app_entries, entries); } return entries; } /* If we have a focused app with menus, use it's windows */ if (iapp->default_app != NULL) { return window_menu_get_entries(iapp->default_app); } /* Else, let's go with desktop windows if there isn't a focused window */ if (iapp->active_window == NULL) { if (iapp->desktop_menu == NULL) { return NULL; } else { return window_menu_get_entries(iapp->desktop_menu); } } /* Oh, now we're looking at stubs. */ if (iapp->active_stubs == STUBS_UNKNOWN) { iapp->active_stubs = STUBS_SHOW; BamfApplication * app = bamf_matcher_get_application_for_window(iapp->matcher, iapp->active_window); if (app != NULL) { /* First check to see if we can find an app, then if we can check to see if it has an opinion on whether we should show the stubs or not. */ if (show_menu_stubs(app) == FALSE) { /* If it blocks them, fall out. */ iapp->active_stubs = STUBS_HIDE; } } } if (iapp->active_stubs == STUBS_HIDE) { return NULL; } /* There is only one item in window_menus now, but there was more, and there is likely to be more in the future so we're leaving this here to avoid a possible bug. */ int i; for (i = 0; i < iapp->window_menus->len; i++) { entries = g_list_append(entries, &g_array_index(iapp->window_menus, IndicatorObjectEntry, i)); } return entries; } /* Grabs the location of the entry */ static guint get_location (IndicatorObject * io, IndicatorObjectEntry * entry) { guint count = 0; IndicatorAppmenu * iapp = INDICATOR_APPMENU(io); if (iapp->mode == MODE_UNITY_ALL_MENUS) { GHashTableIter iter; gpointer value; g_hash_table_iter_init(&iter, iapp->apps); while (g_hash_table_iter_next(&iter, NULL, &value)) { count = window_menu_get_location(WINDOW_MENU (value), entry); if (count != G_MAXUINT) return count; } return 0; } if (iapp->default_app != NULL) { /* Find the location in the app */ count = window_menu_get_location(iapp->default_app, entry); } else if (iapp->active_window != NULL && iapp->window_menus) { /* Find the location in the window menus */ for (count = 0; count < iapp->window_menus->len; count++) { if (entry == &g_array_index(iapp->window_menus, IndicatorObjectEntry, count)) { break; } } if (count == iapp->window_menus->len) { g_warning("Unable to find entry in default window menus"); count = G_MAXUINT; } } else { /* Find the location in the desktop menu */ if (iapp->desktop_menu != NULL) { count = window_menu_get_location(iapp->desktop_menu, entry); } } return (count == G_MAXUINT) ? 0 : count; } /* Responds to a menuitem being activated on the panel. */ static void entry_activate (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp) { return entry_activate_window(io, entry, 0, timestamp); } /* Find the BAMF Window that is associated with that XID. Unfortunately this requires a bit of searching, don't do it too often */ static BamfWindow * xid_to_bamf_window (IndicatorAppmenu * iapp, guint xid) { BamfWindow * newwindow = bamf_matcher_get_window_for_xid(iapp->matcher, xid); if (BAMF_IS_WINDOW(newwindow)) return newwindow; BamfApplication *application = bamf_matcher_get_application_for_xid(iapp->matcher, xid); GList * children = bamf_view_peek_children (BAMF_VIEW (application)); GList * l; for (l = children; l; l = l->next) { if (!BAMF_IS_WINDOW(l->data)) { continue; } BamfWindow * testwindow = BAMF_WINDOW(l->data); if (xid == bamf_window_get_xid(testwindow)) { newwindow = testwindow; break; } } return newwindow; } /* Responds to a menuitem being activated on the panel. */ static void entry_activate_window (IndicatorObject * io, IndicatorObjectEntry * entry, guint windowid, guint timestamp) { WindowMenu * menus = NULL; IndicatorAppmenu * iapp = INDICATOR_APPMENU(io); /* We need to force a focus change in this case as we probably just haven't gotten the signal from BAMF yet */ if (windowid != 0) { BamfWindow * newwindow = xid_to_bamf_window(iapp, windowid); if (newwindow != NULL) { menus = update_active_window(iapp, newwindow); } } if (iapp->mode != MODE_UNITY_ALL_MENUS && iapp->default_app != NULL) { menus = iapp->default_app; if (!menus && iapp->active_window == NULL) { menus = iapp->desktop_menu; } } if (menus) { window_menu_entry_activate(menus, entry, timestamp); } } /* Checks to see we cared about a window that's going away, so that we can deal with that */ static void window_finalized_is_active (gpointer user_data, GObject * old_window) { g_return_if_fail(IS_INDICATOR_APPMENU(user_data)); IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); /* Pointer comparison as we can't really trust any of the pointers to do any dereferencing */ if ((gpointer)iapp->active_window != (gpointer)old_window) { /* Ah, no issue, we weren't caring about this one anyway. */ return; } /* We're going to a state where we don't know what the active window is, hopefully BAMF will save us */ active_window_changed(iapp->matcher, NULL, NULL, iapp); return; } /* A helper for switch_default_app that takes care of the switching of the active window variable */ static void switch_active_window (IndicatorAppmenu * iapp, BamfWindow * active_window) { if (iapp->active_window == active_window || iapp->mode == MODE_UNITY_ALL_MENUS) { return; } if (iapp->active_window != NULL) { g_object_weak_unref(G_OBJECT(iapp->active_window), window_finalized_is_active, iapp); } iapp->active_window = active_window; if (iapp->mode == MODE_STANDARD) iapp->active_stubs = STUBS_UNKNOWN; /* Close any existing open menu by showing a null entry */ window_show_menu(iapp->default_app, NULL, gtk_get_current_event_time(), iapp); if (active_window != NULL) { g_object_weak_ref(G_OBJECT(active_window), window_finalized_is_active, iapp); } if (iapp->close_item == NULL) { g_warning("No close item!?!?!"); return; } gtk_widget_set_sensitive(GTK_WIDGET(iapp->close_item), FALSE); if (iapp->active_window == NULL) { return; } guint32 xid = bamf_window_get_xid(iapp->active_window); if (xid == 0 || bamf_view_is_closed (BAMF_VIEW (iapp->active_window))) { return; } GdkWMFunction functions; if (!egg_xid_get_functions(xid, &functions)) { g_debug("Unable to get MWM functions for: %d", xid); functions = GDK_FUNC_ALL; } if (functions & GDK_FUNC_ALL || functions & GDK_FUNC_CLOSE) { gtk_widget_set_sensitive(GTK_WIDGET(iapp->close_item), TRUE); } return; } static void connect_to_menu_signals (IndicatorAppmenu * iapp, WindowMenu * menus) { g_return_if_fail(G_IS_OBJECT(menus)); /* Connect signals */ g_signal_connect(menus, WINDOW_MENU_SIGNAL_ENTRY_ADDED, G_CALLBACK(window_entry_added), iapp); g_signal_connect(menus, WINDOW_MENU_SIGNAL_ENTRY_REMOVED, G_CALLBACK(window_entry_removed), iapp); g_signal_connect(menus, WINDOW_MENU_SIGNAL_STATUS_CHANGED, G_CALLBACK(window_status_changed), iapp); g_signal_connect(menus, WINDOW_MENU_SIGNAL_SHOW_MENU, G_CALLBACK(window_show_menu), iapp); g_signal_connect(menus, WINDOW_MENU_SIGNAL_A11Y_UPDATE, G_CALLBACK(window_a11y_update), iapp); } /* Switch applications, remove all the entires for the previous one and add them for the new application */ static void switch_default_app (IndicatorAppmenu * iapp, WindowMenu * newdef, BamfWindow * active_window) { if (iapp->mode == MODE_UNITY_ALL_MENUS) { return; } if (iapp->default_app == newdef && iapp->default_app != NULL) { /* We've got an app with menus and it hasn't changed. */ /* Keep active window up-to-date, though we're probably not using it much. */ switch_active_window(iapp, active_window); return; } if (iapp->default_app == NULL && iapp->active_window == active_window && newdef == NULL) { /* There's no application menus, but the active window hasn't changed. So there's no change. */ return; } /* hide the entries that we're swapping out */ indicator_object_set_visible (INDICATOR_OBJECT(iapp), FALSE); if (iapp->default_app) { /* Disconnect signals */ g_signal_handlers_disconnect_by_data(iapp->default_app, iapp); /* Default App is NULL, let's see if it needs replacement */ iapp->default_app = NULL; } /* Update the active window pointer -- may be NULL */ switch_active_window(iapp, active_window); /* If we're putting up a new window, let's do that now. */ if (newdef != NULL) { /* Switch */ iapp->default_app = newdef; connect_to_menu_signals(iapp, iapp->default_app); } /* show the entries that we're swapping in */ indicator_object_set_visible (INDICATOR_OBJECT(iapp), TRUE); /* Set up initial state for new entries if needed */ if (iapp->default_app != NULL && window_menu_get_status (iapp->default_app) != WINDOW_MENU_STATUS_NORMAL) { window_status_changed(iapp->default_app, window_menu_get_status (iapp->default_app), iapp); } return; } static void track_menus (IndicatorAppmenu * iapp, guint xid, WindowMenu * menus) { g_return_if_fail(IS_WINDOW_MENU(menus)); g_hash_table_insert(iapp->apps, GUINT_TO_POINTER(xid), menus); if (iapp->mode == MODE_UNITY_ALL_MENUS) { GList *entries, *l; WindowMenuStatus status; connect_to_menu_signals(iapp, menus); entries = window_menu_get_entries(menus); status = window_menu_get_status(menus); for (l = entries; l; l = l->next) { window_entry_added(menus, l->data, iapp); } if (status != WINDOW_MENU_STATUS_ACTIVE) { window_status_changed(menus, status, iapp); } g_list_free(entries); } } static WindowMenu * ensure_menus (IndicatorAppmenu * iapp, BamfWindow * window) { WindowMenu * menus = NULL; guint32 xid = 0; while (window != NULL && menus == NULL) { xid = bamf_window_get_xid(window); menus = g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(xid)); /* First look to see if we can get these from the GMenuModel access */ if (menus == NULL) { gchar * uniquename = bamf_window_get_utf8_prop (window, "_GTK_UNIQUE_BUS_NAME"); if (uniquename != NULL) { BamfApplication * app = bamf_matcher_get_application_for_window(iapp->matcher, window); menus = WINDOW_MENU(window_menu_model_new(app, window)); track_menus(iapp, xid, menus); } g_free(uniquename); } if (menus == NULL) { g_debug("Looking for parent window on XID %d", xid); window = bamf_window_get_transient(window); } } return menus; } /* Recieve the signal that the window being shown has now changed. */ static void active_window_changed (BamfMatcher * matcher, BamfView * oldview, BamfView * newview, gpointer user_data) { update_active_window(INDICATOR_APPMENU(user_data), (BamfWindow *) newview); } static WindowMenu * update_active_window (IndicatorAppmenu * appmenu, BamfWindow *window) { WindowMenu * menus = NULL; if (window != NULL) { if (!BAMF_IS_WINDOW(window)) { window = NULL; g_warning("Active window changed to View thats not a window."); } } else { g_debug("Active window is: NULL"); } if (appmenu->mode == MODE_UNITY_ALL_MENUS) { if (window != NULL) { menus = ensure_menus(appmenu, window); } return menus; } if (window != NULL && bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP) { g_debug("Switching to menus from desktop"); switch_default_app(appmenu, NULL, NULL); return menus; } g_debug("Switching to menus from XID %d", window ? bamf_window_get_xid(window) : 0); menus = ensure_menus(appmenu, window); switch_default_app(appmenu, menus, window); return menus; } /* Respond to the menus being destroyed. We need to deregister and make sure we weren't being shown. */ static void menus_destroyed (IndicatorAppmenu * iapp, guint windowid) { gboolean reload_menus = FALSE; WindowMenu * wm = g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)); g_return_if_fail (IS_WINDOW_MENU(wm)); g_hash_table_steal(iapp->apps, GUINT_TO_POINTER(windowid)); g_signal_handlers_disconnect_by_data(wm, iapp); g_debug("Removing menus for %d", windowid); if (iapp->desktop_menu == wm) { iapp->desktop_menu = NULL; determine_new_desktop(iapp); if (iapp->default_app == NULL && iapp->active_window == NULL) { reload_menus = TRUE; } } /* If we're it, let's remove ourselves and BAMF will probably give us a new entry in a bit. */ if (iapp->default_app == wm) { reload_menus = TRUE; } if (reload_menus) { switch_default_app(iapp, NULL, NULL); } if (iapp->mode == MODE_UNITY_ALL_MENUS) { GList * entries, * l; entries = window_menu_get_entries(wm); for (l = entries; l; l = l->next) { window_entry_removed(wm, l->data, iapp); } g_list_free(entries); } g_object_unref(wm); } /* A new window wishes to register it's windows with us */ static GVariant * register_window (IndicatorAppmenu * iapp, guint windowid, const gchar * objectpath, const gchar * sender) { g_debug("Registering window ID %d with path %s from %s", windowid, objectpath, sender); if (g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)) == NULL && windowid != 0) { WindowMenu * wm = WINDOW_MENU(window_menu_dbusmenu_new(windowid, sender, objectpath)); g_return_val_if_fail(wm != NULL, FALSE); track_menus(iapp, windowid, wm); emit_signal(iapp, "WindowRegistered", g_variant_new("(uso)", windowid, sender, objectpath)); gpointer pdesktop = g_hash_table_lookup(iapp->desktop_windows, GUINT_TO_POINTER(windowid)); if (pdesktop != NULL) { determine_new_desktop(iapp); } /* Note: Does not cause ref */ BamfWindow * win = bamf_matcher_get_active_window(iapp->matcher); update_active_window(iapp, win); } else { if (windowid == 0) { g_warning("Can't build windows for a NULL window ID %d with path %s from %s", windowid, objectpath, sender); } else { g_warning("Already have a menu for window ID %d with path %s from %s, unregistering that one", windowid, objectpath, sender); unregister_window(iapp, windowid); /* NOTE: So we're doing a lookup here. That seems pretty useless now doesn't it. It's for a good reason. We're going recursive with a pretty complex set of functions we want to ensure that we're not going to end up infinitely recursive otherwise things could go really bad. */ if (g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)) == NULL) { return register_window(iapp, windowid, objectpath, sender); } g_warning("Unable to unregister window!"); } } return g_variant_new("()"); } /* Kindly remove an entry from our DB */ static GVariant * unregister_window (IndicatorAppmenu * iapp, guint windowid) { g_debug("Unregistering: %d", windowid); g_return_val_if_fail(IS_INDICATOR_APPMENU(iapp), NULL); g_return_val_if_fail(iapp->matcher != NULL, NULL); /* If it's a desktop window remove it from that table as well */ g_hash_table_remove(iapp->desktop_windows, GUINT_TO_POINTER(windowid)); emit_signal(iapp, "WindowUnregistered", g_variant_new ("(u)", windowid)); menus_destroyed(iapp, windowid); return NULL; } /* Grab the menu information for a specific window */ static GVariant * get_menu_for_window (IndicatorAppmenu * iapp, guint windowid, GError ** error) { WindowMenu * wm = NULL; if (windowid == 0) { wm = iapp->default_app; } else { wm = WINDOW_MENU(g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid))); } if (wm == NULL) { g_set_error_literal(error, error_quark(), ERROR_WINDOW_NOT_FOUND, "Window not found"); return NULL; } GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_TUPLE); if (IS_WINDOW_MENU_DBUSMENU(wm)) { gchar * address = window_menu_dbusmenu_get_address(WINDOW_MENU_DBUSMENU(wm)); gchar * path = window_menu_dbusmenu_get_path(WINDOW_MENU_DBUSMENU(wm)); g_variant_builder_add_value(&builder, g_variant_new_string(address)); g_variant_builder_add_value(&builder, g_variant_new_object_path(path)); g_free(path); g_free(address); } else { g_variant_builder_add_value(&builder, g_variant_new_string("")); g_variant_builder_add_value(&builder, g_variant_new_object_path("/")); } return g_variant_builder_end(&builder); } /* Get all the menus we have */ static GVariant * get_menus (IndicatorAppmenu * iapp, GError ** error) { if (iapp->apps == NULL) { g_set_error_literal(error, error_quark(), ERROR_NO_APPLICATIONS, "No applications are registered"); return NULL; } GVariantBuilder builder; GHashTableIter hash_iter; gpointer value; g_variant_builder_init (&builder, G_VARIANT_TYPE("a(uso)")); g_hash_table_iter_init (&hash_iter, iapp->apps); while (g_hash_table_iter_next (&hash_iter, NULL, &value)) { if (value != NULL) { WindowMenu * wm = WINDOW_MENU(value); if (IS_WINDOW_MENU_DBUSMENU(wm)) { gchar * address = window_menu_dbusmenu_get_address(WINDOW_MENU_DBUSMENU(wm)); gchar * path = window_menu_dbusmenu_get_path(WINDOW_MENU_DBUSMENU(wm)); g_variant_builder_add (&builder, "(uso)", window_menu_get_xid(wm), address, path); g_free(path); g_free(address); } else { g_variant_builder_add (&builder, "(uso)", window_menu_get_xid(wm), "", "/"); } } } return g_variant_new ("(a(uso))", &builder); } /* A method has been called from our dbus inteface. Figure out what it is and dispatch it. */ static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * object_path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data) { IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data); GVariant * retval = NULL; GError * error = NULL; if (g_strcmp0(method, "RegisterWindow") == 0) { guint32 xid; const gchar * path; g_variant_get(params, "(u&o)", &xid, &path); retval = register_window(iapp, xid, path, sender); } else if (g_strcmp0(method, "UnregisterWindow") == 0) { guint32 xid; g_variant_get(params, "(u)", &xid); retval = unregister_window(iapp, xid); } else if (g_strcmp0(method, "GetMenuForWindow") == 0) { guint32 xid; g_variant_get(params, "(u)", &xid); retval = get_menu_for_window(iapp, xid, &error); } else if (g_strcmp0(method, "GetMenus") == 0) { retval = get_menus(iapp, &error); } else { g_warning("Calling method '%s' on the indicator service and it's unknown", method); } if (error != NULL) { g_dbus_method_invocation_return_dbus_error(invocation, "com.canonical.AppMenu.Error", error->message); g_error_free(error); } else { g_dbus_method_invocation_return_value(invocation, retval); } return; } /* Pass up the entry added event */ static void window_entry_added (WindowMenu * mw, IndicatorObjectEntry * entry, IndicatorAppmenu * iapp) { entry->parent_object = INDICATOR_OBJECT(iapp); g_signal_emit_by_name(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, entry); } /* Pass up the entry removed event */ static void window_entry_removed (WindowMenu * mw, IndicatorObjectEntry * entry, IndicatorAppmenu * iapp) { entry->parent_object = INDICATOR_OBJECT(iapp); g_signal_emit_by_name(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, entry); } /* Pass up the status changed event */ static void window_status_changed (WindowMenu * mw, DbusmenuStatus status, IndicatorAppmenu * iapp) { gboolean show_now = (status == DBUSMENU_STATUS_NOTICE); GList * l, * window_entries = window_menu_get_entries(mw); for (l = window_entries; l; l = l->next) { IndicatorObjectEntry * entry = l->data; g_signal_emit(G_OBJECT(iapp), INDICATOR_OBJECT_SIGNAL_SHOW_NOW_CHANGED_ID, 0, entry, show_now); } g_list_free (window_entries); } /* Pass up the show menu event */ static void window_show_menu (WindowMenu * mw, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data) { g_signal_emit_by_name(G_OBJECT(user_data), INDICATOR_OBJECT_SIGNAL_MENU_SHOW, entry, timestamp); } /* Pass up the accessible string update */ static void window_a11y_update (WindowMenu * mw, IndicatorObjectEntry * entry, gpointer user_data) { g_signal_emit_by_name(G_OBJECT(user_data), INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE, entry); } /********************** DEBUG INTERFACE **********************/ /* Builds the error quark if we need it, otherwise just returns the same value */ static GQuark error_quark (void) { static GQuark error_quark = 0; if (error_quark == 0) { error_quark = g_quark_from_static_string("indicator-appmenu"); } return error_quark; } ./src/gdk-get-func.c0000644000004100000410000000705212772465331014467 0ustar www-datawww-data/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball, * Josh MacDonald, Ryan Lortie * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "config.h" #include #include #include /* #ifdef HAVE_XKB #include #endif #include #include */ #include #include #include "MwmUtil.h" /* #include "gdkwindowimpl.h" #include "gdkasync.h" #include "gdkinputprivate.h" #include "gdkdisplay-x11.h" #include "gdkprivate-x11.h" #include "gdkregion.h" #include "gdkinternals.h" #include "gdkwindow-x11.h" #include "gdkalias.h" #include #include #include #include #ifdef HAVE_XCOMPOSITE #include #endif #ifdef HAVE_XFIXES #include #endif #ifdef HAVE_XDAMAGE #include #endif */ #define WINDOW_IS_TOPLEVEL_OR_FOREIGN(window) \ (GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD && \ GDK_WINDOW_TYPE (window) != GDK_WINDOW_OFFSCREEN) static MotifWmHints * gdk_xid_get_mwm_hints (Window window) { GdkDisplay *display; Atom hints_atom = None; guchar *data = NULL; Atom type; gint format; gulong nitems; gulong bytes_after; int ret = 0; display = gdk_display_get_default (); hints_atom = gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS); gdk_error_trap_push (); XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), window, hints_atom, 0, sizeof (MotifWmHints)/sizeof (long), False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); gdk_flush (); if ((ret = gdk_error_trap_pop ())) { g_warning ("%s: Unable to get hints for %u: Error Code: %d", G_STRFUNC, (guint32)window, ret); return NULL; } if (type == None) return NULL; return (MotifWmHints *)data; } /** * gdk_window_get_functions: * @window: The toplevel #X11Window to get the functions for * @functions: The window functions will be written here * * Returns the functions set on the GdkWindow with #gdk_window_set_functions * Returns: TRUE if the window has functions set, FALSE otherwise. **/ gboolean egg_xid_get_functions (Window window, GdkWMFunction *functions) { MotifWmHints *hints; gboolean result = FALSE; hints = gdk_xid_get_mwm_hints (window); if (hints) { if (hints->flags & MWM_HINTS_FUNCTIONS) { if (functions) *functions = hints->functions; result = TRUE; } XFree (hints); } return result; } ./src/window-menu-dbusmenu.c0000644000004100000410000007147012772465331016312 0ustar www-datawww-data/* An implementation of indicator object showing menus from applications. Copyright 2010 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include "window-menu-dbusmenu.h" #include "indicator-appmenu-marshal.h" /* Private parts */ typedef struct _WindowMenuDbusmenuPrivate WindowMenuDbusmenuPrivate; struct _WindowMenuDbusmenuPrivate { guint windowid; DbusmenuGtkClient * client; DbusmenuMenuitem * root; GCancellable * props_cancel; GDBusProxy * props; GArray * entries; gboolean error_state; guint retry_timer; }; typedef struct _WMEntry WMEntry; struct _WMEntry { IndicatorObjectEntry ioentry; gboolean disabled; gboolean hidden; DbusmenuMenuitem * mi; WindowMenuDbusmenu * wm; GVariant * vaccessible_desc; }; #define WINDOW_MENU_DBUSMENU_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), WINDOW_MENU_DBUSMENU_TYPE, WindowMenuDbusmenuPrivate)) /* Prototypes */ static void window_menu_dbusmenu_dispose (GObject *object); static void root_changed (DbusmenuClient * client, DbusmenuMenuitem * new_root, gpointer user_data); static void event_status (DbusmenuClient * client, DbusmenuMenuitem * mi, gchar * event, GVariant * evdata, guint timestamp, GError * error, gpointer user_data); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * item, guint timestamp, gpointer user_data); static void status_changed (DbusmenuClient * client, GParamSpec * pspec, gpointer user_data); static void menu_entry_added (DbusmenuMenuitem * root, DbusmenuMenuitem * newentry, guint position, gpointer user_data); static void menu_entry_removed (DbusmenuMenuitem * root, DbusmenuMenuitem * oldentry, gpointer user_data); static void menu_entry_realized (DbusmenuMenuitem * newentry, gpointer user_data); static void menu_entry_realized_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer user_data); static void menu_prop_changed (DbusmenuMenuitem * item, const gchar * property, GVariant * value, gpointer user_data); static void menu_child_realized (DbusmenuMenuitem * child, gpointer user_data); static void props_cb (GObject * object, GAsyncResult * res, gpointer user_data); static GList * get_entries (WindowMenu * wm); static guint get_location (WindowMenu * wm, IndicatorObjectEntry * entry); static guint get_xid (WindowMenu * wm); static gboolean get_error_state (WindowMenu * wm); static WindowMenuStatus get_status (WindowMenu * wm); static void entry_restore (WindowMenu * wm, IndicatorObjectEntry * entry); static void entry_activate (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp); G_DEFINE_TYPE (WindowMenuDbusmenu, window_menu_dbusmenu, WINDOW_MENU_TYPE); /* Build the one-time class */ static void window_menu_dbusmenu_class_init (WindowMenuDbusmenuClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); g_type_class_add_private (klass, sizeof (WindowMenuDbusmenuPrivate)); object_class->dispose = window_menu_dbusmenu_dispose; WindowMenuClass * menu_class = WINDOW_MENU_CLASS(klass); menu_class->get_entries = get_entries; menu_class->get_location = get_location; menu_class->get_xid = get_xid; menu_class->get_error_state = get_error_state; menu_class->get_status = get_status; menu_class->entry_restore = entry_restore; menu_class->entry_activate = entry_activate; return; } /* Initialize the per-instance data */ static void window_menu_dbusmenu_init (WindowMenuDbusmenu *self) { WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(self); priv->client = NULL; priv->props_cancel = NULL; priv->props = NULL; priv->root = NULL; priv->error_state = FALSE; priv->entries = g_array_new(FALSE, FALSE, sizeof(WMEntry *)); return; } static void entry_free(IndicatorObjectEntry * entry) { g_return_if_fail(entry != NULL); WMEntry * wmentry = (WMEntry *)entry; if (wmentry->mi != NULL) { g_signal_handlers_disconnect_by_func(wmentry->mi, G_CALLBACK(menu_prop_changed), &wmentry->ioentry); g_object_unref(G_OBJECT(wmentry->mi)); wmentry->mi = NULL; } if (entry->label != NULL) { g_object_unref(entry->label); entry->label = NULL; } if (entry->accessible_desc != NULL) { entry->accessible_desc = NULL; } g_clear_pointer(&wmentry->vaccessible_desc, g_variant_unref); if (entry->image != NULL) { g_object_unref(entry->image); entry->image = NULL; } if (entry->menu != NULL) { g_signal_handlers_disconnect_by_func(entry->menu, G_CALLBACK(gtk_widget_destroyed), &entry->menu); g_object_unref(entry->menu); entry->menu = NULL; } g_free(entry); } static void free_entries(GObject *object, gboolean should_signal) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(object)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(object); if (priv->entries != NULL) { while (priv->entries->len > 0) { IndicatorObjectEntry * entry; entry = g_array_index(priv->entries, IndicatorObjectEntry *, 0); g_array_remove_index(priv->entries, 0); if (should_signal) { g_signal_emit_by_name(object, WINDOW_MENU_SIGNAL_ENTRY_REMOVED, entry, TRUE); } entry_free(entry); } } } /* Destroy objects */ static void window_menu_dbusmenu_dispose (GObject *object) { WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(object); free_entries(object, FALSE); if (priv->entries != NULL) { g_array_free(priv->entries, TRUE); priv->entries = NULL; } if (priv->root != NULL) { root_changed(DBUSMENU_CLIENT(priv->client), NULL, object); g_warn_if_fail(priv->root == NULL); } if (priv->client != NULL) { g_signal_handlers_disconnect_by_data(priv->client, object); g_object_unref(G_OBJECT(priv->client)); priv->client = NULL; } if (priv->props != NULL) { g_object_unref(G_OBJECT(priv->props)); priv->props = NULL; } if (priv->props_cancel != NULL) { g_cancellable_cancel(priv->props_cancel); g_object_unref(priv->props_cancel); priv->props_cancel = NULL; } if (priv->retry_timer != 0) { g_source_remove(priv->retry_timer); priv->retry_timer = 0; } G_OBJECT_CLASS (window_menu_dbusmenu_parent_class)->dispose (object); return; } /* Retry the event sending to the server to see if we can get things working again. */ static gboolean retry_event (gpointer user_data) { g_debug("Retrying event"); g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data), FALSE); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); dbusmenu_menuitem_handle_event(dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client)), "x-appmenu-retry-ping", NULL, 0); priv->retry_timer = 0; return FALSE; } /* Listen to whether our events are successfully sent */ static void event_status (DbusmenuClient * client, DbusmenuMenuitem * mi, gchar * event, GVariant * evdata, guint timestamp, GError * error, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); /* We don't care about status where there are no errors when we're in a happy state, just let them go. */ if (error == NULL && priv->error_state == FALSE) { return; } int i; /* Oh, things are working now! */ if (error == NULL) { g_debug("Error state repaired"); priv->error_state = FALSE; g_signal_emit_by_name(G_OBJECT(user_data), WINDOW_MENU_SIGNAL_ERROR_STATE, priv->error_state, TRUE); for (i = 0; i < priv->entries->len; i++) { IndicatorObjectEntry * entry = g_array_index(priv->entries, IndicatorObjectEntry *, i); entry_restore(WINDOW_MENU(user_data), entry); } if (priv->retry_timer != 0) { g_source_remove(priv->retry_timer); priv->retry_timer = 0; } return; } /* Uhg, means that events are breaking, now we need to try and handle that case. */ priv->error_state = TRUE; g_signal_emit_by_name(G_OBJECT(user_data), WINDOW_MENU_SIGNAL_ERROR_STATE, priv->error_state, TRUE); for (i = 0; i < priv->entries->len; i++) { IndicatorObjectEntry * entry = g_array_index(priv->entries, IndicatorObjectEntry *, i); if (entry->label != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->label), FALSE); } if (entry->image != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->image), FALSE); } } if (priv->retry_timer == 0) { g_debug("Setting up retry timer"); priv->retry_timer = g_timeout_add_seconds(1, retry_event, user_data); } return; } static IndicatorObjectEntry * get_entry(WindowMenuDbusmenu *wm, DbusmenuMenuitem * item, guint *index) { WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); guint position = 0; for (position = 0; position < priv->entries->len; ++position) { WMEntry * entry = g_array_index(priv->entries, WMEntry *, position); if (entry->mi == item) { if (index != NULL) { *index = position; } return &entry->ioentry; } } /* Not found */ return NULL; } /* Called when a menu item wants to be displayed. We need to see if it's one of our root items and pass it up if so. */ static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * item, guint timestamp, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); if (priv->root == NULL) { return; } IndicatorObjectEntry * entry = get_entry(WINDOW_MENU_DBUSMENU(user_data), item, NULL); if (entry == NULL) { /* Not found */ return; } g_signal_emit_by_name(G_OBJECT(user_data), WINDOW_MENU_SIGNAL_SHOW_MENU, entry, timestamp, TRUE); return; } /* Called when the client changes its status. Used to show panel if requested. (Say, by an Alt press.) */ static void status_changed (DbusmenuClient * client, GParamSpec * pspec, gpointer user_data) { g_signal_emit_by_name(G_OBJECT(user_data), WINDOW_MENU_SIGNAL_STATUS_CHANGED, dbusmenu_client_get_status (client)); } WindowMenuStatus dbusmenu_status_table[] = { [DBUSMENU_STATUS_NORMAL] = WINDOW_MENU_STATUS_NORMAL, [DBUSMENU_STATUS_NOTICE] = WINDOW_MENU_STATUS_ACTIVE }; static WindowMenuStatus get_status (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), DBUSMENU_STATUS_NORMAL); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); return dbusmenu_status_table[dbusmenu_client_get_status (DBUSMENU_CLIENT (priv->client))]; } /* Build a new window menus object and attach to the signals to build up the representative menu. */ WindowMenuDbusmenu * window_menu_dbusmenu_new (const guint windowid, const gchar * dbus_addr, const gchar * dbus_object) { g_debug("Creating new windows menu: %X, %s, %s", windowid, dbus_addr, dbus_object); g_return_val_if_fail(windowid != 0, NULL); g_return_val_if_fail(dbus_addr != NULL, NULL); g_return_val_if_fail(dbus_object != NULL, NULL); WindowMenuDbusmenu * newmenu = WINDOW_MENU_DBUSMENU(g_object_new(WINDOW_MENU_DBUSMENU_TYPE, NULL)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(newmenu); priv->windowid = windowid; /* Build the service proxy */ priv->props_cancel = g_cancellable_new(); g_object_ref(newmenu); /* Take a ref for the async callback */ g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, dbus_addr, dbus_object, "org.freedesktop.DBus.Properties", priv->props_cancel, props_cb, newmenu); priv->client = dbusmenu_gtkclient_new((gchar *)dbus_addr, (gchar *)dbus_object); GtkAccelGroup * agroup = gtk_accel_group_new(); dbusmenu_gtkclient_set_accel_group(priv->client, agroup); g_object_unref(agroup); g_signal_connect(G_OBJECT(priv->client), DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed), newmenu); g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT, G_CALLBACK(event_status), newmenu); g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, G_CALLBACK(item_activate), newmenu); g_signal_connect(G_OBJECT(priv->client), "notify::" DBUSMENU_CLIENT_PROP_STATUS, G_CALLBACK(status_changed), newmenu); DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client)); if (root != NULL) { root_changed(DBUSMENU_CLIENT(priv->client), root, newmenu); } return newmenu; } /* Callback from trying to create the proxy for the service, this could include starting the service. */ static void props_cb (GObject * object, GAsyncResult * res, gpointer user_data) { GError * error = NULL; GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_error_free (error); return; // Must exit before accessing freed memory } WindowMenuDbusmenu * self = WINDOW_MENU_DBUSMENU(user_data); g_return_if_fail(self != NULL); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(self); if (priv->props_cancel != NULL) { g_object_unref(priv->props_cancel); priv->props_cancel = NULL; } if (error != NULL) { g_warning("Could not grab DBus proxy for window %u: %s", priv->windowid, error->message); g_error_free(error); goto out; } /* Okay, we're good to grab the proxy at this point, we're sure that it's ours. */ priv->props = proxy; out: g_object_unref(G_OBJECT(self)); return; } /* Get the location of this entry */ static guint get_location (WindowMenu * wm, IndicatorObjectEntry * entry) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), 0); if (entry == NULL) { return G_MAXUINT; } guint i; WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); for (i = 0; i < priv->entries->len; i++) { if (entry == g_array_index(priv->entries, IndicatorObjectEntry *, i)) { break; } } if (i == priv->entries->len) { return G_MAXUINT; } return i; } /* Get the entries that we have */ static GList * get_entries (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), NULL); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); int i; GList * output = NULL; for (i = 0; i < priv->entries->len; i++) { output = g_list_prepend(output, g_array_index(priv->entries, IndicatorObjectEntry *, i)); } if (output != NULL) { output = g_list_reverse(output); } return output; } /* Goes through the items in the root node and adds them to the flock */ static void new_root_helper (DbusmenuMenuitem * item, gpointer user_data) { WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); menu_entry_added(dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client)), item, priv->entries->len, user_data); return; } /* Remove the various signals that we attach to menuitems to ensure they don't pop up later. */ static void remove_menuitem_signals (DbusmenuMenuitem * mi, gpointer user_data) { g_signal_handlers_disconnect_by_func(G_OBJECT(mi), G_CALLBACK(menu_entry_realized), user_data); g_signal_handlers_disconnect_by_func(G_OBJECT(mi), G_CALLBACK(menu_entry_realized_child_added), user_data); g_signal_handlers_disconnect_matched(mi, G_SIGNAL_MATCH_FUNC, 0, 0, 0, menu_child_realized, NULL); g_signal_handlers_disconnect_matched(mi, G_SIGNAL_MATCH_FUNC, 0, 0, 0, menu_prop_changed, NULL); return; } /* Respond to the root menu item on our client changing */ static void root_changed (DbusmenuClient * client, DbusmenuMenuitem * new_root, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); /* Remove the old entries */ free_entries(G_OBJECT(user_data), TRUE); if (priv->root != NULL) { dbusmenu_menuitem_foreach(priv->root, remove_menuitem_signals, user_data); g_signal_handlers_disconnect_by_data(priv->root, user_data); g_object_unref(priv->root); } priv->root = new_root; /* See if we've got new entries */ if (new_root == NULL) { return; } g_object_ref(priv->root); /* Set up signals */ g_signal_connect(G_OBJECT(new_root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(menu_entry_added), user_data); g_signal_connect(G_OBJECT(new_root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(menu_entry_removed), user_data); /* TODO: Child Moved */ /* Add the new entries */ GList * children = dbusmenu_menuitem_get_children(new_root); while (children != NULL) { new_root_helper(DBUSMENU_MENUITEM(children->data), user_data); children = g_list_next(children); } return; } /* Respond to an entry getting added to the menu */ static void menu_entry_added (DbusmenuMenuitem * root, DbusmenuMenuitem * newentry, guint position, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); g_signal_connect(G_OBJECT(newentry), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(menu_entry_realized), user_data); GtkMenuItem * mi = dbusmenu_gtkclient_menuitem_get(priv->client, newentry); if (mi != NULL) { menu_entry_realized(newentry, user_data); } return; } /* A small clean up function to ensure that the data gets free'd and the ref lost in all cases. */ static void child_realized_data_cleanup (gpointer user_data, GClosure * closure) { gpointer * data = (gpointer *)user_data; g_object_unref(data[1]); g_free(user_data); return; } /* This is the callback for when we're done waiting for a new entry to have children */ static void menu_entry_realized_child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer user_data) { /* Child added may be called more than once, so make sure we only handle it once by disconnecting. */ g_signal_handlers_disconnect_by_func(G_OBJECT(parent), G_CALLBACK(menu_entry_realized_child_added), user_data); menu_entry_realized (parent, user_data); } /* React to the menuitem when we know that it's got all the data that we really need. */ static void menu_entry_realized (DbusmenuMenuitem * newentry, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); GtkMenu * menu = dbusmenu_gtkclient_menuitem_get_submenu(priv->client, newentry); /* Check to see if we have any children, if we don't let's see if we can scare some up for fun. */ GList * children = dbusmenu_menuitem_get_children(newentry); if (children == NULL && g_strcmp0(DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU, dbusmenu_menuitem_property_get(newentry, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) == 0) { dbusmenu_menuitem_send_about_to_show(newentry, NULL, NULL); } if (menu == NULL) { if (children != NULL) { gpointer * data = g_new(gpointer, 2); data[0] = user_data; data[1] = g_object_ref(newentry); g_signal_connect_data(G_OBJECT(children->data), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(menu_child_realized), data, child_realized_data_cleanup, 0); } else { /* Menu entry has no children */ gpointer * data = g_new(gpointer, 2); data[0] = user_data; data[1] = g_object_ref(newentry); /* Make sure the menu item gets displayed on the menu bar */ menu_child_realized(NULL, data); g_free (data); g_signal_connect(G_OBJECT(newentry), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(menu_entry_realized_child_added), user_data); } } else { gpointer * data = g_new(gpointer, 2); data[0] = user_data; data[1] = newentry; menu_child_realized(NULL, data); g_free (data); } return; } /* Respond to properties changing on the menu item so that we can properly hide and show them. */ static void menu_prop_changed (DbusmenuMenuitem * item, const gchar * property, GVariant * value, gpointer user_data) { IndicatorObjectEntry * entry = (IndicatorObjectEntry *)user_data; WMEntry * wmentry = (WMEntry *)user_data; if (!g_strcmp0(property, DBUSMENU_MENUITEM_PROP_VISIBLE)) { if (g_variant_get_boolean(value)) { gtk_widget_show(GTK_WIDGET(entry->label)); wmentry->hidden = FALSE; } else { gtk_widget_hide(GTK_WIDGET(entry->label)); wmentry->hidden = TRUE; } } else if (!g_strcmp0(property, DBUSMENU_MENUITEM_PROP_ENABLED)) { gtk_widget_set_sensitive(GTK_WIDGET(entry->label), g_variant_get_boolean(value)); wmentry->disabled = !g_variant_get_boolean(value); } else if (!g_strcmp0(property, DBUSMENU_MENUITEM_PROP_LABEL)) { const gchar* str = g_variant_get_string(value, NULL); if(str != NULL) gtk_label_set_text_with_mnemonic(entry->label, str); g_clear_pointer(&wmentry->vaccessible_desc, g_variant_unref); entry->accessible_desc = g_variant_get_string(value, NULL); wmentry->vaccessible_desc = g_variant_ref(value); if (wmentry->wm != NULL) { g_signal_emit_by_name(G_OBJECT(wmentry->wm), WINDOW_MENU_SIGNAL_A11Y_UPDATE, entry, TRUE); } } return; } /* We can't go until we have some kids. Really, it's important. */ static void menu_child_realized (DbusmenuMenuitem * child, gpointer user_data) { /* Grab our values out to stack variables */ DbusmenuMenuitem * newentry = DBUSMENU_MENUITEM(((gpointer *)user_data)[1]); WindowMenuDbusmenu * wm = WINDOW_MENU_DBUSMENU(((gpointer *)user_data)[0]); g_return_if_fail(newentry != NULL); g_return_if_fail(wm != NULL); /* Disconnection below will drop the ref for this signal handler, let's make sure that's not a problem */ g_object_ref(G_OBJECT(newentry)); /* Only care about the first */ /* This will cause the cleanup function attached to the signal handler to be run. */ if (child != NULL) { g_signal_handlers_disconnect_by_func(G_OBJECT(child), menu_child_realized, user_data); } WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); WMEntry * wmentry = g_new0(WMEntry, 1); wmentry->wm = wm; IndicatorObjectEntry * entry = &wmentry->ioentry; entry->parent_window = priv->windowid; wmentry->mi = newentry; g_object_ref(G_OBJECT(wmentry->mi)); entry->label = GTK_LABEL(gtk_label_new_with_mnemonic(dbusmenu_menuitem_property_get(newentry, DBUSMENU_MENUITEM_PROP_LABEL))); if (entry->label != NULL) { g_object_ref_sink(entry->label); } g_clear_pointer(&wmentry->vaccessible_desc, g_variant_unref); wmentry->vaccessible_desc = g_variant_ref(dbusmenu_menuitem_property_get_variant(newentry, DBUSMENU_MENUITEM_PROP_LABEL)); entry->accessible_desc = g_variant_get_string(wmentry->vaccessible_desc, NULL); entry->menu = dbusmenu_gtkclient_menuitem_get_submenu(priv->client, newentry); if (entry->menu == NULL) { g_debug("Submenu for %s is NULL", dbusmenu_menuitem_property_get(newentry, DBUSMENU_MENUITEM_PROP_LABEL)); } else { g_object_ref(entry->menu); gtk_menu_detach(entry->menu); g_signal_connect(entry->menu, "destroy", G_CALLBACK(gtk_widget_destroyed), &entry->menu); } g_signal_connect(G_OBJECT(newentry), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_changed), entry); if (dbusmenu_menuitem_property_get_variant(newentry, DBUSMENU_MENUITEM_PROP_VISIBLE) != NULL && dbusmenu_menuitem_property_get_bool(newentry, DBUSMENU_MENUITEM_PROP_VISIBLE) == FALSE) { gtk_widget_hide(GTK_WIDGET(entry->label)); wmentry->hidden = TRUE; } else { gtk_widget_show(GTK_WIDGET(entry->label)); wmentry->hidden = FALSE; } if (dbusmenu_menuitem_property_get_variant (newentry, DBUSMENU_MENUITEM_PROP_ENABLED) != NULL) { gboolean sensitive = dbusmenu_menuitem_property_get_bool(newentry, DBUSMENU_MENUITEM_PROP_ENABLED); gtk_widget_set_sensitive(GTK_WIDGET(entry->label), sensitive); wmentry->disabled = !sensitive; } g_array_append_val(priv->entries, wmentry); g_signal_emit_by_name(G_OBJECT(wm), WINDOW_MENU_SIGNAL_ENTRY_ADDED, entry, TRUE); g_object_unref(newentry); guint pos = dbusmenu_menuitem_get_position (newentry, dbusmenu_menuitem_get_parent (newentry)); if (pos < priv->entries->len - 1) { /* Our entry added signals that we pass up don't have position information, so we can only add to the end of the list of entries. So when we get an inserted-in-the-middle entry, we fake a root change to remove all entries and add them back up again */ g_object_ref(priv->root); root_changed(DBUSMENU_CLIENT(priv->client), priv->root, wm); g_object_unref(priv->root); } return; } /* Respond to an entry getting removed from the menu */ static void menu_entry_removed (DbusmenuMenuitem * root, DbusmenuMenuitem * oldentry, gpointer user_data) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(user_data)); g_return_if_fail(DBUSMENU_IS_MENUITEM(oldentry)); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(user_data); if (priv->entries == NULL || priv->entries->len == 0) { return; } guint position; IndicatorObjectEntry * entry = get_entry(WINDOW_MENU_DBUSMENU(user_data), oldentry, &position); if (entry != NULL) { g_array_remove_index(priv->entries, position); g_signal_emit_by_name(G_OBJECT(user_data), WINDOW_MENU_SIGNAL_ENTRY_REMOVED, entry, TRUE); entry_free(entry); } else { /* We've been called before menu_child_realized fired, * so there isn't a WMEntry yet. Don't be going ahead * and creating one if this menu item continues to live! */ g_signal_handlers_disconnect_by_func(G_OBJECT(oldentry), G_CALLBACK(menu_entry_realized), user_data); g_signal_handlers_disconnect_by_func(G_OBJECT(oldentry), G_CALLBACK(menu_entry_realized_child_added), user_data); } return; } /* Get the XID of this window */ static guint get_xid (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), 0); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); return priv->windowid; } /* Get the path for this object */ gchar * window_menu_dbusmenu_get_path (WindowMenuDbusmenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), NULL); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); GValue obj = {0}; g_value_init(&obj, G_TYPE_STRING); g_object_get_property(G_OBJECT(priv->client), DBUSMENU_CLIENT_PROP_DBUS_OBJECT, &obj); gchar * retval = g_value_dup_string(&obj); g_value_unset(&obj); return retval; } /* Get the address of this object */ gchar * window_menu_dbusmenu_get_address (WindowMenuDbusmenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), NULL); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); GValue obj = {0}; g_value_init(&obj, G_TYPE_STRING); g_object_get_property(G_OBJECT(priv->client), DBUSMENU_CLIENT_PROP_DBUS_NAME, &obj); gchar * retval = g_value_dup_string(&obj); g_value_unset(&obj); return retval; } /* Return whether we're in an error state or not */ static gboolean get_error_state (WindowMenu * wm) { g_return_val_if_fail(IS_WINDOW_MENU_DBUSMENU(wm), TRUE); WindowMenuDbusmenuPrivate * priv = WINDOW_MENU_DBUSMENU_GET_PRIVATE(wm); return priv->error_state; } /* Regain whether we're supposed to be hidden or disabled, we want to keep that if that's the case, otherwise bring back to the base state */ static void entry_restore (WindowMenu * wm, IndicatorObjectEntry * entry) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(wm)); WMEntry * wmentry = (WMEntry *)entry; if (entry->label != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->label), !wmentry->disabled); if (wmentry->hidden) { gtk_widget_hide(GTK_WIDGET(entry->label)); } else { gtk_widget_show(GTK_WIDGET(entry->label)); } } if (entry->image != NULL) { gtk_widget_set_sensitive(GTK_WIDGET(entry->image), !wmentry->disabled); if (wmentry->hidden) { gtk_widget_hide(GTK_WIDGET(entry->image)); } else { gtk_widget_show(GTK_WIDGET(entry->image)); } } return; } /* Signaled when the menu item is activated on the panel so we can pass it down the stack. */ static void entry_activate (WindowMenu * wm, IndicatorObjectEntry * entry, guint timestamp) { g_return_if_fail(IS_WINDOW_MENU_DBUSMENU(wm)); g_return_if_fail(entry != NULL); WMEntry * wme = (WMEntry *)entry; /* If entry is a childless menu item, activate the entry. */ if (entry->menu == NULL) { dbusmenu_menuitem_handle_event(wme->mi, DBUSMENU_MENUITEM_EVENT_ACTIVATED, NULL, 0); /* Otherwise, show the menu */ } else { dbusmenu_menuitem_send_about_to_show(wme->mi, NULL, NULL); } return; } ./src/application-menu-renderer.xml0000644000004100000410000000563112772465331017644 0ustar www-datawww-data An interface to register a menu from an application's window to be displayed in another window.  This manages that association between XWindow Window IDs and the dbus address and object that provides the menu using the dbusmenu dbus interface. Get the location of the menu currently being displayed to the user. The address of the connection on DBus (e.g. :1.23 or org.example.service) The path to the object which implements the com.canonical.dbusmenu interface. Activate menus via DBus An array of indexes of how to get to the menu item to activate. The list only includes menu items that are visible to the user. So if the array was something like [1, 2] it would be the first submenu, second item as if you looked at the menu using a mouse. Turns the currently displayed menu into a JSON representation JSON describing the menu structure rendered by the renderer. The format is described in the website https://wiki.ubuntu.com/DesktopExperienceTeam/ApplicationMenuXdTests#JSON%20format Dumps JSON data describing the menus from a specific window. The XWindow ID of the window to get JSON describing the menu structure rendered by the renderer. Look at @DumpCurrentMenu for more information. ./src/Makefile.am0000644000004100000410000000403712772465331014104 0ustar www-datawww-dataCLEANFILES = DISTCLEANFILES = BUILT_SOURCES = EXTRA_DIST = include $(top_srcdir)/Makefile.am.marshal ###################################### # Building the indicator ###################################### appmenulibdir = $(INDICATORDIR) appmenulib_LTLIBRARIES = libappmenu.la libappmenu_la_SOURCES = \ dbus-shared.h \ gdk-get-func.h \ gdk-get-func.c \ MwmUtil.h \ indicator-appmenu.c \ indicator-appmenu-marshal.c \ window-menu.c \ window-menu.h \ window-menu-dbusmenu.c \ window-menu-dbusmenu.h \ window-menu-model.c \ window-menu-model.h \ gen-application-menu-renderer.xml.c \ gen-application-menu-renderer.xml.h \ gen-application-menu-registrar.xml.c \ gen-application-menu-registrar.xml.h libappmenu_la_CFLAGS = \ $(INDICATOR_CFLAGS) \ $(COVERAGE_CFLAGS) \ -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror -Wno-error=deprecated-declarations -DG_LOG_DOMAIN=\"Indicator-Appmenu\" libappmenu_la_LIBADD = $(INDICATOR_LIBS) -lX11 libappmenu_la_LDFLAGS = \ $(COVERAGE_LDFLAGS) \ -module -avoid-version ###################################### # Build your own marshaller ###################################### glib_marshal_list = indicator-appmenu-marshal.list glib_marshal_prefix = _indicator_appmenu_marshal ###################################### # DBus Love ###################################### DBUS_SPECS = \ application-menu-renderer.xml \ application-menu-registrar.xml gen-%.xml.c: %.xml @echo "Building $@ from $<" @echo "const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<)))) = " > $@ @$(XSLT_PROC) $(srcdir)/clean-namespaces.xslt $< | \ sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": >> $@ @echo ";" >> $@ gen-%.xml.h: %.xml @echo "Building $@ from $<" @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<))));" > $@ BUILT_SOURCES += \ gen-application-menu-renderer.xml.c \ gen-application-menu-renderer.xml.h \ gen-application-menu-registrar.xml.c \ gen-application-menu-registrar.xml.h CLEANFILES += $(BUILT_SOURCES) EXTRA_DIST += $(DBUS_SPECS) clean-namespaces.xslt ./src/window-menu-dbusmenu.h0000644000004100000410000000407512772465331016314 0ustar www-datawww-data/* An implementation of indicator object showing menus from applications. Copyright 2010 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef __WINDOW_MENU_DBUSMENU_H__ #define __WINDOW_MENU_DBUSMENU_H__ #include "window-menu.h" G_BEGIN_DECLS #define WINDOW_MENU_DBUSMENU_TYPE (window_menu_dbusmenu_get_type ()) #define WINDOW_MENU_DBUSMENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), WINDOW_MENU_DBUSMENU_TYPE, WindowMenuDbusmenu)) #define WINDOW_MENU_DBUSMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), WINDOW_MENU_DBUSMENU_TYPE, WindowMenuDbusmenuClass)) #define IS_WINDOW_MENU_DBUSMENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), WINDOW_MENU_DBUSMENU_TYPE)) #define IS_WINDOW_MENU_DBUSMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), WINDOW_MENU_DBUSMENU_TYPE)) #define WINDOW_MENU_DBUSMENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), WINDOW_MENU_DBUSMENU_TYPE, WindowMenuDbusmenuClass)) typedef struct _WindowMenuDbusmenu WindowMenuDbusmenu; typedef struct _WindowMenuDbusmenuClass WindowMenuDbusmenuClass; struct _WindowMenuDbusmenuClass { WindowMenuClass parent_class; }; struct _WindowMenuDbusmenu { WindowMenu parent; }; GType window_menu_dbusmenu_get_type (void); WindowMenuDbusmenu * window_menu_dbusmenu_new (const guint windowid, const gchar * dbus_addr, const gchar * dbus_object); gchar * window_menu_dbusmenu_get_path (WindowMenuDbusmenu * wm); gchar * window_menu_dbusmenu_get_address (WindowMenuDbusmenu * wm); G_END_DECLS #endif ./autogen.sh0000755000004100000410000000032312772465331013254 0ustar www-datawww-data#!/bin/sh PKG_NAME="indicator-appmenu" which gnome-autogen.sh || { echo "You need gnome-common from GNOME SVN" exit 1 } USE_GNOME2_MACROS=1 \ USE_COMMON_DOC_BUILD=yes \ gnome-autogen.sh --enable-gtk-doc $@ ./ChangeLog0000644000004100000410000000003012772465331013020 0ustar www-datawww-data# Generated by Makefile ./Makefile.am.coverage0000644000004100000410000000250512772465331015105 0ustar www-datawww-data # Coverage targets .PHONY: clean-gcno clean-gcda \ coverage-html generate-coverage-html clean-coverage-html \ coverage-gcovr generate-coverage-gcovr clean-coverage-gcovr clean-local: clean-gcno clean-coverage-html clean-coverage-gcovr if HAVE_GCOV clean-gcno: @echo Removing old coverage instrumentation -find -name '*.gcno' -print | xargs -r rm clean-gcda: @echo Removing old coverage results -find -name '*.gcda' -print | xargs -r rm coverage-html: clean-gcda -$(MAKE) $(AM_MAKEFLAGS) -k check $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html generate-coverage-html: @echo Collecting coverage data $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info clean-coverage-html: clean-gcda -$(LCOV) --directory $(top_builddir) -z -rm -rf coverage.info coveragereport if HAVE_GCOVR coverage-gcovr: clean-gcda -$(MAKE) $(AM_MAKEFLAGS) -k check $(MAKE) $(AM_MAKEFLAGS) generate-coverage-gcovr generate-coverage-gcovr: @echo Generating coverage GCOVR report $(GCOVR) -x -r $(top_builddir) -o $(top_builddir)/coverage.xml clean-coverage-gcovr: clean-gcda -rm -rf $(top_builddir)/coverage.xml endif # HAVE_GCOVR endif # HAVE_GCOV ./tests/0000755000004100000410000000000012772465331012417 5ustar www-datawww-data./tests/autopilot/0000755000004100000410000000000012772465331014437 5ustar www-datawww-data./tests/autopilot/tests/0000755000004100000410000000000012772465331015601 5ustar www-datawww-data./tests/autopilot/tests/__init__.py0000644000004100000410000000000012772465331017700 0ustar www-datawww-data./tests/autopilot/tests/test_gedit.py0000644000004100000410000000335512772465331020314 0ustar www-datawww-data from unity.emulators.unity import Unity from unity.tests import UnityTestCase from testtools.matchers import NotEquals, Equals from autopilot.matchers import Eventually from autopilot.introspection.gtk import GtkIntrospectionTestMixin class GeditTestCase(UnityTestCase, GtkIntrospectionTestMixin): def setUp(self): super(GeditTestCase, self).setUp() self.panel_controller = Unity.get_root_instance().panels self.app = self.launch_test_application('gedit') def guess_quit_location(self, file_menu): """Returns an (x, y) location on which to click the 'Quit' menu item.""" # TODO autopilot-gtk could grok location of GtkImageMenuItem geometry = file_menu.menu_geometry lower_margin_click_offset = 20 return (geometry[0] + int(0.5 * geometry[2]), geometry[1] + geometry[3] - lower_margin_click_offset) def test_file_quit(self): """Clicking on 'Quit' exits the application.""" # open the file menu panel = self.panel_controller.get_active_panel() file_menu = lambda : panel.menus.get_menu_by_label('_File') self.assertThat(file_menu, Eventually(NotEquals(None))) file_menu = panel.menus.get_menu_by_label('_File') file_menu.mouse_click() # click on 'Quit' file_menu_is_open = lambda : file_menu.menu_geometry != (0, 0, 0, 0) self.assertThat(file_menu_is_open, Eventually(Equals(True))) location = self.guess_quit_location(file_menu) self.mouse.move(location[0], location[1]) self.mouse.click() # make sure we exited app_is_running = lambda : self.app_is_running('Text Editor') self.assertThat(app_is_running, Eventually(Equals(False))) ./tests/manual/0000755000004100000410000000000012772465331013674 5ustar www-datawww-data./tests/manual/appmenu-firefox.txt0000644000004100000410000000252512772465331017546 0ustar www-datawww-dataTest Firefox Menus ================== These test show that the Firefox menus work in indicator-appmenu Test About Item --------------- #. Start Firefox #. Select Help > About Firefox Outcome A small window should appear with the Firefox logo and version in it Test Bookmark ------------- #. Start Firefox #. Navigate to http://ubuntu.com #. Select Bookmarks > Bookmark this Page Outcome A small dialog should appear with the option to bookmark this page Test Bookmarking ---------------- #. Start Firefox #. Ensure there is no "Homepage | Ubuntu" entry in the Bookmarks menu #. Navigate to http://ubuntu.com #. Select Bookmarks > Bookmark this Page #. Click on "Done" in this dialog #. Open the "Bookmarks" menu Outcome An entry for "Homepage | Ubuntu" should now appear in the Bookmarks menu Test History ---------------- #. Start Firefox #. Navigate to http://canonical.com #. Click on "About Canonical" #. Click on "About Ubuntu" #. Click on "Enterprise Services" #. Click on "Engineering Services" #. Click on "Consumer Services" #. Click on "Partners" #. Open the "History" menu Outcome The history menu should contain entries, from top to bottom, that are "Partners", "Consumer Services", "Engineering Services", "Enterprise Services", "About Ubuntu", "About Canonical" and "Canonical Homepage". All entries should have the Canonical logo. ./tests/manual/appmenu-thunderbird.txt0000644000004100000410000000066512772465331020421 0ustar www-datawww-dataTest Thunderbird Menus ====================== These test validate the menus in Thunderbird Test About Item --------------- #. Open Thunderbird #. Select Help > About Thunderbird Outcome A small window should appear with the Thunderbird logo and version in it Test New Message Item --------------------- #. Open Thunderbird #. Select Message > New Message Outcome A small window should appear with the ability to write an e-mail ./tests/manual/appmenu-evince.txt0000644000004100000410000000143012772465331017347 0ustar www-datawww-dataTest Evince Menus ================= These tests ensure that the menus are working in Evince Test About Item --------------- #. Open the Document Viewer #. Select Help > About Outcome A small dialog should appear with the Evince logo and the version number Test Fullscreen Item -------------------- #. Open the Document Viewer #. Select View > Fullscreen Outcome The screen should be entirely covered with the Document Viewer application Test Sidebar Item -------------------- #. Open the Document Viewer #. Open a PDF file using File > Open #. Verify there is a thumbnails pane on the left hand side #. Open the View menu #. Verify there is a check next to "Side Pane" #. Select "Side Pane" Outcome The thumbnails sidebar on the left hand side of the application should disappear ./tests/manual/appmenu-gedit.txt0000644000004100000410000000153212772465331017175 0ustar www-datawww-dataTest GEdit Menus ================ These tests show that the GEdit menus are working Test About Item --------------- #. Open Text Editor #. Select Help > About Outcome A small window should appear with the GEdit logo and version in it Test Syntax Selection --------------------- #. Open Text Editor #. Type "int foo;" into the editor #. Select View > Highlight Mode > Sources > C Outcome The text 'int' should change color from black Test Undo/Redo Items -------------------- #. Open Text Editor #. Type in "foo" #. Select Edit > Undo #. Select Edit > Redo Outcome The text "foo" should appear when typed. Disappear when selecting to undo it. And then repear when selecting redo. Test Close Item --------------- #. Open Text Editor #. Select File > Close Outcome The window should stay open but the default document tab should be closed. ./tests/manual/appmenu-eog.txt0000644000004100000410000000120712772465331016652 0ustar www-datawww-dataEye of GNOME Menus ================== These tests ensure that the menus work in Eye of GNOME Test About Item --------------- #. Start Image Viewer #. Select Help > About Outcome A small window should appear with the Image View logo and version in it Test Toolbar visibility ----------------------- #. Start Image Viewer #. Open the View menu #. Ensure that the Toolbar item is checked #. Select the Toolbar item Outcome The Image Viewer window should be visible without a toolbar Test Open Dialog ---------------- #. Start Image Viewer #. Select Image > Open Outcome A new dialog should appear that allows you to select a file to open ./tests/manual/Makefile.am0000644000004100000410000000017712772465331015735 0ustar www-datawww-data EXTRA_DIST = \ appmenu-eog.txt \ appmenu-evince.txt \ appmenu-firefox.txt \ appmenu-gedit.txt \ appmenu-thunderbird.txt ./tests/Makefile.am0000644000004100000410000000002512772465331014450 0ustar www-datawww-data SUBDIRS = \ manual ./po/0000755000004100000410000000000012772465331011673 5ustar www-datawww-data./po/POTFILES.skip0000644000004100000410000000020112772465331014001 0ustar www-datawww-datasrc/create-db.c src/gen-application-menu-registrar.xml.c src/gen-application-menu-renderer.xml.c src/indicator-appmenu-marshal.c ./po/POTFILES.in0000644000004100000410000000024112772465331013445 0ustar www-datawww-datadata/com.canonical.indicator.appmenu.gschema.xml src/gdk-get-func.c src/indicator-appmenu.c src/window-menu.c src/window-menu-dbusmenu.c src/window-menu-model.c ./po/indicator-appmenu.pot0000644000004100000410000000156112772465331016041 0ustar www-datawww-data# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-21 11:22+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: ../data/com.canonical.indicator.appmenu.gschema.xml.h:1 msgid "Where the menu is displayed." msgstr "" #: ../data/com.canonical.indicator.appmenu.gschema.xml.h:2 msgid "Controls the menu display location." msgstr "" #: ../src/window-menu-model.c:170 msgid "Unknown Application Name" msgstr "" ./Makefile.am0000644000004100000410000000237312772465331013316 0ustar www-datawww-dataACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} SUBDIRS = \ data \ po \ src if BUILD_TESTS SUBDIRS += \ scripts \ tests \ tools endif tests: src DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --enable-localinstall --enable-deprecations dist-hook: @if test -d "$(top_srcdir)/.bzr"; \ then \ echo Creating ChangeLog && \ ( cd "$(top_srcdir)" && \ echo '# Generated by Makefile. Do not edit.'; echo; \ $(top_srcdir)/missing --run bzr log --gnu-changelog ) > ChangeLog.tmp \ && mv -f ChangeLog.tmp $(top_distdir)/ChangeLog \ || (rm -f ChangeLog.tmp; \ echo Failed to generate ChangeLog >&2 ); \ else \ echo Failed to generate ChangeLog: not a branch >&2; \ fi @if test -d "$(top_srcdir)/.bzr"; \ then \ echo Creating AUTHORS && \ ( cd "$(top_srcdir)" && \ echo '# Generated by Makefile. Do not edit.'; echo; \ $(top_srcdir)/missing --run bzr log --long --levels=0 | grep -e "^\s*author:" -e "^\s*committer:" | cut -d ":" -f 2 | cut -d "<" -f 1 | sort -u) > AUTHORS.tmp \ && mv -f AUTHORS.tmp $(top_distdir)/AUTHORS \ || (rm -f AUTHORS.tmp; \ echo Failed to generate AUTHORS >&2 ); \ else \ echo Failed to generate AUTHORS: not a branch >&2; \ fi include $(top_srcdir)/Makefile.am.coverage ./m4/0000755000004100000410000000000012772465331011575 5ustar www-datawww-data./m4/gcov.m40000644000004100000410000000472412772465331013004 0ustar www-datawww-data# Checks for existence of coverage tools: # * gcov # * lcov # * genhtml # * gcovr # # Sets ac_cv_check_gcov to yes if tooling is present # and reports the executables to the variables LCOV, GCOVR and GENHTML. AC_DEFUN([AC_TDD_GCOV], [ AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov], [enable coverage testing with gcov]), [use_gcov=$enableval], [use_gcov=no]) if test "x$use_gcov" = "xyes"; then # we need gcc: if test "$GCC" != "yes"; then AC_MSG_ERROR([GCC is required for --enable-gcov]) fi # Check if ccache is being used AC_CHECK_PROG(SHTOOL, shtool, shtool) case `$SHTOOL path $CC` in *ccache*[)] gcc_ccache=yes;; *[)] gcc_ccache=no;; esac if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) fi lcov_version_list="1.6 1.7 1.8 1.9 1.10 1.11 1.12" AC_CHECK_PROG(LCOV, lcov, lcov) AC_CHECK_PROG(GENHTML, genhtml, genhtml) if test "$LCOV"; then AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ glib_cv_lcov_version=invalid lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'` for lcov_check_version in $lcov_version_list; do if test "$lcov_version" = "$lcov_check_version"; then glib_cv_lcov_version="$lcov_check_version (ok)" fi done ]) else lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list" AC_MSG_ERROR([$lcov_msg]) fi case $glib_cv_lcov_version in ""|invalid[)] lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)." AC_MSG_ERROR([$lcov_msg]) LCOV="exit 0;" ;; esac if test -z "$GENHTML"; then AC_MSG_ERROR([Could not find genhtml from the lcov package]) fi ac_cv_check_gcov=yes ac_cv_check_lcov=yes # Remove all optimization flags from CFLAGS changequote({,}) CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` changequote([,]) # Add the special gcc flags COVERAGE_CFLAGS="-O0 -fprofile-arcs -ftest-coverage" COVERAGE_CXXFLAGS="-O0 -fprofile-arcs -ftest-coverage" COVERAGE_LDFLAGS="-lgcov" # Check availability of gcovr AC_CHECK_PROG(GCOVR, gcovr, gcovr) if test -z "$GCOVR"; then ac_cv_check_gcovr=no else ac_cv_check_gcovr=yes fi fi ]) # AC_TDD_GCOV ./tools/0000755000004100000410000000000012772465331012415 5ustar www-datawww-data./tools/current-menu-dump.in0000755000004100000410000000056712772465331016347 0ustar www-datawww-data#!/bin/sh TMPFILE=`mktemp` CURMENU="@LIBEXECDIR@/current-menu" DBUSDUMP="@LIBEXECDIR@/dbusmenu-dumper" $CURMENU > $TMPFILE OBPATH=`cat $TMPFILE | cut -d " " -f 3 | cut -d "'" -f 2` echo -n "Path: " echo $OBPATH OBADDR=`cat $TMPFILE | cut -d " " -f 1 | cut -d "'" -f 2` echo -n "Addr: " echo $OBADDR rm -f $TMPFILE $DBUSDUMP --dbus-name $OBADDR --dbus-object $OBPATH ./tools/current-menu0000755000004100000410000000077412772465331014777 0ustar www-datawww-data#!/bin/sh BAMFWINDOW=`gdbus call --session --dest org.ayatana.bamf --object-path /org/ayatana/bamf/matcher --method org.ayatana.bamf.matcher.ActiveWindow | cut -d "'" -f 2` WINDOWID=`gdbus call --session --dest org.ayatana.bamf --object-path $BAMFWINDOW --method org.ayatana.bamf.window.GetXid | cut -d "," -f 1 | cut -d " " -f 2` gdbus call --session --dest com.canonical.AppMenu.Registrar --object-path /com/canonical/AppMenu/Registrar --method com.canonical.AppMenu.Registrar.GetMenuForWindow $WINDOWID ./tools/mock-json-app.c0000644000004100000410000000705712772465331015250 0ustar www-datawww-data/* A little utility to make a mock application using the JSON menu description. Copyright 2010 Canonical Ltd. Authors: Ted Gould This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3, 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 GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include "../src/dbus-shared.h" #define MENU_PATH "/mock/json/app/menu" GtkWidget * window = NULL; DbusmenuServer * server = NULL; GDBusProxy * registrar = NULL; static void dbus_owner_change (GObject *gobject, GParamSpec *pspec, gpointer user_data) { GDBusProxy * proxy = G_DBUS_PROXY(gobject); gchar * owner = g_dbus_proxy_get_name_owner(proxy); if (owner == NULL || owner[0] == '\0') { /* We only care about folks coming on the bus. Exit quickly otherwise. */ g_free(owner); return; } if (g_strcmp0(owner, DBUS_NAME)) { /* We only care about this address, reject all others. */ g_free(owner); return; } GError * error = NULL; g_dbus_proxy_call_sync(registrar, "RegisterWindow", g_variant_new("(uo)", GDK_WINDOW_XID (gtk_widget_get_window (window)), MENU_PATH), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); if (error != NULL) { g_warning("Unable to register: %s", error->message); g_error_free(error); } g_free(owner); return; } static gboolean idle_func (gpointer user_data) { DbusmenuMenuitem * root = dbusmenu_json_build_from_file((const gchar *)user_data); g_return_val_if_fail(root != NULL, FALSE); DbusmenuServer * server = dbusmenu_server_new(MENU_PATH); dbusmenu_server_set_root(server, root); registrar = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, DBUS_NAME, REG_OBJECT, REG_IFACE, NULL, NULL); g_return_val_if_fail(registrar != NULL, FALSE); GError * error = NULL; g_dbus_proxy_call_sync(registrar, "RegisterWindow", g_variant_new("(uo)", GDK_WINDOW_XID (gtk_widget_get_window (window)), MENU_PATH), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (error != NULL) { g_warning("Unable to register: %s", error->message); g_error_free(error); } g_signal_connect(registrar, "notify::g-name-owner", G_CALLBACK(dbus_owner_change), NULL); return FALSE; } static void destroy_cb (void) { gtk_main_quit(); return; } int main (int argv, char ** argc) { if (argv != 2) { g_print("'%s ' is how you should use this program.\n", argc[0]); return 1; } gtk_init(&argv, &argc); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy_cb), NULL); gtk_widget_show(window); g_idle_add(idle_func, argc[1]); gtk_main(); return 0; } ./tools/Makefile.am0000644000004100000410000000102012772465331014442 0ustar www-datawww-data libexec_SCRIPTS = \ current-menu \ current-menu-dump libexec_PROGRAMS = \ mock-json-app current-menu-dump: current-menu-dump.in sed \ -e s:@LIBEXECDIR@:$(libexecdir):g \ $< > $@ chmod +x $@ mock_json_app_SOURCES = \ mock-json-app.c mock_json_app_CFLAGS = \ $(INDICATOR_CFLAGS) \ $(INDICATORTEST_CFLAGS) \ -Wall -Werror -Wno-error=deprecated-declarations mock_json_app_LDADD = \ $(INDICATOR_LIBS) \ $(INDICATORTEST_LIBS) EXTRA_DIST = \ current-menu \ current-menu-dump.in CLEANFILES = \ current-menu-dump ./AUTHORS0000644000004100000410000000003012772465331012316 0ustar www-datawww-data# Generate by Makefile ./data/0000755000004100000410000000000012772465331012166 5ustar www-datawww-data./data/com.canonical.indicator.appmenu.gschema.xml0000644000004100000410000000105012772465331022435 0ustar www-datawww-data 'global' Where the menu is displayed. Controls the menu display location. ./data/Makefile.am0000644000004100000410000000020012772465331014212 0ustar www-datawww-datagsettings_SCHEMAS = \ com.canonical.indicator.appmenu.gschema.xml @GSETTINGS_RULES@ EXTRA_DIST = \ $(gsettings_SCHEMAS)