2011-11-30 14:34:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-30 14:34:29 +00:00
|
|
|
*
|
|
|
|
* Author: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkapplicationwindow.h"
|
|
|
|
|
2011-12-17 17:28:30 +00:00
|
|
|
#include "gtkapplicationprivate.h"
|
2012-08-18 03:23:51 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2012-01-20 06:01:08 +00:00
|
|
|
#include "gtkwindowprivate.h"
|
2013-11-16 06:52:04 +00:00
|
|
|
#include "gtkheaderbar.h"
|
2019-12-27 04:49:26 +00:00
|
|
|
#include "gtkpopovermenubar.h"
|
2011-12-01 04:49:23 +00:00
|
|
|
#include "gtkintl.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtksettings.h"
|
2016-04-17 17:38:51 +00:00
|
|
|
#include "gtkshortcutswindowprivate.h"
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2017-03-14 20:00:37 +00:00
|
|
|
#if defined(HAVE_GIO_UNIX) && !defined(__APPLE__)
|
2012-04-11 14:24:04 +00:00
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 00:14:48 +00:00
|
|
|
/**
|
2021-02-27 22:50:24 +00:00
|
|
|
* GtkApplicationWindow:
|
2011-12-01 00:14:48 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* `GtkApplicationWindow` is a `GtkWindow` subclass that integrates with
|
|
|
|
* `GtkApplication`.
|
2011-12-01 22:47:34 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Notably, `GtkApplicationWindow` can handle an application menubar.
|
|
|
|
*
|
|
|
|
* This class implements the `GActionGroup` and `GActionMap` interfaces,
|
2011-12-01 22:47:34 +00:00
|
|
|
* to let you add window-specific actions that will be exported by the
|
2021-02-27 22:50:24 +00:00
|
|
|
* associated [class@Gtk.Application], together with its application-wide
|
|
|
|
* actions. Window-specific actions are prefixed with the “win.”
|
2014-02-05 18:07:34 +00:00
|
|
|
* prefix and application-wide actions are prefixed with the “app.”
|
2021-02-27 22:50:24 +00:00
|
|
|
* prefix. Actions must be addressed with the prefixed name when
|
|
|
|
* referring to them from a `GMenuModel`.
|
2011-12-01 00:14:48 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Note that widgets that are placed inside a `GtkApplicationWindow`
|
2012-01-25 03:51:05 +00:00
|
|
|
* can also activate these actions, if they implement the
|
2021-02-27 22:50:24 +00:00
|
|
|
* [iface@Gtk.Actionable] interface.
|
2011-12-17 18:17:31 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* The settings [property@Gtk.Settings:gtk-shell-shows-app-menu] and
|
|
|
|
* [property@Gtk.Settings:gtk-shell-shows-menubar] tell GTK whether the
|
2011-12-08 04:55:33 +00:00
|
|
|
* desktop environment is showing the application menu and menubar
|
|
|
|
* models outside the application as part of the desktop shell.
|
|
|
|
* For instance, on OS X, both menus will be displayed remotely;
|
2021-02-27 22:50:24 +00:00
|
|
|
* on Windows neither will be.
|
2011-12-08 04:55:33 +00:00
|
|
|
*
|
|
|
|
* If the desktop environment does not display the menubar, then
|
2021-02-27 22:50:24 +00:00
|
|
|
* `GtkApplicationWindow` will automatically show a menubar for it.
|
|
|
|
* This behaviour can be overridden with the
|
|
|
|
* [property@Gtk.ApplicationWindow:show-menubar] property. If the
|
|
|
|
* desktop environment does not display the application menu, then
|
|
|
|
* it will automatically be included in the menubar or in the windows
|
|
|
|
* client-side decorations.
|
2011-12-05 00:16:08 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* See [class@Gtk.PopoverMenu] for information about the XML language
|
|
|
|
* used by `GtkBuilder` for menu models.
|
2020-04-30 00:27:32 +00:00
|
|
|
*
|
2021-02-18 18:28:48 +00:00
|
|
|
* See also: [method@Gtk.Application.set_menubar].
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
* ## A GtkApplicationWindow with a menubar
|
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* The code sample below shows how to set up a `GtkApplicationWindow`
|
|
|
|
* with a menu bar defined on the [class@Gtk.Application]:
|
2021-02-18 18:28:48 +00:00
|
|
|
*
|
|
|
|
* ```c
|
2017-10-11 10:41:47 +00:00
|
|
|
* GtkApplication *app = gtk_application_new ("org.gtk.test", 0);
|
2011-12-05 00:16:08 +00:00
|
|
|
*
|
2017-10-11 10:41:47 +00:00
|
|
|
* GtkBuilder *builder = gtk_builder_new_from_string (
|
2011-12-05 00:16:08 +00:00
|
|
|
* "<interface>"
|
|
|
|
* " <menu id='menubar'>"
|
2020-09-04 11:49:28 +00:00
|
|
|
* " <submenu>"
|
|
|
|
* " <attribute name='label' translatable='yes'>_Edit</attribute>"
|
|
|
|
* " <item>"
|
|
|
|
* " <attribute name='label' translatable='yes'>_Copy</attribute>"
|
|
|
|
* " <attribute name='action'>win.copy</attribute>"
|
|
|
|
* " </item>"
|
|
|
|
* " <item>"
|
|
|
|
* " <attribute name='label' translatable='yes'>_Paste</attribute>"
|
|
|
|
* " <attribute name='action'>win.paste</attribute>"
|
|
|
|
* " </item>"
|
2011-12-05 00:16:08 +00:00
|
|
|
* " </submenu>"
|
|
|
|
* " </menu>"
|
2014-12-23 10:35:40 +00:00
|
|
|
* "</interface>",
|
|
|
|
* -1);
|
2014-02-12 21:09:09 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* GMenuModel *menubar = G_MENU_MODEL (gtk_builder_get_object (builder, "menubar"));
|
2017-10-11 10:41:47 +00:00
|
|
|
* gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
|
2011-12-05 00:16:08 +00:00
|
|
|
* g_object_unref (builder);
|
|
|
|
*
|
2017-10-11 10:41:47 +00:00
|
|
|
* // ...
|
2011-12-05 00:16:08 +00:00
|
|
|
*
|
2017-10-11 10:41:47 +00:00
|
|
|
* GtkWidget *window = gtk_application_window_new (app);
|
2021-02-18 18:28:48 +00:00
|
|
|
* ```
|
2011-12-01 00:14:48 +00:00
|
|
|
*/
|
2011-12-17 17:50:02 +00:00
|
|
|
|
|
|
|
typedef GSimpleActionGroupClass GtkApplicationWindowActionsClass;
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSimpleActionGroup parent_instance;
|
|
|
|
GtkWindow *window;
|
|
|
|
} GtkApplicationWindowActions;
|
|
|
|
|
|
|
|
static GType gtk_application_window_actions_get_type (void);
|
|
|
|
static void gtk_application_window_actions_iface_init (GRemoteActionGroupInterface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindowActions, gtk_application_window_actions, G_TYPE_SIMPLE_ACTION_GROUP,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, gtk_application_window_actions_iface_init))
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_activate_action_full (GRemoteActionGroup *remote,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2011-12-17 17:50:02 +00:00
|
|
|
GVariant *parameter,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions = (GtkApplicationWindowActions *) remote;
|
|
|
|
GApplication *application;
|
|
|
|
GApplicationClass *class;
|
|
|
|
|
|
|
|
application = G_APPLICATION (gtk_window_get_application (actions->window));
|
|
|
|
class = G_APPLICATION_GET_CLASS (application);
|
|
|
|
|
|
|
|
class->before_emit (application, platform_data);
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (actions), action_name, parameter);
|
|
|
|
class->after_emit (application, platform_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_change_action_state_full (GRemoteActionGroup *remote,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2011-12-17 17:50:02 +00:00
|
|
|
GVariant *value,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions = (GtkApplicationWindowActions *) remote;
|
|
|
|
GApplication *application;
|
|
|
|
GApplicationClass *class;
|
|
|
|
|
|
|
|
application = G_APPLICATION (gtk_window_get_application (actions->window));
|
|
|
|
class = G_APPLICATION_GET_CLASS (application);
|
|
|
|
|
|
|
|
class->before_emit (application, platform_data);
|
|
|
|
g_action_group_change_action_state (G_ACTION_GROUP (actions), action_name, value);
|
|
|
|
class->after_emit (application, platform_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_init (GtkApplicationWindowActions *actions)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_iface_init (GRemoteActionGroupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->activate_action_full = gtk_application_window_actions_activate_action_full;
|
|
|
|
iface->change_action_state_full = gtk_application_window_actions_change_action_state_full;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_class_init (GtkApplicationWindowActionsClass *class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSimpleActionGroup *
|
|
|
|
gtk_application_window_actions_new (GtkApplicationWindow *window)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions;
|
|
|
|
|
|
|
|
actions = g_object_new (gtk_application_window_actions_get_type (), NULL);
|
|
|
|
actions->window = GTK_WINDOW (window);
|
|
|
|
|
|
|
|
return G_SIMPLE_ACTION_GROUP (actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now onto GtkApplicationWindow... */
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
typedef struct _GtkApplicationWindowPrivate GtkApplicationWindowPrivate;
|
2011-11-30 14:34:29 +00:00
|
|
|
struct _GtkApplicationWindowPrivate
|
|
|
|
{
|
2011-11-30 16:51:41 +00:00
|
|
|
GSimpleActionGroup *actions;
|
2011-12-02 03:01:07 +00:00
|
|
|
GtkWidget *menubar;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-09-22 03:37:48 +00:00
|
|
|
gboolean show_menubar;
|
2020-07-25 02:57:34 +00:00
|
|
|
guint id;
|
2011-12-02 03:01:07 +00:00
|
|
|
GMenu *menubar_section;
|
2011-12-17 17:28:30 +00:00
|
|
|
|
2015-10-21 04:11:59 +00:00
|
|
|
GtkShortcutsWindow *help_overlay;
|
2011-11-30 14:34:29 +00:00
|
|
|
};
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
static void gtk_application_window_group_iface_init (GActionGroupInterface *iface);
|
|
|
|
static void gtk_application_window_map_iface_init (GActionMapInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_WINDOW,
|
|
|
|
G_ADD_PRIVATE (GtkApplicationWindow)
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_application_window_group_iface_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, gtk_application_window_map_iface_init))
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_update_menubar (GtkApplicationWindow *window)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-12-02 03:01:07 +00:00
|
|
|
gboolean should_have_menubar;
|
|
|
|
gboolean have_menubar;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
have_menubar = priv->menubar != NULL;
|
2011-12-02 03:01:07 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
should_have_menubar = priv->show_menubar &&
|
2020-05-22 21:06:30 +00:00
|
|
|
g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section));
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (have_menubar && !should_have_menubar)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_unparent (priv->menubar);
|
|
|
|
priv->menubar = NULL;
|
2011-12-02 03:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_menubar && should_have_menubar)
|
|
|
|
{
|
|
|
|
GMenu *combined;
|
|
|
|
|
|
|
|
combined = g_menu_new ();
|
2019-05-19 19:52:34 +00:00
|
|
|
g_menu_append_section (combined, NULL, G_MENU_MODEL (priv->menubar_section));
|
2011-12-02 03:01:07 +00:00
|
|
|
|
2019-12-27 04:49:26 +00:00
|
|
|
priv->menubar = gtk_popover_menu_bar_new_from_model (G_MENU_MODEL (combined));
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_set_parent (priv->menubar, GTK_WIDGET (window));
|
2011-12-02 03:01:07 +00:00
|
|
|
g_object_unref (combined);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 20:41:43 +00:00
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
static void
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
|
|
|
|
GtkSettings *settings)
|
2011-12-02 03:01:07 +00:00
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-12-02 03:01:07 +00:00
|
|
|
gboolean shown_by_shell;
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
g_object_get (settings, "gtk-shell-shows-menubar", &shown_by_shell, NULL);
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (shown_by_shell)
|
|
|
|
{
|
|
|
|
/* the shell shows it, so don't show it locally */
|
2019-05-19 19:52:34 +00:00
|
|
|
if (g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)) != 0)
|
|
|
|
g_menu_remove (priv->menubar_section, 0);
|
2011-12-02 03:01:07 +00:00
|
|
|
}
|
|
|
|
else
|
2011-12-01 22:47:34 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
/* the shell does not show it, so make sure we show it */
|
2019-05-19 19:52:34 +00:00
|
|
|
if (g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)) == 0)
|
2011-12-02 03:01:07 +00:00
|
|
|
{
|
2014-06-07 18:04:57 +00:00
|
|
|
GMenuModel *menubar = NULL;
|
2011-12-02 03:01:07 +00:00
|
|
|
|
2014-06-07 18:04:57 +00:00
|
|
|
if (gtk_window_get_application (GTK_WINDOW (window)) != NULL)
|
|
|
|
menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window)));
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (menubar != NULL)
|
2019-05-19 19:52:34 +00:00
|
|
|
g_menu_append_section (priv->menubar_section, NULL, menubar);
|
2011-12-02 03:01:07 +00:00
|
|
|
}
|
2011-12-01 22:47:34 +00:00
|
|
|
}
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_shell_shows_menubar_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = user_data;
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_menubar (window, GTK_SETTINGS (object));
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_application_window_update_menubar (window);
|
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char **
|
2011-11-30 16:51:41 +00:00
|
|
|
gtk_application_window_list_actions (GActionGroup *group)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
/* may be NULL after dispose has run */
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return g_new0 (char *, 0 + 1);
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
return g_action_group_list_actions (G_ACTION_GROUP (priv->actions));
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_application_window_query_action (GActionGroup *group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2011-11-30 16:51:41 +00:00
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
return g_action_group_query_action (G_ACTION_GROUP (priv->actions),
|
2011-11-30 16:51:41 +00:00
|
|
|
action_name, enabled, parameter_type, state_type, state_hint, state);
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:06:40 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_activate_action (GActionGroup *group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2011-11-30 17:06:40 +00:00
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 17:06:40 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (priv->actions), action_name, parameter);
|
2011-11-30 17:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_change_action_state (GActionGroup *group,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name,
|
2011-11-30 17:06:40 +00:00
|
|
|
GVariant *state)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 17:06:40 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_action_group_change_action_state (G_ACTION_GROUP (priv->actions), action_name, state);
|
2011-11-30 17:06:40 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
static GAction *
|
2011-12-01 05:21:11 +00:00
|
|
|
gtk_application_window_lookup_action (GActionMap *action_map,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name)
|
2011-11-30 16:51:41 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return NULL;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
return g_action_map_lookup_action (G_ACTION_MAP (priv->actions), action_name);
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_add_action (GActionMap *action_map,
|
|
|
|
GAction *action)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_action_map_add_action (G_ACTION_MAP (priv->actions), action);
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_remove_action (GActionMap *action_map,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *action_name)
|
2011-11-30 16:51:41 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->actions)
|
2013-12-16 17:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_action_map_remove_action (G_ACTION_MAP (priv->actions), action_name);
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_group_iface_init (GActionGroupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->list_actions = gtk_application_window_list_actions;
|
|
|
|
iface->query_action = gtk_application_window_query_action;
|
2011-11-30 17:06:40 +00:00
|
|
|
iface->activate_action = gtk_application_window_activate_action;
|
|
|
|
iface->change_action_state = gtk_application_window_change_action_state;
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_map_iface_init (GActionMapInterface *iface)
|
|
|
|
{
|
|
|
|
iface->lookup_action = gtk_application_window_lookup_action;
|
|
|
|
iface->add_action = gtk_application_window_add_action;
|
|
|
|
iface->remove_action = gtk_application_window_remove_action;
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2011-12-01 22:47:34 +00:00
|
|
|
PROP_SHOW_MENUBAR,
|
2011-11-30 14:34:29 +00:00
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
static GParamSpec *gtk_application_window_properties[N_PROPS];
|
|
|
|
|
|
|
|
static void
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_application_window_measure (GtkWidget *widget,
|
2016-10-22 14:06:14 +00:00
|
|
|
GtkOrientation orientation,
|
|
|
|
int for_size,
|
|
|
|
int *minimum,
|
|
|
|
int *natural,
|
|
|
|
int *minimum_baseline,
|
|
|
|
int *natural_baseline)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2016-10-22 14:06:14 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
|
|
|
|
orientation,
|
|
|
|
for_size,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
if (priv->menubar != NULL)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
2016-10-22 14:06:14 +00:00
|
|
|
int menubar_min, menubar_nat;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
int menubar_height = 0;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2018-01-17 15:02:28 +00:00
|
|
|
gtk_widget_measure (priv->menubar, GTK_ORIENTATION_VERTICAL,
|
|
|
|
for_size, &menubar_height, NULL, NULL, NULL);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
|
|
|
|
orientation,
|
|
|
|
for_size - menubar_height,
|
|
|
|
minimum, natural,
|
|
|
|
minimum_baseline, natural_baseline);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_measure (priv->menubar, orientation, menubar_height, &menubar_min, &menubar_nat, NULL, NULL);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
*minimum = MAX (*minimum, menubar_min);
|
|
|
|
*natural = MAX (*natural, menubar_nat);
|
2013-11-16 19:49:21 +00:00
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
}
|
|
|
|
else /* VERTICAL */
|
|
|
|
{
|
2016-10-26 15:59:33 +00:00
|
|
|
gtk_widget_measure (priv->menubar, orientation, for_size, &menubar_min, &menubar_nat, NULL, NULL);
|
2016-10-22 14:06:14 +00:00
|
|
|
*minimum += menubar_min;
|
|
|
|
*natural += menubar_nat;
|
|
|
|
}
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_application_window_real_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->menubar != NULL)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
2013-02-26 19:33:04 +00:00
|
|
|
GtkAllocation menubar_allocation;
|
|
|
|
GtkAllocation child_allocation;
|
2020-07-24 13:54:49 +00:00
|
|
|
int menubar_height;
|
2011-11-30 14:34:29 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2018-08-16 04:53:03 +00:00
|
|
|
_gtk_window_set_allocation (GTK_WINDOW (widget), width, height, &child_allocation);
|
2013-02-26 19:33:04 +00:00
|
|
|
menubar_allocation = child_allocation;
|
2012-01-15 00:48:40 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_measure (priv->menubar, GTK_ORIENTATION_VERTICAL,
|
2017-03-04 07:18:21 +00:00
|
|
|
menubar_allocation.width,
|
|
|
|
&menubar_height, NULL, NULL, NULL);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2012-01-14 18:23:02 +00:00
|
|
|
menubar_allocation.height = menubar_height;
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_size_allocate (priv->menubar, &menubar_allocation, baseline);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-11-13 02:01:29 +00:00
|
|
|
child_allocation.y += menubar_height;
|
|
|
|
child_allocation.height -= menubar_height;
|
2020-05-02 19:17:20 +00:00
|
|
|
child = gtk_window_get_child (GTK_WINDOW (window));
|
2011-11-30 14:34:29 +00:00
|
|
|
if (child != NULL && gtk_widget_get_visible (child))
|
2018-03-31 19:02:28 +00:00
|
|
|
gtk_widget_size_allocate (child, &child_allocation, baseline);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
else
|
2017-07-11 07:58:21 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->size_allocate (widget,
|
2018-08-16 04:53:03 +00:00
|
|
|
width,
|
|
|
|
height,
|
2018-03-31 19:02:28 +00:00
|
|
|
baseline);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 20:41:43 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2011-12-03 19:55:03 +00:00
|
|
|
GtkSettings *settings;
|
2011-11-30 20:41:43 +00:00
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
|
|
|
|
g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
|
|
|
|
G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);
|
|
|
|
|
2013-11-16 19:46:10 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->realize (widget);
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_menubar (window, settings);
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_application_window_update_menubar (window);
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_menubar_changed, widget);
|
|
|
|
|
2013-11-16 19:46:10 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unrealize (widget);
|
2011-12-03 19:55:03 +00:00
|
|
|
}
|
|
|
|
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
GActionGroup *
|
|
|
|
gtk_application_window_get_action_group (GtkApplicationWindow *window)
|
2019-05-19 19:52:34 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
|
|
|
return G_ACTION_GROUP (priv->actions);
|
2011-12-17 17:28:30 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-01 04:53:39 +00:00
|
|
|
/* XXX could eliminate this by tweaking gtk_window_map */
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->menubar)
|
|
|
|
gtk_widget_map (priv->menubar);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-11-19 21:24:57 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->map (widget);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 13:27:14 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2014-05-05 13:27:14 +00:00
|
|
|
|
|
|
|
/* XXX could eliminate this by tweaking gtk_window_unmap */
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->menubar)
|
|
|
|
gtk_widget_unmap (priv->menubar);
|
2014-05-05 13:27:14 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
static void
|
2011-12-01 04:59:32 +00:00
|
|
|
gtk_application_window_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-12-01 22:47:34 +00:00
|
|
|
case PROP_SHOW_MENUBAR:
|
2019-05-19 19:52:34 +00:00
|
|
|
g_value_set_boolean (value, priv->show_menubar);
|
2011-11-30 14:34:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 04:59:32 +00:00
|
|
|
gtk_application_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-12-01 22:47:34 +00:00
|
|
|
case PROP_SHOW_MENUBAR:
|
|
|
|
gtk_application_window_set_show_menubar (window, g_value_get_boolean (value));
|
2011-11-30 14:34:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-30 20:55:31 +00:00
|
|
|
gtk_application_window_dispose (GObject *object)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->menubar)
|
2011-12-02 03:13:56 +00:00
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_unparent (priv->menubar);
|
|
|
|
priv->menubar = NULL;
|
2011-12-02 03:13:56 +00:00
|
|
|
}
|
2011-12-02 03:14:57 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_clear_object (&priv->menubar_section);
|
2016-10-12 12:33:39 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->help_overlay)
|
2016-10-12 12:33:39 +00:00
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (priv->help_overlay));
|
2019-05-19 19:52:34 +00:00
|
|
|
g_clear_object (&priv->help_overlay);
|
2016-10-12 12:33:39 +00:00
|
|
|
}
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2015-10-21 04:11:59 +00:00
|
|
|
G_OBJECT_CLASS (gtk_application_window_parent_class)->dispose (object);
|
2013-12-16 17:25:54 +00:00
|
|
|
|
|
|
|
/* We do this below the chain-up above to give us a chance to be
|
|
|
|
* removed from the GtkApplication (which is done in the dispose
|
|
|
|
* handler of GtkWindow).
|
|
|
|
*
|
|
|
|
* That reduces our chances of being watched as a GActionGroup from a
|
2014-01-14 15:33:13 +00:00
|
|
|
* muxer constructed by GtkApplication.
|
2013-12-16 17:25:54 +00:00
|
|
|
*/
|
2019-05-19 19:52:34 +00:00
|
|
|
g_clear_object (&priv->actions);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_init (GtkApplicationWindow *window)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
priv->actions = gtk_application_window_actions_new (window);
|
|
|
|
priv->menubar_section = g_menu_new ();
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (priv->actions));
|
2012-08-17 22:21:59 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
/* priv->actions is the one and only ref on the group, so when
|
2011-11-30 20:55:31 +00:00
|
|
|
* we dispose, the action group will die, disconnecting all signals.
|
2011-11-30 16:51:41 +00:00
|
|
|
*/
|
2019-05-19 19:52:34 +00:00
|
|
|
g_signal_connect_swapped (priv->actions, "action-added",
|
2011-11-30 16:51:41 +00:00
|
|
|
G_CALLBACK (g_action_group_action_added), window);
|
2019-05-19 19:52:34 +00:00
|
|
|
g_signal_connect_swapped (priv->actions, "action-enabled-changed",
|
2011-11-30 16:51:41 +00:00
|
|
|
G_CALLBACK (g_action_group_action_enabled_changed), window);
|
2019-05-19 19:52:34 +00:00
|
|
|
g_signal_connect_swapped (priv->actions, "action-state-changed",
|
2011-11-30 16:51:41 +00:00
|
|
|
G_CALLBACK (g_action_group_action_state_changed), window);
|
2019-05-19 19:52:34 +00:00
|
|
|
g_signal_connect_swapped (priv->actions, "action-removed",
|
2011-11-30 16:51:41 +00:00
|
|
|
G_CALLBACK (g_action_group_action_removed), window);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_class_init (GtkApplicationWindowClass *class)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
2016-10-22 14:06:14 +00:00
|
|
|
widget_class->measure = gtk_application_window_measure;
|
2011-11-30 14:34:29 +00:00
|
|
|
widget_class->size_allocate = gtk_application_window_real_size_allocate;
|
2011-11-30 20:41:43 +00:00
|
|
|
widget_class->realize = gtk_application_window_real_realize;
|
2011-12-03 19:55:03 +00:00
|
|
|
widget_class->unrealize = gtk_application_window_real_unrealize;
|
2011-11-30 14:34:29 +00:00
|
|
|
widget_class->map = gtk_application_window_real_map;
|
2014-05-05 13:27:14 +00:00
|
|
|
widget_class->unmap = gtk_application_window_real_unmap;
|
2017-10-08 02:24:09 +00:00
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
object_class->get_property = gtk_application_window_get_property;
|
|
|
|
object_class->set_property = gtk_application_window_set_property;
|
2011-11-30 20:55:31 +00:00
|
|
|
object_class->dispose = gtk_application_window_dispose;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
2021-02-27 22:50:24 +00:00
|
|
|
* GtkApplicationWindow:show-menubar: (attributes org.gtk.Property.get=gtk_application_window_get_show_menubar org.gtk.Property.set=gtk_application_window_set_show_menubar)
|
2011-12-04 23:40:19 +00:00
|
|
|
*
|
|
|
|
* If this property is %TRUE, the window will display a menubar
|
2021-02-27 22:50:24 +00:00
|
|
|
* unless it is shown by the desktop shell.
|
|
|
|
*
|
|
|
|
* See [method@Gtk.Application.set_menubar].
|
2011-12-04 23:40:19 +00:00
|
|
|
*
|
|
|
|
* If %FALSE, the window will not display a menubar, regardless
|
2020-05-22 21:06:30 +00:00
|
|
|
* of whether the desktop shell is showing it or not.
|
2011-12-04 23:40:19 +00:00
|
|
|
*/
|
2011-12-01 22:47:34 +00:00
|
|
|
gtk_application_window_properties[PROP_SHOW_MENUBAR] =
|
|
|
|
g_param_spec_boolean ("show-menubar",
|
|
|
|
P_("Show a menubar"),
|
2011-12-04 23:40:19 +00:00
|
|
|
P_("TRUE if the window should show a "
|
|
|
|
"menubar at the top of the window"),
|
2020-05-11 00:15:31 +00:00
|
|
|
FALSE, G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
|
2011-11-30 14:34:29 +00:00
|
|
|
g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
|
|
|
|
}
|
|
|
|
|
2011-12-01 04:59:32 +00:00
|
|
|
/**
|
|
|
|
* gtk_application_window_new:
|
2021-02-27 22:50:24 +00:00
|
|
|
* @application: a `GtkApplication`
|
2011-12-01 04:59:32 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Creates a new `GtkApplicationWindow`.
|
2011-12-01 04:59:32 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Returns: a newly created `GtkApplicationWindow`
|
2011-12-01 04:59:32 +00:00
|
|
|
*/
|
2011-11-30 14:34:29 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_application_window_new (GtkApplication *application)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_APPLICATION_WINDOW,
|
|
|
|
"application", application,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
2021-02-27 22:50:24 +00:00
|
|
|
* gtk_application_window_get_show_menubar: (attributes org.gtk.Method.get_property=show-menubar)
|
|
|
|
* @window: a `GtkApplicationWindow`
|
2011-12-04 23:40:19 +00:00
|
|
|
*
|
|
|
|
* Returns whether the window will display a menubar for the app menu
|
|
|
|
* and menubar as needed.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @window will display a menubar when needed
|
|
|
|
*/
|
2011-11-30 14:34:29 +00:00
|
|
|
gboolean
|
2011-12-01 22:47:34 +00:00
|
|
|
gtk_application_window_get_show_menubar (GtkApplicationWindow *window)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
|
|
|
return priv->show_menubar;
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
2021-02-27 22:50:24 +00:00
|
|
|
* gtk_application_window_set_show_menubar: (attributes org.gtk.Method.set_property=show-menubar)
|
|
|
|
* @window: a `GtkApplicationWindow`
|
2011-12-04 23:40:19 +00:00
|
|
|
* @show_menubar: whether to show a menubar when needed
|
|
|
|
*
|
|
|
|
* Sets whether the window will display a menubar for the app menu
|
|
|
|
* and menubar as needed.
|
|
|
|
*/
|
2011-12-02 03:01:07 +00:00
|
|
|
void
|
|
|
|
gtk_application_window_set_show_menubar (GtkApplicationWindow *window,
|
|
|
|
gboolean show_menubar)
|
2011-11-30 20:41:43 +00:00
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2011-12-02 03:01:07 +00:00
|
|
|
g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
|
2011-12-01 22:47:34 +00:00
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
show_menubar = !!show_menubar;
|
2011-12-01 22:47:34 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->show_menubar != show_menubar)
|
2011-11-30 20:41:43 +00:00
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
priv->show_menubar = show_menubar;
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
gtk_application_window_update_menubar (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-01 22:47:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_MENUBAR]);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-06 03:22:06 +00:00
|
|
|
|
2012-04-20 17:29:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_application_window_get_id:
|
2021-02-27 22:50:24 +00:00
|
|
|
* @window: a `GtkApplicationWindow`
|
2012-04-20 17:29:11 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Returns the unique ID of the window.
|
|
|
|
*
|
|
|
|
* If the window has not yet been added to a `GtkApplication`, returns `0`.
|
2012-04-20 17:29:11 +00:00
|
|
|
*
|
2014-02-04 23:21:13 +00:00
|
|
|
* Returns: the unique ID for @window, or `0` if the window
|
2021-02-27 22:50:24 +00:00
|
|
|
* has not yet been added to a `GtkApplication`
|
2012-04-20 17:29:11 +00:00
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gtk_application_window_get_id (GtkApplicationWindow *window)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2012-04-20 17:29:11 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), 0);
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
return priv->id;
|
2012-04-20 17:29:11 +00:00
|
|
|
}
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_application_window_set_id (GtkApplicationWindow *window,
|
|
|
|
guint id)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
|
2019-05-19 19:52:34 +00:00
|
|
|
priv->id = id;
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
}
|
2015-10-21 04:11:59 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
show_help_overlay (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = user_data;
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2015-10-21 04:11:59 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->help_overlay)
|
|
|
|
gtk_widget_show (GTK_WIDGET (priv->help_overlay));
|
2015-10-21 04:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_application_window_set_help_overlay:
|
2021-02-27 22:50:24 +00:00
|
|
|
* @window: a `GtkApplicationWindow`
|
|
|
|
* @help_overlay: (nullable): a `GtkShortcutsWindow`
|
|
|
|
*
|
|
|
|
* Associates a shortcuts window with the application window.
|
2015-10-21 04:11:59 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Additionally, sets up an action with the name
|
|
|
|
* `win.show-help-overlay` to present it.
|
2015-10-21 04:11:59 +00:00
|
|
|
*
|
2020-08-21 12:41:13 +00:00
|
|
|
* @window takes responsibility for destroying @help_overlay.
|
2015-10-21 04:11:59 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_application_window_set_help_overlay (GtkApplicationWindow *window,
|
|
|
|
GtkShortcutsWindow *help_overlay)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2015-10-21 04:11:59 +00:00
|
|
|
g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
|
|
|
|
g_return_if_fail (help_overlay == NULL || GTK_IS_SHORTCUTS_WINDOW (help_overlay));
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (priv->help_overlay)
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (priv->help_overlay));
|
2019-05-19 19:52:34 +00:00
|
|
|
g_set_object (&priv->help_overlay, help_overlay);
|
2015-10-21 04:11:59 +00:00
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!priv->help_overlay)
|
2015-10-21 04:11:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (help_overlay), TRUE);
|
2017-12-31 16:41:09 +00:00
|
|
|
gtk_window_set_hide_on_close (GTK_WINDOW (help_overlay), TRUE);
|
2015-10-21 04:11:59 +00:00
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (help_overlay), GTK_WINDOW (window));
|
2016-04-17 17:38:51 +00:00
|
|
|
gtk_shortcuts_window_set_window (help_overlay, GTK_WINDOW (window));
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
if (!g_action_map_lookup_action (G_ACTION_MAP (priv->actions), "show-help-overlay"))
|
2015-10-21 04:11:59 +00:00
|
|
|
{
|
|
|
|
GSimpleAction *action;
|
|
|
|
|
|
|
|
action = g_simple_action_new ("show-help-overlay", NULL);
|
|
|
|
g_signal_connect (action, "activate", G_CALLBACK (show_help_overlay), window);
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
g_action_map_add_action (G_ACTION_MAP (priv->actions), G_ACTION (action));
|
2017-10-06 14:30:31 +00:00
|
|
|
g_object_unref (G_OBJECT (action));
|
2015-10-21 04:11:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_application_window_get_help_overlay:
|
2021-02-27 22:50:24 +00:00
|
|
|
* @window: a `GtkApplicationWindow`
|
|
|
|
*
|
|
|
|
* Gets the `GtkShortcutsWindow` that is associated with @window.
|
2015-10-21 04:11:59 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* See [method@Gtk.ApplicationWindow.set_help_overlay].
|
2015-10-21 04:11:59 +00:00
|
|
|
*
|
2021-02-27 22:50:24 +00:00
|
|
|
* Returns: (transfer none) (nullable): the help overlay associated
|
|
|
|
* with @window, or %NULL
|
2015-10-21 04:11:59 +00:00
|
|
|
*/
|
|
|
|
GtkShortcutsWindow *
|
|
|
|
gtk_application_window_get_help_overlay (GtkApplicationWindow *window)
|
|
|
|
{
|
2019-05-19 19:52:34 +00:00
|
|
|
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
|
2015-10-21 04:11:59 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), NULL);
|
|
|
|
|
2019-05-19 19:52:34 +00:00
|
|
|
return priv->help_overlay;
|
2015-10-21 04:11:59 +00:00
|
|
|
}
|