diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-11-28 13:41:07 +0100 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-11-28 16:42:51 +0100 |
commit | 21a392341034169fff18db626e1c356545289af5 (patch) | |
tree | 945dd4cd61bdfd052e9e9ec1302d0c9a977b4c19 /core/bind | |
parent | 7735af7e768e16efb4b3b6de1c72c3dfb50c9412 (diff) |
Add an `OS.is_window_focused()` getter
This makes it possible to know whether the window is focused
at a given time, without having to track the focus state manually
using `NOTIFICATION_WM_FOCUS_IN` and `NOTIFICATION_WM_FOCUS_OUT`.
This partially addresses #33928.
Diffstat (limited to 'core/bind')
-rw-r--r-- | core/bind/core_bind.cpp | 5 | ||||
-rw-r--r-- | core/bind/core_bind.h | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 1544503045..082c220aec 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -400,6 +400,10 @@ bool _OS::is_window_always_on_top() const { return OS::get_singleton()->is_window_always_on_top(); } +bool _OS::is_window_focused() const { + return OS::get_singleton()->is_window_focused(); +} + void _OS::set_borderless_window(bool p_borderless) { OS::get_singleton()->set_borderless_window(p_borderless); } @@ -1213,6 +1217,7 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized); ClassDB::bind_method(D_METHOD("set_window_always_on_top", "enabled"), &_OS::set_window_always_on_top); ClassDB::bind_method(D_METHOD("is_window_always_on_top"), &_OS::is_window_always_on_top); + ClassDB::bind_method(D_METHOD("is_window_focused"), &_OS::is_window_focused); ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention); ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size); ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 18182860c6..06fd162149 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -198,6 +198,7 @@ public: 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 bool is_window_focused() const; virtual void request_attention(); virtual void center_window(); virtual void move_window_to_foreground(); |