+ vid_joystate_t joystate;
+ VID_EnableJoystick(true);
+ VID_BuildJoyState(&joystate);
+ VID_ApplyJoyState(&joystate);
+}
+
+static bool GetDictionaryBoolean(CFDictionaryRef d, const void *key)
+{
+ CFBooleanRef ref = (CFBooleanRef) CFDictionaryGetValue(d, key);
+ if(ref)
+ return CFBooleanGetValue(ref);
+ return false;
+}
+
+long GetDictionaryLong(CFDictionaryRef d, const void *key)
+{
+ long value = 0;
+ CFNumberRef ref = (CFNumberRef) CFDictionaryGetValue(d, key);
+ if(ref)
+ CFNumberGetValue(ref, kCFNumberLongType, &value);
+ return value;
+}
+
+size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
+{
+ CGDirectDisplayID mainDisplay = CGMainDisplayID();
+ CFArrayRef vidmodes = CGDisplayAvailableModes(mainDisplay);
+ CFDictionaryRef thismode;
+ unsigned int n = CFArrayGetCount(vidmodes);
+ unsigned int i;
+ size_t k;
+
+ k = 0;
+ for(i = 0; i < n; ++i)
+ {
+ thismode = (CFDictionaryRef) CFArrayGetValueAtIndex(vidmodes, i);
+ if(!GetDictionaryBoolean(thismode, kCGDisplayModeIsSafeForHardware))
+ continue;
+
+ if(k >= maxcount)
+ break;
+ modes[k].width = GetDictionaryLong(thismode, kCGDisplayWidth);
+ modes[k].height = GetDictionaryLong(thismode, kCGDisplayHeight);
+ modes[k].bpp = GetDictionaryLong(thismode, kCGDisplayBitsPerPixel);
+ modes[k].refreshrate = GetDictionaryLong(thismode, kCGDisplayRefreshRate);
+ modes[k].pixelheight_num = 1;
+ modes[k].pixelheight_denom = 1; // OS X doesn't expose this either
+ ++k;
+ }
+ return k;