X Tutup
Skip to content

Hide Control focus when given via mouse input#110250

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:i_just_cant_keep_focused
Sep 22, 2025
Merged

Hide Control focus when given via mouse input#110250
Repiteo merged 1 commit intogodotengine:masterfrom
YeldhamDev:i_just_cant_keep_focused

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 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 a review from a team 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

This comment was marked as resolved.

@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 2 times, most recently from 3830b41 to 58b23fd Compare September 16, 2025 17:31
@Repiteo Repiteo modified the milestones: 4.x, 4.6 Sep 18, 2025
@YeldhamDev YeldhamDev force-pushed the i_just_cant_keep_focused branch from 58b23fd to aeb3a45 Compare September 19, 2025 16:43
@YeldhamDev YeldhamDev requested a review from a team as a code owner September 19, 2025 16:43
@Repiteo Repiteo merged commit be421bc into godotengine:master Sep 22, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 22, 2025

Thanks!

@scgm0
Copy link
Contributor

scgm0 commented Oct 1, 2025

There appears to be a special case where, when the LineEdit does not have focus, right-clicking on it draws a focus outline, whereas left-clicking does not. Additionally, after a left-click, right-clicking also fails to draw the focus outline.

2025-10-01.18-44-46.mp4

@automatika-mega
Copy link

automatika-mega commented Jan 29, 2026

is there anyway to get the old way back, this pr is causing a lot of issues with highlighting. highlighting goes away when clicking on empty space or whilst holding the mouse button down on a button and moving off it. Not good for interfaces that support multiple inputs as you cant tell what had focus last.

seems inconsistent between different ui elements as well

edit: fix to go back to normal is Project Settings > GUI > Common > Show Focus State on Pointer Event

@YeldhamDev
Copy link
Member Author

@automatika-mega Project Settings > GUI > Common > Show Focus State on Pointer Event

@automatika-mega
Copy link

@automatika-mega Project Settings > GUI > Common > Show Focus State on Pointer Event

Thank you. Back to working normally!

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

9 participants

X Tutup