Skip to content

Commit 6f682da

Browse files
committed
Take initial percentage as on_gesture_handled return
1 parent 11b70fd commit 6f682da

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/Gestures/GestureTracker.vala

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ public class Gala.GestureTracker : Object {
9595
* start receiving updates.
9696
* @param gesture the same gesture as in {@link on_gesture_detected}
9797
* @param timestamp the timestamp of the event that initiated the gesture or {@link Meta.CURRENT_TIME}.
98+
* @return the initial percentage that should already be preapplied. This is useful
99+
* if an animation was still ongoing when the gesture was started.
98100
*/
99-
public signal void on_gesture_handled (Gesture gesture, uint32 timestamp);
101+
public signal double on_gesture_handled (Gesture gesture, uint32 timestamp);
100102

101103
/**
102104
* Emitted right after on_gesture_detected with the initial gesture information.
@@ -123,17 +125,6 @@ public class Gala.GestureTracker : Object {
123125
public delegate void OnUpdate (double percentage);
124126
public delegate void OnEnd (double percentage, int completions, int calculated_duration);
125127

126-
public double initial_percentage {
127-
set {
128-
if (applied_percentage != 0) {
129-
critical ("Gesture has already started and is in progress.");
130-
return;
131-
}
132-
133-
applied_percentage = value;
134-
}
135-
}
136-
137128
/**
138129
* Backend used if enable_touchpad is called.
139130
*/
@@ -261,7 +252,7 @@ public class Gala.GestureTracker : Object {
261252
private bool gesture_detected (GestureBackend backend, Gesture gesture, uint32 timestamp) {
262253
if (enabled && on_gesture_detected (gesture)) {
263254
backend.prepare_gesture_handling ();
264-
on_gesture_handled (gesture, timestamp);
255+
applied_percentage = on_gesture_handled (gesture, timestamp);
265256
return true;
266257
}
267258

src/Widgets/MultitaskingView.vala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace Gala {
6666
multitasking_gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
6767
multitasking_gesture_tracker.enable_touchpad ();
6868
multitasking_gesture_tracker.on_gesture_detected.connect (on_multitasking_gesture_detected);
69-
multitasking_gesture_tracker.on_gesture_handled.connect (() => toggle (true, false));
69+
multitasking_gesture_tracker.on_gesture_handled.connect (on_multitasking_gesture_handled);
7070

7171
workspace_gesture_tracker = new GestureTracker (AnimationDuration.WORKSPACE_SWITCH_MIN, AnimationDuration.WORKSPACE_SWITCH);
7272
workspace_gesture_tracker.enable_touchpad ();
@@ -299,6 +299,11 @@ namespace Gala {
299299
return false;
300300
}
301301

302+
private double on_multitasking_gesture_handled (Gesture gesture, uint32 timestamp) {
303+
toggle (true, false);
304+
return 0;
305+
}
306+
302307
private bool on_workspace_gesture_detected (Gesture gesture) {
303308
if (!opened) {
304309
return false;
@@ -311,7 +316,7 @@ namespace Gala {
311316
return false;
312317
}
313318

314-
private void switch_workspace_with_gesture (Gesture gesture, uint32 timestamp) {
319+
private double switch_workspace_with_gesture (Gesture gesture, uint32 timestamp) {
315320
var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture);
316321

317322
unowned var manager = display.get_workspace_manager ();
@@ -355,7 +360,7 @@ namespace Gala {
355360
var upper_clamp = (direction == LEFT) ? (active_workspace.index () + 0.1) : (num_workspaces - active_workspace.index () - 0.9);
356361
var lower_clamp = (direction == RIGHT) ? - (active_workspace.index () + 0.1) : - (num_workspaces - active_workspace.index () - 0.9);
357362

358-
workspace_gesture_tracker.initial_percentage = new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x) {
363+
var initial_percentage = new GesturePropertyTransition (workspaces, workspace_gesture_tracker, "x", null, target_x) {
359364
overshoot_lower_clamp = lower_clamp,
360365
overshoot_upper_clamp = upper_clamp
361366
}.start (true);
@@ -372,6 +377,8 @@ namespace Gala {
372377
} else {
373378
workspace_gesture_tracker.connect_handlers (null, null, (owned) on_animation_end);
374379
}
380+
381+
return initial_percentage;
375382
}
376383

377384
/**

src/WindowManager.vala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ namespace Gala {
585585
return switch_workspace_with_gesture || (action == SWITCH_WINDOWS && !window_switcher.opened);
586586
}
587587

588-
private void on_gesture_handled (Gesture gesture, uint32 timestamp) {
588+
private double on_gesture_handled (Gesture gesture, uint32 timestamp) {
589589
var direction = gesture_tracker.settings.get_natural_scroll_direction (gesture);
590590

591591
switch (GestureSettings.get_action (gesture)) {
@@ -609,6 +609,8 @@ namespace Gala {
609609
default:
610610
break;
611611
}
612+
613+
return 0;
612614
}
613615

614616
/**

src/Zoom.vala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Gala.Zoom : Object {
3333
gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
3434
gesture_tracker.enable_touchpad ();
3535
gesture_tracker.on_gesture_detected.connect (on_gesture_detected);
36-
gesture_tracker.on_gesture_handled.connect ((gesture) => zoom_with_gesture (gesture.direction));
36+
gesture_tracker.on_gesture_handled.connect (on_gesture_handled);
3737

3838
behavior_settings = new GLib.Settings ("io.elementary.desktop.wm.behavior");
3939

@@ -101,9 +101,9 @@ public class Gala.Zoom : Object {
101101
return Clutter.EVENT_STOP;
102102
}
103103

104-
private void zoom_with_gesture (GestureDirection direction) {
104+
private double on_gesture_handled (Gesture gesture, uint32 timestamp) {
105105
var initial_zoom = current_zoom;
106-
var target_zoom = (direction == GestureDirection.IN)
106+
var target_zoom = (gesture.direction == GestureDirection.IN)
107107
? initial_zoom - MAX_ZOOM
108108
: initial_zoom + MAX_ZOOM;
109109

@@ -123,6 +123,8 @@ public class Gala.Zoom : Object {
123123
};
124124

125125
gesture_tracker.connect_handlers (null, (owned) on_animation_update, null);
126+
127+
return 0;
126128
}
127129

128130
private inline Graphene.Point compute_new_pivot_point () {

0 commit comments

Comments
 (0)