Skip to content

Commit 307e40e

Browse files
committed
Clean up Viewport forced_mouse_focus
1 parent 826de79 commit 307e40e

File tree

5 files changed

+5
-38
lines changed

5 files changed

+5
-38
lines changed

editor/gui/editor_object_selector.cpp

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 8 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 5 additions & 24 deletions
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
@@ -1831,7 +1829,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18311829
// as the release will never be received otherwise.
18321830
if (gui.mouse_focus_mask.is_empty()) {
18331831
gui.mouse_focus = nullptr;
1834-
gui.forced_mouse_focus = false;
18351832
}
18361833

18371834
bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb);
@@ -1860,7 +1857,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
18601857
gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos - gui.drag_accum));
18611858
if (gui.drag_data.get_type() != Variant::NIL) {
18621859
gui.mouse_focus = nullptr;
1863-
gui.forced_mouse_focus = false;
18641860
gui.mouse_focus_mask.clear();
18651861
break;
18661862
} else {
@@ -2398,7 +2394,6 @@ void Viewport::_gui_hide_control(Control *p_control) {
23982394
void Viewport::_gui_remove_control(Control *p_control) {
23992395
if (gui.mouse_focus == p_control) {
24002396
gui.mouse_focus = nullptr;
2401-
gui.forced_mouse_focus = false;
24022397
gui.mouse_focus_mask.clear();
24032398
}
24042399
if (gui.key_focus == p_control) {
@@ -2564,9 +2559,12 @@ void Viewport::_drop_mouse_focus() {
25642559
Control *c = gui.mouse_focus;
25652560
BitField<MouseButtonMask> mask = gui.mouse_focus_mask;
25662561
gui.mouse_focus = nullptr;
2567-
gui.forced_mouse_focus = false;
25682562
gui.mouse_focus_mask.clear();
25692563

2564+
if (!c) {
2565+
return;
2566+
}
2567+
25702568
for (int i = 0; i < 3; i++) {
25712569
if ((int)mask & (1 << i)) {
25722570
Ref<InputEventMouseButton> mb;
@@ -3893,23 +3891,6 @@ Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
38933891
return gui.sub_windows[index].parent_safe_rect;
38943892
}
38953893

3896-
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
3897-
ERR_MAIN_THREAD_GUARD;
3898-
ERR_FAIL_NULL(p_viewport);
3899-
ERR_FAIL_NULL(p_control);
3900-
3901-
if (gui.mouse_focus) {
3902-
p_viewport->gui.mouse_focus = p_control;
3903-
p_viewport->gui.mouse_focus_mask = gui.mouse_focus_mask;
3904-
p_viewport->gui.key_focus = p_control;
3905-
p_viewport->gui.forced_mouse_focus = true;
3906-
3907-
gui.mouse_focus = nullptr;
3908-
gui.forced_mouse_focus = false;
3909-
gui.mouse_focus_mask.clear();
3910-
}
3911-
}
3912-
39133894
void Viewport::set_sdf_oversize(SDFOversize p_sdf_oversize) {
39143895
ERR_MAIN_THREAD_GUARD;
39153896
ERR_FAIL_INDEX(p_sdf_oversize, SDF_OVERSIZE_MAX);

scene/main/viewport.h

Lines changed: 0 additions & 3 deletions
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)