From d090b3bcd5b656554fba96ec85d5e8ae74ffa37e Mon Sep 17 00:00:00 2001 From: Daniel Sheeler Date: Sat, 4 Nov 2023 03:35:25 -0500 Subject: [PATCH] Introduce an option to invert the swipe direction. --- ...ome.shell.extensions.coverflowalttab.gschema.xml | 4 ++++ src/platform.js | 5 +++-- src/prefs.js | 10 ++++++---- src/swipeTracker.js | 13 +++++++++---- src/switcher.js | 3 ++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/schemas/org.gnome.shell.extensions.coverflowalttab.gschema.xml b/schemas/org.gnome.shell.extensions.coverflowalttab.gschema.xml index d482bbb..737d9af 100644 --- a/schemas/org.gnome.shell.extensions.coverflowalttab.gschema.xml +++ b/schemas/org.gnome.shell.extensions.coverflowalttab.gschema.xml @@ -214,5 +214,9 @@ false Use a "glitch effect" on the background application switcher + + false + Swipe content instead of view + diff --git a/src/platform.js b/src/platform.js index f354835..9c6ddbe 100644 --- a/src/platform.js +++ b/src/platform.js @@ -129,6 +129,7 @@ class AbstractPlatform { use_theme_color_for_tint_color: false, use_glitch_effect: false, use_tint: false, + invert_swipes: false, }; } @@ -164,8 +165,6 @@ export class PlatformGnomeShell extends AbstractPlatform { } enable() { - //this.disable(); - this._settings_changed_callbacks = []; if (this._desktopSettings == null) @@ -202,6 +201,7 @@ export class PlatformGnomeShell extends AbstractPlatform { "tint-color", "use-theme-color-for-tint-color", "use-glitch-effect", + "invert-swipes", ]; let dkeys = [ @@ -316,6 +316,7 @@ export class PlatformGnomeShell extends AbstractPlatform { use_theme_color_for_tint_color: settings.get_boolean("use-theme-color-for-tint-color"), use_glitch_effect: settings.get_boolean("use-glitch-effect"), use_tint: settings.get_boolean("use-tint"), + invert_swipes: settings.get_boolean("invert-swipes"), }; } catch (e) { global.log(e); diff --git a/src/prefs.js b/src/prefs.js index 98811e4..d53e681 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -146,15 +146,17 @@ export default class CoverflowAltTabPreferences extends ExtensionPreferences { let switcher_pref_group = new Adw.PreferencesGroup({ title: _('Switcher'), }); - switcher_pref_group.add(buildRadioAdw(settings, "switcher-style", new Map([ [_("Coverflow"), []], [_("Timeline"), []] ]), _("Style"), _("Pick the type of switcher."))) + let switcher_looping_method_buttons = new Map([ [_("Flip Stack"), []], [_("Carousel"), []]]); + + let switcher_looping_method_row = buildRadioAdw(settings, "switcher-looping-method", switcher_looping_method_buttons, _("Looping Method"), _("How to cycle through windows.")); + switcher_pref_group.add(buildRadioAdw(settings, "switcher-style", new Map([ [_("Coverflow"), [switcher_looping_method_row]], [_("Timeline"), []] ]), _("Style"), _("Pick the type of switcher."))) switcher_pref_group.add(buildSpinAdw(settings, "offset", [-500, 500, 1, 10], _("Vertical Offset"), _("Positive value moves everything down, negative up."))); switcher_pref_group.add(buildRadioAdw(settings, "position", new Map([ [_("Bottom"), []], [_("Top"), []]]), _("Window Title Position"), _("Place window title above or below the switcher."))); switcher_pref_group.add(buildSwitcherAdw(settings, "enforce-primary-monitor", [], _("Enforce Primary Monitor"), _("Always show on the primary monitor, otherwise, show on the active monitor."))); - let switcher_looping_method_buttons = new Map([ [_("Flip Stack"), []], [_("Carousel"), []]]); - switcher_pref_group.add(buildRadioAdw(settings, "switcher-looping-method", switcher_looping_method_buttons, _("Looping Method"), _("How to cycle through windows."))); + switcher_pref_group.add(switcher_looping_method_row); switcher_pref_group.add(buildSwitcherAdw(settings, "hide-panel", [], _("Hide Panel"), _("Hide panel when switching windows."))); - + switcher_pref_group.add(buildSwitcherAdw(settings, "invert-swipes", [], _("Invert Swipes"), _("Swipe content instead of view."))); let animation_pref_group = new Adw.PreferencesGroup({ title: _('Animation'), }); diff --git a/src/swipeTracker.js b/src/swipeTracker.js index 5936ea9..e55174d 100644 --- a/src/swipeTracker.js +++ b/src/swipeTracker.js @@ -321,8 +321,9 @@ const ScrollGesture = GObject.registerClass({ 'end': { param_types: [GObject.TYPE_UINT, GObject.TYPE_DOUBLE] }, }, }, class ScrollGesture extends GObject.Object { - _init(actor, allowedModes) { + _init(actor, allowedModes, inverted=false) { super._init(); + this._inverted = inverted; this._allowedModes = allowedModes; this._began = false; this._enabled = true; @@ -373,7 +374,10 @@ const ScrollGesture = GObject.registerClass({ let time = event.get_time(); let [dx, dy] = event.get_scroll_delta(); - dx = -dx; dy = -dy; + if (this._inverted) { + dx = -dx; dy = -dy; + } + if (dx === 0 && dy === 0) { this.emit('end', time, distance); this._began = false; @@ -454,10 +458,11 @@ export const MySwipeTracker = GObject.registerClass({ 'end': { param_types: [GObject.TYPE_UINT64, GObject.TYPE_DOUBLE] }, }, }, class MySwipeTracker extends GObject.Object { - _init(actor, orientation, allowedModes, params) { + _init(actor, orientation, allowedModes, params, inverted=false) { super._init(); params = Params.parse(params, { allowDrag: true, allowScroll: true }); this.orientation = orientation; + this._inverted = inverted; this._allowedModes = allowedModes; this._enabled = true; this._distance = global.screen_height; @@ -502,7 +507,7 @@ export const MySwipeTracker = GObject.registerClass({ } if (params.allowScroll) { - this._scrollGesture = new ScrollGesture(actor, allowedModes); + this._scrollGesture = new ScrollGesture(actor, allowedModes, this._inverted); this._scrollGesture.connect('begin', this._beginGesture.bind(this)); this._scrollGesture.connect('update', this._updateGesture.bind(this)); this._scrollGesture.connect('end', this._endTouchpadGesture.bind(this)); diff --git a/src/switcher.js b/src/switcher.js index 4868d3a..6c43f15 100644 --- a/src/switcher.js +++ b/src/switcher.js @@ -118,7 +118,8 @@ export class Switcher { const swipeTracker = new MySwipeTracker(this.actor, Clutter.Orientation.HORIZONTAL, 0, - { allowDrag: true, allowScroll: true }); + { allowDrag: true, allowScroll: true }, + this._settings.invert_swipes); swipeTracker.allowLongSwipes = true; swipeTracker.connect('begin', this._gestureBegin.bind(this)); swipeTracker.connect('update', this._gestureUpdate.bind(this));