mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app/internal/window: [macOS] split out gio_createWindow
Updates #19 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -109,9 +109,30 @@ void gio_setDisplayLinkDisplay(CFTypeRef dl, uint64_t did) {
|
|||||||
CVDisplayLinkSetCurrentCGDisplay((CVDisplayLinkRef)dl, (CGDirectDisplayID)did);
|
CVDisplayLinkSetCurrentCGDisplay((CVDisplayLinkRef)dl, (CGDirectDisplayID)did);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CFTypeRef gio_createWindow(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height) {
|
||||||
|
@autoreleasepool {
|
||||||
|
NSRect rect = NSMakeRect(0, 0, width, height);
|
||||||
|
NSUInteger styleMask = NSTitledWindowMask |
|
||||||
|
NSResizableWindowMask |
|
||||||
|
NSMiniaturizableWindowMask |
|
||||||
|
NSClosableWindowMask;
|
||||||
|
|
||||||
|
NSWindow* window = [[NSWindow alloc] initWithContentRect:rect
|
||||||
|
styleMask:styleMask
|
||||||
|
backing:NSBackingStoreBuffered
|
||||||
|
defer:NO];
|
||||||
|
[window setAcceptsMouseMovedEvents:YES];
|
||||||
|
window.title = [NSString stringWithUTF8String: title];
|
||||||
|
NSView *view = (NSView *)CFBridgingRelease(viewRef);
|
||||||
|
[window setContentView:view];
|
||||||
|
[window makeFirstResponder:view];
|
||||||
|
gio_onCreate((__bridge CFTypeRef)view);
|
||||||
|
return (__bridge_retained CFTypeRef)window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void gio_main(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height) {
|
void gio_main(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat height) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
NSView *view = (NSView *)CFBridgingRelease(viewRef);
|
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
|
||||||
@@ -131,25 +152,12 @@ void gio_main(CFTypeRef viewRef, const char *title, CGFloat width, CGFloat heigh
|
|||||||
[menuBar addItem:mainMenu];
|
[menuBar addItem:mainMenu];
|
||||||
[NSApp setMainMenu:menuBar];
|
[NSApp setMainMenu:menuBar];
|
||||||
|
|
||||||
NSRect rect = NSMakeRect(0, 0, width, height);
|
NSWindow *window = (__bridge NSWindow *)gio_createWindow(viewRef, title, width, height);
|
||||||
NSUInteger styleMask = NSTitledWindowMask |
|
|
||||||
NSResizableWindowMask |
|
|
||||||
NSMiniaturizableWindowMask |
|
|
||||||
NSClosableWindowMask;
|
|
||||||
NSWindow* window = [[NSWindow alloc] initWithContentRect:rect
|
|
||||||
styleMask:styleMask
|
|
||||||
backing:NSBackingStoreBuffered
|
|
||||||
defer:NO];
|
|
||||||
window.title = [NSString stringWithUTF8String: title];
|
|
||||||
[window setAcceptsMouseMovedEvents:YES];
|
|
||||||
|
|
||||||
gio_onCreate((__bridge CFTypeRef)view);
|
|
||||||
GioDelegate *del = [[GioDelegate alloc] init];
|
GioDelegate *del = [[GioDelegate alloc] init];
|
||||||
del.window = window;
|
del.window = window;
|
||||||
[window setDelegate:del];
|
[window setDelegate:del];
|
||||||
[NSApp setDelegate:del];
|
[NSApp setDelegate:del];
|
||||||
[window setContentView:view];
|
|
||||||
[window makeFirstResponder:view];
|
|
||||||
|
|
||||||
[NSApp run];
|
[NSApp run];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user