Skip to content

Conversation

YeldhamDev
Copy link
Member

Closes godotengine/godot-proposals#6577 (by covering godotengine/godot-proposals#2011).

This PR makes so that Controls will not show their focus state when activated via a mouse click. It also modifies two functions in order to make this work:

  • Control.grab_focus() has the new optional argument hide_focus.
  • Control.has_focus() has the new optional argument ignored_hidden_focus.

Here's the full ruleset for when focus is shown or not:

Situation
Clicking a Control with the mouse, giving it focus.
Successfully switching focus via keyboard/joypad actions.
Attempting to switching focus via keyboard/joypad actions but still remaining on the same Control.
Clicking somewhere with the mouse while having a Control with visible focus.
Clicking with the mouse a visibly focused Control (deviates from how it works in browsers, feedback welcome).
Using Control.grab_focus(true).

@YeldhamDev YeldhamDev added this to the 4.x milestone Sep 4, 2025
@YeldhamDev YeldhamDev requested review from a team as code owners September 4, 2025 13:06
@YeldhamDev YeldhamDev requested a review from a team as a code owner September 4, 2025 13:06
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 11b72df to 8a0123c Compare September 4, 2025 14:24
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 8a0123c to 4bdb7aa Compare September 4, 2025 15:37
@YeldhamDev YeldhamDev requested review from a team as code owners September 4, 2025 15:37
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 4bdb7aa to 0b89ee1 Compare September 4, 2025 16:11
@AThousandShips
Copy link
Member

You need to add the entries to the expected file, see here

@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 0b89ee1 to 2b9caf2 Compare September 4, 2025 17:10
@YeldhamDev YeldhamDev requested review from a team as code owners September 4, 2025 17:10
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 2b9caf2 to be1b57a Compare September 4, 2025 17:29
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from be1b57a to 835f087 Compare September 4, 2025 18:49
@Giganzo
Copy link
Contributor

Giganzo commented Sep 4, 2025

I was working on a similar thing.

This would not make it possible to show the focus stylebox on grab focus with mouse anymore?
If yes this could be bad for accessibility and customizing how you want the behavior to work in your game/app.

W3 has this note:

There may be situations where mouse/pointer users could also benefit from having a visible focus indicator, even though they did not set focus to an element using the keyboard. As a best practice, consider still providing an explicit focus indicator for these cases.

And I did see a couple of comments when looking into this that says that don't think that a users that need a focus indicator only use keyboard all the time, they might use a mouse in some cases and still need the help of a focus indicator. Say you want an accessibility setting in your game that always draw focus, would this be possible with this PR?

And how does this handle cases like LineEdit focus? In a browser they get a focus ring even if clicked with a mouse.

Does this also include touch input as "mouse"?

@YeldhamDev
Copy link
Member Author

YeldhamDev commented Sep 4, 2025

Say you want an accessibility setting in your game that always draw focus, would this be possible with this PR?

Currently no, but I'm fine in adding a project setting that forces focus to always show.
Yes, see below.

And how does this handle cases like LineEdit focus? In a browser they get a focus ring even if clicked with a mouse.

No Control gets visible focus via mouse, but I'm open to feedback in changing this in a case-by-case manner.

Does this also include touch input as "mouse"?

Yes.

@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 835f087 to bff7bc5 Compare September 5, 2025 19:43
@YeldhamDev
Copy link
Member Author

I've added gui/common/always_show_focus_state to the project settings, disabled by default and tagged as advanced. If set to true, it will mimic the old behavior.

@passivestar
Copy link
Contributor

Did a quick test, mostly works as expected

Here are some things that still draw focus on mouse input:

  • Filesystem tree when you right click on a file
  • Inspector scroll container when you click on a float property (in both inspector dock and project settings)
  • Scene tree when you add a new node

There are some things that will need to be decided case-by-case, for example popup windows drawing focus after being called is generally good, especially when you're expected to type some text in, or to press a button in a simple yes/no confirmation popup. But some popups however draw focus around the main big area (i.e file selection popup) which most apps don't do because it'd be too visually intrusive. Blender is one example of that, it highlights the buttons in yes/no popups but doesn't highlight the main area of the file selection window even though that's what reacts to keyboard shortcuts

I've added gui/common/always_show_focus_state to the project settings

It currently also affects the editor and not just the game, which will be undesirable if more than one person is working on the project with different preferences on that

@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from bff7bc5 to 019d97b Compare September 6, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add seperate focus style to controls for keyboard/gamepad and mouse/touch
5 participants