Ladybird/Qt: Prevent adding multiple audio state buttons

If the left-hand side of the tab is already occupied with an audio state
button, we would add a second button to the right-hand side. Prevent
that by checking if the occupant is our audio state button.
This commit is contained in:
Timothy Flynn 2024-04-02 12:52:03 -04:00 committed by Tim Flynn
parent de97497d26
commit c1c1ad8678
Notes: sideshowbarker 2024-07-17 08:13:43 +09:00

View file

@ -671,6 +671,7 @@ void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlay
case Web::HTML::AudioPlayState::Playing:
auto* button = new QPushButton(icon_for_page_mute_state(*tab), {});
button->setToolTip(tool_tip_for_page_mute_state(*tab));
button->setObjectName("LadybirdAudioState");
button->setFlat(true);
button->resize({ 20, 20 });
@ -721,8 +722,11 @@ QString BrowserWindow::tool_tip_for_page_mute_state(Tab& tab) const
QTabBar::ButtonPosition BrowserWindow::audio_button_position_for_tab(int tab_index) const
{
if (m_tabs_container->tabBar()->tabButton(tab_index, QTabBar::LeftSide))
return QTabBar::RightSide;
if (auto* button = m_tabs_container->tabBar()->tabButton(tab_index, QTabBar::LeftSide)) {
if (button->objectName() != "LadybirdAudioState")
return QTabBar::RightSide;
}
return QTabBar::LeftSide;
}