From d054fbee91aac06c439aad8d6ca45d9a2ded806f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Feb 2019 15:50:05 +0100 Subject: [PATCH] WindowServer: Don't spam clients with resize events. Wait for them to finish a paint, then send them a new resize event. The exception is when releasing the mouse button to end the resize. Then we send a new resize event right away. --- WindowServer/WSClientConnection.cpp | 1 + WindowServer/WSWindow.h | 4 ++++ WindowServer/WSWindowManager.cpp | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/WindowServer/WSClientConnection.cpp b/WindowServer/WSClientConnection.cpp index ad11034333..e0f5cc3e7a 100644 --- a/WindowServer/WSClientConnection.cpp +++ b/WindowServer/WSClientConnection.cpp @@ -358,6 +358,7 @@ void WSClientConnection::handle_request(WSAPIDidFinishPaintingNotification& requ return; } auto& window = *(*it).value; + window.set_has_painted_since_last_resize(true); WSWindowManager::the().invalidate(window, request.rect()); } diff --git a/WindowServer/WSWindow.h b/WindowServer/WSWindow.h index f2ca9980ee..4518e78cc1 100644 --- a/WindowServer/WSWindow.h +++ b/WindowServer/WSWindow.h @@ -63,6 +63,9 @@ public: bool has_alpha_channel() const { return m_has_alpha_channel; } void set_has_alpha_channel(bool value) { m_has_alpha_channel = value; } + void set_has_painted_since_last_resize(bool b) { m_has_painted_since_last_resize = b; } + bool has_painted_since_last_resize() const { return m_has_painted_since_last_resize; } + // For InlineLinkedList. // FIXME: Maybe make a ListHashSet and then WSWindowManager can just use that. WSWindow* m_next { nullptr }; @@ -76,6 +79,7 @@ private: bool m_global_cursor_tracking_enabled { false }; bool m_visible { true }; bool m_has_alpha_channel { false }; + bool m_has_painted_since_last_resize { false }; WSMenu* m_menu { nullptr }; RetainPtr m_backing; int m_window_id { -1 }; diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index c8beefc03b..690eb37a58 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -531,7 +531,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& event_ #ifdef RESIZE_DEBUG printf("[WM] Finish resizing WSWindow{%p}\n", m_resize_window.ptr()); #endif - invalidate(*m_resize_window); + WSMessageLoop::the().post_message(m_resize_window.ptr(), make(m_resize_window->rect(), m_resize_window->rect())); m_resize_window = nullptr; return; } @@ -553,7 +553,10 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& event_ if (new_rect.height() < 50) new_rect.set_height(50); m_resize_window->set_rect(new_rect); - WSMessageLoop::the().post_message(m_resize_window.ptr(), make(old_rect, new_rect)); + if (m_resize_window->has_painted_since_last_resize()) { + m_resize_window->set_has_painted_since_last_resize(false); + WSMessageLoop::the().post_message(m_resize_window.ptr(), make(old_rect, new_rect)); + } return; } }