Add gtk_application_prefers_app_menu()

Applications can call this to determine if they should an app menu.
This will be %FALSE on desktop environments that do not have an
application menu like the one in gnome-shell.  It is %FALSE on Windows
and Mac OS.

Applications are completely free to totally ignore this API -- it is
only provided as a hint to help applications that may be interested in
supporting non-GNOME platforms with a more native 'look and feel'.

https://bugzilla.gnome.org/show_bug.cgi?id=722092
This commit is contained in:
Ryan Lortie
2014-06-30 12:16:19 -04:00
parent d8934ea233
commit d3b34d3cf2
6 changed files with 101 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "config.h"
#include "gtkapplicationprivate.h"
#include "gtksettings.h"
G_DEFINE_TYPE (GtkApplicationImplDBus, gtk_application_impl_dbus, GTK_TYPE_APPLICATION_IMPL)
@ -411,6 +412,38 @@ gtk_application_impl_dbus_is_inhibited (GtkApplicationImpl *impl,
return inhibited;
}
static gboolean
gtk_application_impl_dbus_prefers_app_menu (GtkApplicationImpl *impl)
{
static gboolean decided;
static gboolean result;
/* We do not support notifying if/when the result changes, so make
* sure that once we give an answer, we will always give the same one.
*/
if (!decided)
{
GtkSettings *gtk_settings;
gboolean show_app_menu;
gboolean show_menubar;
gtk_settings = gtk_settings_get_default ();
g_object_get (G_OBJECT (gtk_settings),
"gtk-shell-shows-app-menu", &show_app_menu,
"gtk-shell-shows-menubar", &show_menubar,
NULL);
/* We prefer traditional menus when we have a shell that doesn't
* show the appmenu or we have a shell that shows menubars
* (ie: Unity)
*/
result = show_app_menu && !show_menubar;
decided = TRUE;
}
return result;
}
static void
gtk_application_impl_dbus_init (GtkApplicationImplDBus *dbus)
{
@ -446,6 +479,7 @@ gtk_application_impl_dbus_class_init (GtkApplicationImplDBusClass *class)
impl_class->inhibit = gtk_application_impl_dbus_inhibit;
impl_class->uninhibit = gtk_application_impl_dbus_uninhibit;
impl_class->is_inhibited = gtk_application_impl_dbus_is_inhibited;
impl_class->prefers_app_menu = gtk_application_impl_dbus_prefers_app_menu;
gobject_class->finalize = gtk_application_impl_dbus_finalize;
}