Skip to content

Commit 3dfb8b7

Browse files
MacOS app: Customize window appearance and maximize on API selection
1 parent 667186f commit 3dfb8b7

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

NativeApp/Apple/Source/Classes/OSX/AppDelegate.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ @implementation AppDelegate
1717
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
1818
NSWindow* mainWindow = [[NSApplication sharedApplication]mainWindow];
1919
[mainWindow setAcceptsMouseMovedEvents:YES];
20+
21+
// Force dark appearance for the entire application
22+
[NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
2023
}
2124

2225
- (void)applicationWillTerminate:(NSNotification *)aNotification {

NativeApp/Apple/Source/Classes/OSX/ModeSelectionViewController.mm

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ @implementation ModeSelectionViewController
3333
{
3434
}
3535

36-
- (void) setWindowTitle:(NSString*) title
36+
- (void) setWindowTitle:(NSString*) title forWindow:(NSWindow*) window
3737
{
38-
NSWindow* mainWindow = [[NSApplication sharedApplication]mainWindow];
39-
[mainWindow setTitle:title];
38+
[window setTitle:title];
39+
}
40+
41+
- (void) maximizeWindow:(NSWindow*)window
42+
{
43+
if (window)
44+
{
45+
// Fill the entire visible screen area (excluding Dock and menu bar)
46+
NSRect screenFrame = window.screen.visibleFrame;
47+
[window setFrame:screenFrame display:YES animate:YES];
48+
}
4049
}
4150

4251
- (void)viewDidLoad
@@ -97,8 +106,9 @@ - (void) terminateApp:(NSString*) error
97106

98107
- (IBAction)goOpenGL:(id)sender
99108
{
109+
NSWindow* window = self.view.window;
100110
ViewController* glViewController = [self.storyboard instantiateControllerWithIdentifier:@"GLViewControllerID"];
101-
self.view.window.contentViewController = glViewController;
111+
window.contentViewController = glViewController;
102112

103113
GLView* glView = (GLView*)[glViewController view];
104114
NSString* error = [glView getError];
@@ -108,13 +118,15 @@ - (IBAction)goOpenGL:(id)sender
108118
}
109119

110120
NSString* name = [glView getAppName];
111-
[self setWindowTitle:name];
121+
[self setWindowTitle:name forWindow:window];
122+
[self maximizeWindow:window];
112123
}
113124

114125
- (IBAction)goVulkan:(id)sender
115126
{
127+
NSWindow* window = self.view.window;
116128
ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MoltenVKViewControllerID"];
117-
self.view.window.contentViewController = metalViewController;
129+
window.contentViewController = metalViewController;
118130

119131
MetalView* mtlView = (MetalView*)[metalViewController view];
120132
NSString* error = [mtlView getError];
@@ -124,14 +136,16 @@ - (IBAction)goVulkan:(id)sender
124136
}
125137

126138
NSString* name = [mtlView getAppName];
127-
[self setWindowTitle:name];
139+
[self setWindowTitle:name forWindow:window];
140+
[self maximizeWindow:window];
128141
}
129142

130143
- (IBAction)goMetal:(id)sender
131144
{
145+
NSWindow* window = self.view.window;
132146
ViewController* metalViewController = [self.storyboard instantiateControllerWithIdentifier:@"MetalViewControllerID"];
133147
MetalView* mtlView = (MetalView*)[metalViewController view];
134-
self.view.window.contentViewController = metalViewController;
148+
window.contentViewController = metalViewController;
135149

136150
NSString* error = [mtlView getError];
137151
if(error != nil)
@@ -140,14 +154,16 @@ - (IBAction)goMetal:(id)sender
140154
}
141155

142156
NSString* name = [mtlView getAppName];
143-
[self setWindowTitle:name];
157+
[self setWindowTitle:name forWindow:window];
158+
[self maximizeWindow:window];
144159
}
145160

146161
- (IBAction)goWebGPU:(id)sender
147162
{
163+
NSWindow* window = self.view.window;
148164
ViewController* webgpuViewController = [self.storyboard instantiateControllerWithIdentifier:@"WebGPUViewControllerID"];
149165
WebGPUView* webgpuView = (WebGPUView*)[webgpuViewController view];
150-
self.view.window.contentViewController = webgpuViewController;
166+
window.contentViewController = webgpuViewController;
151167

152168
NSString* error = [webgpuView getError];
153169
if(error != nil)
@@ -156,7 +172,8 @@ - (IBAction)goWebGPU:(id)sender
156172
}
157173

158174
NSString* name = [webgpuView getAppName];
159-
[self setWindowTitle:name];
175+
[self setWindowTitle:name forWindow:window];
176+
[self maximizeWindow:window];
160177
}
161178

162179
@end

NativeApp/Apple/Source/Classes/OSX/WindowController.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ - (instancetype)initWithWindow:(NSWindow *)window
4040
return self;
4141
}
4242

43+
- (void)windowDidLoad
44+
{
45+
[super windowDidLoad];
46+
47+
NSWindow* window = self.window;
48+
49+
// Force dark appearance to match the application UI
50+
window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
51+
52+
// Make the titlebar transparent so it blends with the window background
53+
window.titlebarAppearsTransparent = YES;
54+
55+
// Set window background color matching ImGuiColors::TitleBg (~0.07, 0.08, 0.11)
56+
window.backgroundColor = [NSColor colorWithRed:0.07 green:0.08 blue:0.11 alpha:1.0];
57+
58+
// Hide the title text (the app name is shown in the content area)
59+
window.titleVisibility = NSWindowTitleHidden;
60+
}
61+
4362
- (void) goFullscreen
4463
{
4564
// If app is already fullscreen...

0 commit comments

Comments
 (0)