Skip to content

Commit

Permalink
Merge pull request godotengine#95902 from kitbdev/remove-forced-mouse…
Browse files Browse the repository at this point in the history
…-focus

Clean up Viewport's `forced_mouse_focus`
  • Loading branch information
akien-mga committed Sep 3, 2024
2 parents 293c0cb + 307e40e commit e2dd56b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 38 deletions.
1 change: 0 additions & 1 deletion editor/gui/editor_object_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void EditorObjectSelector::_show_popup() {
sub_objects_menu->set_position(gp);
sub_objects_menu->set_size(Size2(size.width, 1));

sub_objects_menu->take_mouse_focus();
sub_objects_menu->popup();
}

Expand Down
8 changes: 0 additions & 8 deletions scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2592,14 +2592,6 @@ void PopupMenu::clear_autohide_areas() {
autohide_areas.clear();
}

void PopupMenu::take_mouse_focus() {
ERR_FAIL_COND(!is_inside_tree());

if (get_parent()) {
get_parent()->get_viewport()->pass_mouse_focus_to(this, control);
}
}

bool PopupMenu::_set(const StringName &p_name, const Variant &p_value) {
if (property_helper.property_set_value(p_name, p_value)) {
return true;
Expand Down
2 changes: 0 additions & 2 deletions scene/gui/popup_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,6 @@ class PopupMenu : public Popup {
virtual void popup(const Rect2i &p_bounds = Rect2i()) override;
virtual void set_visible(bool p_visible) override;

void take_mouse_focus();

PopupMenu();
~PopupMenu();
};
Expand Down
29 changes: 5 additions & 24 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,7 @@ void Viewport::_notification(int p_what) {
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
_gui_cancel_tooltip();
_drop_physics_mouseover();
if (gui.mouse_focus && !gui.forced_mouse_focus) {
_drop_mouse_focus();
}
_drop_mouse_focus();
// When the window focus changes, we want to end mouse_focus, but
// not the mouse_over. Note: The OS will trigger a separate mouse
// exit event if the change in focus results in the mouse exiting
Expand Down Expand Up @@ -1835,7 +1833,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
// as the release will never be received otherwise.
if (gui.mouse_focus_mask.is_empty()) {
gui.mouse_focus = nullptr;
gui.forced_mouse_focus = false;
}

bool stopped = mouse_focus && mouse_focus->can_process() && _gui_call_input(mouse_focus, mb);
Expand Down Expand Up @@ -1864,7 +1861,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos - gui.drag_accum));
if (gui.drag_data.get_type() != Variant::NIL) {
gui.mouse_focus = nullptr;
gui.forced_mouse_focus = false;
gui.mouse_focus_mask.clear();
break;
} else {
Expand Down Expand Up @@ -2407,7 +2403,6 @@ void Viewport::_gui_hide_control(Control *p_control) {
void Viewport::_gui_remove_control(Control *p_control) {
if (gui.mouse_focus == p_control) {
gui.mouse_focus = nullptr;
gui.forced_mouse_focus = false;
gui.mouse_focus_mask.clear();
}
if (gui.key_focus == p_control) {
Expand Down Expand Up @@ -2573,9 +2568,12 @@ void Viewport::_drop_mouse_focus() {
Control *c = gui.mouse_focus;
BitField<MouseButtonMask> mask = gui.mouse_focus_mask;
gui.mouse_focus = nullptr;
gui.forced_mouse_focus = false;
gui.mouse_focus_mask.clear();

if (!c) {
return;
}

for (int i = 0; i < 3; i++) {
if ((int)mask & (1 << i)) {
Ref<InputEventMouseButton> mb;
Expand Down Expand Up @@ -3902,23 +3900,6 @@ Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
return gui.sub_windows[index].parent_safe_rect;
}

void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_NULL(p_viewport);
ERR_FAIL_NULL(p_control);

if (gui.mouse_focus) {
p_viewport->gui.mouse_focus = p_control;
p_viewport->gui.mouse_focus_mask = gui.mouse_focus_mask;
p_viewport->gui.key_focus = p_control;
p_viewport->gui.forced_mouse_focus = true;

gui.mouse_focus = nullptr;
gui.forced_mouse_focus = false;
gui.mouse_focus_mask.clear();
}
}

void Viewport::set_sdf_oversize(SDFOversize p_sdf_oversize) {
ERR_MAIN_THREAD_GUARD;
ERR_FAIL_INDEX(p_sdf_oversize, SDF_OVERSIZE_MAX);
Expand Down
3 changes: 0 additions & 3 deletions scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ class Viewport : public Node {
Ref<Texture2D> vrs_texture;

struct GUI {
bool forced_mouse_focus = false; //used for menu buttons
bool mouse_in_viewport = false;
bool key_event_accepted = false;
HashMap<int, ObjectID> touch_focus;
Expand Down Expand Up @@ -662,8 +661,6 @@ class Viewport : public Node {
Viewport *get_parent_viewport() const;
Window *get_base_window() const;

void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);

void set_canvas_cull_mask(uint32_t p_layers);
uint32_t get_canvas_cull_mask() const;

Expand Down

0 comments on commit e2dd56b

Please sign in to comment.