summaryrefslogtreecommitdiff
path: root/platform/x11/os_x11.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2019-11-28 13:41:07 +0100
committerHugo Locurcio <hugo.locurcio@hugo.pro>2019-11-28 16:42:51 +0100
commit21a392341034169fff18db626e1c356545289af5 (patch)
tree945dd4cd61bdfd052e9e9ec1302d0c9a977b4c19 /platform/x11/os_x11.cpp
parent7735af7e768e16efb4b3b6de1c72c3dfb50c9412 (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 'platform/x11/os_x11.cpp')
-rw-r--r--platform/x11/os_x11.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 54d3759cc5..d4b7538fc8 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1689,6 +1689,10 @@ bool OS_X11::is_window_always_on_top() const {
return current_videomode.always_on_top;
}
+bool OS_X11::is_window_focused() const {
+ return window_focused;
+}
+
void OS_X11::set_borderless_window(bool p_borderless) {
if (get_borderless_window() == p_borderless)
@@ -2281,6 +2285,8 @@ void OS_X11::process_xevents() {
minimized = false;
window_has_focus = true;
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
+ window_focused = true;
+
if (mouse_mode_grab) {
// Show and update the cursor if confined and the window regained focus.
if (mouse_mode == MOUSE_MODE_CONFINED)
@@ -2308,6 +2314,7 @@ void OS_X11::process_xevents() {
window_has_focus = false;
input->release_pressed_events();
main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
+ window_focused = false;
if (mouse_mode_grab) {
//dear X11, I try, I really try, but you never work, you do whathever you want.
@@ -3502,6 +3509,7 @@ OS_X11::OS_X11() {
xi.last_relative_time = 0;
layered_window = false;
minimized = false;
+ window_focused = true;
xim_style = 0L;
mouse_mode = MOUSE_MODE_VISIBLE;
}