Created
March 8, 2021 19:38
-
-
Save michicc/9d040e31f6412b8557531df96e0f36a1 to your computer and use it in GitHub Desktop.
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
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h | |
index 371e4b5bc..3d3db5454 100644 | |
--- a/src/video/cocoa/cocoa_v.h | |
+++ b/src/video/cocoa/cocoa_v.h | |
@@ -47,6 +47,8 @@ public: | |
void EditBoxLostFocus() override; | |
+ std::vector<int> GetListOfMonitorRefreshRates() override; | |
+ | |
/* --- The following methods should be private, but can't be due to Obj-C limitations. --- */ | |
void MainLoopReal(); | |
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm | |
index 8d1fd4447..19bf7e800 100644 | |
--- a/src/video/cocoa/cocoa_v.mm | |
+++ b/src/video/cocoa/cocoa_v.mm | |
@@ -43,6 +43,7 @@ | |
#import <sys/param.h> /* for MAXPATHLEN */ | |
#import <sys/time.h> /* gettimeofday */ | |
+#include <array> | |
/** | |
* Important notice regarding all modifications!!!!!!! | |
@@ -228,6 +229,30 @@ void VideoDriver_Cocoa::EditBoxLostFocus() | |
HandleTextInput(nullptr, true); | |
} | |
+/** | |
+ * Get refresh rates of all connected monitors. | |
+ */ | |
+std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates() | |
+{ | |
+ std::vector<int> rates{}; | |
+ | |
+ if (MacOSVersionIsAtLeast(10, 6, 0)) { | |
+ std::array<CGDirectDisplayID, 16> displays; | |
+ | |
+ uint32_t count = 0; | |
+ CGGetActiveDisplayList(displays.size(), displays.data(), &count); | |
+ | |
+ for (uint32_t i = 0; i < count; i++) { | |
+ CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]); | |
+ int rate = (int)CGDisplayModeGetRefreshRate(mode); | |
+ if (rate > 0) rates.push_back(rate); | |
+ CGDisplayModeRelease(mode); | |
+ } | |
+ } | |
+ | |
+ return rates; | |
+} | |
+ | |
/** | |
* Get the resolution of the main screen. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment