1
0
mirror of https://gitlab.gnome.org/GNOME/nautilus synced 2024-06-30 23:46:35 +00:00

window: Limit managed shortcuts to :child

In order for some window-level shortcuts to trigger on a FileChooser
dialog, which do not belong to NautilusApplication, we need to stop
using gtk_application_set_accels_for_action() and set the shortcuts
directly on widgets.

While at it, their GtkShortcutScope is to be changed from `GLOBAL`
to `MANAGED`. This gives us an opportunity to fully control their
scope and, thus, prevent them from being triggered while, e.g., an
AdwDialog is up.

Related to https://gitlab.gnome.org/GNOME/nautilus/-/work_items/3411
This commit is contained in:
António Fernandes 2024-04-26 18:21:44 +01:00
parent 9edcd430c3
commit 3f17995dbc
5 changed files with 184 additions and 104 deletions

View File

@ -233,6 +233,8 @@ libnautilus_sources = [
'nautilus-search-engine-simple.h',
'nautilus-search-hit.c',
'nautilus-search-hit.h',
'nautilus-shortcut-manager.c',
'nautilus-shortcut-manager.h',
'nautilus-signaller.h',
'nautilus-signaller.c',
'nautilus-query.c',

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2024 GNOME Foundation Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "nautilus-shortcut-manager.h"
/**
* NautilusShortcutManager:
*
* A bin container to limit the scope of GTK_SHORTCUT_SCOPE_MANAGED shortcuts.
*
* The primary use case is to prevent keyboard shortcuts from being triggered
* while `AdwDialog`s are presented. This assumes an implementation detail: that
* `AdwDialog`s are internally children of `AdwWindow`/`AdwApplicationWindow`,
* but not children of `AdwWindow:child`/`AdwApplicationWindow:child`.
*
* This is simply an AdwBin augmented with the GtkShortcutManager interface. The
* default implementation of the interface is sufficient for the purpose.
*/
struct _NautilusShortcutManager
{
AdwBin parent_instance;
};
static void
nautilus_shortcut_manager_interface_init (GtkShortcutManagerInterface *iface)
{
}
G_DEFINE_TYPE_WITH_CODE (NautilusShortcutManager, nautilus_shortcut_manager, ADW_TYPE_BIN,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SHORTCUT_MANAGER,
nautilus_shortcut_manager_interface_init))
static void
nautilus_shortcut_manager_class_init (NautilusShortcutManagerClass *klass)
{
}
static void
nautilus_shortcut_manager_init (NautilusShortcutManager *self)
{
}
NautilusShortcutManager *
nautilus_shortcut_manager_new (void)
{
return g_object_new (NAUTILUS_TYPE_SHORTCUT_MANAGER, NULL);
}

View File

@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 GNOME Foundation Inc.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gtk/gtk.h>
#include <adwaita.h>
G_BEGIN_DECLS
#define NAUTILUS_TYPE_SHORTCUT_MANAGER (nautilus_shortcut_manager_get_type())
G_DECLARE_FINAL_TYPE (NautilusShortcutManager, nautilus_shortcut_manager, NAUTILUS, SHORTCUT_MANAGER, AdwBin)
NautilusShortcutManager * nautilus_shortcut_manager_new (void);
G_END_DECLS

View File

