Skip to content

Commit 1b4ed4c

Browse files
committed
Merge pull request #105595 from bruvzg/focus_fx
Fix `FOCUS_ACCESSIBILITY` grabbing focus when it is not supposed to, forward `GraphNode` key input to `GraphEdit`.
2 parents 9c324a8 + db0c0a9 commit 1b4ed4c

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

scene/gui/control.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,11 @@ Control::FocusBehaviorRecursive Control::get_focus_behavior_recursive() const {
21582158
return data.focus_behavior_recursive;
21592159
}
21602160

2161+
bool Control::_is_focusable() const {
2162+
bool ac_enabled = is_inside_tree() && get_tree()->is_accessibility_enabled();
2163+
return (is_visible_in_tree() && ((get_focus_mode_with_override() == FOCUS_ALL) || (get_focus_mode_with_override() == FOCUS_CLICK) || (ac_enabled && get_focus_mode_with_override() == FOCUS_ACCESSIBILITY)));
2164+
}
2165+
21612166
bool Control::_is_focus_mode_enabled() const {
21622167
if (data.focus_behavior_recursive == FOCUS_BEHAVIOR_INHERITED) {
21632168
if (data.parent_control) {
@@ -2270,7 +2275,7 @@ Control *Control::find_next_valid_focus() const {
22702275
ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + data.focus_next + "'.");
22712276
Control *c = Object::cast_to<Control>(n);
22722277
ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'.");
2273-
if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) {
2278+
if (c->_is_focusable()) {
22742279
return c;
22752280
}
22762281
}
@@ -2374,7 +2379,7 @@ Control *Control::find_prev_valid_focus() const {
23742379
ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + data.focus_prev + "'.");
23752380
Control *c = Object::cast_to<Control>(n);
23762381
ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'.");
2377-
if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) {
2382+
if (c->_is_focusable()) {
23782383
return c;
23792384
}
23802385
}
@@ -2494,7 +2499,7 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
24942499
ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + data.focus_neighbor[p_side] + "'.");
24952500
Control *c = Object::cast_to<Control>(n);
24962501
ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'.");
2497-
if (c->is_visible_in_tree() && c->get_focus_mode_with_override() != FOCUS_NONE) {
2502+
if (c->_is_focusable()) {
24982503
return c;
24992504
}
25002505

scene/gui/control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ class Control : public CanvasItem {
337337

338338
// Focus.
339339

340+
bool _is_focusable() const;
340341
void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Rect2 &p_rect, const Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist_squared, Control **r_closest);
341342
Control *_get_focus_neighbor(Side p_side, int p_count = 0);
342343
bool _is_focus_mode_enabled() const;

scene/gui/graph_edit.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,10 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
22632263
}
22642264
}
22652265

2266+
key_input(p_ev);
2267+
}
2268+
2269+
void GraphEdit::key_input(const Ref<InputEvent> &p_ev) {
22662270
if (p_ev->is_pressed()) {
22672271
if (p_ev->is_action("ui_graph_duplicate", true)) {
22682272
emit_signal(SNAME("duplicate_nodes_request"));

scene/gui/graph_edit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ class GraphEdit : public Control {
401401

402402
PackedStringArray get_configuration_warnings() const override;
403403

404+
void key_input(const Ref<InputEvent> &p_ev);
405+
404406
// This method has to be public (for undo redo).
405407
// TODO: Find a better way to do this.
406408
void _update_graph_frame(GraphFrame *p_frame);

scene/gui/graph_element.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ void GraphElement::gui_input(const Ref<InputEvent> &p_ev) {
173173

174174
emit_signal(SNAME("resize_request"), resizing_from_size + diff);
175175
}
176+
177+
GraphEdit *graph = Object::cast_to<GraphEdit>(get_parent());
178+
if (graph && has_focus()) {
179+
graph->key_input(p_ev);
180+
}
176181
}
177182

178183
void GraphElement::set_resizable(bool p_enable) {

scene/main/viewport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
19331933
while (ci) {
19341934
Control *control = Object::cast_to<Control>(ci);
19351935
if (control) {
1936-
if (control->get_focus_mode_with_override() != Control::FOCUS_NONE) {
1936+
if (control->_is_focusable()) {
19371937
// Grabbing unhovered focus can cause issues when mouse is dragged
19381938
// with another button held down.
19391939
if (control != gui.key_focus && gui.mouse_over_hierarchy.has(control)) {

0 commit comments

Comments
 (0)