From 3ca07f86ab66e3b00a264d0f5dd9c41e700f724b Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:11:31 +0200 Subject: [PATCH] HideTracker: Reveal panel on swipe (#2091) --- src/ShellClients/HideTracker.vala | 42 ++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/ShellClients/HideTracker.vala b/src/ShellClients/HideTracker.vala index ef8d29d2d..37505f6ab 100644 --- a/src/ShellClients/HideTracker.vala +++ b/src/ShellClients/HideTracker.vala @@ -15,6 +15,8 @@ public class Gala.HideTracker : Object { public unowned PanelWindow panel { get; construct; } public Pantheon.Desktop.HideMode hide_mode { get; set; default = NEVER; } + private Clutter.PanAction pan_action; + private bool hovered = false; private bool overlap = false; @@ -60,6 +62,15 @@ public class Gala.HideTracker : Object { }); display.get_workspace_manager ().active_workspace_changed.connect (schedule_update); + + pan_action = new Clutter.PanAction () { + n_touch_points = 1, + pan_axis = X_AXIS + }; + pan_action.gesture_begin.connect (check_valid_gesture); + pan_action.pan.connect (on_pan); + + display.get_stage ().add_action_full ("panel-swipe-gesture", CAPTURE, pan_action); } //Can be removed with mutter > 45 @@ -181,7 +192,7 @@ public class Gala.HideTracker : Object { hovered = window_has_pointer (); #endif - if (should_hide && !hovered) { + if (should_hide && !hovered && !panel.window.has_focus ()) { // Don't hide if we have transients, e.g. an open popover, dialog, etc. var has_transients = false; panel.window.foreach_transient (() => { @@ -198,4 +209,33 @@ public class Gala.HideTracker : Object { show (); } } + + private bool check_valid_gesture () { + if (panel.anchor != BOTTOM) { + debug ("Swipe to reveal is currently only supported for bottom anchors"); + return false; + } + + float y; + pan_action.get_press_coords (0, null, out y); + + var monitor_geom = display.get_monitor_geometry (panel.window.get_monitor ()); + if ((y - monitor_geom.y - monitor_geom.height).abs () < 50) { // Only start if the gesture starts near the bottom of the monitor + return true; + } + + return false; + } + + private bool on_pan () { + float delta_y; + pan_action.get_motion_delta (0, null, out delta_y); + + if (delta_y < 0) { // Only allow swipes upwards + panel.window.focus (pan_action.get_last_event (0).get_time ()); + show (); + } + + return false; + } }