Implement always-on-top for MacOS

Courtesy of @bruvzg.
This commit is contained in:
Pedro J. Estébanez 2018-01-30 20:39:53 +01:00
parent ee2c31d306
commit 2e8c7824c0
2 changed files with 16 additions and 0 deletions

View File

@ -205,6 +205,8 @@ public:
virtual bool is_window_minimized() const; virtual bool is_window_minimized() const;
virtual void set_window_maximized(bool p_enabled); virtual void set_window_maximized(bool p_enabled);
virtual bool is_window_maximized() const; virtual bool is_window_maximized() const;
virtual void set_window_always_on_top(bool p_enabled);
virtual bool is_window_always_on_top() const;
virtual void request_attention(); virtual void request_attention();
virtual String get_joy_guid(int p_device) const; virtual String get_joy_guid(int p_device) const;

View File

@ -1891,6 +1891,20 @@ void OS_OSX::move_window_to_foreground() {
[window_object orderFrontRegardless]; [window_object orderFrontRegardless];
} }
void OS_OSX::set_window_always_on_top(bool p_enabled) {
if (is_window_always_on_top() == p_enabled)
return;
if (p_enabled)
[window_object setLevel:NSFloatingWindowLevel];
else
[window_object setLevel:NSNormalWindowLevel];
}
bool OS_OSX::is_window_always_on_top() const {
return [window_object level] == NSFloatingWindowLevel;
}
void OS_OSX::request_attention() { void OS_OSX::request_attention() {
[NSApp requestUserAttention:NSCriticalRequest]; [NSApp requestUserAttention:NSCriticalRequest];