impr: Hide window on macOS when close button is pressed

This commit is contained in:
WerWolv
2025-01-19 17:04:31 +01:00
parent 04ab87cd8e
commit 7c0331df65
3 changed files with 28 additions and 2 deletions

View File

@@ -48,6 +48,17 @@
return [[NSScreen mainScreen] backingScaleFactor];
}
void macOSCloseButtonPressed(void);
@interface CloseButtonHandler : NSObject
@end
@implementation CloseButtonHandler
- (void)pressed:(id)sender {
macOSCloseButtonPressed();
}
@end
void setupMacosWindowStyle(GLFWwindow *window, bool borderlessWindowMode) {
NSWindow* cocoaWindow = glfwGetCocoaWindow(window);
@@ -61,6 +72,10 @@
[cocoaWindow setHasShadow:YES];
[cocoaWindow setBackgroundColor:[NSColor colorWithWhite: 0 alpha: 0.001f]];
}
NSButton *closeButton = [cocoaWindow standardWindowButton:NSWindowCloseButton];
[closeButton setAction:@selector(pressed:)];
[closeButton setTarget:[CloseButtonHandler alloc]];
}
bool isMacosFullScreenModeEnabled(GLFWwindow *window) {