@@ -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,7 @@ 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 ( ) && !self . block_touch . get ( ) && ! self . canvas . touch_drawing ( ) {
300316 self . canvas_zoom_gesture
301317 . set_propagation_phase ( PropagationPhase :: Capture ) ;
302318 } else {
@@ -305,9 +321,21 @@ mod imp {
305321 }
306322 }
307323
324+ fn canvas_touch_pan_update ( & self ) {
325+ if !self . block_touch . get ( ) && !self . canvas . touch_drawing ( ) {
326+ self . canvas_drag_gesture . set_propagation_phase ( PropagationPhase :: Bubble ) ;
327+ self . touch_two_finger_long_press_gesture . set_propagation_phase ( PropagationPhase :: Capture ) ;
328+ self . touch_long_press_gesture . set_propagation_phase ( PropagationPhase :: Capture ) ;
329+ } else { // set everythinbg to `None`
330+ self . canvas_drag_gesture . set_propagation_phase ( PropagationPhase :: None ) ;
331+ self . touch_two_finger_long_press_gesture . set_propagation_phase ( PropagationPhase :: None ) ;
332+ self . touch_long_press_gesture . set_propagation_phase ( PropagationPhase :: None ) ;
333+ }
334+ }
335+
308336 fn canvas_kinetic_scrolling_update ( & self ) {
309337 self . scroller . set_kinetic_scrolling (
310- !self . canvas . touch_drawing ( ) && self . inertial_scrolling . get ( ) ,
338+ !self . block_touch . get ( ) && ! self . canvas . touch_drawing ( ) && self . inertial_scrolling . get ( ) ,
311339 ) ;
312340 }
313341
@@ -397,6 +425,7 @@ mod imp {
397425
398426 // Drag canvas gesture
399427 {
428+
400429 let touch_drag_start = Rc :: new ( Cell :: new ( na:: vector![ 0.0 , 0.0 ] ) ) ;
401430
402431 self . canvas_drag_gesture . connect_drag_begin ( clone ! (
@@ -405,6 +434,7 @@ mod imp {
405434 #[ weak( rename_to=canvaswrapper) ]
406435 obj,
407436 move |_, _, _| {
437+ if canvaswrapper. block_touch( ) { return ( ) ; }
408438 // We don't claim the sequence, because we we want to allow touch zooming.
409439 // When the zoom gesture is recognized, it claims it and denies this touch drag gesture.
410440
@@ -420,6 +450,7 @@ mod imp {
420450 #[ weak( rename_to=canvaswrapper) ]
421451 obj,
422452 move |_, x, y| {
453+ if canvaswrapper. block_touch( ) { return ( ) ; }
423454 let canvas = canvaswrapper. canvas( ) ;
424455 let new_offset = touch_drag_start. get( ) - na:: vector![ x, y] ;
425456 let widget_flags = canvas. engine_mut( ) . camera_set_offset_expand( new_offset) ;
@@ -430,6 +461,7 @@ mod imp {
430461 #[ weak( rename_to=canvaswrapper) ]
431462 obj,
432463 move |_, _, _| {
464+ if canvaswrapper. block_touch( ) { return ( ) ; }
433465 let widget_flags = canvaswrapper
434466 . canvas( )
435467 . engine_mut( )
@@ -832,6 +864,7 @@ impl RnCanvasWrapper {
832864 pub ( crate ) fn set_show_scrollbars ( & self , show_scrollbars : bool ) {
833865 self . set_property ( "show-scrollbars" , show_scrollbars. to_value ( ) ) ;
834866 }
867+
835868 #[ allow( unused) ]
836869 pub ( crate ) fn block_pinch_zoom ( & self ) -> bool {
837870 self . property :: < bool > ( "block-pinch-zoom" )
@@ -842,6 +875,16 @@ impl RnCanvasWrapper {
842875 self . set_property ( "block-pinch-zoom" , block_pinch_zoom) ;
843876 }
844877
878+ #[ allow( unused) ]
879+ pub ( crate ) fn block_touch ( & self ) -> bool {
880+ self . property :: < bool > ( "block-touch" )
881+ }
882+
883+ #[ allow( unused) ]
884+ pub ( crate ) fn set_block_touch ( & self , block_touch : bool ) {
885+ self . set_property ( "block-touch" , block_touch) ;
886+ }
887+
845888 #[ allow( unused) ]
846889 pub ( crate ) fn inertial_scrolling ( & self ) -> bool {
847890 self . property :: < bool > ( "inertial-scrolling" )
@@ -885,6 +928,11 @@ impl RnCanvasWrapper {
885928 . sync_create ( )
886929 . build ( ) ;
887930
931+ let appwindow_block_touch_bind = appwindow
932+ . bind_property ( "block-touch" , self , "block_touch" )
933+ . sync_create ( )
934+ . build ( ) ;
935+
888936 let appwindow_show_scrollbars_bind = appwindow
889937 . sidebar ( )
890938 . settings_panel ( )
@@ -920,6 +968,12 @@ impl RnCanvasWrapper {
920968 {
921969 old. unbind ( )
922970 }
971+ if let Some ( old) = connections
972+ . appwindow_block_touch_bind
973+ . replace ( appwindow_block_touch_bind)
974+ {
975+ old. unbind ( )
976+ }
923977 if let Some ( old) = connections
924978 . appwindow_show_scrollbars_bind
925979 . replace ( appwindow_show_scrollbars_bind)
@@ -951,6 +1005,9 @@ impl RnCanvasWrapper {
9511005 if let Some ( old) = connections. appwindow_block_pinch_zoom_bind . take ( ) {
9521006 old. unbind ( ) ;
9531007 }
1008+ if let Some ( old) = connections. appwindow_block_touch_bind . take ( ) {
1009+ old. unbind ( ) ;
1010+ }
9541011 if let Some ( old) = connections. appwindow_show_scrollbars_bind . take ( ) {
9551012 old. unbind ( ) ;
9561013 }
0 commit comments