Skip to content

Instantly share code, notes, and snippets.

@MasonRemaley
Last active May 13, 2018 23:04
Show Gist options
  • Save MasonRemaley/74b9f3e01ed57379bd9d8026728a5acb to your computer and use it in GitHub Desktop.
Save MasonRemaley/74b9f3e01ed57379bd9d8026728a5acb to your computer and use it in GitHub Desktop.
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)[
[screen deviceDescription][@"NSScreenNumber"] intValue];
CVDisplayLinkRef link = NULL;
if (CVDisplayLinkCreateWithCGDisplay(id, &link) != 0) {
printf("failed to create display link");
return 1;
}
CVTime time = CVDisplayLinkGetNominalOutputVideoRefreshPeriod(link);
CVDisplayLinkRelease(link);
if (!(time.flags & kCVTimeIsIndefinite)) {
printf(
"%f (%i / %lld)\n",
(float)time.timeScale / (float)time.timeValue,
time.timeScale,
time.timeValue);
} else {
printf("kCVTimeIsIndefinite");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment