Last active
January 27, 2021 21:04
-
-
Save slmjkdbtl/a6d592a17e60d1f61588ab288dc038b6 to your computer and use it in GitHub Desktop.
opens a basic window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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