[libadwaita/wip/exalm/leaflet-shortcuts: 5/6] leaflet: Add back/forward shortcuts




commit ecb46da72ce54324a8e786924b5c9cc59a2b9fad
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Feb 13 19:56:19 2021 +0500

    leaflet: Add back/forward shortcuts

 src/adw-leaflet.c            | 39 ++++++++++++++++++++++++++++++++++++++-
 src/adw-preferences-window.c |  4 ++++
 2 files changed, 42 insertions(+), 1 deletion(-)
---
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index 0fcba9b9..e9b3f588 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -2226,6 +2226,20 @@ adw_leaflet_finalize (GObject *object)
   G_OBJECT_CLASS (adw_leaflet_parent_class)->finalize (object);
 }
 
+static gboolean
+back_forward_shortcut_cb (AdwLeaflet *self,
+                          GVariant   *args)
+{
+  AdwNavigationDirection direction;
+
+  g_variant_get (args, "h", &direction);
+
+  direction = adjust_direction_for_rtl (self, direction);
+
+  return can_navigate_in_direction (self, direction) &&
+         adw_leaflet_navigate (self, direction);
+}
+
 static void
 adw_leaflet_class_init (AdwLeafletClass *klass)
 {
@@ -2409,6 +2423,11 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
    * - Horizontal scrolling on touchpads (usually two-finger swipe)
    * - Back/forward mouse buttons
    *
+   * The keyboard back/forward keys are also supported, as well as the Alt+←
+   * and Alt+→ shortcuts.
+   *
+   * For right-to-left locales, gestures and shortcuts are reversed.
+   *
    * Only children that have [property@Adw.LeafletPage:navigatable] set to
    * `TRUE` can be navigated to.
    *
@@ -2431,6 +2450,11 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
    * - Horizontal scrolling on touchpads (usually two-finger swipe)
    * - Back/forward mouse buttons
    *
+   * The keyboard back/forward keys are also supported, as well as the Alt+←
+   * and Alt+→ shortcuts.
+   *
+   * For right-to-left locales, gestures and shortcuts are reversed.
+   *
    * Only children that have [property@Adw.LeafletPage:navigatable] set to
    * `TRUE` can be navigated to.
    *
@@ -2478,7 +2502,20 @@ adw_leaflet_class_init (AdwLeafletClass *klass)
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
   gtk_widget_class_set_css_name (widget_class, "leaflet");
-}
+
+  gtk_widget_class_add_binding (widget_class, GDK_KEY_Back, 0,
+                                (GtkShortcutFunc) back_forward_shortcut_cb,
+                                "h", ADW_NAVIGATION_DIRECTION_BACK);
+  gtk_widget_class_add_binding (widget_class, GDK_KEY_Forward, 0,
+                                (GtkShortcutFunc) back_forward_shortcut_cb,
+                                "h", ADW_NAVIGATION_DIRECTION_FORWARD);
+
+  gtk_widget_class_add_binding (widget_class, GDK_KEY_Left, GDK_ALT_MASK,
+                                (GtkShortcutFunc) back_forward_shortcut_cb,
+                                "h", ADW_NAVIGATION_DIRECTION_BACK);
+  gtk_widget_class_add_binding (widget_class,  GDK_KEY_Right, GDK_ALT_MASK,
+                                (GtkShortcutFunc) back_forward_shortcut_cb,
+                                "h", ADW_NAVIGATION_DIRECTION_FORWARD);}
 
 
 static void
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index b50ced49..6e951516 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -570,6 +570,10 @@ adw_preferences_window_class_init (AdwPreferencesWindowClass *klass)
    * - Horizontal scrolling on touchpads (usually two-finger swipe)
    * - Back mouse button
    *
+   * The keyboard back key is also supported, as well as the Alt+← shortcut.
+   *
+   * For right-to-left locales, gestures and shortcuts are reversed.
+   *
    * Since: 1.0
    */
   props[PROP_CAN_NAVIGATE_BACK] =


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]