WindowServer: Send mouse release to same window as mouse press

This commit is contained in:
Bananymous 2025-05-10 03:30:17 +03:00
parent c18fefd5f3
commit a8844ddd28
2 changed files with 14 additions and 8 deletions

View File

@ -475,15 +475,19 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
return; return;
} }
const size_t button_idx = static_cast<size_t>(event.button);
if (button_idx >= m_mouse_button_windows.size())
{
dwarnln("invalid mouse button {}", button_idx);
return;
}
BAN::RefPtr<Window> target_window; BAN::RefPtr<Window> target_window;
for (size_t i = m_client_windows.size(); i > 0; i--) if (!event.pressed)
{ target_window = m_mouse_button_windows[button_idx];
for (size_t i = m_client_windows.size(); i > 0 && !target_window; i--)
if (m_client_windows[i - 1]->full_area().contains(m_cursor)) if (m_client_windows[i - 1]->full_area().contains(m_cursor))
{
target_window = m_client_windows[i - 1]; target_window = m_client_windows[i - 1];
break;
}
}
switch (m_state) switch (m_state)
{ {
@ -530,7 +534,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
[[fallthrough]]; [[fallthrough]];
case State::Fullscreen: case State::Fullscreen:
if (target_window && target_window->client_area().contains(m_cursor)) if (target_window && (!event.pressed || target_window->client_area().contains(m_cursor)))
{ {
LibGUI::EventPacket::MouseButtonEvent packet; LibGUI::EventPacket::MouseButtonEvent packet;
packet.event.button = event.button; packet.event.button = event.button;
@ -542,6 +546,7 @@ void WindowServer::on_mouse_button(LibInput::MouseButtonEvent event)
dwarnln("could not send mouse button event: {}", ret.error()); dwarnln("could not send mouse button event: {}", ret.error());
return; return;
} }
m_mouse_button_windows[button_idx] = event.pressed ? target_window : nullptr;
} }
break; break;
case State::Moving: case State::Moving:

View File

@ -96,6 +96,7 @@ private:
State m_state { State::Normal }; State m_state { State::Normal };
bool m_is_mod_key_held { false }; bool m_is_mod_key_held { false };
BAN::RefPtr<Window> m_focused_window; BAN::RefPtr<Window> m_focused_window;
BAN::Array<BAN::RefPtr<Window>, 5> m_mouse_button_windows;
Position m_cursor; Position m_cursor;
Rectangle m_non_full_screen_rect; Rectangle m_non_full_screen_rect;