WindowServer: Compute final window title before passing to WM clients
We were not substituting the window modified marker ("[*]") in the title strings we were sending to WM clients. This caused the Taskbar to show pre-substitution window titles for the Text Editor application. This patch moves the window title resolution to Window::compute_title() which is then used throughout.
This commit is contained in:
parent
1f24ab91f2
commit
353a831c8c
Notes:
sideshowbarker
2024-07-18 18:24:23 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/353a831c8ca
7 changed files with 21 additions and 20 deletions
|
@ -52,11 +52,8 @@ Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, cons
|
|||
};
|
||||
}
|
||||
|
||||
void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, const IntRect& window_rect, const StringView& window_title, const Bitmap& icon, const Palette& palette, const IntRect& leftmost_button_rect, int menu_row_count, bool window_modified) const
|
||||
void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, const IntRect& window_rect, const StringView& window_title, const Bitmap& icon, const Palette& palette, const IntRect& leftmost_button_rect, int menu_row_count, [[maybe_unused]] bool window_modified) const
|
||||
{
|
||||
String final_title = window_title;
|
||||
final_title.replace("[*]", window_modified ? " (*)" : "");
|
||||
|
||||
auto frame_rect = frame_rect_for_window(WindowType::Normal, window_rect, palette, menu_row_count);
|
||||
frame_rect.set_location({ 0, 0 });
|
||||
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
|
||||
|
@ -67,7 +64,7 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_title_rect = titlebar_inner_rect;
|
||||
titlebar_title_rect.set_width(FontDatabase::default_bold_font().width(final_title));
|
||||
titlebar_title_rect.set_width(FontDatabase::default_bold_font().width(window_title));
|
||||
|
||||
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
|
||||
|
||||
|
@ -89,9 +86,9 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
auto clipped_title_rect = titlebar_title_rect;
|
||||
clipped_title_rect.set_width(stripe_right - clipped_title_rect.x());
|
||||
if (!clipped_title_rect.is_empty()) {
|
||||
painter.draw_text(clipped_title_rect.translated(1, 2), final_title, title_font, Gfx::TextAlignment::CenterLeft, shadow_color, Gfx::TextElision::Right);
|
||||
painter.draw_text(clipped_title_rect.translated(1, 2), window_title, title_font, Gfx::TextAlignment::CenterLeft, shadow_color, Gfx::TextElision::Right);
|
||||
// FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline.
|
||||
painter.draw_text(clipped_title_rect.translated(0, 1), final_title, title_font, Gfx::TextAlignment::CenterLeft, title_color, Gfx::TextElision::Right);
|
||||
painter.draw_text(clipped_title_rect.translated(0, 1), window_title, title_font, Gfx::TextAlignment::CenterLeft, title_color, Gfx::TextElision::Right);
|
||||
}
|
||||
|
||||
painter.draw_scaled_bitmap(titlebar_icon_rect, icon, icon.rect());
|
||||
|
|
|
@ -1002,4 +1002,13 @@ void Window::set_modified(bool modified)
|
|||
frame().invalidate_titlebar();
|
||||
}
|
||||
|
||||
String Window::computed_title() const
|
||||
{
|
||||
String title = m_title;
|
||||
title.replace("[*]", is_modified() ? " (*)" : "");
|
||||
if (client() && client()->is_unresponsive())
|
||||
return String::formatted("{} (Not responding)", title);
|
||||
return title;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -125,6 +125,8 @@ public:
|
|||
String title() const { return m_title; }
|
||||
void set_title(const String&);
|
||||
|
||||
String computed_title() const;
|
||||
|
||||
float opacity() const { return m_opacity; }
|
||||
void set_opacity(float);
|
||||
|
||||
|
|
|
@ -270,18 +270,11 @@ void WindowFrame::paint_notification_frame(Gfx::Painter& painter)
|
|||
Gfx::WindowTheme::current().paint_notification_frame(painter, m_window.rect(), palette, m_buttons.last().relative_rect());
|
||||
}
|
||||
|
||||
String WindowFrame::compute_title_text() const
|
||||
{
|
||||
if (m_window.client() && m_window.client()->is_unresponsive())
|
||||
return String::formatted("{} (Not responding)", m_window.title());
|
||||
return m_window.title();
|
||||
}
|
||||
|
||||
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(), compute_title_text(), 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_button_rect);
|
||||
}
|
||||
|
||||
void WindowFrame::paint_menubar(Gfx::Painter& painter)
|
||||
|
@ -316,7 +309,7 @@ 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(), compute_title_text(), 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_button_rect, menu_row_count(), m_window.is_modified());
|
||||
|
||||
if (m_window.menubar() && m_window.should_show_menubar())
|
||||
paint_menubar(painter);
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
void handle_menu_mouse_event(Menu&, const MouseEvent&);
|
||||
|
||||
Gfx::WindowTheme::WindowState window_state_for_theme() const;
|
||||
String compute_title_text() const;
|
||||
String computed_title() const;
|
||||
|
||||
Window& m_window;
|
||||
NonnullOwnPtrVector<Button> m_buttons;
|
||||
|
|
|
@ -299,7 +299,7 @@ void WindowManager::tell_wm_about_window(WMClientConnection& conn, Window& windo
|
|||
if (window.is_internal())
|
||||
return;
|
||||
auto* parent = window.parent_window();
|
||||
conn.async_window_state_changed(conn.window_id(), window.client_id(), window.window_id(), parent ? parent->client_id() : -1, parent ? parent->window_id() : -1, window.is_active(), window.is_minimized(), window.is_modal_dont_unparent(), window.is_frameless(), (i32)window.type(), window.title(), window.rect(), window.progress());
|
||||
conn.async_window_state_changed(conn.window_id(), window.client_id(), window.window_id(), parent ? parent->client_id() : -1, parent ? parent->window_id() : -1, window.is_active(), window.is_minimized(), window.is_modal_dont_unparent(), window.is_frameless(), (i32)window.type(), window.computed_title(), window.rect(), window.progress());
|
||||
}
|
||||
|
||||
void WindowManager::tell_wm_about_window_rect(WMClientConnection& conn, Window& window)
|
||||
|
|
|
@ -185,7 +185,7 @@ void WindowSwitcher::draw()
|
|||
Gfx::IntRect icon_rect = { thumbnail_rect.bottom_right().translated(-window.icon().width(), -window.icon().height()), { window.icon().width(), window.icon().height() } };
|
||||
painter.fill_rect(icon_rect, palette.window());
|
||||
painter.blit(icon_rect.location(), window.icon(), window.icon().rect());
|
||||
painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0), window.title(), WindowManager::the().window_title_font(), Gfx::TextAlignment::CenterLeft, text_color);
|
||||
painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0), window.computed_title(), WindowManager::the().window_title_font(), Gfx::TextAlignment::CenterLeft, text_color);
|
||||
painter.draw_text(item_rect, window.rect().to_string(), Gfx::TextAlignment::CenterRight, rect_text_color);
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ void WindowSwitcher::refresh()
|
|||
if (window.is_frameless())
|
||||
return IterationDecision::Continue;
|
||||
++window_count;
|
||||
longest_title_width = max(longest_title_width, wm.font().width(window.title()));
|
||||
longest_title_width = max(longest_title_width, wm.font().width(window.computed_title()));
|
||||
if (selected_window == &window)
|
||||
m_selected_index = m_windows.size();
|
||||
m_windows.append(window);
|
||||
|
|
Loading…
Add table
Reference in a new issue