-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose getters for the currently focused Window #79261
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me, and I can confirm this works well by applying this patch in my project!
@@ -1555,6 +1555,10 @@ DisplayServerX11::WindowID DisplayServerX11::get_window_at_screen_position(const | |||
return found_window; | |||
} | |||
|
|||
ObjectID DisplayServerX11::get_focused_window_or_popup() const { | |||
return window_get_attached_instance_id(_get_focused_window_or_popup()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there's no popups, _get_focused_window_or_popup
is using the last focused window, not the current focused window, so it won't work if non of the windows is focused. But this probably should be fixed in the _get_focused_window_or_popup
implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this information. I didn't test this case.
I have updated the PR and reset the variable to INVALID_WINDOW_ID
, when a window loses focus (on Linux, Windows and macOS)
Since this is a change in behavior, I would consider this PR now as experimental, especially because I can't test the implementation on macOS.
8e0ad5f
to
abbb595
Compare
I think that this is indeed a fine feature to have. That said, I don't really like the name The Regarding |
The current implementation of
Instead of My understanding (might be wrong about that) is, that this was implemented, in order that Popups don't steal the focus of the main window for things like Menus, so that the main window appears in the Window Manager as still having focus. For the embedded case, this PR currently just returns the focused window. From my recent experiences with bugs related to focused embedded windows, I believe it is necessary, to also track popup-windows in the embedded case, like the |
@Sauermann thanks for the explanation, the context explains a lot. I didn't understand from the name that the logic had actually a separate case for popups and I didn't know that this logic existed before internally (it did with the same name too) so I parsed the name in a different way, which is unfortunate, but it indeed makes sense. I just guess that the "or" cuts the meaning of the sentence too cleanly, especially considering the order of operation. Perhaps a clearer, yet more verbose, name could be "get_top_popup_or_focused_window". No idea if it would fit with the API but eh, this is really a nitpick considering the rest of the windowing API with all of its unavoidable quirks. I'm not sure why you want to keep the |
My long-term goal is to change the Viewport-implementation, so that it returns conceptionally the same as the DisplayServer-implementation. |
91a4cab
to
378a4d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could maybe the following alternative design work?:
_get_focused_window_or_popup()
is made public (with the underscore removed).- A default, no-opish, implementation is added to
DisplayServer
.
Con: - Scritps have to call
window_get_attached_instance_id()
themselves on the returnedWindowID
.
Pro: - The various, almost identical
get_top_popup_or_focused_window()
can be removed.
Alternative 2:
_get_focused_window_or_popup()
is made protected
and virtual
, with the same pro as the approach described above.
Combining the two approaches would look like this:
|
Soudns good! |
Makes sense. IMO a refactoring is needed in the long term, especially for the need to account client-side decorations. I'd love to help after the Wayland mess settles down. |
378a4d1
to
6ba8743
Compare
b068611
to
fd17c5e
Compare
9c6d9c5
to
41d66b3
Compare
EDIT: It was a false alarm (sorry for that), I was fooled by scons. |
Thanks for the report. I find it noticeable, that the stacktrace doesn't contain any files, that were changed by this PR. |
41d66b3
to
97ade19
Compare
Replace the last focused Window by the currently focused Window on Linux, Windows and macOS.
97ade19
to
b9a3bd2
Compare
Make it easier to get the focused
Window
-node be exposingViewport
andDisplayServer
functions, that return the focused window.Currently it is necessary to traverse the scene-tree recursively in order to check every Node, if it is a Window, that has focus.
Here is a MRP to showcase how the exposed functions can be used to find the focused
Control
-node, that receives Key-InputEvents during the GUI-Input-stage.GetFocusedControl.zip (updated 2023-07-16)
Press
F1
to print the currently focused Control in the console.resolve godotengine/godot-proposals#7242 by making it easier to find the focused
Control
-node, that receives Key-InputEvents during the GUI-Input-stageUpdated 2023-08-09: Fix merge conflict
Updated 2023-08-12: Fix merge conflict
Updated 2023-08-22: Fix merge conflict
Updated 2024-01-19: Fix merge conflict