From 857cac6d1d240b9113a5dd5fd8166488c675c5f9 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 22 Oct 2021 09:07:50 -0400 Subject: [PATCH] WindowServer: Support displaying window titles when there are no buttons Currently, if there are not titlebar buttons, we fail to paint the title because we treat the leftmost titlebar button as the empty rect. We will now use the rightmost edge of the titlebar when there are no buttons. --- Userland/Services/WindowServer/WindowFrame.cpp | 16 ++++++++++++---- Userland/Services/WindowServer/WindowFrame.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 9d41ef5b90..c9382bb1c6 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -245,8 +245,7 @@ void WindowFrame::paint_notification_frame(Gfx::Painter& painter) void WindowFrame::paint_tool_window_frame(Gfx::Painter& painter) { auto palette = WindowManager::the().palette(); - auto leftmost_button_rect = m_buttons.is_empty() ? Gfx::IntRect() : m_buttons.last().relative_rect(); - Gfx::WindowTheme::current().paint_tool_window_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), palette, leftmost_button_rect); + Gfx::WindowTheme::current().paint_tool_window_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), palette, leftmost_titlebar_button_rect()); } void WindowFrame::paint_menubar(Gfx::Painter& painter) @@ -281,8 +280,7 @@ void WindowFrame::paint_menubar(Gfx::Painter& painter) void WindowFrame::paint_normal_frame(Gfx::Painter& painter) { auto palette = WindowManager::the().palette(); - auto leftmost_button_rect = m_buttons.is_empty() ? Gfx::IntRect() : m_buttons.last().relative_rect(); - Gfx::WindowTheme::current().paint_normal_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), m_window.icon(), palette, leftmost_button_rect, menu_row_count(), m_window.is_modified()); + Gfx::WindowTheme::current().paint_normal_frame(painter, window_state_for_theme(), m_window.rect(), m_window.computed_title(), m_window.icon(), palette, leftmost_titlebar_button_rect(), menu_row_count(), m_window.is_modified()); if (m_window.menubar().has_menus() && m_window.should_show_menubar()) paint_menubar(painter); @@ -529,6 +527,16 @@ Gfx::IntRect WindowFrame::constrained_render_rect_to_screen(const Gfx::IntRect& return render_rect; } +Gfx::IntRect WindowFrame::leftmost_titlebar_button_rect() const +{ + if (!m_buttons.is_empty()) + return m_buttons.last().relative_rect(); + + auto rect = titlebar_rect(); + rect.translate_by(rect.width(), 0); + return rect; +} + Gfx::IntRect WindowFrame::render_rect() const { return constrained_render_rect_to_screen(inflated_for_shadow(rect())); diff --git a/Userland/Services/WindowServer/WindowFrame.h b/Userland/Services/WindowServer/WindowFrame.h index 677e503cb0..f889d8a66d 100644 --- a/Userland/Services/WindowServer/WindowFrame.h +++ b/Userland/Services/WindowServer/WindowFrame.h @@ -136,6 +136,7 @@ private: String computed_title() const; Gfx::IntRect constrained_render_rect_to_screen(const Gfx::IntRect&) const; + Gfx::IntRect leftmost_titlebar_button_rect() const; Window& m_window; NonnullOwnPtrVector