@@ -17,6 +17,7 @@ use std::time::Instant;
17
17
#[ derive( Debug , Default ) ]
18
18
struct Connections {
19
19
appwindow_block_pinch_zoom_bind : Option < glib:: Binding > ,
20
+ appwindow_block_touch_bind : Option < glib:: Binding > ,
20
21
appwindow_show_scrollbars_bind : Option < glib:: Binding > ,
21
22
appwindow_inertial_scrolling_bind : Option < glib:: Binding > ,
22
23
appwindow_righthanded_bind : Option < glib:: Binding > ,
@@ -32,6 +33,7 @@ mod imp {
32
33
pub ( crate ) canvas_touch_drawing_handler : RefCell < Option < glib:: SignalHandlerId > > ,
33
34
pub ( crate ) show_scrollbars : Cell < bool > ,
34
35
pub ( crate ) block_pinch_zoom : Cell < bool > ,
36
+ pub ( crate ) block_touch : Cell < bool > ,
35
37
pub ( crate ) inertial_scrolling : Cell < bool > ,
36
38
pub ( crate ) pointer_pos : Cell < Option < na:: Vector2 < f64 > > > ,
37
39
pub ( crate ) last_contextmenu_pos : Cell < Option < na:: Vector2 < f64 > > > ,
@@ -131,6 +133,7 @@ mod imp {
131
133
canvas_touch_drawing_handler : RefCell :: new ( None ) ,
132
134
show_scrollbars : Cell :: new ( false ) ,
133
135
block_pinch_zoom : Cell :: new ( false ) ,
136
+ block_touch : Cell :: new ( false ) ,
134
137
inertial_scrolling : Cell :: new ( true ) ,
135
138
pointer_pos : Cell :: new ( None ) ,
136
139
last_contextmenu_pos : Cell :: new ( None ) ,
@@ -244,6 +247,9 @@ mod imp {
244
247
glib:: ParamSpecBoolean :: builder( "block-pinch-zoom" )
245
248
. default_value( false )
246
249
. build( ) ,
250
+ glib:: ParamSpecBoolean :: builder( "block-touch" )
251
+ . default_value( false )
252
+ . build( ) ,
247
253
glib:: ParamSpecBoolean :: builder( "inertial-scrolling" )
248
254
. default_value( true )
249
255
. build( ) ,
@@ -256,6 +262,7 @@ mod imp {
256
262
match pspec. name ( ) {
257
263
"show-scrollbars" => self . show_scrollbars . get ( ) . to_value ( ) ,
258
264
"block-pinch-zoom" => self . block_pinch_zoom . get ( ) . to_value ( ) ,
265
+ "block-touch" => self . block_pinch_zoom . get ( ) . to_value ( ) ,
259
266
"inertial-scrolling" => self . inertial_scrolling . get ( ) . to_value ( ) ,
260
267
_ => unimplemented ! ( ) ,
261
268
}
@@ -279,6 +286,15 @@ mod imp {
279
286
self . block_pinch_zoom . replace ( block_pinch_zoom) ;
280
287
self . canvas_zoom_gesture_update ( ) ;
281
288
}
289
+ "block-touch" => {
290
+ let block_touch = value
291
+ . get :: < bool > ( )
292
+ . expect ( "The value needs to be of type `bool`" ) ;
293
+ self . block_touch . replace ( block_touch) ;
294
+ self . canvas_touch_pan_update ( ) ;
295
+ self . canvas_zoom_gesture_update ( ) ;
296
+ self . canvas_kinetic_scrolling_update ( ) ;
297
+ }
282
298
"inertial-scrolling" => {
283
299
let inertial_scrolling = value
284
300
. get :: < bool > ( )
@@ -296,7 +312,10 @@ mod imp {
296
312
297
313
impl RnCanvasWrapper {
298
314
fn canvas_zoom_gesture_update ( & self ) {
299
- if !self . block_pinch_zoom . get ( ) && !self . canvas . touch_drawing ( ) {
315
+ if !self . block_pinch_zoom . get ( )
316
+ && !self . block_touch . get ( )
317
+ && !self . canvas . touch_drawing ( )
318
+ {
300
319
self . canvas_zoom_gesture
301
320
. set_propagation_phase ( PropagationPhase :: Capture ) ;
302
321
} else {
@@ -305,9 +324,30 @@ mod imp {
305
324
}
306
325
}
307
326
327
+ fn canvas_touch_pan_update ( & self ) {
328
+ if !self . block_touch . get ( ) && !self . canvas . touch_drawing ( ) {
329
+ self . canvas_drag_gesture
330
+ . set_propagation_phase ( PropagationPhase :: Bubble ) ;
331
+ self . touch_two_finger_long_press_gesture
332
+ . set_propagation_phase ( PropagationPhase :: Capture ) ;
333
+ self . touch_long_press_gesture
334
+ . set_propagation_phase ( PropagationPhase :: Capture ) ;
335
+ } else {
336
+ // set everythinbg to `None`
337
+ self . canvas_drag_gesture
338
+ . set_propagation_phase ( PropagationPhase :: None ) ;
339
+ self . touch_two_finger_long_press_gesture
340
+ . set_propagation_phase ( PropagationPhase :: None ) ;
341
+ self . touch_long_press_gesture
342
+ . set_propagation_phase ( PropagationPhase :: None ) ;
343
+ }
344
+ }
345
+
308
346
fn canvas_kinetic_scrolling_update ( & self ) {
309
347
self . scroller . set_kinetic_scrolling (
310
- !self . canvas . touch_drawing ( ) && self . inertial_scrolling . get ( ) ,
348
+ !self . block_touch . get ( )
349
+ && !self . canvas . touch_drawing ( )
350
+ && self . inertial_scrolling . get ( ) ,
311
351
) ;
312
352
}
313
353
@@ -405,6 +445,9 @@ mod imp {
405
445
#[ weak( rename_to=canvaswrapper) ]
406
446
obj,
407
447
move |_, _, _| {
448
+ if canvaswrapper. block_touch( ) {
449
+ return ( ) ;
450
+ }
408
451
// We don't claim the sequence, because we we want to allow touch zooming.
409
452
// When the zoom gesture is recognized, it claims it and denies this touch drag gesture.
410
453
@@ -420,6 +463,9 @@ mod imp {
420
463
#[ weak( rename_to=canvaswrapper) ]
421
464
obj,
422
465
move |_, x, y| {
466
+ if canvaswrapper. block_touch( ) {
467
+ return ( ) ;
468
+ }
423
469
let canvas = canvaswrapper. canvas( ) ;
424
470
let new_offset = touch_drag_start. get( ) - na:: vector![ x, y] ;
425
471
let widget_flags = canvas. engine_mut( ) . camera_set_offset_expand( new_offset) ;
@@ -430,6 +476,9 @@ mod imp {
430
476
#[ weak( rename_to=canvaswrapper) ]
431
477
obj,
432
478
move |_, _, _| {
479
+ if canvaswrapper. block_touch( ) {
480
+ return ( ) ;
481
+ }
433
482
let widget_flags = canvaswrapper
434
483
. canvas( )
435
484
. engine_mut( )
@@ -832,6 +881,7 @@ impl RnCanvasWrapper {
832
881
pub ( crate ) fn set_show_scrollbars ( & self , show_scrollbars : bool ) {
833
882
self . set_property ( "show-scrollbars" , show_scrollbars. to_value ( ) ) ;
834
883
}
884
+
835
885
#[ allow( unused) ]
836
886
pub ( crate ) fn block_pinch_zoom ( & self ) -> bool {
837
887
self . property :: < bool > ( "block-pinch-zoom" )
@@ -842,6 +892,16 @@ impl RnCanvasWrapper {
842
892
self . set_property ( "block-pinch-zoom" , block_pinch_zoom) ;
843
893
}
844
894
895
+ #[ allow( unused) ]
896
+ pub ( crate ) fn block_touch ( & self ) -> bool {
897
+ self . property :: < bool > ( "block-touch" )
898
+ }
899
+
900
+ #[ allow( unused) ]
901
+ pub ( crate ) fn set_block_touch ( & self , block_touch : bool ) {
902
+ self . set_property ( "block-touch" , block_touch) ;
903
+ }
904
+
845
905
#[ allow( unused) ]
846
906
pub ( crate ) fn inertial_scrolling ( & self ) -> bool {
847
907
self . property :: < bool > ( "inertial-scrolling" )
@@ -885,6 +945,11 @@ impl RnCanvasWrapper {
885
945
. sync_create ( )
886
946
. build ( ) ;
887
947
948
+ let appwindow_block_touch_bind = appwindow
949
+ . bind_property ( "block-touch" , self , "block_touch" )
950
+ . sync_create ( )
951
+ . build ( ) ;
952
+
888
953
let appwindow_show_scrollbars_bind = appwindow
889
954
. sidebar ( )
890
955
. settings_panel ( )
@@ -920,6 +985,12 @@ impl RnCanvasWrapper {
920
985
{
921
986
old. unbind ( )
922
987
}
988
+ if let Some ( old) = connections
989
+ . appwindow_block_touch_bind
990
+ . replace ( appwindow_block_touch_bind)
991
+ {
992
+ old. unbind ( )
993
+ }
923
994
if let Some ( old) = connections
924
995
. appwindow_show_scrollbars_bind
925
996
. replace ( appwindow_show_scrollbars_bind)
@@ -951,6 +1022,9 @@ impl RnCanvasWrapper {
951
1022
if let Some ( old) = connections. appwindow_block_pinch_zoom_bind . take ( ) {
952
1023
old. unbind ( ) ;
953
1024
}
1025
+ if let Some ( old) = connections. appwindow_block_touch_bind . take ( ) {
1026
+ old. unbind ( ) ;
1027
+ }
954
1028
if let Some ( old) = connections. appwindow_show_scrollbars_bind . take ( ) {
955
1029
old. unbind ( ) ;
956
1030
}
0 commit comments