summaryrefslogtreecommitdiff
path: root/WindowServer
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-27 08:48:34 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-27 08:48:34 +0100
commit069d21ed7f2cf6d5b5f277602b8a969284298b0f (patch)
tree7337af7a88ca2c469e70b4f74eed28ec54b7eb81 /WindowServer
parent15fad649ea51d25e168e0456b5621beb820e254d (diff)
downloadserenity-069d21ed7f2cf6d5b5f277602b8a969284298b0f.zip
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.
Diffstat (limited to 'WindowServer')
-rw-r--r--WindowServer/WSWindow.cpp6
-rw-r--r--WindowServer/WSWindow.h4
-rw-r--r--WindowServer/WSWindowManager.cpp8
3 files changed, 18 insertions, 0 deletions
diff --git a/WindowServer/WSWindow.cpp b/WindowServer/WSWindow.cpp
index ff2432def0..81a24ef20e 100644
--- a/WindowServer/WSWindow.cpp
+++ b/WindowServer/WSWindow.cpp
@@ -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;
+}
diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h
index e91845f02b..12a30da4b7 100644
--- a/WindowServer/WSWindow.h
+++ b/WindowServer/WSWindow.h
@@ -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;
diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp
index bd9a69236e..4679b9afe9 100644
--- a/WindowServer/WSWindowManager.cpp
+++ b/WindowServer/WSWindowManager.cpp
@@ -288,6 +288,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) {
move_to_front(*window);