summaryrefslogtreecommitdiff
path: root/Widgets
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-12 06:47:55 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-12 06:47:55 +0100
commit57b13274da13440f66f3bda3ec62d17be6c52e5c (patch)
tree970d255ecb69cfa1261e24ca04b403899ba3747a /Widgets
parent780e15a6cc08db0b8a956400a0515c220493abdd (diff)
downloadserenity-57b13274da13440f66f3bda3ec62d17be6c52e5c.zip
Let the EventLoop drive the WindowManager through WM_Compose events.
Diffstat (limited to 'Widgets')
-rw-r--r--Widgets/Event.h1
-rw-r--r--Widgets/WindowManager.cpp21
-rw-r--r--Widgets/WindowManager.h2
3 files changed, 16 insertions, 8 deletions
diff --git a/Widgets/Event.h b/Widgets/Event.h
index a1ebb45c88..31b48c3161 100644
--- a/Widgets/Event.h
+++ b/Widgets/Event.h
@@ -39,6 +39,7 @@ public:
WindowBecameActive,
FocusIn,
FocusOut,
+ WM_Compose,
};
Event() { }
diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp
index a0c042f3c1..1b2a5fd4c1 100644
--- a/Widgets/WindowManager.cpp
+++ b/Widgets/WindowManager.cpp
@@ -76,6 +76,7 @@ WindowManager::WindowManager()
m_inactiveWindowTitleColor = Color::White;
invalidate();
+ compose();
}
WindowManager::~WindowManager()
@@ -130,7 +131,6 @@ void WindowManager::move_to_front(Window& window)
void WindowManager::did_paint(Window& window)
{
invalidate(window);
- compose();
}
void WindowManager::removeWindow(Window& window)
@@ -143,7 +143,6 @@ void WindowManager::removeWindow(Window& window)
m_windows_in_order.remove(&window);
if (!activeWindow() && !m_windows.is_empty())
setActiveWindow(*m_windows.begin());
- compose();
}
void WindowManager::notifyTitleChanged(Window& window)
@@ -156,7 +155,6 @@ void WindowManager::notifyRectChanged(Window& window, const Rect& old_rect, cons
printf("[WM] Window %p rect changed (%d,%d %dx%d) -> (%d,%d %dx%d)\n", &window, old_rect.x(), old_rect.y(), old_rect.width(), old_rect.height(), new_rect.x(), new_rect.y(), new_rect.width(), new_rect.height());
invalidate(outerRectForWindow(old_rect));
invalidate(outerRectForWindow(new_rect));
- compose();
}
void WindowManager::handleTitleBarMouseEvent(Window& window, MouseEvent& event)
@@ -182,7 +180,6 @@ void WindowManager::processMouseEvent(MouseEvent& event)
m_dragWindow->setIsBeingDragged(false);
m_dragEndRect = outerRectForWindow(m_dragWindow->rect());
m_dragWindow = nullptr;
- compose();
return;
}
}
@@ -196,7 +193,6 @@ void WindowManager::processMouseEvent(MouseEvent& event)
m_dragWindow->setPositionWithoutRepaint(pos);
invalidate(outerRectForWindow(old_window_rect));
invalidate(outerRectForWindow(m_dragWindow->rect()));
- compose();
return;
}
}
@@ -226,7 +222,7 @@ void WindowManager::processMouseEvent(MouseEvent& event)
void WindowManager::compose()
{
- printf("[WM] recompose_count: %u\n", ++m_recompose_count);
+ printf("[WM] compose #%u (%u rects)\n", ++m_recompose_count, m_invalidated_rects.size());
auto any_window_contains_rect = [this] (const Rect& r) {
for (auto* window = m_windows_in_order.head(); window; window = window->next()) {
if (outerRectForWindow(window->rect()).contains(r))
@@ -283,6 +279,12 @@ void WindowManager::event(Event& event)
return Object::event(event);
}
+ if (event.type() == Event::WM_Compose) {
+ m_pending_compose_event = false;
+ compose();
+ return;
+ }
+
return Object::event(event);
}
@@ -300,8 +302,6 @@ void WindowManager::setActiveWindow(Window* window)
invalidate(*m_activeWindow);
EventLoop::main().postEvent(m_activeWindow.ptr(), make<Event>(Event::WindowBecameActive));
}
-
- compose();
}
bool WindowManager::isVisible(Window& window) const
@@ -336,6 +336,11 @@ void WindowManager::invalidate(const Rect& a_rect)
}
m_invalidated_rects.append(rect);
+
+ if (!m_pending_compose_event) {
+ EventLoop::main().postEvent(this, make<Event>(Event::WM_Compose));
+ m_pending_compose_event = true;
+ }
}
void WindowManager::invalidate(const Window& window)
diff --git a/Widgets/WindowManager.h b/Widgets/WindowManager.h
index 711c161b21..30e3a8a4b3 100644
--- a/Widgets/WindowManager.h
+++ b/Widgets/WindowManager.h
@@ -78,4 +78,6 @@ private:
RetainPtr<GraphicsBitmap> m_back_bitmap;
Vector<Rect> m_invalidated_rects;
+
+ bool m_pending_compose_event { false };
};