diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-02-07 13:22:02 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-08 16:37:46 +0100 |
commit | 1607fd511fdfc590042ea5384ebef793cc515dab (patch) | |
tree | ba8b5a7952213babf5105d160111201d676fec10 | |
parent | 3d7e70145105660498a02f11bb3b3f49bad13736 (diff) | |
download | serenity-1607fd511fdfc590042ea5384ebef793cc515dab.zip |
WindowServer: Unify Window restore rects
Previously, different rects were used to restore tiled and maximized
windows, creating edge cases for inconsistent restoration. All states
now restore m_floating_rect, which saves the last valid size and
location of a window while free-floating.
-rw-r--r-- | Userland/Services/WindowServer/Window.cpp | 14 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Window.h | 5 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.cpp | 6 |
3 files changed, 19 insertions, 6 deletions
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index dadb571e15..304a60a179 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -159,6 +159,9 @@ void Window::set_rect(const Gfx::IntRect& rect) m_backing_store = Gfx::Bitmap::try_create(format, m_rect.size()).release_value_but_fixme_should_propagate_errors(); } + if (m_floating_rect.is_empty()) + m_floating_rect = rect; + invalidate(true, old_rect.size() != rect.size()); m_frame.window_rect_changed(old_rect, rect); invalidate_last_rendered_screen_rects(); @@ -481,7 +484,7 @@ void Window::set_maximized(bool maximized, Optional<Gfx::IntPoint> fixed_point) m_maximized = maximized; update_window_menu_items(); if (maximized) { - m_unmaximized_rect = m_rect; + m_unmaximized_rect = m_floating_rect; set_rect(WindowManager::the().maximized_window_rect(*this)); } else { if (fixed_point.has_value()) { @@ -1090,10 +1093,10 @@ bool Window::set_untiled(Optional<Gfx::IntPoint> fixed_point) if (fixed_point.has_value()) { auto new_rect = Gfx::IntRect(m_rect); - new_rect.set_size_around(m_untiled_rect.size(), fixed_point.value()); + new_rect.set_size_around(m_floating_rect.size(), fixed_point.value()); set_rect(new_rect); } else { - set_rect(m_untiled_rect); + set_rect(m_floating_rect); } Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect)); @@ -1111,8 +1114,9 @@ void Window::set_tiled(Screen* screen, WindowTileType tile_type) if (resize_aspect_ratio().has_value()) return; - if (m_tile_type == WindowTileType::None) - m_untiled_rect = m_rect; + if (is_maximized()) + set_maximized(false); + m_tile_type = tile_type; set_rect(tiled_rect(screen, tile_type)); diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 261cbcf4f4..89796a99ca 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -123,6 +123,9 @@ public: void check_untile_due_to_resize(Gfx::IntRect const&); bool set_untiled(Optional<Gfx::IntPoint> fixed_point = {}); + Gfx::IntRect floating_rect() const { return m_floating_rect; } + void set_floating_rect(Gfx::IntRect rect) { m_floating_rect = rect; } + void set_forced_shadow(bool b) { m_forced_shadow = b; } bool has_forced_shadow() const { return m_forced_shadow; } @@ -436,7 +439,7 @@ private: bool m_invalidate_last_render_rects { false }; Vector<i32> m_stealable_by_client_ids; WindowTileType m_tile_type { WindowTileType::None }; - Gfx::IntRect m_untiled_rect; + Gfx::IntRect m_floating_rect; bool m_occluded { false }; RefPtr<Gfx::Bitmap> m_backing_store; RefPtr<Gfx::Bitmap> m_last_backing_store; diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 805be5be30..ff9226a295 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -740,6 +740,9 @@ bool WindowManager::process_ongoing_window_move(MouseEvent& event) dbgln_if(MOVE_DEBUG, "[WM] Finish moving Window({})", m_move_window); + if (!m_move_window->is_tiled() && !m_move_window->is_maximized()) + m_move_window->set_floating_rect(m_move_window->rect()); + m_move_window->invalidate(true, true); if (m_move_window->is_resizable()) { process_event_for_doubleclick(*m_move_window, event); @@ -824,6 +827,9 @@ bool WindowManager::process_ongoing_window_resize(MouseEvent const& event) if (event.type() == Event::MouseUp && event.button() == m_resizing_mouse_button) { dbgln_if(RESIZE_DEBUG, "[WM] Finish resizing Window({})", m_resize_window); + if (!m_resize_window->is_tiled() && !m_resize_window->is_maximized()) + m_resize_window->set_floating_rect(m_resize_window->rect()); + const int vertical_maximize_deadzone = 5; auto& cursor_screen = ScreenInput::the().cursor_location_screen(); if (&cursor_screen == &Screen::closest_to_rect(m_resize_window->rect())) { |