@@ -2,7 +2,7 @@ use crate::camera::PanOrbitCamera;
22use bevy:: {
33 math:: sampling:: mesh_sampling,
44 prelude:: * ,
5- window:: { PrimaryWindow , RequestRedraw , Window , WindowLevel } ,
5+ window:: { CursorOptions , PrimaryWindow , RequestRedraw , Window , WindowLevel } ,
66 winit:: WinitWindows ,
77} ;
88
@@ -264,29 +264,25 @@ pub fn toggle_decorations(input: Res<ButtonInput<KeyCode>>, mut windows: Query<&
264264}
265265
266266/// System:
267- /// Toggle mouse passthrough.
267+ /// Toggle mouse passthrough (click-through window) .
268268/// This is ONLY supported on Windows.
269269#[ cfg( target_os = "windows" ) ]
270270pub fn toggle_window_passthrough (
271271 keyboard_input : Res < ButtonInput < KeyCode > > ,
272- mut windows : Query < & mut Window > ,
272+ mut windows : Query < ( & mut Window , & mut CursorOptions ) > ,
273273) {
274- if keyboard_input. just_pressed ( KeyCode :: KeyP ) {
275- #[ allow( unused_mut) ]
276- let mut window = windows. single_mut ( ) . unwrap ( ) ;
277- info ! ( "PASSTHROUGH TOGGLED.: {:?}" , window. decorations) ;
278- }
274+ let Ok ( ( mut window, mut cursor_options) ) = windows. single_mut ( ) else {
275+ error ! ( "No primary window found" ) ;
276+ return ;
277+ } ;
279278
280- if keyboard_input. just_pressed ( KeyCode :: KeyX ) {
281- let mut window = match windows. single_mut ( ) {
282- Ok ( w) => w,
283- Err ( e) => {
284- error ! ( "No primary window found {}" , e) ;
285- return ;
286- }
287- } ;
288- debug ! ( "PASSTHROUGH TOGGLED.: {:?}" , window. decorations) ;
289- window. cursor_options . hit_test = !window. cursor_options . hit_test ;
279+ if keyboard_input. just_pressed ( KeyCode :: KeyP ) || keyboard_input. just_pressed ( KeyCode :: KeyX ) {
280+ cursor_options. hit_test = !cursor_options. hit_test ;
281+
282+ info ! (
283+ "PASSTHROUGH TOGGLED → hit_test: {} | decorations: {:}" ,
284+ cursor_options. hit_test, window. decorations
285+ ) ;
290286 }
291287}
292288
0 commit comments