summaryrefslogtreecommitdiff
path: root/WindowServer/WSWindowManager.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-20 10:12:19 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-20 10:12:19 +0100
commitbf305025601b28c9c489b97af75a7273e3bd79ed (patch)
treefd7835164f946d7da7aea38a1de32122b4903fac /WindowServer/WSWindowManager.cpp
parentaf7eb5c89c974cdaeadeffa9db2f70b39fb7f373 (diff)
downloadserenity-bf305025601b28c9c489b97af75a7273e3bd79ed.zip
LibGUI: Implement enter/leave events (with WindowServer support.)
Windows now learn when the mouse cursor leaves or enters them. Use this to implement GWidget::{enter,leave}_event() and use that to implement the CoolBar button effect. :^)
Diffstat (limited to 'WindowServer/WSWindowManager.cpp')
-rw-r--r--WindowServer/WSWindowManager.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp
index eafa5f38e7..65db97df6d 100644
--- a/WindowServer/WSWindowManager.cpp
+++ b/WindowServer/WSWindowManager.cpp
@@ -488,8 +488,10 @@ void WSWindowManager::handle_close_button_mouse_event(WSWindow& window, WSMouseE
}
}
-void WSWindowManager::process_mouse_event(WSMouseEvent& event)
+void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& event_window)
{
+ event_window = nullptr;
+
if (event.type() == WSMessage::MouseUp && event.button() == MouseButton::Left) {
if (m_drag_window) {
#ifdef DRAG_DEBUG
@@ -561,6 +563,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event)
move_to_front(window);
set_active_window(&window);
}
+ event_window = &window;
// FIXME: Should we just alter the coordinates of the existing MouseEvent and pass it through?
Point position { event.x() - window.rect().x(), event.y() - window.rect().y() };
auto local_event = make<WSMouseEvent>(event.type(), position, event.buttons(), event.button());
@@ -753,8 +756,12 @@ void WSWindowManager::draw_cursor()
void WSWindowManager::on_message(WSMessage& message)
{
- if (message.is_mouse_event())
- return process_mouse_event(static_cast<WSMouseEvent&>(message));
+ if (message.is_mouse_event()) {
+ WSWindow* event_window = nullptr;
+ process_mouse_event(static_cast<WSMouseEvent&>(message), event_window);
+ set_hovered_window(event_window);
+ return;
+ }
if (message.is_key_event()) {
// FIXME: This is a good place to hook key events globally. :)
@@ -795,6 +802,20 @@ void WSWindowManager::set_active_window(WSWindow* window)
}
}
+void WSWindowManager::set_hovered_window(WSWindow* window)
+{
+ if (m_hovered_window.ptr() == window)
+ return;
+
+ if (m_hovered_window)
+ WSMessageLoop::the().post_message(m_hovered_window.ptr(), make<WSMessage>(WSMessage::WindowLeft));
+
+ m_hovered_window = window ? window->make_weak_ptr() : nullptr;
+
+ if (m_hovered_window)
+ WSMessageLoop::the().post_message(m_hovered_window.ptr(), make<WSMessage>(WSMessage::WindowEntered));
+}
+
void WSWindowManager::invalidate()
{
m_dirty_rects.clear_with_capacity();