@@ -255,13 +255,15 @@ impl ShowCapWindow {
255255 return Err ( tauri:: Error :: WindowNotFound ) ;
256256 } ;
257257
258- let size = display. physical_size ( ) . unwrap ( ) ;
259-
260258 #[ cfg( target_os = "macos" ) ]
261259 let position = display. raw_handle ( ) . logical_position ( ) ;
260+ #[ cfg( target_os = "macos" ) ]
261+ let size = display. logical_size ( ) . unwrap ( ) ;
262262
263263 #[ cfg( windows) ]
264264 let position = display. raw_handle ( ) . physical_position ( ) . unwrap ( ) ;
265+ #[ cfg( windows) ]
266+ let size = display. physical_size ( ) . unwrap ( ) ;
265267
266268 let mut window_builder = self
267269 . window_builder (
@@ -479,7 +481,8 @@ impl ShowCapWindow {
479481 if let Some ( main_window) = CapWindowId :: Main . get ( app)
480482 && let ( Ok ( outer_pos) , Ok ( outer_size) ) =
481483 ( main_window. outer_position ( ) , main_window. outer_size ( ) )
482- && display. intersects ( outer_pos, outer_size)
484+ && let Ok ( scale_factor) = main_window. scale_factor ( )
485+ && display. intersects ( outer_pos, outer_size, scale_factor)
483486 {
484487 let _ = main_window. minimize ( ) ;
485488 } ;
@@ -729,12 +732,44 @@ fn position_traffic_lights_impl(
729732
730733// Credits: tauri-plugin-window-state
731734trait MonitorExt {
732- fn intersects ( & self , position : PhysicalPosition < i32 > , size : PhysicalSize < u32 > ) -> bool ;
735+ fn intersects (
736+ & self ,
737+ position : PhysicalPosition < i32 > ,
738+ size : PhysicalSize < u32 > ,
739+ scale : f64 ,
740+ ) -> bool ;
733741}
734742
735743impl MonitorExt for Display {
736- fn intersects ( & self , position : PhysicalPosition < i32 > , size : PhysicalSize < u32 > ) -> bool {
737- return false ;
744+ fn intersects (
745+ & self ,
746+ position : PhysicalPosition < i32 > ,
747+ size : PhysicalSize < u32 > ,
748+ _scale : f64 ,
749+ ) -> bool {
750+ #[ cfg( target_os = "macos" ) ]
751+ {
752+ let Some ( bounds) = self . raw_handle ( ) . logical_bounds ( ) else {
753+ return false ;
754+ } ;
755+
756+ let left = ( bounds. position ( ) . x ( ) * _scale) as i32 ;
757+ let right = left + ( bounds. size ( ) . width ( ) * _scale) as i32 ;
758+ let top = ( bounds. position ( ) . y ( ) * _scale) as i32 ;
759+ let bottom = top + ( bounds. size ( ) . height ( ) * _scale) as i32 ;
760+
761+ [
762+ ( position. x , position. y ) ,
763+ ( position. x + size. width as i32 , position. y ) ,
764+ ( position. x , position. y + size. height as i32 ) ,
765+ (
766+ position. x + size. width as i32 ,
767+ position. y + size. height as i32 ,
768+ ) ,
769+ ]
770+ . into_iter ( )
771+ . any ( |( x, y) | x >= left && x < right && y >= top && y < bottom)
772+ }
738773
739774 #[ cfg( windows) ]
740775 {
0 commit comments