@@ -17,6 +17,7 @@ use std::time::Instant;
1717#[ derive( Debug , Default ) ]
1818struct Connections {
1919 appwindow_block_pinch_zoom_bind : Option < glib:: Binding > ,
20+ appwindow_block_touch_bind : Option < glib:: Binding > ,
2021 appwindow_show_scrollbars_bind : Option < glib:: Binding > ,
2122 appwindow_inertial_scrolling_bind : Option < glib:: Binding > ,
2223 appwindow_righthanded_bind : Option < glib:: Binding > ,
@@ -32,6 +33,7 @@ mod imp {
3233 pub ( crate ) canvas_touch_drawing_handler : RefCell < Option < glib:: SignalHandlerId > > ,
3334 pub ( crate ) show_scrollbars : Cell < bool > ,
3435 pub ( crate ) block_pinch_zoom : Cell < bool > ,
36+ pub ( crate ) block_touch : Cell < bool > ,
3537 pub ( crate ) inertial_scrolling : Cell < bool > ,
3638 pub ( crate ) pointer_pos : Cell < Option < na:: Vector2 < f64 > > > ,
3739 pub ( crate ) last_contextmenu_pos : Cell < Option < na:: Vector2 < f64 > > > ,
@@ -131,6 +133,7 @@ mod imp {
131133 canvas_touch_drawing_handler : RefCell :: new ( None ) ,
132134 show_scrollbars : Cell :: new ( false ) ,
133135 block_pinch_zoom : Cell :: new ( false ) ,
136+ block_touch : Cell :: new ( false ) ,
134137 inertial_scrolling : Cell :: new ( true ) ,
135138 pointer_pos : Cell :: new ( None ) ,
136139 last_contextmenu_pos : Cell :: new ( None ) ,
@@ -244,6 +247,9 @@ mod imp {
244247 glib:: ParamSpecBoolean :: builder( "block-pinch-zoom" )
245248 . default_value( false )
246249 . build( ) ,
250+ glib:: ParamSpecBoolean :: builder( "block-touch" )
251+ . default_value( false )
252+ . build( ) ,
247253 glib:: ParamSpecBoolean :: builder( "inertial-scrolling" )
248254 . default_value( true )
249255 . build( ) ,
@@ -256,6 +262,7 @@ mod imp {
256262 match pspec. name ( ) {
257263 "show-scrollbars" => self . show_scrollbars . get ( ) . to_value ( ) ,
258264 "block-pinch-zoom" => self . block_pinch_zoom . get ( ) . to_value ( ) ,
265+ "block-touch" => self . block_pinch_zoom . get ( ) . to_value ( ) ,
259266 "inertial-scrolling" => self . inertial_scrolling . get ( ) . to_value ( ) ,
260267 _ => unimplemented ! ( ) ,
261268 }
@@ -279,6 +286,15 @@ mod imp {
279286 self . block_pinch_zoom . replace ( block_pinch_zoom) ;
280287 self . canvas_zoom_gesture_update ( ) ;
281288 }
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+ }
282298 "inertial-scrolling" => {
283299 let inertial_scrolling = value
284300 . get :: < bool > ( )
@@ -296,7 +312,10 @@ mod imp {
296312
297313 impl RnCanvasWrapper {
298314 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+ {
300319 self . canvas_zoom_gesture
301320 . set_propagation_phase ( PropagationPhase :: Capture ) ;
302321 } else {
@@ -305,9 +324,30 @@ mod imp {
305324 }
306325 }
307326
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+
308346 fn canvas_kinetic_scrolling_update ( & self ) {
309347 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 ( ) ,
311351 ) ;
312352 }
313353
@@ -405,6 +445,9 @@ mod imp {
405445 #[ weak( rename_to=canvaswrapper) ]
406446 obj,
407447 move |_, _, _| {
448+ if canvaswrapper. block_touch( ) {
449+ return ( ) ;
450+ }
408451 // We don't claim the sequence, because we we want to allow touch zooming.
409452 // When the zoom gesture is recognized, it claims it and denies this touch drag gesture.
410453
@@ -420,6 +463,9 @@ mod imp {
420463 #[ weak( rename_to=canvaswrapper) ]
421464 obj,
422465 move |_, x, y| {
466+ if canvaswrapper. block_touch( ) {
467+ return ( ) ;
468+ }
423469 let canvas = canvaswrapper. canvas( ) ;
424470 let new_offset = touch_drag_start. get( ) - na:: vector![ x, y] ;
425471 let widget_flags = canvas. engine_mut( ) . camera_set_offset_expand( new_offset) ;
@@ -430,6 +476,9 @@ mod imp {
430476 #[ weak( rename_to=canvaswrapper) ]
431477 obj,
432478 move |_, _, _| {
479+ if canvaswrapper. block_touch( ) {
480+ return ( ) ;
481+ }
433482 let widget_flags = canvaswrapper
434483 . canvas( )
435484 . engine_mut( )
@@ -832,6 +881,7 @@ impl RnCanvasWrapper {
832881 pub ( crate ) fn set_show_scrollbars ( & self , show_scrollbars : bool ) {
833882 self . set_property ( "show-scrollbars" , show_scrollbars. to_value ( ) ) ;
834883 }
884+
835885 #[ allow( unused) ]
836886 pub ( crate ) fn block_pinch_zoom ( & self ) -> bool {
837887 self . property :: < bool > ( "block-pinch-zoom" )
@@ -842,6 +892,16 @@ impl RnCanvasWrapper {
842892 self . set_property ( "block-pinch-zoom" , block_pinch_zoom) ;
843893 }
844894
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+
845905 #[ allow( unused) ]
846906 pub ( crate ) fn inertial_scrolling ( & self ) -> bool {
847907 self . property :: < bool > ( "inertial-scrolling" )
@@ -885,6 +945,11 @@ impl RnCanvasWrapper {
885945 . sync_create ( )
886946 . build ( ) ;
887947
948+ let appwindow_block_touch_bind = appwindow
949+ . bind_property ( "block-touch" , self , "block_touch" )
950+ . sync_create ( )
951+ . build ( ) ;
952+
888953 let appwindow_show_scrollbars_bind = appwindow
889954 . sidebar ( )
890955 . settings_panel ( )
@@ -920,6 +985,12 @@ impl RnCanvasWrapper {
920985 {
921986 old. unbind ( )
922987 }
988+ if let Some ( old) = connections
989+ . appwindow_block_touch_bind
990+ . replace ( appwindow_block_touch_bind)
991+ {
992+ old. unbind ( )
993+ }
923994 if let Some ( old) = connections
924995 . appwindow_show_scrollbars_bind
925996 . replace ( appwindow_show_scrollbars_bind)
@@ -951,6 +1022,9 @@ impl RnCanvasWrapper {
9511022 if let Some ( old) = connections. appwindow_block_pinch_zoom_bind . take ( ) {
9521023 old. unbind ( ) ;
9531024 }
1025+ if let Some ( old) = connections. appwindow_block_touch_bind . take ( ) {
1026+ old. unbind ( ) ;
1027+ }
9541028 if let Some ( old) = connections. appwindow_show_scrollbars_bind . take ( ) {
9551029 old. unbind ( ) ;
9561030 }
0 commit comments