Skip to content

Instantly share code, notes, and snippets.

@slmjkdbtl
Last active January 27, 2021 21:04
Show Gist options
  • Save slmjkdbtl/a6d592a17e60d1f61588ab288dc038b6 to your computer and use it in GitHub Desktop.
Save slmjkdbtl/a6d592a17e60d1f61588ab288dc038b6 to your computer and use it in GitHub Desktop.
opens a basic window
// macOS
// CFLAGS += -ObjC
// LDFLAGS += -framework Cocoa
#import <Cocoa/Cocoa.h>
int main() {
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];
NSWindow *window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 400, 400)
styleMask:
0
| NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable
| NSWindowStyleMaskResizable
| NSWindowStyleMaskMiniaturizable
backing:NSBackingStoreBuffered
defer:NO
];
[window setTitle:@"hi"];
[window center];
[window makeKeyAndOrderFront:nil];
while (1) {
while (1) {
NSEvent *event = [NSApp
nextEventMatchingMask:NSEventMaskAny
untilDate:[NSDate distantPast]
inMode:NSDefaultRunLoopMode
dequeue:YES
];
if (event == nil) {
break;
}
switch (event.type) {
case NSEventTypeKeyDown:
printf("down\n");
break;
default:
break;
}
[NSApp sendEvent:event];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment