Revert "Fix mouse_over not dropped when mouse leaves window"

This reverts commit 33a2d5e20b.
This commit is contained in:
Relintai 2022-08-19 02:48:36 +02:00
parent 59f4eb55d9
commit 1b503ad711
2 changed files with 20 additions and 21 deletions

View File

@ -188,7 +188,6 @@ public:
Viewport::GUI::GUI() { Viewport::GUI::GUI() {
dragging = false; dragging = false;
drag_successful = false; drag_successful = false;
mouse_in_window = true;
mouse_focus = nullptr; mouse_focus = nullptr;
mouse_click_grabber = nullptr; mouse_click_grabber = nullptr;
mouse_focus_mask = 0; mouse_focus_mask = 0;
@ -403,26 +402,21 @@ void Viewport::_notification(int p_what) {
_process_picking(false); _process_picking(false);
} }
} break; } break;
case NOTIFICATION_WM_MOUSE_ENTER: { case SceneTree::NOTIFICATION_WM_MOUSE_EXIT: {
gui.mouse_in_window = true;
} break;
case NOTIFICATION_WM_MOUSE_EXIT: {
gui.mouse_in_window = false;
_drop_physics_mouseover(); _drop_physics_mouseover();
_drop_mouse_over();
// When the mouse exits the window, we want to end mouse_over, but // Unlike on loss of focus (NOTIFICATION_WM_WINDOW_FOCUS_OUT), do not
// not mouse_focus, because, for example, we want to continue // drop the gui mouseover here, as a scrollbar may be dragged while the
// dragging a scrollbar even if the mouse has left the window. // mouse is outside the window (without the window having lost focus).
// See bug #39634
} break; } break;
case NOTIFICATION_WM_FOCUS_OUT: { case SceneTree::NOTIFICATION_WM_FOCUS_OUT: {
_drop_physics_mouseover(); _drop_physics_mouseover();
if (gui.mouse_focus) { if (gui.mouse_focus) {
//if mouse is being pressed, send a release event
_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
// the window.
} break; } break;
} }
} }
@ -1870,6 +1864,9 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (mb.is_valid()) { if (mb.is_valid()) {
gui.key_event_accepted = false; gui.key_event_accepted = false;
Control *over = nullptr;
Point2 mpos = mb->get_position(); Point2 mpos = mb->get_position();
if (mb->is_pressed()) { if (mb->is_pressed()) {
Size2 pos = mpos; Size2 pos = mpos;
@ -2064,8 +2061,6 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
// it is different, rather than wait for it to be updated the next time the // it is different, rather than wait for it to be updated the next time the
// mouse is moved, notify the control so that it can e.g. drop the highlight. // mouse is moved, notify the control so that it can e.g. drop the highlight.
// This code is duplicated from the mm.is_valid()-case further below. // This code is duplicated from the mm.is_valid()-case further below.
Control *over = nullptr;
if (gui.mouse_focus) { if (gui.mouse_focus) {
over = gui.mouse_focus; over = gui.mouse_focus;
} else { } else {
@ -2098,6 +2093,8 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.last_mouse_pos = mpos; gui.last_mouse_pos = mpos;
Control *over = nullptr;
// D&D // D&D
if (!gui.drag_attempted && gui.mouse_focus && mm->get_button_mask() & BUTTON_MASK_LEFT) { if (!gui.drag_attempted && gui.mouse_focus && mm->get_button_mask() & BUTTON_MASK_LEFT) {
gui.drag_accum += mm->get_relative(); gui.drag_accum += mm->get_relative();
@ -2144,10 +2141,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
} }
} }
Control *over = nullptr; // These sections of code are reused in the mb.is_valid() case further up
// for the purpose of notifying controls about potential changes in focus
// when the mousebutton is released.
if (gui.mouse_focus) { if (gui.mouse_focus) {
over = gui.mouse_focus; over = gui.mouse_focus;
} else if (gui.mouse_in_window) { } else {
over = _gui_find_control(mpos); over = _gui_find_control(mpos);
} }
@ -2196,10 +2195,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (over) { if (over) {
_gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER); _gui_call_notification(over, Control::NOTIFICATION_MOUSE_ENTER);
gui.mouse_over = over;
} }
} }
gui.mouse_over = over;
Control *drag_preview = _gui_get_drag_preview(); Control *drag_preview = _gui_get_drag_preview();
if (drag_preview) { if (drag_preview) {
drag_preview->set_position(mpos); drag_preview->set_position(mpos);

View File

@ -296,7 +296,6 @@ private:
// info used when this is a window // info used when this is a window
bool key_event_accepted; bool key_event_accepted;
bool mouse_in_window;
Control *mouse_focus; Control *mouse_focus;
Control *last_mouse_focus; Control *last_mouse_focus;
Control *mouse_click_grabber; Control *mouse_click_grabber;