Last active
August 29, 2015 13:55
-
-
Save swillits/8744503 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // | |
| // AppDelegate.m | |
| // MouseTest | |
| // | |
| // Created by Seth Willits on 1/30/14. | |
| // Copyright (c) 2014 Araelium Group. All rights reserved. | |
| // | |
| #import "AppDelegate.h" | |
| #define dispatch_after_s(secs, queue, block) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, secs * NSEC_PER_SEC), queue, block) | |
| #define QMAIN dispatch_get_main_queue() | |
| @implementation AppDelegate | |
| { | |
| CGDisplayModeRef oldMode; | |
| CGDisplayModeRef newMode; | |
| } | |
| - (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
| { | |
| oldMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); | |
| newMode = QZ_BestMode(32, 1280, 960); //!!!!!!!!!!!!!!!!!!!!!! pick a display size your screen supports | |
| dispatch_after_s(2.0, QMAIN, ^{ | |
| CGError error = CGDisplaySetDisplayMode(CGMainDisplayID(), newMode, NULL); | |
| if (error) NSLog(@"%d", error); | |
| CGSetDisplayTransferByFormula(CGMainDisplayID(), 0.0, 1.0, 0.5, 0.0, 1.0, 0.5, 0.0, 1.0, 0.5); | |
| }); | |
| } | |
| - (void)applicationWillTerminate:(NSNotification *)notification | |
| { | |
| CGDisplaySetDisplayMode(CGMainDisplayID(), oldMode, NULL); | |
| } | |
| CGDisplayModeRef QZ_BestMode(const int bpp, const int w, const int h) | |
| { | |
| CGDisplayModeRef best = NULL; | |
| if (bpp == 0) { | |
| return NULL; | |
| } | |
| /* apparently, we have to roll our own now. :/ */ | |
| CFArrayRef mode_list = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL); | |
| if (mode_list != NULL) { | |
| const CFIndex num_modes = CFArrayGetCount(mode_list); | |
| CFIndex i; | |
| for (i = 0; i < num_modes; i++) { | |
| CGDisplayModeRef vidmode = (CGDisplayModeRef)CFArrayGetValueAtIndex(mode_list, i); | |
| CFStringRef fmt = CGDisplayModeCopyPixelEncoding(vidmode); | |
| int thisw = (int)CGDisplayModeGetWidth(vidmode); | |
| int thish = (int)CGDisplayModeGetHeight(vidmode); | |
| int thisbpp = 0; | |
| /* we only care about the 32-bit modes... */ | |
| if (CFStringCompare(fmt, CFSTR(IO32BitDirectPixels), | |
| kCFCompareCaseInsensitive) == kCFCompareEqualTo) { | |
| thisbpp = 32; | |
| } | |
| CFRelease(fmt); | |
| /* We only care about exact matches, apparently. */ | |
| if ((thisbpp == bpp) && (thisw == w) && (thish == h)) { | |
| best = vidmode; | |
| break; /* got it! */ | |
| } | |
| } | |
| CGDisplayModeRetain((CGDisplayModeRef) best); /* NULL is ok */ | |
| CFRelease(mode_list); | |
| } | |
| return best; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment