summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-05-12 17:55:48 +0100
committerLinus Groh <mail@linusgroh.de>2021-05-12 17:55:48 +0100
commitf2154bca179e5242390e8b3230607360bdaa2949 (patch)
treee806aca4f03e19ad385ce5fcccf3ca8f13e50cc6
parentc8738bbd7e56f6298981cc2f0195bb460c4ad65a (diff)
downloadserenity-f2154bca179e5242390e8b3230607360bdaa2949.zip
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: "<URL> - Browser". Also consolidate the two places where this code is used into a lambda to make any future changes easier.
-rw-r--r--Userland/Applications/Browser/main.cpp10
1 files 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<Browser::Tab&>(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) {