mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
Let the EventLoop drive the WindowManager through WM_Compose events.
This commit is contained in:
parent
780e15a6cc
commit
57b13274da
Notes:
sideshowbarker
2024-07-19 16:04:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/57b13274da1
3 changed files with 16 additions and 8 deletions
|
@ -39,6 +39,7 @@ public:
|
|||
WindowBecameActive,
|
||||
FocusIn,
|
||||
FocusOut,
|
||||
WM_Compose,
|
||||
};
|
||||
|
||||
Event() { }
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -78,4 +78,6 @@ private:
|
|||
RetainPtr<GraphicsBitmap> m_back_bitmap;
|
||||
|
||||
Vector<Rect> m_invalidated_rects;
|
||||
|
||||
bool m_pending_compose_event { false };
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue