@@ -48,7 +48,7 @@ use core_graphics::{
4848use objc2:: {
4949 msg_send,
5050 rc:: Retained ,
51- runtime:: { AnyClass as Class , AnyObject as Object , ClassBuilder as ClassDecl , Sel } ,
51+ runtime:: { AnyClass as Class , AnyObject as Object , Bool , ClassBuilder as ClassDecl , Sel } ,
5252} ;
5353use objc2_app_kit:: {
5454 self as appkit, NSApp , NSApplicationPresentationOptions , NSBackingStoreType , NSColor , NSEvent ,
@@ -242,16 +242,21 @@ fn create_window(
242242 masks |= NSWindowStyleMask :: FullSizeContentView ;
243243 }
244244
245- let ns_window = msg_send ! [ WINDOW_CLASS . 0 , alloc] ;
246- let ns_window : Option < Retained < NSWindow > > = msg_send ! [
245+ let ns_window: id = msg_send ! [ WINDOW_CLASS . 0 , alloc] ;
246+ let ns_window_ptr : id = msg_send ! [
247247 ns_window,
248248 initWithContentRect: frame,
249249 styleMask: masks,
250250 backing: NSBackingStoreType :: Buffered ,
251251 defer: NO ,
252252 ] ;
253253
254- ns_window. map ( |ns_window| {
254+ Retained :: retain ( ns_window_ptr) . and_then ( |r| r. downcast :: < NSWindow > ( ) . ok ( ) ) . map ( |ns_window| {
255+ #[ allow( deprecated) ]
256+ {
257+ * ( ( * ns_window_ptr) . get_mut_ivar :: < Bool > ( "focusable" ) ) = attrs. focusable . into ( ) ;
258+ }
259+
255260 let title = NSString :: from_str ( & attrs. title ) ;
256261 ns_window. setReleasedWhenClosed ( false ) ;
257262 ns_window. setTitle ( & title) ;
@@ -409,17 +414,26 @@ lazy_static! {
409414 . unwrap( ) ;
410415 decl. add_method(
411416 sel!( canBecomeMainWindow) ,
412- util :: yes as extern "C" fn ( _, _) -> _,
417+ is_focusable as extern "C" fn ( _, _) -> _,
413418 ) ;
414419 decl. add_method(
415420 sel!( canBecomeKeyWindow) ,
416- util :: yes as extern "C" fn ( _, _) -> _,
421+ is_focusable as extern "C" fn ( _, _) -> _,
417422 ) ;
418423 decl. add_method( sel!( sendEvent: ) , send_event as extern "C" fn ( _, _, _) ) ;
424+ // progress bar states, follows ProgressState
425+ decl. add_ivar:: <Bool >( CStr :: from_bytes_with_nul( b"focusable\0 " ) . unwrap( ) ) ;
419426 WindowClass ( decl. register( ) )
420427 } ;
421428}
422429
430+ extern "C" fn is_focusable ( this : & Object , _: Sel ) -> Bool {
431+ #[ allow( deprecated) ] // TODO: Use define_class!
432+ unsafe {
433+ * ( this. get_ivar ( "focusable" ) )
434+ }
435+ }
436+
423437extern "C" fn send_event ( this : & Object , _sel : Sel , event : & NSEvent ) {
424438 unsafe {
425439 let event_type = event. r#type ( ) ;
@@ -666,6 +680,16 @@ impl UnownedWindow {
666680 }
667681 }
668682
683+ #[ inline]
684+ pub fn set_focusable ( & self , focusable : bool ) {
685+ #[ allow( deprecated) ] // TODO: Use define_class!
686+ unsafe {
687+ let ns_window =
688+ Retained :: into_raw ( Retained :: cast_unchecked :: < Object > ( self . ns_window . clone ( ) ) ) ;
689+ * ( ( * ns_window) . get_mut_ivar :: < Bool > ( "focusable" ) ) = focusable. into ( ) ;
690+ }
691+ }
692+
669693 #[ inline]
670694 pub fn is_focused ( & self ) -> bool {
671695 unsafe { self . ns_window . isKeyWindow ( ) }
0 commit comments