@@ -16,7 +16,7 @@ use objc2_app_kit::{
16
16
NSAppearanceNameAqua , NSApplication , NSApplicationPresentationOptions , NSBackingStoreType ,
17
17
NSColor , NSDraggingDestination , NSFilenamesPboardType , NSPasteboard ,
18
18
NSRequestUserAttentionType , NSScreen , NSToolbar , NSView , NSViewFrameDidChangeNotification ,
19
- NSWindowButton , NSWindowDelegate , NSWindowFullScreenButton , NSWindowLevel ,
19
+ NSWindow , NSWindowButton , NSWindowDelegate , NSWindowFullScreenButton , NSWindowLevel ,
20
20
NSWindowOcclusionState , NSWindowOrderingMode , NSWindowSharingType , NSWindowStyleMask ,
21
21
NSWindowTabbingMode , NSWindowTitleVisibility , NSWindowToolbarStyle ,
22
22
} ;
@@ -33,22 +33,23 @@ use super::cursor::cursor_from_icon;
33
33
use super :: monitor:: { self , flip_window_screen_coordinates, get_display_id} ;
34
34
use super :: observer:: RunLoop ;
35
35
use super :: view:: WinitView ;
36
- use super :: window:: WinitWindow ;
36
+ use super :: window:: { ns_window_id , WinitPanel , WinitWindow } ;
37
37
use super :: { ffi, Fullscreen , MonitorHandle } ;
38
38
use crate :: dpi:: {
39
39
LogicalInsets , LogicalPosition , LogicalSize , PhysicalInsets , PhysicalPosition , PhysicalSize ,
40
40
Position , Size ,
41
41
} ;
42
42
use crate :: error:: { NotSupportedError , RequestError } ;
43
43
use crate :: event:: { SurfaceSizeWriter , WindowEvent } ;
44
- use crate :: platform:: macos:: { OptionAsAlt , WindowExtMacOS } ;
44
+ use crate :: platform:: macos:: { OptionAsAlt , WindowExtMacOS , WindowKind } ;
45
45
use crate :: window:: {
46
46
Cursor , CursorGrabMode , Icon , ImePurpose , ResizeDirection , Theme , UserAttentionType ,
47
47
WindowAttributes , WindowButtons , WindowId , WindowLevel ,
48
48
} ;
49
49
50
50
#[ derive( Clone , Debug , PartialEq ) ]
51
51
pub struct PlatformSpecificWindowAttributes {
52
+ pub window_kind : WindowKind ,
52
53
pub movable_by_window_background : bool ,
53
54
pub titlebar_transparent : bool ,
54
55
pub title_hidden : bool ,
@@ -68,6 +69,7 @@ impl Default for PlatformSpecificWindowAttributes {
68
69
#[ inline]
69
70
fn default ( ) -> Self {
70
71
Self {
72
+ window_kind : WindowKind :: default ( ) ,
71
73
movable_by_window_background : false ,
72
74
titlebar_transparent : false ,
73
75
title_hidden : false ,
@@ -90,7 +92,7 @@ pub(crate) struct State {
90
92
/// Strong reference to the global application state.
91
93
app_state : Rc < AppState > ,
92
94
93
- window : Retained < WinitWindow > ,
95
+ window : Retained < NSWindow > ,
94
96
95
97
// During `windowDidResize`, we use this to only send Moved if the position changed.
96
98
//
@@ -501,7 +503,7 @@ fn new_window(
501
503
app_state : & Rc < AppState > ,
502
504
attrs : & WindowAttributes ,
503
505
mtm : MainThreadMarker ,
504
- ) -> Option < Retained < WinitWindow > > {
506
+ ) -> Option < Retained < NSWindow > > {
505
507
autoreleasepool ( |_| {
506
508
let screen = match attrs. fullscreen . clone ( ) . map ( Into :: into) {
507
509
Some ( Fullscreen :: Borderless ( Some ( monitor) ) )
@@ -584,16 +586,35 @@ fn new_window(
584
586
// confusing issues with the window not being properly activated.
585
587
//
586
588
// Winit ensures this by not allowing access to `ActiveEventLoop` before handling events.
587
- let window: Option < Retained < WinitWindow > > = unsafe {
588
- msg_send_id ! [
589
- super ( mtm. alloc( ) . set_ivars( ( ) ) ) ,
590
- initWithContentRect: frame,
591
- styleMask: masks,
592
- backing: NSBackingStoreType :: NSBackingStoreBuffered ,
593
- defer: false ,
594
- ]
589
+ let window: Retained < NSWindow > = match attrs. platform_specific . window_kind {
590
+ WindowKind :: Normal => {
591
+ let window: Option < Retained < WinitWindow > > = unsafe {
592
+ msg_send_id ! [
593
+ super ( mtm. alloc( ) . set_ivars( ( ) ) ) ,
594
+ initWithContentRect: frame,
595
+ styleMask: masks,
596
+ backing: NSBackingStoreType :: NSBackingStoreBuffered ,
597
+ defer: false ,
598
+ ]
599
+ } ;
600
+
601
+ window?. as_super ( ) . retain ( )
602
+ } ,
603
+ WindowKind :: Popup => {
604
+ masks |= NSWindowStyleMask :: NonactivatingPanel ;
605
+ let window: Option < Retained < WinitPanel > > = unsafe {
606
+ msg_send_id ! [
607
+ super ( mtm. alloc( ) . set_ivars( ( ) ) ) ,
608
+ initWithContentRect: frame,
609
+ styleMask: masks,
610
+ backing: NSBackingStoreType :: NSBackingStoreBuffered ,
611
+ defer: false ,
612
+ ]
613
+ } ;
614
+
615
+ window?. as_super ( ) . as_super ( ) . retain ( )
616
+ } ,
595
617
} ;
596
- let window = window?;
597
618
598
619
// It is very important for correct memory management that we
599
620
// disable the extra release that would otherwise happen when
@@ -841,17 +862,17 @@ impl WindowDelegate {
841
862
}
842
863
843
864
#[ track_caller]
844
- pub ( super ) fn window ( & self ) -> & WinitWindow {
865
+ pub ( super ) fn window ( & self ) -> & NSWindow {
845
866
& self . ivars ( ) . window
846
867
}
847
868
848
869
#[ track_caller]
849
870
pub ( crate ) fn id ( & self ) -> WindowId {
850
- self . window ( ) . id ( )
871
+ ns_window_id ( & self . window ( ) )
851
872
}
852
873
853
874
pub ( crate ) fn queue_event ( & self , event : WindowEvent ) {
854
- let window_id = self . window ( ) . id ( ) ;
875
+ let window_id = ns_window_id ( & self . window ( ) ) ;
855
876
self . ivars ( ) . app_state . maybe_queue_with_handler ( move |app, event_loop| {
856
877
app. window_event ( event_loop, window_id, event) ;
857
878
} ) ;
@@ -950,7 +971,7 @@ impl WindowDelegate {
950
971
}
951
972
952
973
pub fn request_redraw ( & self ) {
953
- self . ivars ( ) . app_state . queue_redraw ( self . window ( ) . id ( ) ) ;
974
+ self . ivars ( ) . app_state . queue_redraw ( ns_window_id ( & self . window ( ) ) ) ;
954
975
}
955
976
956
977
#[ inline]
@@ -1488,7 +1509,7 @@ impl WindowDelegate {
1488
1509
1489
1510
self . ivars ( ) . fullscreen . replace ( fullscreen. clone ( ) ) ;
1490
1511
1491
- fn toggle_fullscreen ( window : & WinitWindow ) {
1512
+ fn toggle_fullscreen ( window : & NSWindow ) {
1492
1513
// Window level must be restored from `CGShieldingWindowLevel()
1493
1514
// + 1` back to normal in order for `toggleFullScreen` to do
1494
1515
// anything
0 commit comments