Skip to content

Commit

Permalink
Introduce an option to invert the swipe direction.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsheeler committed Nov 4, 2023
1 parent 0b9522c commit d090b3b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,9 @@
<default>false</default>
<summary>Use a "glitch effect" on the background application switcher</summary>
</key>
<key type="b" name="invert-swipes">
<default>false</default>
<summary>Swipe content instead of view</summary>
</key>
</schema>
</schemalist>
5 changes: 3 additions & 2 deletions src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class AbstractPlatform {
use_theme_color_for_tint_color: false,
use_glitch_effect: false,
use_tint: false,
invert_swipes: false,
};
}

Expand Down Expand Up @@ -164,8 +165,6 @@ export class PlatformGnomeShell extends AbstractPlatform {
}

enable() {
//this.disable();

this._settings_changed_callbacks = [];

if (this._desktopSettings == null)
Expand Down Expand Up @@ -202,6 +201,7 @@ export class PlatformGnomeShell extends AbstractPlatform {
"tint-color",
"use-theme-color-for-tint-color",
"use-glitch-effect",
"invert-swipes",
];

let dkeys = [
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
Expand Down
13 changes: 9 additions & 4 deletions src/swipeTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit d090b3b

Please sign in to comment.