From 0d49c2d7bfd759dda0eebb4141a09d59b672c341 Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 21 Dec 2024 16:54:43 +0100 Subject: [PATCH 1/5] Gestures: Introduce GestureAction --- src/Gestures/Gesture.vala | 43 ++++---- src/Gestures/GestureSettings.vala | 101 +++++++++--------- src/Gestures/GestureTracker.vala | 18 ++-- src/Gestures/ScrollBackend.vala | 38 +++---- src/Gestures/ToucheggBackend.vala | 27 ++--- src/Widgets/MultitaskingView.vala | 20 ++-- .../WindowSwitcher/WindowSwitcher.vala | 8 +- src/WindowManager.vala | 15 ++- src/Zoom.vala | 22 +--- 9 files changed, 130 insertions(+), 162 deletions(-) diff --git a/src/Gestures/Gesture.vala b/src/Gestures/Gesture.vala index 5ffd2831d..54d1b09c3 100644 --- a/src/Gestures/Gesture.vala +++ b/src/Gestures/Gesture.vala @@ -18,7 +18,7 @@ namespace Gala { /** - * Physical direction of the gesture. This direction doesn't follow natural scroll preferences. + * Physical direction of the gesture. */ public enum GestureDirection { UNKNOWN = 0, @@ -34,26 +34,31 @@ namespace Gala { OUT = 6, } - public class Gesture { - public const float INVALID_COORD = float.MAX; + /** + * Action triggered by the gesture. + */ + public class GestureAction { + public enum Type { + NONE, + CUSTOM, // Means we have less than three fingers. Usually only emitted if we are interacting with a component itself e.g. MultitaskingView + SWITCH_WORKSPACE, + MOVE_TO_WORKSPACE, + SWITCH_WINDOWS, + MULTITASKING_VIEW, + ZOOM + } - public Clutter.EventType type; - public GestureDirection direction; - public int fingers; - public Clutter.InputDeviceType performed_on_device_type; + public enum Direction { + FORWARD, + BACKWARD + } - /** - * The x coordinate of the initial contact point for the gesture. - * Doesn't have to be set. In that case it is set to {@link INVALID_COORD}. - * Currently the only backend not setting this is {@link GestureTracker.enable_touchpad}. - */ - public float origin_x = INVALID_COORD; + public GestureAction (Type type, Direction direction) { + this.type = type; + this.direction = direction; + } - /** - * The y coordinate of the initial contact point for the gesture. - * Doesn't have to be set. In that case it is set to {@link INVALID_COORD}. - * Currently the only backend not setting this is {@link GestureTracker.enable_touchpad}. - */ - public float origin_y = INVALID_COORD; + public Type type; + public Direction direction; } } diff --git a/src/Gestures/GestureSettings.vala b/src/Gestures/GestureSettings.vala index 4dd6da0bb..bbdac4b04 100644 --- a/src/Gestures/GestureSettings.vala +++ b/src/Gestures/GestureSettings.vala @@ -20,14 +20,6 @@ * Utility class to access the gesture settings. Easily accessible through GestureTracker.settings. */ public class Gala.GestureSettings : Object { - public enum GestureAction { - NONE, - SWITCH_WORKSPACE, - MOVE_TO_WORKSPACE, - SWITCH_WINDOWS, - MULTITASKING_VIEW - } - private static GLib.Settings gala_settings; private static GLib.Settings touchpad_settings; @@ -36,82 +28,89 @@ public class Gala.GestureSettings : Object { touchpad_settings = new GLib.Settings ("org.gnome.desktop.peripherals.touchpad"); } - public bool is_natural_scroll_enabled (Clutter.InputDeviceType device_type) { + public static bool is_natural_scroll_enabled (Clutter.InputDeviceType device_type) { return (device_type == Clutter.InputDeviceType.TOUCHSCREEN_DEVICE) ? true : touchpad_settings.get_boolean ("natural-scroll"); } - public Meta.MotionDirection? get_direction (Gesture gesture) { - switch (gesture.direction) { - case GestureDirection.UP: - return Meta.MotionDirection.UP; - case GestureDirection.DOWN: - return Meta.MotionDirection.DOWN; - case GestureDirection.LEFT: - return Meta.MotionDirection.LEFT; - case GestureDirection.RIGHT: - return Meta.MotionDirection.RIGHT; - default: - return null; - } + public static string get_string (string setting_id) { + return gala_settings.get_string (setting_id); } - public Meta.MotionDirection? get_natural_scroll_direction (Gesture gesture) { - bool natural_scroll = is_natural_scroll_enabled (gesture.performed_on_device_type); - - switch (gesture.direction) { - case GestureDirection.UP: - return natural_scroll ? Meta.MotionDirection.DOWN : Meta.MotionDirection.UP; - case GestureDirection.DOWN: - return natural_scroll ? Meta.MotionDirection.UP : Meta.MotionDirection.DOWN; - case GestureDirection.LEFT: - return natural_scroll ? Meta.MotionDirection.RIGHT : Meta.MotionDirection.LEFT; - case GestureDirection.RIGHT: - return natural_scroll ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT; + private static GestureAction.Direction get_action_direction (GestureDirection direction) { + switch (direction) { + case LEFT: + case RIGHT: + return direction == RIGHT ? GestureAction.Direction.FORWARD : GestureAction.Direction.BACKWARD; + + case DOWN: + case UP: + return direction == UP ? GestureAction.Direction.FORWARD : GestureAction.Direction.BACKWARD; + + case IN: + case OUT: + return direction == IN ? GestureAction.Direction.FORWARD : GestureAction.Direction.BACKWARD; + default: - return null; + return FORWARD; } } - public static string get_string (string setting_id) { - return gala_settings.get_string (setting_id); - } - - public static GestureAction get_action (Gesture gesture) { - if (gesture.type == TOUCHPAD_SWIPE) { - var fingers = gesture.fingers; + public static GestureAction get_action (Clutter.EventType type, int fingers, GestureDirection direction) { + if (fingers <= 2) { + return new GestureAction (CUSTOM, get_action_direction (direction)); + } - if (gesture.direction == LEFT || gesture.direction == RIGHT) { + switch (direction) { + case RIGHT: + case LEFT: var three_finger_swipe_horizontal = get_string ("three-finger-swipe-horizontal"); var four_finger_swipe_horizontal = get_string ("four-finger-swipe-horizontal"); if (fingers == 3 && three_finger_swipe_horizontal == "switch-to-workspace" || fingers == 4 && four_finger_swipe_horizontal == "switch-to-workspace") { - return SWITCH_WORKSPACE; + return new GestureAction (SWITCH_WORKSPACE, get_action_direction (direction)); } if (fingers == 3 && three_finger_swipe_horizontal == "move-to-workspace" || fingers == 4 && four_finger_swipe_horizontal == "move-to-workspace") { - return MOVE_TO_WORKSPACE; + return new GestureAction (MOVE_TO_WORKSPACE, get_action_direction (direction)); } - if (fingers == 3 && three_finger_swipe_horizontal == "switch-windows" || fingers == 4 && four_finger_swipe_horizontal == "switch-windows") { - return SWITCH_WINDOWS; + return new GestureAction (SWITCH_WINDOWS, get_action_direction (direction)); } - } else if (gesture.direction == UP || gesture.direction == DOWN) { + + break; + + case UP: + case DOWN: var three_finger_swipe_up = get_string ("three-finger-swipe-up"); var four_finger_swipe_up = get_string ("four-finger-swipe-up"); if (fingers == 3 && three_finger_swipe_up == "multitasking-view" || fingers == 4 && four_finger_swipe_up == "multitasking-view") { - return MULTITASKING_VIEW; + return new GestureAction (MULTITASKING_VIEW, get_action_direction (direction)); } - } + + break; + + case IN: + case OUT: + if ((fingers == 3 && GestureSettings.get_string ("three-finger-pinch") == "zoom") || + (fingers == 4 && GestureSettings.get_string ("four-finger-pinch") == "zoom") + ) { + return new GestureAction (ZOOM, get_action_direction (direction)); + } + + break; + + default: + break; } - return NONE; + return new GestureAction (NONE, FORWARD); } } diff --git a/src/Gestures/GestureTracker.vala b/src/Gestures/GestureTracker.vala index 9ca525bb9..8ed1c5766 100644 --- a/src/Gestures/GestureTracker.vala +++ b/src/Gestures/GestureTracker.vala @@ -17,7 +17,7 @@ */ public interface Gala.GestureBackend : Object { - public signal bool on_gesture_detected (Gesture gesture, uint32 timestamp); + public signal bool on_gesture_detected (GestureAction action, uint32 timestamp); public signal void on_begin (double delta, uint64 time); public signal void on_update (double delta, uint64 time); public signal void on_end (double delta, uint64 time); @@ -81,20 +81,20 @@ public class Gala.GestureTracker : Object { * do any preparations instead those should be done in {@link on_gesture_handled}. This is because * the backend might have to do some preparations itself before you are allowed to do some to avoid * conflicts. - * @param gesture Information about the gesture. + * @param action Information about the gesture. * @return true if the gesture will be handled false otherwise. If false is returned the other * signals may still be emitted but aren't guaranteed to be. */ - public signal bool on_gesture_detected (Gesture gesture); + public signal bool on_gesture_detected (GestureAction action); /** * Emitted if true was returned form {@link on_gesture_detected}. This should * be used to do any preparations for gesture handling and to call {@link connect_handlers} to * start receiving updates. - * @param gesture the same gesture as in {@link on_gesture_detected} + * @param action the same gesture as in {@link on_gesture_detected} * @param timestamp the timestamp of the event that initiated the gesture or {@link Meta.CURRENT_TIME}. */ - public signal void on_gesture_handled (Gesture gesture, uint32 timestamp); + public signal void on_gesture_handled (GestureAction action, uint32 timestamp); /** * Emitted right after on_gesture_detected with the initial gesture information. @@ -169,7 +169,7 @@ public class Gala.GestureTracker : Object { * @param orientation If we are interested in the horizontal or vertical axis. */ public void enable_scroll (Clutter.Actor actor, Clutter.Orientation orientation) { - scroll_backend = new ScrollBackend (actor, orientation, settings); + scroll_backend = new ScrollBackend (actor, orientation); scroll_backend.on_gesture_detected.connect (gesture_detected); scroll_backend.on_begin.connect (gesture_begin); scroll_backend.on_update.connect (gesture_update); @@ -227,10 +227,10 @@ public class Gala.GestureTracker : Object { return value; } - private bool gesture_detected (GestureBackend backend, Gesture gesture, uint32 timestamp) { - if (enabled && on_gesture_detected (gesture)) { + private bool gesture_detected (GestureBackend backend, GestureAction action, uint32 timestamp) { + if (enabled && on_gesture_detected (action)) { backend.prepare_gesture_handling (); - on_gesture_handled (gesture, timestamp); + on_gesture_handled (action, timestamp); return true; } diff --git a/src/Gestures/ScrollBackend.vala b/src/Gestures/ScrollBackend.vala index d833264cb..bb70415f4 100644 --- a/src/Gestures/ScrollBackend.vala +++ b/src/Gestures/ScrollBackend.vala @@ -28,22 +28,21 @@ public class Gala.ScrollBackend : Object, GestureBackend { public Clutter.Actor actor { get; construct; } public Clutter.Orientation orientation { get; construct; } - public GestureSettings settings { get; construct; } private bool started; private double delta_x; private double delta_y; - private GestureDirection direction; + private GestureAction.Direction direction; construct { started = false; delta_x = 0; delta_y = 0; - direction = GestureDirection.UNKNOWN; + direction = FORWARD; } - public ScrollBackend (Clutter.Actor actor, Clutter.Orientation orientation, GestureSettings settings) { - Object (actor: actor, orientation: orientation, settings: settings); + public ScrollBackend (Clutter.Actor actor, Clutter.Orientation orientation) { + Object (actor: actor, orientation: orientation); actor.scroll_event.connect (on_scroll_event); } @@ -64,8 +63,8 @@ public class Gala.ScrollBackend : Object, GestureBackend { // Scroll events apply the natural scroll preferences out of the box // Standardize them so the direction matches the physical direction of the gesture and the // GestureTracker user can decide if it wants to follow natural scroll settings or not - bool natural_scroll = settings.is_natural_scroll_enabled (Clutter.InputDeviceType.TOUCHPAD_DEVICE); - if (natural_scroll) { + bool natural_scroll = GestureSettings.is_natural_scroll_enabled (Clutter.InputDeviceType.TOUCHPAD_DEVICE); + if (!natural_scroll) { x *= -1; y *= -1; } @@ -77,10 +76,10 @@ public class Gala.ScrollBackend : Object, GestureBackend { if (delta_x != 0 || delta_y != 0) { float origin_x, origin_y; event.get_coords (out origin_x, out origin_y); - Gesture gesture = build_gesture (origin_x, origin_y, delta_x, delta_y, orientation, time); + GestureAction action = build_gesture (origin_x, origin_y, delta_x, delta_y, orientation, time); started = true; - direction = gesture.direction; - on_gesture_detected (gesture, time); + direction = action.direction; + on_gesture_detected (action, time); double delta = calculate_delta (delta_x, delta_y, direction); on_begin (delta, time); @@ -91,7 +90,7 @@ public class Gala.ScrollBackend : Object, GestureBackend { started = false; delta_x = 0; delta_y = 0; - direction = GestureDirection.UNKNOWN; + direction = FORWARD; on_end (delta, time); } else { on_update (delta, time); @@ -111,7 +110,7 @@ public class Gala.ScrollBackend : Object, GestureBackend { && event.get_scroll_direction () == Clutter.ScrollDirection.SMOOTH; } - private static Gesture build_gesture (float origin_x, float origin_y, double delta_x, double delta_y, Clutter.Orientation orientation, uint32 timestamp) { + private static GestureAction build_gesture (float origin_x, float origin_y, double delta_x, double delta_y, Clutter.Orientation orientation, uint32 timestamp) { GestureDirection direction; if (orientation == Clutter.Orientation.HORIZONTAL) { direction = delta_x > 0 ? GestureDirection.RIGHT : GestureDirection.LEFT; @@ -119,22 +118,15 @@ public class Gala.ScrollBackend : Object, GestureBackend { direction = delta_y > 0 ? GestureDirection.DOWN : GestureDirection.UP; } - return new Gesture () { - type = Clutter.EventType.SCROLL, - direction = direction, - fingers = 2, - performed_on_device_type = Clutter.InputDeviceType.TOUCHPAD_DEVICE, - origin_x = origin_x, - origin_y = origin_y - }; + return GestureSettings.get_action (SCROLL, 2, direction); } - private static double calculate_delta (double delta_x, double delta_y, GestureDirection direction) { - bool is_horizontal = (direction == GestureDirection.LEFT || direction == GestureDirection.RIGHT); + private double calculate_delta (double delta_x, double delta_y, GestureAction.Direction direction) { + bool is_horizontal = orientation == HORIZONTAL; double used_delta = is_horizontal ? delta_x : delta_y; double finish_delta = is_horizontal ? FINISH_DELTA_HORIZONTAL : FINISH_DELTA_VERTICAL; - bool is_positive = (direction == GestureDirection.RIGHT || direction == GestureDirection.DOWN); + bool is_positive = direction == FORWARD; return (used_delta / finish_delta) * (is_positive ? 1 : -1); } diff --git a/src/Gestures/ToucheggBackend.vala b/src/Gestures/ToucheggBackend.vala index df3f076d1..0f81cc4a5 100644 --- a/src/Gestures/ToucheggBackend.vala +++ b/src/Gestures/ToucheggBackend.vala @@ -192,12 +192,16 @@ public class Gala.ToucheggBackend : Object, GestureBackend { signal_params.get ("(uudiut)", out type, out direction, out percentage, out fingers, out performed_on_device_type, out elapsed_time); + if (direction == LEFT || direction == RIGHT) { + direction = direction == RIGHT ? GestureDirection.LEFT : GestureDirection.RIGHT; + } + var delta = percentage * DELTA_MULTIPLIER; switch (signal_name) { case DBUS_ON_GESTURE_BEGIN: Idle.add (() => { - on_gesture_detected (make_gesture (type, direction, fingers, performed_on_device_type), Meta.CURRENT_TIME); + on_gesture_detected (make_gesture (type, direction, fingers), Meta.CURRENT_TIME); on_begin (delta, elapsed_time); return false; }); @@ -219,7 +223,7 @@ public class Gala.ToucheggBackend : Object, GestureBackend { } } - private static Gesture? make_gesture (GestureType type, GestureDirection direction, int fingers, DeviceType performed_on_device_type) { + private static GestureAction? make_gesture (GestureType type, GestureDirection direction, int fingers) { Clutter.EventType event_type; switch (type) { case GestureType.SWIPE: @@ -232,23 +236,6 @@ public class Gala.ToucheggBackend : Object, GestureBackend { return null; } - Clutter.InputDeviceType input_source; - switch (performed_on_device_type) { - case DeviceType.TOUCHPAD: - input_source = Clutter.InputDeviceType.TOUCHPAD_DEVICE; - break; - case DeviceType.TOUCHSCREEN: - input_source = Clutter.InputDeviceType.TOUCHSCREEN_DEVICE; - break; - default: - return null; - } - - return new Gesture () { - type = event_type, - direction = direction, - fingers = fingers, - performed_on_device_type = input_source - }; + return GestureSettings.get_action (event_type, fingers, direction); } } diff --git a/src/Widgets/MultitaskingView.vala b/src/Widgets/MultitaskingView.vala index 6c00b783f..acd51aa19 100644 --- a/src/Widgets/MultitaskingView.vala +++ b/src/Widgets/MultitaskingView.vala @@ -292,40 +292,38 @@ namespace Gala { workspaces.add_transition ("nudge", nudge); } - private bool on_multitasking_gesture_detected (Gesture gesture) { - if (GestureSettings.get_action (gesture) != MULTITASKING_VIEW) { + private bool on_multitasking_gesture_detected (GestureAction action) { + if (action.type != MULTITASKING_VIEW) { return false; } - if (gesture.direction == UP && !opened || gesture.direction == DOWN && opened) { + if (action.direction == FORWARD && !opened || action.direction == BACKWARD && opened) { return true; } return false; } - private bool on_workspace_gesture_detected (Gesture gesture) { + private bool on_workspace_gesture_detected (GestureAction action) { if (!opened) { return false; } - if (gesture.type == SCROLL || GestureSettings.get_action (gesture) == SWITCH_WORKSPACE) { + if (action.type == CUSTOM || action.type == SWITCH_WORKSPACE) { return true; } return false; } - private void switch_workspace_with_gesture (Gesture gesture, uint32 timestamp) { + private void switch_workspace_with_gesture (GestureAction action, uint32 timestamp) { if (switching_workspace_in_progress) { return; } - var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture); - unowned var manager = display.get_workspace_manager (); var num_workspaces = manager.get_n_workspaces (); - var relative_dir = (direction == Meta.MotionDirection.LEFT) ? -1 : 1; + var relative_dir = (action.direction == BACKWARD) ? -1 : 1; unowned var active_workspace = manager.get_active_workspace (); @@ -361,8 +359,8 @@ namespace Gala { switching_workspace_with_gesture = true; - var upper_clamp = (direction == LEFT) ? (active_workspace.index () + 0.1) : (num_workspaces - active_workspace.index () - 0.9); - var lower_clamp = (direction == RIGHT) ? - (active_workspace.index () + 0.1) : - (num_workspaces - active_workspace.index () - 0.9); + var upper_clamp = (action.direction == BACKWARD) ? (active_workspace.index () + 0.1) : (num_workspaces - active_workspace.index () - 0.9); + var lower_clamp = (action.direction == FORWARD) ? - (active_workspace.index () + 0.1) : - (num_workspaces - active_workspace.index () - 0.9); new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x) { overshoot_lower_clamp = lower_clamp, diff --git a/src/Widgets/WindowSwitcher/WindowSwitcher.vala b/src/Widgets/WindowSwitcher/WindowSwitcher.vala index 41ab88f55..506f0f26a 100644 --- a/src/Widgets/WindowSwitcher/WindowSwitcher.vala +++ b/src/Widgets/WindowSwitcher/WindowSwitcher.vala @@ -264,7 +264,7 @@ public class Gala.WindowSwitcher : CanvasActor { next_window (backward); } - public void handle_gesture (GestureDirection direction) { + public void handle_gesture (GestureAction.Direction direction) { handling_gesture = true; unowned var display = wm.get_display (); @@ -278,7 +278,7 @@ public class Gala.WindowSwitcher : CanvasActor { open_switcher (); // if direction == LEFT we need to move to the end of the list first, thats why last_window_index is set to -1 - var last_window_index = direction == RIGHT ? 0 : -1; + var last_window_index = direction == BACKWARD ? 0 : -1; GestureTracker.OnUpdate on_animation_update = (percentage) => { var window_index = GestureTracker.animation_value (0, GESTURE_RANGE_LIMIT, percentage, true); @@ -288,12 +288,12 @@ public class Gala.WindowSwitcher : CanvasActor { if (window_index > last_window_index) { while (last_window_index < window_index) { - next_window (direction == LEFT); + next_window (direction == FORWARD); last_window_index++; } } else if (window_index < last_window_index) { while (last_window_index > window_index) { - next_window (direction == RIGHT); + next_window (direction == BACKWARD); last_window_index--; } } diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 8a1b90375..843a3014d 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -575,20 +575,19 @@ namespace Gala { } } - private bool on_gesture_detected (Gesture gesture) { + private bool on_gesture_detected (GestureAction action) { if (workspace_view.is_opened ()) { return false; } - var action = GestureSettings.get_action (gesture); - switch_workspace_with_gesture = action == SWITCH_WORKSPACE || action == MOVE_TO_WORKSPACE; - return switch_workspace_with_gesture || (action == SWITCH_WINDOWS && !window_switcher.opened); + switch_workspace_with_gesture = action.type == SWITCH_WORKSPACE || action.type == MOVE_TO_WORKSPACE; + return switch_workspace_with_gesture || (action.type == SWITCH_WINDOWS && !window_switcher.opened); } - private void on_gesture_handled (Gesture gesture, uint32 timestamp) { - var direction = gesture_tracker.settings.get_natural_scroll_direction (gesture); + private void on_gesture_handled (GestureAction action, uint32 timestamp) { + var direction = action.direction == FORWARD ? Meta.MotionDirection.RIGHT : Meta.MotionDirection.LEFT; - switch (GestureSettings.get_action (gesture)) { + switch (action.type) { case MOVE_TO_WORKSPACE: unowned var display = get_display (); unowned var manager = display.get_workspace_manager (); @@ -605,7 +604,7 @@ namespace Gala { break; case SWITCH_WINDOWS: - window_switcher.handle_gesture (gesture.direction); + window_switcher.handle_gesture (action.direction); break; default: diff --git a/src/Zoom.vala b/src/Zoom.vala index e833f4134..a038e26a6 100644 --- a/src/Zoom.vala +++ b/src/Zoom.vala @@ -33,7 +33,7 @@ public class Gala.Zoom : Object { gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION); gesture_tracker.enable_touchpad (); gesture_tracker.on_gesture_detected.connect (on_gesture_detected); - gesture_tracker.on_gesture_handled.connect ((gesture) => zoom_with_gesture (gesture.direction)); + gesture_tracker.on_gesture_handled.connect (zoom_with_gesture); behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior"); @@ -69,20 +69,8 @@ public class Gala.Zoom : Object { zoom (-SHORTCUT_DELTA, true, AnimationsSettings.get_enable_animations ()); } - private bool on_gesture_detected (Gesture gesture) { - if (gesture.type != Clutter.EventType.TOUCHPAD_PINCH || - (gesture.direction != GestureDirection.IN && gesture.direction != GestureDirection.OUT) - ) { - return false; - } - - if ((gesture.fingers == 3 && GestureSettings.get_string ("three-finger-pinch") == "zoom") || - (gesture.fingers == 4 && GestureSettings.get_string ("four-finger-pinch") == "zoom") - ) { - return true; - } - - return false; + private bool on_gesture_detected (GestureAction action) { + return action.type == ZOOM; } private bool handle_super_scroll (uint32 timestamp, double dx, double dy) { @@ -101,9 +89,9 @@ public class Gala.Zoom : Object { return Clutter.EVENT_STOP; } - private void zoom_with_gesture (GestureDirection direction) { + private void zoom_with_gesture (GestureAction action, uint32 timestamp) { var initial_zoom = current_zoom; - var target_zoom = (direction == GestureDirection.IN) + var target_zoom = (action.direction == FORWARD) ? initial_zoom - MAX_ZOOM : initial_zoom + MAX_ZOOM; From 88317ca1dce4107a5c2f740ec1e13b9433118b0d Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 21 Dec 2024 17:06:05 +0100 Subject: [PATCH 2/5] ScrollBackend: More parameter cleanup --- src/Gestures/ScrollBackend.vala | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Gestures/ScrollBackend.vala b/src/Gestures/ScrollBackend.vala index bb70415f4..45c550536 100644 --- a/src/Gestures/ScrollBackend.vala +++ b/src/Gestures/ScrollBackend.vala @@ -76,16 +76,16 @@ public class Gala.ScrollBackend : Object, GestureBackend { if (delta_x != 0 || delta_y != 0) { float origin_x, origin_y; event.get_coords (out origin_x, out origin_y); - GestureAction action = build_gesture (origin_x, origin_y, delta_x, delta_y, orientation, time); + GestureAction action = build_gesture (delta_x, delta_y); started = true; direction = action.direction; on_gesture_detected (action, time); - double delta = calculate_delta (delta_x, delta_y, direction); + double delta = calculate_delta (delta_x, delta_y); on_begin (delta, time); } } else { - double delta = calculate_delta (delta_x, delta_y, direction); + double delta = calculate_delta (delta_x, delta_y); if (x == 0 && y == 0) { started = false; delta_x = 0; @@ -100,19 +100,9 @@ public class Gala.ScrollBackend : Object, GestureBackend { return true; } -#if HAS_MUTTER45 - private static bool can_handle_event (Clutter.Event event) { -#else - private static bool can_handle_event (Clutter.ScrollEvent event) { -#endif - return event.get_type () == Clutter.EventType.SCROLL - && event.get_source_device ().get_device_type () == Clutter.InputDeviceType.TOUCHPAD_DEVICE - && event.get_scroll_direction () == Clutter.ScrollDirection.SMOOTH; - } - - private static GestureAction build_gesture (float origin_x, float origin_y, double delta_x, double delta_y, Clutter.Orientation orientation, uint32 timestamp) { + private GestureAction build_gesture (double delta_x, double delta_y) { GestureDirection direction; - if (orientation == Clutter.Orientation.HORIZONTAL) { + if (orientation == HORIZONTAL) { direction = delta_x > 0 ? GestureDirection.RIGHT : GestureDirection.LEFT; } else { direction = delta_y > 0 ? GestureDirection.DOWN : GestureDirection.UP; @@ -121,7 +111,7 @@ public class Gala.ScrollBackend : Object, GestureBackend { return GestureSettings.get_action (SCROLL, 2, direction); } - private double calculate_delta (double delta_x, double delta_y, GestureAction.Direction direction) { + private double calculate_delta (double delta_x, double delta_y) { bool is_horizontal = orientation == HORIZONTAL; double used_delta = is_horizontal ? delta_x : delta_y; double finish_delta = is_horizontal ? FINISH_DELTA_HORIZONTAL : FINISH_DELTA_VERTICAL; @@ -130,4 +120,14 @@ public class Gala.ScrollBackend : Object, GestureBackend { return (used_delta / finish_delta) * (is_positive ? 1 : -1); } + +#if HAS_MUTTER45 + private static bool can_handle_event (Clutter.Event event) { +#else + private static bool can_handle_event (Clutter.ScrollEvent event) { +#endif + return event.get_type () == Clutter.EventType.SCROLL + && event.get_source_device ().get_device_type () == Clutter.InputDeviceType.TOUCHPAD_DEVICE + && event.get_scroll_direction () == Clutter.ScrollDirection.SMOOTH; + } } From b82835c2a94f4d96a4d5216ebcf56c5980be927d Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 21 Dec 2024 17:08:29 +0100 Subject: [PATCH 3/5] Remove need for event type --- src/Gestures/GestureSettings.vala | 2 +- src/Gestures/ScrollBackend.vala | 2 +- src/Gestures/ToucheggBackend.vala | 18 +----------------- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/Gestures/GestureSettings.vala b/src/Gestures/GestureSettings.vala index bbdac4b04..31c6dc92c 100644 --- a/src/Gestures/GestureSettings.vala +++ b/src/Gestures/GestureSettings.vala @@ -57,7 +57,7 @@ public class Gala.GestureSettings : Object { } } - public static GestureAction get_action (Clutter.EventType type, int fingers, GestureDirection direction) { + public static GestureAction get_action (int fingers, GestureDirection direction) { if (fingers <= 2) { return new GestureAction (CUSTOM, get_action_direction (direction)); } diff --git a/src/Gestures/ScrollBackend.vala b/src/Gestures/ScrollBackend.vala index 45c550536..c727f3ad6 100644 --- a/src/Gestures/ScrollBackend.vala +++ b/src/Gestures/ScrollBackend.vala @@ -108,7 +108,7 @@ public class Gala.ScrollBackend : Object, GestureBackend { direction = delta_y > 0 ? GestureDirection.DOWN : GestureDirection.UP; } - return GestureSettings.get_action (SCROLL, 2, direction); + return GestureSettings.get_action (2, direction); } private double calculate_delta (double delta_x, double delta_y) { diff --git a/src/Gestures/ToucheggBackend.vala b/src/Gestures/ToucheggBackend.vala index 0f81cc4a5..d8e227e20 100644 --- a/src/Gestures/ToucheggBackend.vala +++ b/src/Gestures/ToucheggBackend.vala @@ -201,7 +201,7 @@ public class Gala.ToucheggBackend : Object, GestureBackend { switch (signal_name) { case DBUS_ON_GESTURE_BEGIN: Idle.add (() => { - on_gesture_detected (make_gesture (type, direction, fingers), Meta.CURRENT_TIME); + on_gesture_detected (GestureSettings.get_action (fingers, direction), Meta.CURRENT_TIME); on_begin (delta, elapsed_time); return false; }); @@ -222,20 +222,4 @@ public class Gala.ToucheggBackend : Object, GestureBackend { break; } } - - private static GestureAction? make_gesture (GestureType type, GestureDirection direction, int fingers) { - Clutter.EventType event_type; - switch (type) { - case GestureType.SWIPE: - event_type = Clutter.EventType.TOUCHPAD_SWIPE; - break; - case GestureType.PINCH: - event_type = Clutter.EventType.TOUCHPAD_PINCH; - break; - default: - return null; - } - - return GestureSettings.get_action (event_type, fingers, direction); - } } From 9f869837585bbd8cca63db93f7f9c993940eeb9f Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 21 Dec 2024 17:22:41 +0100 Subject: [PATCH 4/5] Fix direction --- src/Gestures/ScrollBackend.vala | 2 +- src/Gestures/ToucheggBackend.vala | 4 ---- src/Widgets/MultitaskingView.vala | 7 ++++--- src/Widgets/WindowSwitcher/WindowSwitcher.vala | 8 ++++---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Gestures/ScrollBackend.vala b/src/Gestures/ScrollBackend.vala index c727f3ad6..8659681fc 100644 --- a/src/Gestures/ScrollBackend.vala +++ b/src/Gestures/ScrollBackend.vala @@ -64,7 +64,7 @@ public class Gala.ScrollBackend : Object, GestureBackend { // Standardize them so the direction matches the physical direction of the gesture and the // GestureTracker user can decide if it wants to follow natural scroll settings or not bool natural_scroll = GestureSettings.is_natural_scroll_enabled (Clutter.InputDeviceType.TOUCHPAD_DEVICE); - if (!natural_scroll) { + if (natural_scroll) { x *= -1; y *= -1; } diff --git a/src/Gestures/ToucheggBackend.vala b/src/Gestures/ToucheggBackend.vala index d8e227e20..01f7ebd4d 100644 --- a/src/Gestures/ToucheggBackend.vala +++ b/src/Gestures/ToucheggBackend.vala @@ -192,10 +192,6 @@ public class Gala.ToucheggBackend : Object, GestureBackend { signal_params.get ("(uudiut)", out type, out direction, out percentage, out fingers, out performed_on_device_type, out elapsed_time); - if (direction == LEFT || direction == RIGHT) { - direction = direction == RIGHT ? GestureDirection.LEFT : GestureDirection.RIGHT; - } - var delta = percentage * DELTA_MULTIPLIER; switch (signal_name) { diff --git a/src/Widgets/MultitaskingView.vala b/src/Widgets/MultitaskingView.vala index acd51aa19..f2f720858 100644 --- a/src/Widgets/MultitaskingView.vala +++ b/src/Widgets/MultitaskingView.vala @@ -323,7 +323,8 @@ namespace Gala { unowned var manager = display.get_workspace_manager (); var num_workspaces = manager.get_n_workspaces (); - var relative_dir = (action.direction == BACKWARD) ? -1 : 1; + // If we are going forward we are moving right so in order to have the ui switch forward with us we have to go to a workspace to the left + var relative_dir = (action.direction == FORWARD) ? -1 : 1; unowned var active_workspace = manager.get_active_workspace (); @@ -359,8 +360,8 @@ namespace Gala { switching_workspace_with_gesture = true; - var upper_clamp = (action.direction == BACKWARD) ? (active_workspace.index () + 0.1) : (num_workspaces - active_workspace.index () - 0.9); - var lower_clamp = (action.direction == FORWARD) ? - (active_workspace.index () + 0.1) : - (num_workspaces - active_workspace.index () - 0.9); + var upper_clamp = (action.direction == FORWARD) ? (active_workspace.index () + 0.1) : (num_workspaces - active_workspace.index () - 0.9); + var lower_clamp = (action.direction == BACKWARD) ? - (active_workspace.index () + 0.1) : - (num_workspaces - active_workspace.index () - 0.9); new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x) { overshoot_lower_clamp = lower_clamp, diff --git a/src/Widgets/WindowSwitcher/WindowSwitcher.vala b/src/Widgets/WindowSwitcher/WindowSwitcher.vala index 506f0f26a..1e0de31d1 100644 --- a/src/Widgets/WindowSwitcher/WindowSwitcher.vala +++ b/src/Widgets/WindowSwitcher/WindowSwitcher.vala @@ -277,8 +277,8 @@ public class Gala.WindowSwitcher : CanvasActor { } open_switcher (); - // if direction == LEFT we need to move to the end of the list first, thats why last_window_index is set to -1 - var last_window_index = direction == BACKWARD ? 0 : -1; + // if direction == BACKWARD we need to move to the end of the list first, thats why last_window_index is set to -1 + var last_window_index = direction == FORWARD ? 0 : -1; GestureTracker.OnUpdate on_animation_update = (percentage) => { var window_index = GestureTracker.animation_value (0, GESTURE_RANGE_LIMIT, percentage, true); @@ -288,12 +288,12 @@ public class Gala.WindowSwitcher : CanvasActor { if (window_index > last_window_index) { while (last_window_index < window_index) { - next_window (direction == FORWARD); + next_window (direction == BACKWARD); last_window_index++; } } else if (window_index < last_window_index) { while (last_window_index > window_index) { - next_window (direction == BACKWARD); + next_window (direction == FORWARD); last_window_index--; } } From 9a0fa84ab21aeb36832c14158e35362b1e190dee Mon Sep 17 00:00:00 2001 From: Leonhard Kargl Date: Sat, 21 Dec 2024 17:24:37 +0100 Subject: [PATCH 5/5] Add missing file --- src/WindowManager.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/WindowManager.vala b/src/WindowManager.vala index 843a3014d..802c48077 100644 --- a/src/WindowManager.vala +++ b/src/WindowManager.vala @@ -585,7 +585,8 @@ namespace Gala { } private void on_gesture_handled (GestureAction action, uint32 timestamp) { - var direction = action.direction == FORWARD ? Meta.MotionDirection.RIGHT : Meta.MotionDirection.LEFT; + // If we are going forward we are moving right so in order to have the ui switch forward with us we have to go to a workspace to the left + var direction = action.direction == FORWARD ? Meta.MotionDirection.LEFT : Meta.MotionDirection.RIGHT; switch (action.type) { case MOVE_TO_WORKSPACE: