Skip to content

Commit

Permalink
Draft: new UI to customize gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
adhadse committed Jul 2, 2022
1 parent cce9f80 commit d5dd23f
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 159 deletions.
34 changes: 27 additions & 7 deletions extension/common/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import Gio from '@gi-types/gio2';
import GLib from '@gi-types/glib2';

// define enum
// define enum for Horizontal motion Gesture
export enum SwipeHorizontalGestureType {
WINDOW_SWITCHING = 0,
APP_NAVIGATION = 1,
WORKSPACE_SWITCHING = 2
}

// define enum for Vertical motion Gestures
export enum SwipeVerticalGestureType {
OVERVIEW_NAVIGATION = 0,
APP_NAVIGATION = 1,
WINDOW_MANIPULATION = 2
}

// define enum for Pinch Gesture
export enum PinchGestureType {
NONE = 0,
SHOW_DESKTOP = 1,
Expand All @@ -26,13 +40,13 @@ export enum ForwardBackKeyBinds {
}

export type BooleanSettingsKeys =
'default-session-workspace' |
'default-overview' |
'allow-minimize-window' |
// 'default-session-workspace' |
// 'default-overview' |
// 'allow-minimize-window' |
// 'enable-window-manipulation-gesture' |
'follow-natural-scroll' |
'enable-alttab-gesture' |
'enable-forward-back-gesture' |
'enable-window-manipulation-gesture' |
'default-overview-gesture-direction'
;

Expand All @@ -46,9 +60,13 @@ export type DoubleSettingsKeys =
;

export type EnumSettingsKeys =
'swipe-horizontal-3-finger-gesture' |
'swipe-vertical-3-finger-gesture' |
'pinch-3-finger-gesture' |
'swipe-horizontal-4-finger-gesture' |
'swipe-vertical-4-finger-gesture' |
'pinch-4-finger-gesture' |
'overview-navifation-states'
'overview-navigation-states'
;

export type MiscSettingsKeys =
Expand Down Expand Up @@ -81,8 +99,10 @@ type Enum_Functions<K extends EnumSettingsKeys, T> = {
}

type SettingsEnumFunctions =
Enum_Functions<'swipe-horizontal-3-finger-gesture' | 'swipe-horizontal-4-finger-gesture', SwipeHorizontalGestureType> &
Enum_Functions<'swipe-vertical-3-finger-gesture' | 'swipe-vertical-4-finger-gesture', SwipeVerticalGestureType> &
Enum_Functions<'pinch-3-finger-gesture' | 'pinch-4-finger-gesture', PinchGestureType> &
Enum_Functions<'overview-navifation-states', OverviewNavigationState>
Enum_Functions<'overview-navigation-states', OverviewNavigationState>
;

type Misc_Functions<K extends MiscSettingsKeys, T extends string> = {
Expand Down
15 changes: 13 additions & 2 deletions extension/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ export const OverviewControlsState = {
HIDDEN_N: 3,
};

// export const ExtSettings = {
// DEFAULT_SESSION_WORKSPACE_GESTURE: false,
// DEFAULT_OVERVIEW_GESTURE: false,
// ALLOW_MINIMIZE_WINDOW: false,
// FOLLOW_NATURAL_SCROLL: true,
// APP_GESTURES: false,
// DEFAULT_OVERVIEW_GESTURE_DIRECTION: true,
// };

export const ExtSettings = {
DEFAULT_SESSION_WORKSPACE_GESTURE: false,
DEFAULT_OVERVIEW_GESTURE: false,
// DEFAULT_SESSION_WORKSPACE_GESTURE: false,
// DEFAULT_OVERVIEW_GESTURE: false, // TODO: remove
ALLOW_MINIMIZE_WINDOW: false,


FOLLOW_NATURAL_SCROLL: true,
APP_GESTURES: false,
DEFAULT_OVERVIEW_GESTURE_DIRECTION: true,
Expand Down
74 changes: 50 additions & 24 deletions extension/extension.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import Clutter from '@gi-types/clutter';
import GLib from '@gi-types/glib2';
import { imports } from 'gnome-shell';
import { AllSettingsKeys, GioSettings, PinchGestureType } from './common/settings';
import { AllSettingsKeys, GioSettings, PinchGestureType, SwipeHorizontalGestureType, SwipeVerticalGestureType } from './common/settings';
import * as Constants from './constants';
import { SwipeGestureInfo, SwipeGestureToExtensionMapper } from './src/gestures';
import { AltTabConstants, ExtSettings, TouchpadConstants } from './constants';
import { AltTabGestureExtension } from './src/altTab';
import { ForwardBackGestureExtension } from './src/forwardBack';
import { GestureExtension } from './src/gestures';
import { OverviewRoundTripGestureExtension } from './src/overviewRoundTrip';
import { CloseWindowExtension } from './src/pinchGestures/closeWindow';
import { ShowDesktopExtension } from './src/pinchGestures/showDesktop';
import { SnapWindowExtension } from './src/snapWindow';
import * as DBusUtils from './src/utils/dbus';
import * as VKeyboard from './src/utils/keyboard';

Expand Down Expand Up @@ -73,23 +70,12 @@ class Extension {
this._initializeSettings();
this._extensions = [];
if (this.settings === undefined)
return;

return;
if (this.settings.get_boolean('enable-alttab-gesture'))
this._extensions.push(new AltTabGestureExtension());
// this._extensions.push(new AltTabGestureExtension());

if (this.settings.get_boolean('enable-forward-back-gesture')) {
const appForwardBackKeyBinds = this.settings.get_value('forward-back-application-keyboard-shortcuts').deepUnpack();
this._extensions.push(new ForwardBackGestureExtension(appForwardBackKeyBinds));
}

this._extensions.push(
new OverviewRoundTripGestureExtension(this.settings.get_enum('overview-navifation-states')),
new GestureExtension(),
);

if (this.settings.get_boolean('enable-window-manipulation-gesture'))
this._extensions.push(new SnapWindowExtension());
this._setSwipeGestures()

// pinch to show desktop
const pinchToFingersMap = this._getPinchGestureTypeAndFingers();
Expand Down Expand Up @@ -119,20 +105,60 @@ class Extension {

_initializeSettings() {
if (this.settings) {
ExtSettings.DEFAULT_SESSION_WORKSPACE_GESTURE = this.settings.get_boolean('default-session-workspace');
ExtSettings.DEFAULT_OVERVIEW_GESTURE = this.settings.get_boolean('default-overview');
ExtSettings.ALLOW_MINIMIZE_WINDOW = this.settings.get_boolean('allow-minimize-window');
// TODO: fix this somewhere, somehow
// ExtSettings.ALLOW_MINIMIZE_WINDOW = this.settings.get_boolean('allow-minimize-window');

ExtSettings.FOLLOW_NATURAL_SCROLL = this.settings.get_boolean('follow-natural-scroll');
ExtSettings.DEFAULT_OVERVIEW_GESTURE_DIRECTION = this.settings.get_boolean('default-overview-gesture-direction');
ExtSettings.APP_GESTURES = this.settings.get_boolean('enable-forward-back-gesture');


TouchpadConstants.SWIPE_MULTIPLIER = Constants.TouchpadConstants.DEFAULT_SWIPE_MULTIPLIER * this.settings.get_double('touchpad-speed-scale');
TouchpadConstants.PINCH_MULTIPLIER = Constants.TouchpadConstants.DEFAULT_PINCH_MULTIPLIER * this.settings.get_double('touchpad-pinch-speed');
AltTabConstants.DELAY_DURATION = this.settings.get_int('alttab-delay');
TouchpadConstants.HOLD_SWIPE_DELAY_DURATION = this.settings.get_int('hold-swipe-delay-duration');
}
}

private _setSwipeGestures() {
if (this.settings) {
const swipeHorizontal3FingerGesture = this.settings.get_enum('swipe-horizontal-3-finger-gesture');
const swipeVertical3FingerGesture = this.settings.get_enum('swipe-vertical-3-finger-gesture');
const swipeHorizontal4FingerGesture = this.settings.get_enum('swipe-horizontal-4-finger-gesture');
const swipeVertical4FingerGesture = this.settings.get_enum('swipe-vertical-4-finger-gesture');

const swipeGestureToExtension = new SwipeGestureToExtensionMapper(this.settings)

const swipeHorizontal3FingerGestureInfo = new SwipeGestureInfo(
Clutter.Orientation.HORIZONTAL,
[3], swipeHorizontal3FingerGesture
)
const extension_1 = swipeGestureToExtension.get_extension(swipeHorizontal3FingerGestureInfo)

const swipeVertical3FingerGestureInfo = new SwipeGestureInfo(
Clutter.Orientation.VERTICAL,
[3], swipeVertical3FingerGesture
)
const extension_2 = swipeGestureToExtension.get_extension(swipeVertical3FingerGestureInfo)

const swipeHorizontal4FingerGestureInfo = new SwipeGestureInfo(
Clutter.Orientation.HORIZONTAL,
[4], swipeHorizontal4FingerGesture
)
const extension_3 = swipeGestureToExtension.get_extension(swipeHorizontal4FingerGestureInfo)

const swipeVertical4FingerGestureInfo = new SwipeGestureInfo(
Clutter.Orientation.VERTICAL,
[4], swipeVertical4FingerGesture
)
const extension_4 = swipeGestureToExtension.get_extension(swipeVertical4FingerGestureInfo)

this._extensions.push(
extension_1, extension_2, extension_3, extension_4
);
}
}

private _getPinchGestureTypeAndFingers(): Map<PinchGestureType, number[]> {
if (!this.settings) return new Map();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<enum id='org.gnome.shell.extensions.gestureImprovements.horizontal-swipe-gestures'>
<value value='0' nick='WINDOW_SWITCHING' />
<value value='1' nick='APP_NAVIGATION' />
<value value='2' nick='WORKSPACE_SWITCHING' />
</enum>

<enum id='org.gnome.shell.extensions.gestureImprovements.vertical-swipe-gestures'>
<value value='0' nick='OVERVIEW_NAVIGATION'>
<value value='1' nick='APP_NAVIGATION' />
<value value='2' nick='WINDOW_MANIPULATION' />
</enum>

<enum id='org.gnome.shell.extensions.gestureImprovements.pinch-gestures'>
<value value='0' nick='NONE' />
<value value='1' nick='SHOW_DESKTOP' />
Expand All @@ -12,6 +24,7 @@
<value value='1' nick='GNOME' />
<value value='2' nick='WINDOW_PICKER_ONLY' />
</enum>

<schema id="org.gnome.shell.extensions.gestureImprovements" path="/org/gnome/shell/extensions/gestureImprovements/">
<!-- See also: https://docs.gtk.org/glib/gvariant-format-strings.html -->
<key name="touchpad-speed-scale" type="d">
Expand All @@ -26,18 +39,36 @@
<key name="hold-swipe-delay-duration" type="i">
<default>100</default>
</key>
<key name='default-session-workspace' type='b'>
<default>false</default>
<description>If true, use 3-fingers to switch workspace, 4 for windows</description>

<!-- 3 finger gestures -->
<key name="swipe-horizontal-3-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.horizontal-swipe-gestures">
<default>'WINDOW_SWITCHING'</default>
<description>Gesture for 3 finger Left/Right Swipe</description>
</key>
<key name="swipe-vertical-3-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.vertical-swipe-gestures">
<default>'OVERVIEW_NAVIGATION'</default>
<description>Gesture for 3 finger Top/Down Swipe</description>
</key>
<key name='default-overview' type='b'>
<default>false</default>
<description>If true, use 3-fingers for overview gesture, 4 for snapping/tiling</description>
<key name="pinch-3-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.pinch-gestures">
<default>'NONE'</default>
<description>Gesture for 3 finger pinch</description>
</key>
<key name='allow-minimize-window' type='b'>
<default>false</default>
<description>If true, when swipe down on non-maximized window minimizes it</description>

<!-- 4 finger gestures -->
<key name="swipe-horizontal-4-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.horizontal-swipe-gestures">
<default>'WORKSPACE_SWITCHING'</default>
<description>Gesture for 4 finger Left/Right Swipe</description>
</key>
<key name="swipe-vertical-4-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.vertical-swipe-gestures">
<default>'APP_NAVIGATION'</default>
<description>Gesture for 4 finger Top/Down Swipe</description>
</key>
<key name="pinch-4-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.pinch-gestures">
<default>'SHOW_DESKTOP'</default>
<description>Gesture for 4 finger pinch</description>
</key>


<key name='follow-natural-scroll' type='b'>
<default>true</default>
<description>Whether to follow natural scroll for swipe</description>
Expand All @@ -51,20 +82,8 @@
<description>Enable alttab gesture</description>
</key>
<key name='enable-forward-back-gesture' type='b'>
<default>false</default>
<description>Enable forward/back keybinding gesture</description>
</key>
<key name='enable-window-manipulation-gesture' type='b'>
<default>true</default>
<description>Enable Window manipulation gesture</description>
</key>
<key name="pinch-3-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.pinch-gestures">
<default>'NONE'</default>
<description>Gesture for 3 finger pinch</description>
</key>
<key name="pinch-4-finger-gesture" enum="org.gnome.shell.extensions.gestureImprovements.pinch-gestures">
<default>'SHOW_DESKTOP'</default>
<description>Gesture for 4 finger pinch</description>
<description>Enable forward/back keybinding gesture</description>
</key>
<key name="overview-navifation-states" enum="org.gnome.shell.extensions.gestureImprovements.overview-navigation-states">
<default>'CYCLIC'</default>
Expand Down
Loading

0 comments on commit d5dd23f

Please sign in to comment.