Skip to content

Commit 756e1a4

Browse files
committed
ModalProxy and include time
1 parent b9a305e commit 756e1a4

File tree

7 files changed

+53
-48
lines changed

7 files changed

+53
-48
lines changed

src/Gestures/Gesture.vala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@ namespace Gala {
5555
* Currently the only backend not setting this is {@link GestureTracker.enable_touchpad}.
5656
*/
5757
public float origin_y = INVALID_COORD;
58+
59+
/**
60+
* The timestamp of the event that initiated the gesture or Meta.CURRENT_TIME.
61+
*/
62+
public uint32 timestamp = Meta.CURRENT_TIME;
5863
}
5964
}

src/Gestures/GestureTracker.vala

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,17 @@ public class Gala.GestureTracker : Object {
147147
/**
148148
* Allow to receive pan gestures.
149149
* @param actor Clutter actor that will receive the events.
150-
* @param travel_distances {@link Utils.Size} with width and height. The given size wil be
151-
* used to calculate the percentage. It should be set to the amount something will travel (e.g.
150+
* @param travel_distance_func this will be called if a gesture is detected and true is returned from {@link on_gesture_detected}.
151+
* The returned distance wil be used to calculate the percentage. It should be set to the amount something will travel (e.g.
152152
* when moving an actor) based on the gesture to allow exact finger tracking. It can also be used
153-
* to calculate the raw pixels the finger travelled at a given time with percentage * corresponding distance
154-
* (height for {@link GestureDirection.UP} or DOWN, width for LEFT or RIGHT). If set to null the size of the
155-
* actor will be used. If the values change those changes will apply.
153+
* to calculate the raw pixels the finger travelled at a given time with percentage * distance.
156154
*/
157-
public void enable_pan (Clutter.Actor actor, owned PanBackend.GetTravelDistance travel_distance_func) {
158-
pan_backend = new PanBackend (actor, (owned) travel_distance_func);
155+
public void enable_pan (WindowManager wm, Clutter.Actor actor, owned PanBackend.GetTravelDistance travel_distance_func) {
156+
pan_backend = new PanBackend (wm, actor, (owned) travel_distance_func);
159157
pan_backend.on_gesture_detected.connect (gesture_detected);
160-
pan_backend.on_begin.connect ((percentage, time) => {
161-
gesture_begin (percentage, time);
162-
if (touchpad_backend != null) {
163-
touchpad_backend.ignore_touchscreen = true;
164-
}
165-
});
158+
pan_backend.on_begin.connect (gesture_begin);
166159
pan_backend.on_update.connect (gesture_update);
167-
pan_backend.on_end.connect ((percentage, time) => {
168-
gesture_end (percentage, time);
169-
if (touchpad_backend != null) {
170-
touchpad_backend.ignore_touchscreen = false;
171-
}
172-
});
160+
pan_backend.on_end.connect (gesture_end);
173161
}
174162

175163
/**

src/Gestures/PanBackend.vala

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ public class Gala.PanBackend : Object {
1313
public signal void on_update (double delta, uint64 time);
1414
public signal void on_end (double delta, uint64 time);
1515

16+
public WindowManager wm { get; construct; }
1617
public Clutter.Actor actor { get; construct; }
1718

1819
private GetTravelDistance get_travel_distance_func;
1920

21+
private ModalProxy? modal_proxy;
22+
2023
private Clutter.PanAxis pan_axis;
2124
private Clutter.PanAction pan_action;
2225

@@ -34,8 +37,8 @@ public class Gala.PanBackend : Object {
3437

3538
private float travel_distance;
3639

37-
public PanBackend (Clutter.Actor actor, owned GetTravelDistance get_travel_distance_func) {
38-
Object (actor: actor);
40+
public PanBackend (WindowManager wm, Clutter.Actor actor, owned GetTravelDistance get_travel_distance_func) {
41+
Object (wm: wm, actor: actor);
3942

4043
this.get_travel_distance_func = (owned) get_travel_distance_func;
4144
}
@@ -58,36 +61,51 @@ public class Gala.PanBackend : Object {
5861
}
5962

6063
private bool on_gesture_begin () {
64+
modal_proxy = wm.push_modal (actor);
65+
modal_proxy.allow_all_keybindings ();
66+
6167
float x_coord, y_coord;
6268
pan_action.get_press_coords (0, out x_coord, out y_coord);
6369

6470
origin_x = current_x = x_coord;
6571
origin_y = current_y = y_coord;
6672

67-
var handled = on_gesture_detected (build_gesture ());
73+
var time = pan_action.get_last_event (0).get_time ();
74+
75+
var handled = on_gesture_detected (build_gesture (time));
6876

6977
if (!handled) {
78+
reset ();
7079
return false;
7180
}
7281

7382
travel_distance = get_travel_distance_func ();
7483

75-
on_begin (0, pan_action.get_last_event (0).get_time ());
84+
on_begin (0, time);
7685

7786
return true;
7887
}
7988

8089
private void on_gesture_end () {
8190
on_end (calculate_percentage (), Meta.CURRENT_TIME);
8291

92+
reset ();
93+
}
94+
95+
private void reset () {
96+
if (modal_proxy != null) {
97+
wm.pop_modal (modal_proxy);
98+
modal_proxy = null;
99+
}
100+
83101
direction = GestureDirection.UNKNOWN;
84102
last_n_points = 0;
85103
last_x_coord = 0;
86104
last_y_coord = 0;
87105
}
88106

89107
private bool on_pan (Clutter.PanAction pan_action, Clutter.Actor actor, bool interpolate) {
90-
uint64 time = pan_action.get_last_event (0).get_time ();
108+
var time = pan_action.get_last_event (0).get_time ();
91109

92110
float x, y;
93111
pan_action.get_motion_coords (0, out x, out y);
@@ -119,7 +137,7 @@ public class Gala.PanBackend : Object {
119137
return (current - origin).abs () / travel_distance;
120138
}
121139

122-
private Gesture build_gesture () {
140+
private Gesture build_gesture (uint32 timestamp) {
123141
float delta_x, delta_y;
124142
((Clutter.GestureAction) pan_action).get_motion_delta (0, out delta_x, out delta_y);
125143

@@ -137,7 +155,8 @@ public class Gala.PanBackend : Object {
137155
fingers = (int) pan_action.get_n_current_points (),
138156
performed_on_device_type = Clutter.InputDeviceType.TOUCHSCREEN_DEVICE,
139157
origin_x = origin_x,
140-
origin_y = origin_y
158+
origin_y = origin_y,
159+
timestamp = timestamp
141160
};
142161
}
143162
}

src/Gestures/ScrollBackend.vala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class Gala.ScrollBackend : Object {
6262
return false;
6363
}
6464

65-
uint64 time = event.get_time ();
65+
var time = event.get_time ();
6666
double x, y;
6767
event.get_scroll_delta (out x, out y);
6868

@@ -82,7 +82,7 @@ public class Gala.ScrollBackend : Object {
8282
if (delta_x != 0 || delta_y != 0) {
8383
float origin_x, origin_y;
8484
event.get_coords (out origin_x, out origin_y);
85-
Gesture gesture = build_gesture (origin_x, origin_y, delta_x, delta_y, orientation);
85+
Gesture gesture = build_gesture (origin_x, origin_y, delta_x, delta_y, orientation, time);
8686
started = true;
8787
direction = gesture.direction;
8888
on_gesture_detected (gesture);
@@ -116,7 +116,7 @@ public class Gala.ScrollBackend : Object {
116116
&& event.get_scroll_direction () == Clutter.ScrollDirection.SMOOTH;
117117
}
118118

119-
private static Gesture build_gesture (float origin_x, float origin_y, double delta_x, double delta_y, Clutter.Orientation orientation) {
119+
private static Gesture build_gesture (float origin_x, float origin_y, double delta_x, double delta_y, Clutter.Orientation orientation, uint32 time) {
120120
GestureDirection direction;
121121
if (orientation == Clutter.Orientation.HORIZONTAL) {
122122
direction = delta_x > 0 ? GestureDirection.RIGHT : GestureDirection.LEFT;
@@ -130,7 +130,8 @@ public class Gala.ScrollBackend : Object {
130130
fingers = 2,
131131
performed_on_device_type = Clutter.InputDeviceType.TOUCHPAD_DEVICE,
132132
origin_x = origin_x,
133-
origin_y = origin_y
133+
origin_y = origin_y,
134+
timestamp = time
134135
};
135136
}
136137

src/Gestures/ToucheggBackend.vala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public class Gala.ToucheggBackend : Object {
2626
public signal void on_update (double delta, uint64 time);
2727
public signal void on_end (double delta, uint64 time);
2828

29-
public bool ignore_touchscreen { get; set; default = false; }
30-
3129
/**
3230
* Gesture type as returned by the daemon.
3331
*/
@@ -199,10 +197,6 @@ public class Gala.ToucheggBackend : Object {
199197
signal_params.get ("(uudiut)", out type, out direction, out percentage, out fingers,
200198
out performed_on_device_type, out elapsed_time);
201199

202-
if (ignore_touchscreen && performed_on_device_type == TOUCHSCREEN) {
203-
return;
204-
}
205-
206200
var delta = percentage * DELTA_MULTIPLIER;
207201

208202
switch (signal_name) {

src/Widgets/MultitaskingView.vala

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ namespace Gala {
7272

7373
multitasking_gesture_tracker = new GestureTracker (ANIMATION_DURATION, ANIMATION_DURATION);
7474
multitasking_gesture_tracker.enable_touchpad ();
75-
multitasking_gesture_tracker.enable_pan (display.get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
75+
multitasking_gesture_tracker.enable_pan (wm, display.get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
7676
multitasking_gesture_tracker.on_gesture_detected.connect (on_multitasking_gesture_detected);
7777

7878
workspace_gesture_tracker = new GestureTracker (AnimationDuration.WORKSPACE_SWITCH_MIN, AnimationDuration.WORKSPACE_SWITCH);
7979
workspace_gesture_tracker.enable_touchpad ();
80-
workspace_gesture_tracker.enable_pan (this, () => workspaces_travel_distance);
80+
workspace_gesture_tracker.enable_pan (wm, this, () => workspaces_travel_distance);
8181
workspace_gesture_tracker.enable_scroll (this, Clutter.Orientation.HORIZONTAL);
8282
workspace_gesture_tracker.on_gesture_detected.connect (on_workspace_gesture_detected);
8383

@@ -315,7 +315,6 @@ namespace Gala {
315315
}
316316

317317
private bool on_workspace_gesture_detected (Gesture gesture) {
318-
warning ("DETECTED");
319318
if (!opened) {
320319
return false;
321320
}
@@ -328,15 +327,14 @@ namespace Gala {
328327

329328
if (gesture.type == Clutter.EventType.SCROLL || (can_handle_swipe && fingers)) {
330329
var direction = workspace_gesture_tracker.settings.get_natural_scroll_direction (gesture);
331-
switch_workspace_with_gesture (direction);
332-
warning ("GO");
330+
switch_workspace_with_gesture (direction, gesture.timestamp);
333331
return true;
334332
}
335333

336334
return false;
337335
}
338336

339-
private void switch_workspace_with_gesture (Meta.MotionDirection direction) {
337+
private void switch_workspace_with_gesture (Meta.MotionDirection direction, uint32 timestamp) {
340338
if (switching_workspace_in_progress) {
341339
return;
342340
}
@@ -396,7 +394,7 @@ namespace Gala {
396394

397395
switching_workspace_with_gesture = true;
398396
if (target_workspace != null) {
399-
target_workspace.activate (display.get_current_time ());
397+
target_workspace.activate (timestamp);
400398
}
401399

402400
GestureTracker.OnUpdate on_animation_update = (percentage) => {
@@ -778,11 +776,11 @@ namespace Gala {
778776

779777
wm.pop_modal (modal_proxy);
780778

781-
multitasking_gesture_tracker.enable_pan (wm.get_display ().get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
779+
multitasking_gesture_tracker.enable_pan (wm, wm.get_display ().get_stage (), () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
782780
} else {
783781
modal_proxy = wm.push_modal (this);
784782
modal_proxy.set_keybinding_filter (keybinding_filter);
785-
multitasking_gesture_tracker.enable_pan (primary_monitor_container, () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
783+
multitasking_gesture_tracker.enable_pan (wm, primary_monitor_container, () => InternalUtils.travel_distance_from_primary (wm.get_display (), VERTICAL));
786784
}
787785

788786
animating = false;

src/WindowManager.vala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ namespace Gala {
185185

186186
stage = display.get_stage () as Clutter.Stage;
187187

188-
gesture_tracker.enable_pan (stage, () => InternalUtils.travel_distance_from_primary (get_display (), HORIZONTAL));
188+
gesture_tracker.enable_pan (this, stage, () => InternalUtils.travel_distance_from_primary (get_display (), HORIZONTAL));
189189

190190
var background_settings = new GLib.Settings ("org.gnome.desktop.background");
191191
var color = background_settings.get_string ("primary-color");
@@ -571,7 +571,7 @@ namespace Gala {
571571
switch_workspace_with_gesture = three_fingers_switch_to_workspace || four_fingers_switch_to_workspace;
572572
if (switch_workspace_with_gesture) {
573573
var direction = gesture_tracker.settings.get_natural_scroll_direction (gesture);
574-
switch_to_next_workspace (direction, display.get_current_time ());
574+
switch_to_next_workspace (direction, gesture.timestamp);
575575
return true;
576576
}
577577

@@ -586,7 +586,7 @@ namespace Gala {
586586
moving.change_workspace (manager.get_active_workspace ().get_neighbor (direction));
587587
}
588588

589-
switch_to_next_workspace (direction, display.get_current_time ());
589+
switch_to_next_workspace (direction, gesture.timestamp);
590590
return true;
591591
}
592592

0 commit comments

Comments
 (0)