Skip to content

Commit e870cd9

Browse files
committed
Merge pull request #110895 from Giganzo/input-focus
Add setting for when to show the focus state for mouse input
2 parents 361ea11 + e384085 commit e870cd9

File tree

6 files changed

+12
-8
lines changed

6 files changed

+12
-8
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ ProjectSettings::ProjectSettings() {
17061706
#endif
17071707

17081708
GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true);
1709-
GLOBAL_DEF("gui/common/always_show_focus_state", false);
1709+
GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1);
17101710
GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true);
17111711

17121712
GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "rendering/rendering_device/vsync/frame_queue_size", PROPERTY_HINT_RANGE, "2,3,1"), 2);

doc/classes/Control.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@
627627
<param index="0" name="hide_focus" type="bool" default="false" />
628628
<description>
629629
Steal the focus from another control and become the focused control (see [member focus_mode]).
630-
If [param hide_focus] is [code]true[/code], the control will not visually show its focused state. Has no effect if [member ProjectSettings.gui/common/always_show_focus_state] is set to [code]true[/code].
630+
If [param hide_focus] is [code]true[/code], the control will not visually show its focused state. Has no effect for [LineEdit] and [TextEdit] when [member ProjectSettings.gui/common/show_focus_state_on_pointer_event] is set to [code]Control Supports Keyboard Input[/code], or for any control when it is set to [code]Always[/code].
631631
[b]Note:[/b] Using this method together with [method Callable.call_deferred] makes it more reliable, especially when called inside [method Node._ready].
632632
</description>
633633
</method>

doc/classes/ProjectSettings.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,12 +1183,15 @@
11831183
<member name="filesystem/import/fbx2gltf/enabled.web" type="bool" setter="" getter="" default="false">
11841184
Override for [member filesystem/import/fbx2gltf/enabled] on the Web where FBX2glTF can't easily be accessed from Godot.
11851185
</member>
1186-
<member name="gui/common/always_show_focus_state" type="bool" setter="" getter="" default="false">
1187-
If [code]true[/code], [Control]s will always show if they're focused, even if said focus was gained via mouse/touch input.
1188-
</member>
11891186
<member name="gui/common/default_scroll_deadzone" type="int" setter="" getter="" default="0">
11901187
Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden.
11911188
</member>
1189+
<member name="gui/common/show_focus_state_on_pointer_event" type="int" setter="" getter="" default="1">
1190+
Determines whether a [Control] should visually indicate focus when said focus is gained using a mouse or touch input.
1191+
- [b]Never[/b] ([code]0[/code]) show the focused state for mouse/touch input.
1192+
- [b]Control Supports Keyboard Input[/b] ([code]1[/code]) shows the focused state even when gained via mouse/touch input (similar to how browsers handle focus).
1193+
- [b]Always[/b] ([code]2[/code]) show the focused state, even if said focus was gained via mouse/touch input.
1194+
</member>
11921195
<member name="gui/common/snap_controls_to_pixels" type="bool" setter="" getter="" default="true">
11931196
If [code]true[/code], snaps [Control] node vertices to the nearest pixel to ensure they remain crisp even when the camera moves or zooms.
11941197
</member>

scene/gui/line_edit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "line_edit.h"
3232
#include "line_edit.compat.inc"
3333

34+
#include "core/config/project_settings.h"
3435
#include "core/input/input_map.h"
3536
#include "core/os/keyboard.h"
3637
#include "core/os/os.h"
@@ -1349,7 +1350,7 @@ void LineEdit::_notification(int p_what) {
13491350
style->draw(ci, Rect2(Point2(), size));
13501351
}
13511352

1352-
if (has_focus(true)) {
1353+
if (has_focus(Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") != 1)) {
13531354
theme_cache.focus->draw(ci, Rect2(Point2(), size));
13541355
}
13551356

scene/gui/text_edit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ void TextEdit::_notification(int p_what) {
950950
if (!editable) {
951951
draw_caret = is_drawing_caret_when_editable_disabled();
952952
}
953-
if (has_focus(true)) {
953+
if (has_focus(Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") != 1)) {
954954
theme_cache.style_focus->draw(ci, Rect2(Point2(), size));
955955
}
956956

scene/main/viewport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ void Viewport::_update_viewport_path() {
534534
}
535535

536536
bool Viewport::_can_hide_focus_state() {
537-
return Engine::get_singleton()->is_editor_hint() || !GLOBAL_GET_CACHED(bool, "gui/common/always_show_focus_state");
537+
return Engine::get_singleton()->is_editor_hint() || GLOBAL_GET_CACHED(int, "gui/common/show_focus_state_on_pointer_event") < 2;
538538
}
539539

540540
void Viewport::_on_settings_changed() {

0 commit comments

Comments
 (0)