Skip to content

Commit a993389

Browse files
committed
Make workspace switch gesture follow natural scrolling setting
1 parent fbc6dba commit a993389

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

lib/Gestures/GestureBackend.vala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
*/
77

88
private interface Gala.GestureBackend : Object {
9+
public enum DeviceType {
10+
TOUCHPAD,
11+
TOUCHSCREEN
12+
}
13+
914
public signal bool on_gesture_detected (Gesture gesture, uint32 timestamp);
1015
public signal void on_begin (double percentage, uint64 time);
1116
public signal void on_update (double percentage, uint64 time);
1217
public signal void on_end (double percentage, uint64 time);
1318

19+
public abstract DeviceType device_type { get; }
20+
1421
public virtual void prepare_gesture_handling () { }
1522

1623
/**

lib/Gestures/GestureController.vala

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class Gala.GestureController : Object {
4444
public GestureAction action { get; construct; }
4545
public WindowManager wm { get; construct; }
4646
public Group group { get; construct; }
47+
public bool follow_natural_scroll_settings { get; construct; }
4748

4849
private unowned RootTarget? _target;
4950
public RootTarget target {
@@ -87,6 +88,8 @@ public class Gala.GestureController : Object {
8788

8889
public bool recognizing { get; private set; }
8990

91+
private static GLib.Settings touchpad_settings = new GLib.Settings ("org.gnome.desktop.peripherals.touchpad");
92+
9093
private ToucheggBackend? touchegg_backend;
9194
private TouchpadBackend? touchpad_backend;
9295
private ScrollBackend? scroll_backend;
@@ -101,8 +104,8 @@ public class Gala.GestureController : Object {
101104

102105
private SpringTimeline? timeline;
103106

104-
public GestureController (GestureAction action, WindowManager wm, Group group = NONE) {
105-
Object (action: action, wm: wm, group: group);
107+
public GestureController (GestureAction action, WindowManager wm, Group group = NONE, bool follow_natural_scroll_settings = false) {
108+
Object (action: action, wm: wm, group: group, follow_natural_scroll_settings: follow_natural_scroll_settings);
106109
}
107110

108111
/**
@@ -185,6 +188,8 @@ public class Gala.GestureController : Object {
185188

186189
prepare ();
187190

191+
handle_natural_scroll_settings (ref percentage);
192+
188193
gesture_progress = progress;
189194
previous_percentage = percentage;
190195
previous_time = elapsed_time;
@@ -195,6 +200,8 @@ public class Gala.GestureController : Object {
195200
return;
196201
}
197202

203+
handle_natural_scroll_settings (ref percentage);
204+
198205
var updated_delta = previous_delta;
199206
if (elapsed_time != previous_time) {
200207
double distance = percentage - previous_percentage;
@@ -222,6 +229,7 @@ public class Gala.GestureController : Object {
222229

223230
recognizing = false;
224231

232+
handle_natural_scroll_settings (ref percentage);
225233
update_gesture_progress (percentage, previous_delta);
226234

227235
var to = progress;
@@ -291,6 +299,25 @@ public class Gala.GestureController : Object {
291299
_action_info = null;
292300
}
293301

302+
private void handle_natural_scroll_settings (ref double percentage) requires (recognizing_backend != null) {
303+
if (!follow_natural_scroll_settings) {
304+
return;
305+
}
306+
307+
var multiplier = 1.0;
308+
309+
switch (recognizing_backend.device_type) {
310+
case TOUCHPAD:
311+
multiplier = touchpad_settings.get_boolean ("natural-scroll") ? 1.0 : -1.0;
312+
break;
313+
case TOUCHSCREEN:
314+
multiplier = 1.0;
315+
break;
316+
}
317+
318+
percentage *= multiplier;
319+
}
320+
294321
/**
295322
* Animates to the given progress value.
296323
* If the gesture is currently recognizing, it will do nothing.

lib/Gestures/ScrollBackend.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ private class Gala.ScrollBackend : Object, GestureBackend {
2626
private const double FINISH_DELTA_HORIZONTAL = 40;
2727
private const double FINISH_DELTA_VERTICAL = 30;
2828

29+
public GestureBackend.DeviceType device_type { get { return TOUCHPAD; }}
30+
2931
public Clutter.Orientation orientation { get; construct; }
3032
public GestureSettings settings { get; construct; }
3133

lib/Gestures/ToucheggBackend.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ private class Gala.ToucheggBackend : Object, GestureBackend {
7676
*/
7777
private const double DELTA_MULTIPLIER = 0.01;
7878

79+
public GestureBackend.DeviceType device_type { get { return TOUCHPAD; }}
80+
7981
/**
8082
* Single instance of the class.
8183
*/

lib/Gestures/TouchpadBackend.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ private class Gala.TouchpadBackend : Object, GestureBackend {
1818
ONGOING
1919
}
2020

21+
public GestureBackend.DeviceType device_type { get { return TOUCHPAD; }}
22+
2123
public Clutter.Actor actor { get; construct; }
2224
public GestureController.Group group { get; construct; }
2325

src/Widgets/MultitaskingView/MultitaskingView.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class Gala.MultitaskingView : ActorTarget, RootTarget, ActivatableCompone
6565

6666
workspaces = new WorkspaceRow (display);
6767

68-
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, wm, MULTITASKING_VIEW) {
68+
workspaces_gesture_controller = new GestureController (SWITCH_WORKSPACE, wm, MULTITASKING_VIEW, true) {
6969
overshoot_upper_clamp = 0.1
7070
};
7171
workspaces_gesture_controller.enable_touchpad (wm.stage);

0 commit comments

Comments
 (0)