diff options
author | Linus Groh <mail@linusgroh.de> | 2021-05-12 17:55:48 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-12 17:55:48 +0100 |
commit | f2154bca179e5242390e8b3230607360bdaa2949 (patch) | |
tree | e806aca4f03e19ad385ce5fcccf3ca8f13e50cc6 /Userland | |
parent | c8738bbd7e56f6298981cc2f0195bb460c4ad65a (diff) | |
download | serenity-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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 10 |
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) { |