Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release mouse button presses on window focus change. #92419

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4683,6 +4683,7 @@ void DisplayServerX11::process_events() {
}
wd.focused = false;

last_button_state = 0;
Input::get_singleton()->release_pressed_events();
_send_window_event(wd, WINDOW_EVENT_FOCUS_OUT);

Expand Down
1 change: 1 addition & 0 deletions platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@

void DisplayServerMacOS::release_pressed_events() {
_THREAD_SAFE_METHOD_
last_button_state = 0;
if (Input::get_singleton()) {
Input::get_singleton()->release_pressed_events();
}
Expand Down
2 changes: 2 additions & 0 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4893,6 +4893,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
void DisplayServerWindows::_process_activate_event(WindowID p_window_id) {
WindowData &wd = windows[p_window_id];
if (wd.activate_state == WA_ACTIVE || wd.activate_state == WA_CLICKACTIVE) {
last_button_state = 0;
Copy link
Contributor

@RedMser RedMser May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this break drag&drop operations across applications? e.g. minimizing a game window, starting a file drag, hovering the mouse over the game window's taskbar icon, then releasing the mouse.

Or after #67531 is merged, drag&drop of Nodes between multiple windows of one game app, switching between them using alt+tab or hovering taskbar icon.

We have another notification for tracking "last Godot window unfocused", which might be a better fit here instead.

Also the button is released both on focus gain and loss for Windows, while only focus loss for the other OS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not break file dnd, but definitely will break 67531, so I guess getting current state instead of saving way (similar to #92415) might be better option.

last_focused_window = p_window_id;
alt_mem = false;
control_mem = false;
Expand All @@ -4905,6 +4906,7 @@ void DisplayServerWindows::_process_activate_event(WindowID p_window_id) {
wd.window_focused = true;
_send_window_event(wd, WINDOW_EVENT_FOCUS_IN);
} else { // WM_INACTIVE.
last_button_state = 0;
Input::get_singleton()->release_pressed_events();
track_mouse_leave_event(wd.hWnd);
// Release capture unconditionally because it can be set due to dragging, in addition to captured mode.
Expand Down
Loading