Skip to content

Commit 1941b8a

Browse files
committed
SwipeGestureHandler: currectly grab the mouse
Fixes #6543 Fixes #6542
1 parent 3552e00 commit 1941b8a

File tree

3 files changed

+240
-15
lines changed

3 files changed

+240
-15
lines changed

internal/core/items/input_items.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,10 @@ impl Item for SwipeGestureHandler {
492492

493493
if start_swipe {
494494
Self::FIELD_OFFSETS.swiping.apply_pin(self).set(true);
495-
} else {
496-
return InputEventResult::EventIgnored;
497495
}
498496
}
499497
Self::FIELD_OFFSETS.moved.apply_pin(self).call(&());
500-
InputEventResult::EventAccepted
498+
InputEventResult::GrabMouse
501499
}
502500
MouseEvent::Wheel { .. } => InputEventResult::EventIgnored,
503501
}

tests/cases/elements/swipegesturehandler.slint

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ assert_eq!(instance.get_ta_hover(), false);
161161
assert_eq!(instance.get_down_swiping(), false);
162162
assert_eq!(instance.get_right_swiping(), false);
163163
assert_eq!(instance.get_left_swiping(), true);
164-
// the root gesture cause the mouse event to be repeated twice
165-
assert_eq!(instance.get_r(), "M2(20)M2(20)");
164+
assert_eq!(instance.get_r(), "M2(20)");
166165
instance.window().dispatch_event(WindowEvent::PointerExited);
167-
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
166+
assert_eq!(instance.get_r(), "M2(20)C2(20)");
168167
assert_eq!(instance.get_down_swiping(), false);
169168
assert_eq!(instance.get_left_swiping(), false);
170169
assert_eq!(instance.get_right_swiping(), false);
@@ -191,10 +190,9 @@ assert_eq!(instance.get_ta_hover(), false);
191190
assert_eq!(instance.get_down_swiping(), false);
192191
assert_eq!(instance.get_right_swiping(), false);
193192
assert_eq!(instance.get_left_swiping(), true);
194-
// the root gesture cause the mouse event to be repeated twice
195-
assert_eq!(instance.get_r(), "M2(20)M2(20)");
193+
assert_eq!(instance.get_r(), "M2(20)");
196194
instance.invoke_invoke_cancel();
197-
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
195+
assert_eq!(instance.get_r(), "M2(20)C2(20)");
198196
assert_eq!(instance.get_down_swiping(), false);
199197
assert_eq!(instance.get_left_swiping(), false);
200198
assert_eq!(instance.get_right_swiping(), false);
@@ -204,7 +202,7 @@ instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPo
204202
slint_testing::mock_elapsed_time(120);
205203
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
206204
slint_testing::mock_elapsed_time(120);
207-
assert_eq!(instance.get_r(), "M2(20)M2(20)C2(20)");
205+
assert_eq!(instance.get_r(), "M2(20)C2(20)");
208206
assert_eq!(instance.get_down_swiping(), false);
209207
assert_eq!(instance.get_left_swiping(), false);
210208
assert_eq!(instance.get_right_swiping(), false);
@@ -253,7 +251,7 @@ assert_eq!(instance.get_right_swiping(), false, "got cancelled");
253251
254252
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(220.0, 519.0), button: PointerEventButton::Left });
255253
assert_eq!(instance.get_r(), "S1(169)");
256-
assert_eq!(instance.get_ta_hover(), false, "FIXME: or should it be true as the mouse is still over it?");
254+
assert_eq!(instance.get_ta_hover(), true);
257255
assert_eq!(instance.get_ta_pressed(), false);
258256
assert_eq!(instance.get_down_swiping(), false);
259257
assert_eq!(instance.get_left_swiping(), false);
@@ -278,10 +276,9 @@ assert_eq(instance.get_ta_hover(), false);
278276
assert_eq(instance.get_down_swiping(), false);
279277
assert_eq(instance.get_right_swiping(), false);
280278
assert_eq(instance.get_left_swiping(), true);
281-
// the root gesture cause the mouse event to be repeated twice
282-
assert_eq(instance.get_r(), "M2(20)M2(20)");
279+
assert_eq(instance.get_r(), "M2(20)");
283280
instance.invoke_invoke_cancel();
284-
assert_eq(instance.get_r(), "M2(20)M2(20)C2(20)");
281+
assert_eq(instance.get_r(), "M2(20)C2(20)");
285282
assert_eq(instance.get_down_swiping(), false);
286283
assert_eq(instance.get_left_swiping(), false);
287284
assert_eq(instance.get_right_swiping(), false);
@@ -291,7 +288,7 @@ instance.window().dispatch_pointer_move_event(slint::LogicalPosition({ 60.0, 100
291288
slint_testing::mock_elapsed_time(120);
292289
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({40.0, 100.0}), PointerEventButton::Left);
293290
slint_testing::mock_elapsed_time(120);
294-
assert_eq(instance.get_r(), "M2(20)M2(20)C2(20)");
291+
assert_eq(instance.get_r(), "M2(20)C2(20)");
295292
assert_eq(instance.get_down_swiping(), false);
296293
assert_eq(instance.get_left_swiping(), false);
297294
assert_eq(instance.get_right_swiping(), false);
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// Copyright © SixtyFPS GmbH <[email protected]>
2+
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3+
4+
export component TestCase inherits Window {
5+
width: 400px;
6+
height: 400px;
7+
8+
in-out property <string> result;
9+
out property swiping-sgh-with-ta <=> sgh-with-ta.swiping;
10+
out property swiping-sgh-wo-ta <=> sgh-wo-ta.swiping;
11+
out property swiping-sgh-disabled-ta <=> sgh-disabled-ta.swiping;
12+
13+
14+
// With a TouchArea
15+
sgh-with-ta := SwipeGestureHandler {
16+
width: 200px;
17+
height: 200px;
18+
x: 0px;
19+
y: 0px;
20+
Rectangle {
21+
background: yellow;
22+
}
23+
handle-swipe-down: true;
24+
handle-swipe-up: true;
25+
handle-swipe-left: true;
26+
handle-swipe-right: true;
27+
TouchArea {
28+
clicked => { result += "ta1"; }
29+
}
30+
}
31+
32+
// Without a TouchArea
33+
sgh-wo-ta := SwipeGestureHandler {
34+
width: 200px;
35+
height: 200px;
36+
x: 200px;
37+
y: 0px;
38+
Rectangle {
39+
background: green;
40+
}
41+
handle-swipe-down: true;
42+
handle-swipe-up: true;
43+
handle-swipe-left: true;
44+
handle-swipe-right: true;
45+
}
46+
47+
// With a disabled one
48+
sgh-disabled-ta := SwipeGestureHandler {
49+
width: 200px;
50+
height: 200px;
51+
x: 0px;
52+
y: 200px;
53+
Rectangle {
54+
background: red;
55+
}
56+
handle-swipe-down: true;
57+
handle-swipe-up: true;
58+
handle-swipe-left: true;
59+
handle-swipe-right: true;
60+
ta := TouchArea {
61+
enabled: false;
62+
clicked => { result += "ta2"; }
63+
}
64+
}
65+
}
66+
67+
68+
/*
69+
```rust
70+
use slint::{platform::WindowEvent, LogicalPosition, platform::PointerEventButton};
71+
let instance = TestCase::new().unwrap();
72+
73+
assert_eq!(instance.get_result(), "");
74+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
75+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
76+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
77+
78+
79+
// With TouchArea
80+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
81+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
82+
slint_testing::mock_elapsed_time(200);
83+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
84+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
85+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
86+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
87+
slint_testing::mock_elapsed_time(50);
88+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
89+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
90+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
91+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 50.0) });
92+
assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
93+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
94+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
95+
slint_testing::mock_elapsed_time(50);
96+
97+
98+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
99+
assert_eq!(instance.get_swiping_sgh_with_ta(), true, "we should be swiping 'with-ta'");
100+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
101+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
102+
slint_testing::mock_elapsed_time(50);
103+
104+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
105+
assert_eq!(instance.get_swiping_sgh_with_ta(), true);
106+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
107+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
108+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
109+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
110+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
111+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
112+
assert_eq!(instance.get_result(), "");
113+
114+
115+
// Without TouhArea
116+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
117+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
118+
slint_testing::mock_elapsed_time(200);
119+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
120+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
121+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
122+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
123+
slint_testing::mock_elapsed_time(50);
124+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
125+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
126+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
127+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 50.0, 50.0) });
128+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
129+
assert_eq!(instance.get_swiping_sgh_wo_ta(), true, "we should be swiping 'without-ta'");
130+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
131+
slint_testing::mock_elapsed_time(50);
132+
133+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
134+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
135+
assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
136+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
137+
slint_testing::mock_elapsed_time(50);
138+
139+
140+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(200.0 + 100.0, 100.0) });
141+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
142+
assert_eq!(instance.get_swiping_sgh_wo_ta(), true);
143+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
144+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(200.0 + 100.0, 100.0), button: PointerEventButton::Left });
145+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
146+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
147+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
148+
assert_eq!(instance.get_result(), "");
149+
150+
// With disabled TouchArea
151+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
152+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
153+
slint_testing::mock_elapsed_time(200);
154+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
155+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
156+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
157+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
158+
slint_testing::mock_elapsed_time(50);
159+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
160+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
161+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
162+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(50.0, 200.0 + 50.0) });
163+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
164+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
165+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true, "we should be swiping 'with-disabled-ta'");
166+
slint_testing::mock_elapsed_time(50);
167+
168+
169+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(250.0, 250.0) }); //outside
170+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
171+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
172+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
173+
slint_testing::mock_elapsed_time(50);
174+
175+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 200.0 + 100.0) });
176+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
177+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
178+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), true);
179+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0, 200.0 + 100.0), button: PointerEventButton::Left });
180+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
181+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
182+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
183+
assert_eq!(instance.get_result(), "");
184+
185+
// Do ther click, now.
186+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0) });
187+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0), button: PointerEventButton::Left });
188+
slint_testing::mock_elapsed_time(200);
189+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 101.0) });
190+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
191+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
192+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
193+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 101.0), button: PointerEventButton::Left });
194+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
195+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
196+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
197+
assert_eq!(instance.get_result(), "ta1");
198+
instance.set_result("".into());
199+
200+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 100.0, 100.0) });
201+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0 + 100.0, 100.0), button: PointerEventButton::Left });
202+
slint_testing::mock_elapsed_time(200);
203+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0 + 101.0, 101.0) });
204+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
205+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
206+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
207+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(100.0 + 101.0, 101.0), button: PointerEventButton::Left });
208+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
209+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
210+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
211+
assert_eq!(instance.get_result(), "");
212+
213+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(100.0, 100.0 + 100.0) });
214+
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(100.0, 100.0 + 100.0), button: PointerEventButton::Left });
215+
slint_testing::mock_elapsed_time(200);
216+
instance.window().dispatch_event(WindowEvent::PointerMoved { position: LogicalPosition::new(101.0, 100.0 + 101.0) });
217+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
218+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
219+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
220+
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(101.0, 100.0 + 101.0), button: PointerEventButton::Left });
221+
assert_eq!(instance.get_swiping_sgh_with_ta(), false);
222+
assert_eq!(instance.get_swiping_sgh_wo_ta(), false);
223+
assert_eq!(instance.get_swiping_sgh_disabled_ta(), false);
224+
assert_eq!(instance.get_result(), "");
225+
226+
227+
```
228+
229+
230+
*/

0 commit comments

Comments
 (0)