From 260e4049ff7f40d4a6ca6e1592dd2fa929684cfd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 24 Apr 2020 22:47:53 +0200 Subject: [PATCH] Browser: Use the active tab's favicon as the window icon :^) --- Applications/Browser/Tab.cpp | 5 +++-- Applications/Browser/Tab.h | 3 +++ Applications/Browser/main.cpp | 9 ++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index 02bd5b208b4..f296eaebe91 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -154,9 +154,10 @@ Tab::Tab() on_title_change(m_title); }; - m_html_widget->on_favicon_change = [this](auto& bitmap) { + m_html_widget->on_favicon_change = [this](auto& icon) { + m_icon = icon; if (on_favicon_change) - on_favicon_change(bitmap); + on_favicon_change(icon); }; auto focus_location_box_action = GUI::Action::create("Focus location box", { Mod_Ctrl, Key_L }, [this](auto&) { diff --git a/Applications/Browser/Tab.h b/Applications/Browser/Tab.h index 5eaccd3d5e6..9079716b322 100644 --- a/Applications/Browser/Tab.h +++ b/Applications/Browser/Tab.h @@ -49,6 +49,7 @@ public: Function on_favicon_change; const String& title() const { return m_title; } + const Gfx::Bitmap* icon() const { return m_icon; } private: Tab(); @@ -68,6 +69,8 @@ private: RefPtr m_menubar; String m_title; + RefPtr m_icon; + bool m_should_push_loads_to_history { true }; }; diff --git a/Applications/Browser/main.cpp b/Applications/Browser/main.cpp index 99ffd80d3bf..423c9772db0 100644 --- a/Applications/Browser/main.cpp +++ b/Applications/Browser/main.cpp @@ -89,17 +89,18 @@ int main(int argc, char** argv) tab_widget.set_container_padding(0); tab_widget.set_uniform_tabs(true); + auto default_favicon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"); + ASSERT(default_favicon); + tab_widget.on_change = [&](auto& active_widget) { auto& tab = static_cast(active_widget); window->set_title(String::format("%s - Browser", tab.title().characters())); + window->set_icon(tab.icon() ? tab.icon() : default_favicon.ptr()); tab.did_become_active(); }; Browser::WindowActions window_actions(*window); - auto default_favicon = Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"); - ASSERT(default_favicon); - Function create_new_tab; create_new_tab = [&](auto url, auto activate) { auto& new_tab = tab_widget.add_tab("New tab"); @@ -114,6 +115,8 @@ int main(int argc, char** argv) new_tab.on_favicon_change = [&](auto& bitmap) { tab_widget.set_tab_icon(new_tab, &bitmap); + if (tab_widget.active_widget() == &new_tab) + window->set_icon(&bitmap); }; new_tab.on_tab_open_request = [&](auto& url) {