Skip to content

Instantly share code, notes, and snippets.

// I'm thinking these two will resolve themselves when the others do? There
// doesn't seem to be an explicit way to make a window not key besides replacing
// it with another window, or closing it.
[...]
-> _keyWindow
-> MyWindow
[...]
-> NSDragDestination (_window)
-> MyWindow
// # To test (macOS only)
// - Copy the contents of this file into a file called main.m
// - Run `clang main.m -fobjc-arc -xobjective-c++ -framework Cocoa && ./a.out`
// in bash
// - Send me:
// + The copy pasted console output from the run
// + Your macOS version (Apple > About This Mac)
// + Your clang version (`clang --version`)
// + Whether or not your computer has a Touch Bar
//
@MasonRemaley
MasonRemaley / refresh_rate.m
Last active May 13, 2018 23:04
refresh_rate.m
// gcc refresh_rate.m -framework Cocoa -framework CoreVideo && ./a.out
//
// Prints the refresh rate of your main screen...I think.
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
int main() {
NSScreen *screen = [NSScreen mainScreen];
CGDirectDisplayID id = (CGDirectDisplayID)[
@MasonRemaley
MasonRemaley / minimal_cocoa_gl_text_entry.m
Last active November 17, 2017 03:01
Minimal cocoa text entry for OpenGL apps
// *DISCLAIMER IF YOU FOUND THIS VIA GOOGLE: I'm at the time of writing still figuring this out, it
// works for me but I don't actually know if it's correct yet*
//
// This is a minimal example of how one might accept text entry in Cocoa in an OpenGL app or
// such. Unlike using `[event characters]`, it ignores unprintable keys such as the arrow keys. It
// also allows you to type accents and such, e.g. `alt+e o`. This example contains no error
// checking, and the only way to exit it is to kill it from the command line.
//
// To execute it, run:
// `$ gcc minimal_cocoa_gl_text_entry.m -framework Cocoa && ./a.out`