mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
Ladybird/Qt: Place the tab audio state button on the right on macOS
On macOS, the "close tab" button is on the left, so we should place the audio state button on the right to avoid conflict. Rather than an OS ifdef, we do this by detecting if the left side is occupied.
This commit is contained in:
parent
3e659b10f0
commit
dd54780d5e
Notes:
sideshowbarker
2024-07-17 01:13:25 +09:00
Author: https://github.com/trflynn89
Commit: dd54780d5e
Pull-request: https://github.com/SerenityOS/serenity/pull/23778
2 changed files with 14 additions and 5 deletions
|
@ -650,11 +650,12 @@ void BrowserWindow::tab_favicon_changed(int index, QIcon const& icon)
|
|||
void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlayState play_state)
|
||||
{
|
||||
auto* tab = verify_cast<Tab>(m_tabs_container->widget(index));
|
||||
auto position = audio_button_position_for_tab(index);
|
||||
|
||||
switch (play_state) {
|
||||
case Web::HTML::AudioPlayState::Paused:
|
||||
if (tab->view().page_mute_state() == Web::HTML::MuteState::Unmuted)
|
||||
m_tabs_container->tabBar()->setTabButton(index, QTabBar::LeftSide, nullptr);
|
||||
m_tabs_container->tabBar()->setTabButton(index, position, nullptr);
|
||||
break;
|
||||
|
||||
case Web::HTML::AudioPlayState::Playing:
|
||||
|
@ -663,23 +664,23 @@ void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlay
|
|||
button->setFlat(true);
|
||||
button->resize({ 20, 20 });
|
||||
|
||||
connect(button, &QPushButton::clicked, this, [this, tab]() {
|
||||
connect(button, &QPushButton::clicked, this, [this, tab, position]() {
|
||||
tab->view().toggle_page_mute_state();
|
||||
auto index = tab_index(tab);
|
||||
|
||||
switch (tab->view().audio_play_state()) {
|
||||
case Web::HTML::AudioPlayState::Paused:
|
||||
m_tabs_container->tabBar()->setTabButton(index, QTabBar::LeftSide, nullptr);
|
||||
m_tabs_container->tabBar()->setTabButton(index, position, nullptr);
|
||||
break;
|
||||
case Web::HTML::AudioPlayState::Playing:
|
||||
auto* button = m_tabs_container->tabBar()->tabButton(index, QTabBar::LeftSide);
|
||||
auto* button = m_tabs_container->tabBar()->tabButton(index, position);
|
||||
verify_cast<QPushButton>(button)->setIcon(icon_for_page_mute_state(*tab));
|
||||
button->setToolTip(tool_tip_for_page_mute_state(*tab));
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
m_tabs_container->tabBar()->setTabButton(index, QTabBar::LeftSide, button);
|
||||
m_tabs_container->tabBar()->setTabButton(index, position, button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -708,6 +709,13 @@ QString BrowserWindow::tool_tip_for_page_mute_state(Tab& tab) const
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
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;
|
||||
return QTabBar::LeftSide;
|
||||
}
|
||||
|
||||
void BrowserWindow::open_next_tab()
|
||||
{
|
||||
if (m_tabs_container->count() <= 1)
|
||||
|
|
|
@ -130,6 +130,7 @@ private:
|
|||
|
||||
QIcon icon_for_page_mute_state(Tab&) const;
|
||||
QString tool_tip_for_page_mute_state(Tab&) const;
|
||||
QTabBar::ButtonPosition audio_button_position_for_tab(int tab_index) const;
|
||||
|
||||
QScreen* m_current_screen;
|
||||
double m_device_pixel_ratio { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue