summaryrefslogtreecommitdiff
path: root/platform/macos
diff options
context:
space:
mode:
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/dir_access_macos.h8
-rw-r--r--platform/macos/display_server_macos.h5
-rw-r--r--platform/macos/display_server_macos.mm26
-rw-r--r--platform/macos/export/export_plugin.cpp1
4 files changed, 36 insertions, 4 deletions
diff --git a/platform/macos/dir_access_macos.h b/platform/macos/dir_access_macos.h
index 1ac1b995de..920e69ef3e 100644
--- a/platform/macos/dir_access_macos.h
+++ b/platform/macos/dir_access_macos.h
@@ -43,12 +43,12 @@
class DirAccessMacOS : public DirAccessUnix {
protected:
- virtual String fix_unicode_name(const char *p_name) const;
+ virtual String fix_unicode_name(const char *p_name) const override;
- virtual int get_drive_count();
- virtual String get_drive(int p_drive);
+ virtual int get_drive_count() override;
+ virtual String get_drive(int p_drive) override;
- virtual bool is_hidden(const String &p_name);
+ virtual bool is_hidden(const String &p_name) override;
};
#endif // UNIX ENABLED || LIBC_FILEIO_ENABLED
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 41031ec81b..54c479fc81 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -50,6 +50,7 @@
#import <ApplicationServices/ApplicationServices.h>
#import <CoreVideo/CoreVideo.h>
#import <Foundation/Foundation.h>
+#import <IOKit/pwr_mgt/IOPMLib.h>
#undef BitMap
#undef CursorShape
@@ -171,6 +172,8 @@ private:
HashMap<WindowID, WindowData> windows;
+ IOPMAssertionID screen_keep_on_assertion = kIOPMNullAssertionID;
+
const NSMenu *_get_menu_root(const String &p_menu_root) const;
NSMenu *_get_menu_root(const String &p_menu_root);
@@ -299,6 +302,8 @@ public:
virtual float screen_get_max_scale() const override;
virtual Rect2i screen_get_usable_rect(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
virtual float screen_get_refresh_rate(int p_screen = SCREEN_OF_MAIN_WINDOW) const override;
+ virtual void screen_set_keep_on(bool p_enable) override;
+ virtual bool screen_is_kept_on() const override;
virtual Vector<int> get_window_list() const override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index b9bc182dde..e228007246 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -39,6 +39,7 @@
#include "tts_macos.h"
+#include "core/config/project_settings.h"
#include "core/io/marshalls.h"
#include "core/math/geometry_2d.h"
#include "core/os/keyboard.h"
@@ -1891,6 +1892,24 @@ float DisplayServerMacOS::screen_get_refresh_rate(int p_screen) const {
return SCREEN_REFRESH_RATE_FALLBACK;
}
+bool DisplayServerMacOS::screen_is_kept_on() const {
+ return (screen_keep_on_assertion);
+}
+
+void DisplayServerMacOS::screen_set_keep_on(bool p_enable) {
+ if (screen_keep_on_assertion) {
+ IOPMAssertionRelease(screen_keep_on_assertion);
+ screen_keep_on_assertion = kIOPMNullAssertionID;
+ }
+
+ if (p_enable) {
+ String app_name_string = ProjectSettings::get_singleton()->get("application/config/name");
+ NSString *name = [NSString stringWithUTF8String:(app_name_string.is_empty() ? "Godot Engine" : app_name_string.utf8().get_data())];
+ NSString *reason = @"Godot Engine running with display/window/energy_saving/keep_screen_on = true";
+ IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep, (__bridge CFStringRef)name, (__bridge CFStringRef)reason, (__bridge CFStringRef)reason, nullptr, 0, nullptr, &screen_keep_on_assertion);
+ }
+}
+
Vector<DisplayServer::WindowID> DisplayServerMacOS::get_window_list() const {
_THREAD_SAFE_METHOD_
@@ -3266,9 +3285,16 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM
RendererCompositorRD::make_current();
}
#endif
+
+ screen_set_keep_on(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true));
}
DisplayServerMacOS::~DisplayServerMacOS() {
+ if (screen_keep_on_assertion) {
+ IOPMAssertionRelease(screen_keep_on_assertion);
+ screen_keep_on_assertion = kIOPMNullAssertionID;
+ }
+
// Destroy all windows.
for (HashMap<WindowID, WindowData>::Iterator E = windows.begin(); E;) {
HashMap<WindowID, WindowData>::Iterator F = E;
diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp
index 2ec2bb92d3..bcc2636c07 100644
--- a/platform/macos/export/export_plugin.cpp
+++ b/platform/macos/export/export_plugin.cpp
@@ -32,6 +32,7 @@
#include "codesign.h"
+#include "core/string/translation.h"
#include "editor/editor_node.h"
#include "editor/editor_paths.h"