Skip to content

Instantly share code, notes, and snippets.

@michicc
Created March 8, 2021 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michicc/bef02e3dbfd678efae3a141ecb31ec94 to your computer and use it in GitHub Desktop.
Save michicc/bef02e3dbfd678efae3a141ecb31ec94 to your computer and use it in GitHub Desktop.
OSX refresh rate
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..3f1dadbaf 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -228,6 +228,24 @@ void VideoDriver_Cocoa::EditBoxLostFocus()
HandleTextInput(nullptr, true);
}
+/**
+ * Get refresh rate of the current screen.
+ */
+std::vector<int> VideoDriver_Cocoa::GetListOfMonitorRefreshRates()
+{
+ std::vector<int> rates{};
+
+ NSNumber *scr = [ [ [ this->window screen ] deviceDescription ] objectForKey:@"NSScreenNumber" ];
+ if (scr != nil && MacOSVersionIsAtLeast(10, 6, 0)) {
+ CGDisplayModeRef mode = CGDisplayCopyDisplayMode((CGDirectDisplayID)[ scr unsignedIntValue ]);
+ 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