Skip to content

Commit e2dd56b

Browse files
committed
Merge pull request #95902 from kitbdev/remove-forced-mouse-focus
Clean up Viewport's `forced_mouse_focus`
2 parents 293c0cb + 307e40e commit e2dd56b

File tree

5 files changed

+5
-38
lines changed

5 files changed

+5
-38
lines changed

editor/gui/editor_object_selector.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void EditorObjectSelector::_show_popup() {
103103
sub_objects_menu->set_position(gp);
104104
sub_objects_menu->set_size(Size2(size.width, 1));
105105

106-
sub_objects_menu->take_mouse_focus();
107106
sub_objects_menu->popup();
108107
}
109108

scene/gui/popup_menu.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -2592,14 +2592,6 @@ void PopupMenu::clear_autohide_areas() {
25922592
autohide_areas.clear();
25932593
}
25942594

2595-
void PopupMenu::take_mouse_focus() {
2596-
ERR_FAIL_COND(!is_inside_tree());
2597-
2598-
if (get_parent()) {
2599-
get_parent()->get_viewport()->pass_mouse_focus_to(this, control);
2600-
}
2601-
}
2602-
26032595
bool PopupMenu::_set(const StringName &p_name, const Variant &p_value) {
26042596
if (property_helper.property_set_value(p_name, p_value)) {
26052597
return true;

scene/gui/popup_menu.h

-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,6 @@ class PopupMenu : public Popup {
369369
virtual void popup(const Rect2i &p_bounds = Rect2i()) override;
370370
virtual void set_visible(bool p_visible) override;
371371

372-
void take_mouse_focus();
373-
374372
PopupMenu();
375373
~PopupMenu();
376374
};

scene/main/viewport.cpp

+5-24
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ void Viewport::_notification(int p_what) {
655655
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
656656
_gui_cancel_tooltip();
657657
_drop_physics_mouseover();
658-
if (gui.mouse_focus && !gui.forced_mouse_focus) {
659-
_drop_mouse_focus();
660-
}
658+
_drop_mouse_focus();
661659
// When the window focus changes, we want to end mouse_focus, but
662660
// not the mouse_over. Note: The OS will trigger a separate mouse
663661
// exit event if the change in focus results in the mouse exiting
@@ -1835,7 +1833,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18351833
// as the release will never be received otherwise.
18361834
if (gui.mouse_focus_mask.is_empty()) {
18371835
gui.mouse_focus = nullptr;
1838-
gui.forced_mouse_focus = false;
18391836
}
18401837

18411838
bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb);
@@ -1864,7 +1861,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18641861
gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos - gui.drag_accum));
18651862
if (gui.drag_data.get_type() != Variant::NIL) {
18661863
gui.mouse_focus = nullptr;
1867-
gui.forced_mouse_focus = false;
18681864
gui.mouse_focus_mask.clear();
18691865
break;
18701866
} else {
@@ -2407,7 +2403,6 @@ void Viewport::_gui_hide_control(Control *p_control) {
24072403
void Viewport::_gui_remove_control(Control *p_control) {
24082404
if (gui.mouse_focus == p_control) {
24092405
gui.mouse_focus = nullptr;
2410-
gui.forced_mouse_focus = false;
24112406
gui.mouse_focus_mask.clear();
24122407
}
24132408
if (gui.key_focus == p_control) {
@@ -2573,9 +2568,12 @@ void Viewport::_drop_mouse_focus() {
25732568
Control *c = gui.mouse_focus;
25742569
BitField<MouseButtonMask> mask = gui.mouse_focus_mask;
25752570
gui.mouse_focus = nullptr;
2576-
gui.forced_mouse_focus = false;
25772571
gui.mouse_focus_mask.clear();
25782572

2573+
if (!c) {
2574+
return;
2575+
}
2576+
25792577
for (int i = 0; i < 3; i++) {
25802578
if ((int)mask & (1 << i)) {
25812579
Ref<InputEventMouseButton> mb;
@@ -3902,23 +3900,6 @@ Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
39023900
return gui.sub_windows[index].parent_safe_rect;
39033901
}
39043902

3905-
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
3906-
ERR_MAIN_THREAD_GUARD;
3907-
ERR_FAIL_NULL(p_viewport);
3908-
ERR_FAIL_NULL(p_control);
3909-
3910-
if (gui.mouse_focus) {
3911-
p_viewport->gui.mouse_focus = p_control;
3912-
p_viewport->gui.mouse_focus_mask = gui.mouse_focus_mask;
3913-
p_viewport->gui.key_focus = p_control;
3914-
p_viewport->gui.forced_mouse_focus = true;
3915-
3916-
gui.mouse_focus = nullptr;
3917-
gui.forced_mouse_focus = false;
3918-
gui.mouse_focus_mask.clear();
3919-
}
3920-
}
3921-
39223903
void Viewport::set_sdf_oversize(SDFOversize p_sdf_oversize) {
39233904
ERR_MAIN_THREAD_GUARD;
39243905
ERR_FAIL_INDEX(p_sdf_oversize, SDF_OVERSIZE_MAX);

scene/main/viewport.h

-3
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ class Viewport : public Node {
349349
Ref<Texture2D> vrs_texture;
350350

351351
struct GUI {
352-
bool forced_mouse_focus = false; //used for menu buttons
353352
bool mouse_in_viewport = false;
354353
bool key_event_accepted = false;
355354
HashMap<int, ObjectID> touch_focus;
@@ -662,8 +661,6 @@ class Viewport : public Node {
662661
Viewport *get_parent_viewport() const;
663662
Window *get_base_window() const;
664663

665-
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
666-
667664
void set_canvas_cull_mask(uint32_t p_layers);
668665
uint32_t get_canvas_cull_mask() const;
669666

0 commit comments

Comments
 (0)