1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:27:35 +00:00

Make buttons unpress when the cursor leaves the button rect.

Implement this functionality by adding global cursor tracking.
It's currently only possible for one GWidget per GWindow to track the cursor.
This commit is contained in:
Andreas Kling 2019-01-27 08:48:34 +01:00
parent 15fad649ea
commit 069d21ed7f
15 changed files with 105 additions and 7 deletions

View file

@ -123,3 +123,9 @@ void WSWindow::on_message(WSMessage& message)
m_process.gui_events().append(move(gui_event));
}
}
void WSWindow::set_global_cursor_tracking_enabled(bool enabled)
{
dbgprintf("WSWindow{%p} global_cursor_tracking <- %u\n", enabled);
m_global_cursor_tracking_enabled = enabled;
}

View file

@ -42,6 +42,9 @@ public:
pid_t pid() const { return m_pid; }
void set_global_cursor_tracking_enabled(bool);
bool global_cursor_tracking() const { return m_global_cursor_tracking_enabled; }
// For InlineLinkedList.
// FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that.
WSWindow* m_next { nullptr };
@ -52,6 +55,7 @@ private:
String m_title;
Rect m_rect;
bool m_is_being_dragged { false };
bool m_global_cursor_tracking_enabled { false };
RetainPtr<GraphicsBitmap> m_backing;
Process& m_process;

View file

@ -287,6 +287,14 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
}
}
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
if (!window->global_cursor_tracking())
continue;
Point position { event.x() - window->rect().x(), event.y() - window->rect().y() };
auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
window->on_message(*local_event);
}
for (auto* window = m_windows_in_order.tail(); window; window = window->prev()) {
if (title_bar_rect(window->rect()).contains(event.position())) {
if (event.type() == WSMessage::MouseDown) {