@ -57,6 +57,7 @@
#include "nautilus-pathbar.h"
#include "nautilus-progress-indicator.h"
#include "nautilus-scheme.h"
#include "nautilus-shortcut-manager.h"
#include "nautilus-signaller.h"
#include "nautilus-tag-manager.h"
#include "nautilus-toolbar.h"
@ -2174,6 +2175,7 @@ nautilus_window_init (NautilusWindow *window)
g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
g_type_ensure (NAUTILUS_TYPE_GTK_PLACES_SIDEBAR);
g_type_ensure (NAUTILUS_TYPE_PROGRESS_INDICATOR);
g_type_ensure (NAUTILUS_TYPE_SHORTCUT_MANAGER);
gtk_widget_init_template (GTK_WIDGET (window));
g_signal_connect_object (window->places_sidebar,

View File

@ -112,125 +112,129 @@
<class name="view"/>
</style>
<child>
<object class="AdwToastOverlay" id="toast_overlay">
<object class="NautilusShortcutManager">
<property name="child">
<object class="AdwOverlaySplitView" id="split_view">
<property name="enable-show-gesture">False</property>
<property name="enable-hide-gesture">False</property>
<property name="max-sidebar-width">240</property>
<property name="sidebar-width-unit">px</property>
<property name="sidebar-width-fraction">0.2</property>
<property name="sidebar">
<object class="AdwToolbarView">
<property name="reveal-bottom-bars"
bind-source="progress_indicator" bind-property="reveal"
bind-flags="sync-create"/>
<child type="top">
<object class="AdwHeaderBar">
<child type="start">
<object class="GtkToggleButton">
<property name="tooltip_text" translatable="yes">Search Everywhere</property>
<property name="action_name">slot.search-global</property>
<property name="icon_name">edit-find-symbolic</property>
</object>
</child>
<property name="title-widget">
<object class="AdwWindowTitle">
<property name="title" translatable="yes">Files</property>
</object>
</property>
<child type="end">
<object class="GtkMenuButton">
<property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="icon_name">open-menu-symbolic</property>
<property name="popover">
<object class="GtkPopoverMenu">
<property name="menu-model">app_menu</property>
<child type="zoom-out">
<object class="GtkButton">
<property name="icon-name">zoom-out-symbolic</property>
<property name="action-name">view.zoom-out</property>
<property name="tooltip-text" translatable="yes">Zoom Out</property>
<style>
<class name="flat"/>
<class name="circular"/>
</style>
</object>
</child>
<child type="zoom-in">
<object class="GtkButton">
<property name="icon-name">zoom-in-symbolic</property>
<property name="action-name">view.zoom-in</property>
<property name="tooltip-text" translatable="yes">Zoom In</property>
<style>
<class name="flat"/>
<class name="circular"/>
</style>
</object>
</child>
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="AdwOverlaySplitView" id="split_view">
<property name="enable-show-gesture">False</property>
<property name="enable-hide-gesture">False</property>
<property name="max-sidebar-width">240</property>
<property name="sidebar-width-unit">px</property>
<property name="sidebar-width-fraction">0.2</property>
<property name="sidebar">
<object class="AdwToolbarView">
<property name="reveal-bottom-bars"
bind-source="progress_indicator" bind-property="reveal"
bind-flags="sync-create"/>
<child type="top">
<object class="AdwHeaderBar">
<child type="start">
<object class="GtkToggleButton">
<property name="tooltip_text" translatable="yes">Search Everywhere</property>
<property name="action_name">slot.search-global</property>
<property name="icon_name">edit-find-symbolic</property>
</object>
</child>
<property name="title-widget">
<object class="AdwWindowTitle">
<property name="title" translatable="yes">Files</property>
</object>
</property>
<child type="end">
<object class="GtkMenuButton">
<property name="tooltip-text" translatable="yes">Main Menu</property>
<property name="icon_name">open-menu-symbolic</property>
<property name="popover">
<object class="GtkPopoverMenu">
<property name="menu-model">app_menu</property>
<child type="zoom-out">
<object class="GtkButton">
<property name="icon-name">zoom-out-symbolic</property>
<property name="action-name">view.zoom-out</property>
<property name="tooltip-text" translatable="yes">Zoom Out</property>
<style>
<class name="flat"/>
<class name="circular"/>
</style>
</object>
</child>
<child type="zoom-in">
<object class="GtkButton">
<property name="icon-name">zoom-in-symbolic</property>
<property name="action-name">view.zoom-in</property>
<property name="tooltip-text" translatable="yes">Zoom In</property>
<style>
<class name="flat"/>
<class name="circular"/>
</style>
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="bottom">
<object class="GtkBox">
<style>
<class name="toolbar"/>
</style>
<child>
<object class="NautilusProgressIndicator" id="progress_indicator" />
<child type="bottom">
<object class="GtkBox">
<style>
<class name="toolbar"/>
</style>
<child>
<object class="NautilusProgressIndicator" id="progress_indicator" />
</child>
</object>
</child>
</object>
</child>
<property name="content">
<object class="NautilusGtkPlacesSidebar" id="places_sidebar">
<property name="vexpand">True</property>
<property name="show-other-locations">false</property>
<property name="content">
<object class="NautilusGtkPlacesSidebar" id="places_sidebar">
<property name="vexpand">True</property>
<property name="show-other-locations">false</property>
</object>
</property>
</object>
</property>
</object>
</property>
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="NautilusToolbar" id="toolbar">
<property name="show-toolbar-children">True</property>
<property name="sidebar-button-active" bind-source="split_view" bind-property="show-sidebar" bind-flags="bidirectional|sync-create"/>
<property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" bind-flags="sync-create"/>
</object>
</child>
<child type="top">
<object class="AdwTabBar" id="tab_bar">
<property name="view">tab_view</property>
</object>
</child>
<property name="content">
<object class="AdwTabView" id="tab_view">
<property name="menu-model">tab_menu_model</property>
</object>
</property>
<child type="bottom">
<object class="NautilusNetworkAddressBar" id="network_address_bar">
<property name="visible">False</property>
</object>
</child>
<child type="bottom">
<object class="GtkActionBar" id="action_bar">
<property name="revealed">False</property>
<child type="start">
<object class="NautilusHistoryControls">
<object class="AdwToolbarView">
<child type="top">
<object class="NautilusToolbar" id="toolbar">
<property name="show-toolbar-children">True</property>
<property name="sidebar-button-active" bind-source="split_view" bind-property="show-sidebar" bind-flags="bidirectional|sync-create"/>
<property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" bind-flags="sync-create"/>
</object>
</child>
<child type="end">
<object class="NautilusViewControls">
<property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" bind-flags="sync-create"/>
<child type="top">
<object class="AdwTabBar" id="tab_bar">
<property name="view">tab_view</property>
</object>
</child>
<property name="content">
<object class="AdwTabView" id="tab_view">
<property name="menu-model">tab_menu_model</property>
</object>
</property>
<child type="bottom">
<object class="NautilusNetworkAddressBar" id="network_address_bar">
<property name="visible">False</property>
</object>
</child>
<child type="bottom">
<object class="GtkActionBar" id="action_bar">
<property name="revealed">False</property>
<child type="start">
<object class="NautilusHistoryControls">
<property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" bind-flags="sync-create"/>
</object>
</child>
<child type="end">
<object class="NautilusViewControls">
<property name="window-slot" bind-source="NautilusWindow" bind-property="active-slot" bind-flags="sync-create"/>
</object>
</child>
</object>
</child>
</object>
</child>
</property>
</object>
</property>
</object>