Last active
May 13, 2018 23:04
-
-
Save MasonRemaley/74b9f3e01ed57379bd9d8026728a5acb to your computer and use it in GitHub Desktop.
refresh_rate.m
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
// 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