@@ -12,7 +12,7 @@ use dispatch2::MainThreadBound;
1212pub use error:: Error ;
1313use objc2:: __framework_prelude:: Retained ;
1414use objc2:: rc:: Weak ;
15- use objc2:: MainThreadMarker ;
15+ use objc2:: { MainThreadMarker , MainThreadOnly } ;
1616use objc2_app_kit:: NSView ;
1717use raw_window_handle:: { DisplayHandle , HasWindowHandle } ;
1818use std:: fmt;
@@ -69,9 +69,9 @@ impl fmt::Debug for PlatformHandle {
6969 }
7070}
7171
72- #[ derive( Debug , Clone , PartialEq , Eq ) ]
72+ #[ derive( Debug ) ]
7373pub struct ParentWindowHandle {
74- view : Retained < NSView > ,
74+ view : MainThreadBound < Retained < NSView > > ,
7575}
7676
7777impl ParentWindowHandle {
@@ -80,6 +80,26 @@ impl ParentWindowHandle {
8080 ) -> core:: result:: Result < Self , ParentWindowHandleError > {
8181 let view = extract_raw_window_handle ( window. window_handle ( ) ?) ?;
8282
83- Ok ( Self { view } )
83+ let mtm = view. mtm ( ) ;
84+ Ok ( Self { view : MainThreadBound :: new ( view, mtm) } )
8485 }
8586}
87+
88+ impl Clone for ParentWindowHandle {
89+ fn clone ( & self ) -> Self {
90+ // SAFETY: We only use Retained::clone, which is thread-safe
91+ let mtm = unsafe { MainThreadMarker :: new_unchecked ( ) } ;
92+ let view = self . view . get ( mtm) ;
93+ Self { view : MainThreadBound :: new ( view. clone ( ) , mtm) }
94+ }
95+ }
96+
97+ impl PartialEq for ParentWindowHandle {
98+ fn eq ( & self , other : & Self ) -> bool {
99+ // SAFETY: We only use Retained::eq, which is thread-safe
100+ let mtm = unsafe { MainThreadMarker :: new_unchecked ( ) } ;
101+ Retained :: eq ( self . view . get ( mtm) , other. view . get ( mtm) )
102+ }
103+ }
104+
105+ impl Eq for ParentWindowHandle { }
0 commit comments