summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-05-10 00:00:40 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-10 00:02:05 +0200
commit353a831c8cab0de3484069169f98bed99023f637 (patch)
tree4aababa7337b34fe1576ac3d53010b88490c250c /Userland
parent1f24ab91f2f67735e87e34cff5fe46a9be67ac86 (diff)
downloadserenity-353a831c8cab0de3484069169f98bed99023f637.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/ClassicWindowTheme.cpp11
-rw-r--r--Userland/Services/WindowServer/Window.cpp9
-rw-r--r--Userland/Services/WindowServer/Window.h2
-rw-r--r--Userland/Services/WindowServer/WindowFrame.cpp11
-rw-r--r--Userland/Services/WindowServer/WindowFrame.h2
-rw-r--r--Userland/Services/WindowServer/WindowManager.cpp2
-rw-r--r--Userland/Services/WindowServer/WindowSwitcher.cpp4
7 files changed, 21 insertions, 20 deletions
diff --git a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp
index 9c3ea5e7ba..e8aa426847 100644
--- a/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp
+++ b/Userland/Libraries/LibGfx/ClassicWindowTheme.cpp
@@ -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());
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp
index 5e7946ebe8..01dfe74c67 100644
--- a/Userland/Services/WindowServer/Window.cpp
+++ b/Userland/Services/WindowServer/Window.cpp
@@ -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;
+}
+
}
diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h
index c66f9a921f..53f9f67d75 100644
--- a/Userland/Services/WindowServer/Window.h
+++ b/Userland/Services/WindowServer/Window.h
@@ -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);
diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp
index 67ee92d342..c4c089d7e2 100644
--- a/Userland/Services/WindowServer/WindowFrame.cpp
+++ b/Userland/Services/WindowServer/WindowFrame.cpp
@@ -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);
diff --git a/Userland/Services/WindowServer/WindowFrame.h b/Userland/Services/WindowServer/WindowFrame.h
index ed094355f2..623241c32e 100644
--- a/Userland/Services/WindowServer/WindowFrame.h
+++ b/Userland/Services/WindowServer/WindowFrame.h
@@ -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;
diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp
index dd729f132e..4abfaf3fe7 100644
--- a/Userland/Services/WindowServer/WindowManager.cpp
+++ b/Userland/Services/WindowServer/WindowManager.cpp
@@ -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)
diff --git a/Userland/Services/WindowServer/WindowSwitcher.cpp b/Userland/Services/WindowServer/WindowSwitcher.cpp
index bdec78eaf0..77ca52427e 100644
--- a/Userland/Services/WindowServer/WindowSwitcher.cpp
+++ b/Userland/Services/WindowServer/WindowSwitcher.cpp
@@ -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);