From f2154bca179e5242390e8b3230607360bdaa2949 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 12 May 2021 17:55:48 +0100 Subject: [PATCH] Browser: Use URL for window title if tab title is empty Seeing " - Browser" for loading pages is annoying, so let's do something more sensible instead for empty tab document titles: " - Browser". Also consolidate the two places where this code is used into a lambda to make any future changes easier. --- Userland/Applications/Browser/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 99c91abd18..f9a765d235 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -153,9 +153,15 @@ int main(int argc, char** argv) auto default_favicon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"); VERIFY(default_favicon); + auto set_window_title_for_tab = [&window](auto& tab) { + auto& title = tab.title(); + auto url = tab.url(); + window->set_title(String::formatted("{} - Browser", title.is_empty() ? url.to_string() : title)); + }; + tab_widget.on_change = [&](auto& active_widget) { auto& tab = static_cast(active_widget); - window->set_title(String::formatted("{} - Browser", tab.title())); + set_window_title_for_tab(tab); tab.did_become_active(); }; @@ -182,7 +188,7 @@ int main(int argc, char** argv) new_tab.on_title_change = [&](auto title) { tab_widget.set_tab_title(new_tab, title); if (tab_widget.active_widget() == &new_tab) - window->set_title(String::formatted("{} - Browser", title)); + set_window_title_for_tab(new_tab); }; new_tab.on_favicon_change = [&](auto& bitmap) {