Skip to content

Truly independent web browser

UI/Qt: Show the audio button of a tab moved to another window

Luke Wilde535937f3d7bd
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index d2a9f57263d..7d147ebef49 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -1257,10 +1257,10 @@ void BrowserWindow::initialize_tab_buttons(Tab* tab)
auto index = m_tabs_container->index_of(tab);
m_tabs_container->set_tab_icon(index, tab->tab_icon());
- m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr);
// A pinned tab has no close button.
m_tabs_container->tab_bar()->setTabButton(index, TAB_CLOSE_BUTTON_POSITION, tab->is_pinned() ? nullptr : create_tab_close_button(*tab));
m_tabs_container->update_tab_button_visibility();
+ update_tab_audio_button(*tab);
}
void BrowserWindow::update_tab_close_button(Tab& tab)
@@ -1401,44 +1401,42 @@ void BrowserWindow::set_always_on_top(bool always_on_top)
handle->setFlags(flags);
}
-void BrowserWindow::tab_audibility_changed(int index, Audio::Audibility audibility)
+void BrowserWindow::tab_audibility_changed(int index, Audio::Audibility)
{
if (index < 0)
return;
- auto* tab = m_tabs_container->tab(index);
-
- // The tab is shown playing audio, muted or not, while the AudioServer recently heard it. A muted tab keeps its
- // button, as that is the only way to unmute it.
- switch (audibility) {
- case Audio::Audibility::Inaudible:
- if (tab->view().page_mute_state() == Web::HTML::MuteState::Unmuted) {
- m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr);
- m_tabs_container->update_tab_button_visibility();
- }
- break;
-
- case Audio::Audibility::Audible:
- auto* button = new TabBarButton(icon_for_page_mute_state(*tab), TabBarButton::Role::Audio);
- button->setToolTip(tool_tip_for_page_mute_state(*tab));
- button->setObjectName("LadybirdAudioState");
+ update_tab_audio_button(*m_tabs_container->tab(index));
+}
- connect(button, &QPushButton::clicked, this, [this, tab, button]() {
- tab->view().toggle_page_mute_state();
+// The tab is shown playing audio, muted or not, while the AudioServer recently heard it. A muted tab keeps its button,
+// as that is the only way to unmute it.
+void BrowserWindow::update_tab_audio_button(Tab& tab)
+{
+ auto index = tab_index(&tab);
+ auto* tab_bar = m_tabs_container->tab_bar();
- if (tab->view().audibility() == Audio::Audibility::Inaudible) {
- m_tabs_container->tab_bar()->setTabButton(tab_index(tab), AUDIO_STATE_BUTTON_POSITION, nullptr);
- m_tabs_container->update_tab_button_visibility();
- return;
- }
+ if (!tab.is_loaded() || (tab.view().audibility() == Audio::Audibility::Inaudible && tab.view().page_mute_state() == Web::HTML::MuteState::Unmuted)) {
+ // The tab bar only hides the button it lets go of.
+ if (auto* button = tab_bar->tabButton(index, AUDIO_STATE_BUTTON_POSITION))
+ button->deleteLater();
+ tab_bar->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr);
+ m_tabs_container->update_tab_button_visibility();
+ return;
+ }
- button->setIcon(icon_for_page_mute_state(*tab));
- button->setToolTip(tool_tip_for_page_mute_state(*tab));
+ auto* button = qobject_cast<TabBarButton*>(tab_bar->tabButton(index, AUDIO_STATE_BUTTON_POSITION));
+ if (!button) {
+ button = new TabBarButton(icon_for_page_mute_state(tab), TabBarButton::Role::Audio);
+ button->setObjectName("LadybirdAudioState");
+ connect(button, &QPushButton::clicked, this, [this, &tab]() {
+ tab.view().toggle_page_mute_state();
+ update_tab_audio_button(tab);
});
-
- m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, button);
+ tab_bar->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, button);
m_tabs_container->update_tab_button_visibility();
- break;
}
+ button->setIcon(icon_for_page_mute_state(tab));
+ button->setToolTip(tool_tip_for_page_mute_state(tab));
}
QIcon BrowserWindow::icon_for_page_mute_state(Tab& tab) const
diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.h
index c30a8736f7a..a3aef9b3859 100644
--- a/UI/Qt/BrowserWindow.h
+++ b/UI/Qt/BrowserWindow.h
@@ -174,6 +174,7 @@ public:
Tab& create_new_tab(Web::HTML::ActivateTab activate_tab, TabLocation);
void duplicate_tab(Tab&);
void open_history_entry_in_new_tab(Tab&, int delta);
+ void update_tab_audio_button(Tab&);
// Opens a window's restored tabs, keeping the session rows the store re-adopted for them.
void restore_tabs(Vector<WebView::RestoredSessionTab> const&, i64 active_tab_index);
Tab* current_tab() const { return m_current_tab; }
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index ee04e5db1f0..8a333ce2d54 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1787,8 +1787,10 @@ void Tab::create_tab_context_menu()
auto* mute_tab_action = new QAction("&Mute Tab", this);
QObject::connect(mute_tab_action, &QAction::triggered, this, [this]() {
- if (is_loaded())
+ if (is_loaded()) {
view().toggle_page_mute_state();
+ m_window->update_tab_audio_button(*this);
+ }
});
auto* move_to_new_window_action = new QAction("Move to New &Window", this);