From e1862fe2f5260d480f9368f5bac0ecd14474af73 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 5 Dec 2019 17:44:10 +0100 Subject: [PATCH] WindowServer: Move window minimize animation to a separate function Move this from WSCompositor::compose() to a separate run_animations() function to keep compose() readable. We might want to add some more animations later. --- Servers/WindowServer/WSCompositor.cpp | 75 ++++++++++++++------------- Servers/WindowServer/WSCompositor.h | 1 + 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/Servers/WindowServer/WSCompositor.cpp b/Servers/WindowServer/WSCompositor.cpp index bf93ad7fd1..6590330957 100644 --- a/Servers/WindowServer/WSCompositor.cpp +++ b/Servers/WindowServer/WSCompositor.cpp @@ -212,41 +212,7 @@ void WSCompositor::compose() draw_geometry_label(); } - static const int minimize_animation_steps = 10; - - wm.for_each_window([&](WSWindow& window) { - if (window.in_minimize_animation()) { - int animation_index = window.minimize_animation_index(); - - auto from_rect = window.is_minimized() ? window.frame().rect() : window.taskbar_rect(); - auto to_rect = window.is_minimized() ? window.taskbar_rect() : window.frame().rect(); - - float x_delta_per_step = (float)(from_rect.x() - to_rect.x()) / minimize_animation_steps; - float y_delta_per_step = (float)(from_rect.y() - to_rect.y()) / minimize_animation_steps; - float width_delta_per_step = (float)(from_rect.width() - to_rect.width()) / minimize_animation_steps; - float height_delta_per_step = (float)(from_rect.height() - to_rect.height()) / minimize_animation_steps; - - Rect rect { - from_rect.x() - (int)(x_delta_per_step * animation_index), - from_rect.y() - (int)(y_delta_per_step * animation_index), - from_rect.width() - (int)(width_delta_per_step * animation_index), - from_rect.height() - (int)(height_delta_per_step * animation_index) - }; - -#ifdef MINIMIZE_ANIMATION_DEBUG - dbg() << "Minimize animation from " << from_rect << " to " << to_rect << " frame# " << animation_index << " " << rect; -#endif - - m_back_painter->draw_rect(rect, Color::White); - - window.step_minimize_animation(); - if (window.minimize_animation_index() >= minimize_animation_steps) - window.end_minimize_animation(); - - invalidate(rect); - } - return IterationDecision::Continue; - }); + run_animations(); draw_cursor(); @@ -360,6 +326,45 @@ void WSCompositor::flip_buffers() m_buffers_are_flipped = !m_buffers_are_flipped; } +void WSCompositor::run_animations() +{ + static const int minimize_animation_steps = 10; + + WSWindowManager::the().for_each_window([&](WSWindow& window) { + if (window.in_minimize_animation()) { + int animation_index = window.minimize_animation_index(); + + auto from_rect = window.is_minimized() ? window.frame().rect() : window.taskbar_rect(); + auto to_rect = window.is_minimized() ? window.taskbar_rect() : window.frame().rect(); + + float x_delta_per_step = (float)(from_rect.x() - to_rect.x()) / minimize_animation_steps; + float y_delta_per_step = (float)(from_rect.y() - to_rect.y()) / minimize_animation_steps; + float width_delta_per_step = (float)(from_rect.width() - to_rect.width()) / minimize_animation_steps; + float height_delta_per_step = (float)(from_rect.height() - to_rect.height()) / minimize_animation_steps; + + Rect rect { + from_rect.x() - (int)(x_delta_per_step * animation_index), + from_rect.y() - (int)(y_delta_per_step * animation_index), + from_rect.width() - (int)(width_delta_per_step * animation_index), + from_rect.height() - (int)(height_delta_per_step * animation_index) + }; + +#ifdef MINIMIZE_ANIMATION_DEBUG + dbg() << "Minimize animation from " << from_rect << " to " << to_rect << " frame# " << animation_index << " " << rect; +#endif + + m_back_painter->draw_rect(rect, Color::White); + + window.step_minimize_animation(); + if (window.minimize_animation_index() >= minimize_animation_steps) + window.end_minimize_animation(); + + invalidate(rect); + } + return IterationDecision::Continue; + }); +} + void WSCompositor::set_resolution(int desired_width, int desired_height) { auto screen_rect = WSScreen::the().rect(); diff --git a/Servers/WindowServer/WSCompositor.h b/Servers/WindowServer/WSCompositor.h index 4856108fa8..4a6a64d263 100644 --- a/Servers/WindowServer/WSCompositor.h +++ b/Servers/WindowServer/WSCompositor.h @@ -43,6 +43,7 @@ private: void draw_cursor(); void draw_geometry_label(); void draw_menubar(); + void run_animations(); unsigned m_compose_count { 0 }; unsigned m_flush_count { 0 };