Truly independent web browser
UI/Qt: Keep right sidebar buttons stationary when toggling
Timothy Flynnda970b548089
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cppindex 0a2da16b2ca..6c6e73e9afd 100644--- a/UI/Qt/BrowserWindow.cpp+++ b/UI/Qt/BrowserWindow.cpp@@ -1775,7 +1775,7 @@ bool BrowserWindow::eventFilter(QObject* object, QEvent* event)auto is_press = event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick;auto is_mouse_event = is_press || event->type() == QEvent::MouseMove;auto position = is_mouse_event ? widget->mapTo(this, static_cast<QMouseEvent*>(event)->position().toPoint()) : mapFromGlobal(QCursor::pos());- if (auto edges = resize_edges_for_position(position); edges.testFlag(window_controls_on_left() ? Qt::LeftEdge : Qt::RightEdge)) {+ if (auto edges = resize_edges_for_position(position); edges & (Qt::LeftEdge | Qt::RightEdge)) {// NB: Even if the resize does not start, a press here must not reach the button and close the window.if (is_press) {auto* handle = windowHandle();diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex 45decd60b1f..d2f42fc34e6 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -3346,7 +3346,7 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)m_new_tab_button->setToolTip(qformatted("New Tab {}", QKeySequence(QKeySequence::AddTab).toString(QKeySequence::NativeText)));m_new_tab_button->installEventFilter(this);- // The button after the Ladybird button lists all the tabs, in every layout of the tabs.+ // The all-tabs button follows the sidebar's side, and sits beside the Ladybird button with horizontal tabs.auto* all_tabs_button = new ChromeHeaderButton(this);all_tabs_button->set_size(ALL_TABS_BUTTON_SIZE);m_all_tabs_button = all_tabs_button;@@ -3363,8 +3363,7 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)show_all_tabs();});- // NB: The Ladybird button and the all-tabs button move together, between the strip, the open sidebar's top row and- // the toolbar beside the collapsed sidebar, so they keep their distance wherever they are.+ // The buttons move together on the left. With the sidebar on the right, only the all-tabs button follows it.m_ladybird_buttons = new QWidget(this);auto* ladybird_buttons_layout = new QHBoxLayout(m_ladybird_buttons);ladybird_buttons_layout->setContentsMargins(0, 0, 0, 0);@@ -3435,7 +3434,7 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)m_vertical_tabs_toggle_button->setAutoRaise(true);m_vertical_tabs_toggle_button->setFocusPolicy(Qt::NoFocus);m_vertical_tabs_toggle_button->setIconSize({ 16, 16 });- m_vertical_tabs_toggle_button->setFixedSize(VERTICAL_TABS_TOGGLE_BUTTON_SIZE, VERTICAL_TABS_TOGGLE_BUTTON_SIZE);+ m_vertical_tabs_toggle_button->set_size({ VERTICAL_TABS_TOGGLE_BUTTON_SIZE, VERTICAL_TABS_TOGGLE_BUTTON_SIZE });m_vertical_tabs_content_separator = new QWidget(this);m_vertical_tabs_content_separator->setObjectName("LadybirdVerticalTabsContentSeparator");@@ -3667,7 +3666,7 @@ void TabWidget::set_tab_bar_visible(bool visible)update_tab_layout();// NB: The collapsed sidebar's buttons sit in the toolbar, which a layout built while the tab bar was hidden left// without them.- place_collapsed_sidebar_buttons();+ place_toolbar_sidebar_buttons();}void TabWidget::set_window_controls_visible(bool visible)@@ -3786,7 +3785,7 @@ void TabWidget::set_vertical_tabs_expanded(bool expanded)m_vertical_tabs_toggle_animation->start();}-// The Ladybird and all-tabs buttons sit after the window controls, and the sidebar's toggle sits after them, in the toolbar+// On the left, the Ladybird and all-tabs buttons sit after the window controls, followed by the sidebar's toggle, in the toolbar// beside the collapsed sidebar. While the sidebar opens or closes, no layout holds them, so pictures of them stand in: The// Ladybird and all-tabs buttons keep their place, and the toggle rides the sidebar's edge. With everything in the sidebar,// the all-tabs button fades with the toolbar's row, and the toggle stays in its corner and needs no picture. The pictures@@ -3797,7 +3796,7 @@ void TabWidget::set_vertical_tabs_expanded(bool expanded)void TabWidget::float_sidebar_buttons_while_toggling(){auto controls_float = !use_native_macos_window_controls() && vertical_tabs_hold_window_controls();- auto floats = m_vertical_tabs_toggling && (!vertical_tabs_are_on_right() || controls_float);+ auto floats = m_vertical_tabs_toggling;if (!floats) {if (!m_floating_buttons_strip)return;@@ -3857,20 +3856,35 @@ void TabWidget::float_sidebar_buttons_while_toggling()auto center_y = [&](QWidget const& image) { return (toolbar_height - image.height()) / 2; };if (vertical_tabs_are_on_right()) {- // Only the window controls float on the right, anchored to the window's outer edge.- for (auto* image : { m_floating_ladybird_button, m_floating_all_tabs_button, m_floating_sidebar_toggle }) {- if (image)- image->hide();- }+ // The tab buttons and any window controls stay anchored to the window's right edge.+ if (m_floating_ladybird_button)+ m_floating_ladybird_button->hide();m_ladybird_button->show();- m_all_tabs_button->show();-- auto& controls = *m_floating_window_controls;- controls.move(0, center_y(controls));+ make_image(m_floating_all_tabs_button, *m_all_tabs_button);+ make_image(m_floating_sidebar_toggle, *m_vertical_tabs_toggle_button);++ m_all_tabs_button->hide();+ m_vertical_tabs_toggle_button->hide();+ m_floating_all_tabs_button->show();+ m_floating_sidebar_toggle->show();+ static_cast<QGraphicsOpacityEffect*>(m_floating_all_tabs_button->graphicsEffect())->setOpacity(1);++ auto& all_tabs = *m_floating_all_tabs_button;+ auto& toggle = *m_floating_sidebar_toggle;++ auto gap = m_toolbar->trailing_sidebar_slot().layout()->spacing();+ auto buttons_width = all_tabs.width() + gap + toggle.width();+ auto strip_left = width() - m_toolbar->trailing_sidebar_slot_right_inset(m_window_controls_visible) - buttons_width;+ all_tabs.move(0, center_y(all_tabs));+ toggle.move(all_tabs.width() + gap, center_y(toggle));++ if (controls_float) {+ auto& controls = *m_floating_window_controls;+ controls.move(width() - vertical_tabs_side_margin(true) - controls.width() - strip_left, center_y(controls));+ }- auto strip_width = controls.width() + vertical_tabs_side_margin(true);- m_floating_buttons_strip->setGeometry(width() - strip_width, 0, strip_width, toolbar_height);+ m_floating_buttons_strip->setGeometry(strip_left, 0, width() - strip_left, toolbar_height);m_floating_buttons_strip->show();m_floating_buttons_strip->raise();return;@@ -4386,6 +4400,11 @@ bool TabWidget::vertical_tabs_are_on_right() constreturn m_vertical_tabs_position == WebView::VerticalTabsPosition::Right;}+bool TabWidget::window_controls_are_on_left() const+{+ return (m_vertical_tabs_enabled && m_everything_in_sidebar) || window_controls_on_left();+}+int TabWidget::vertical_tabs_layout_width() const{if (!m_tab_bar_visible)@@ -4401,10 +4420,11 @@ bool TabWidget::should_show_window_controls_in_tab_toolbar() constreturn m_window_controls_visible && m_tab_bar->tab_layout() != TabLayout::Horizontal && !vertical_tabs_hold_window_controls() && !toolbar_is_in_sidebar();}-// The expanded sidebar holds the window controls when it is on the side chosen by the desktop.+// The expanded sidebar holds the window controls when they are on its side. With everything in the sidebar, they stay+// on the left so they remain visible without a toolbar row and keep their place as the sidebar toggles.bool TabWidget::vertical_tabs_hold_window_controls() const{- return m_window_controls_visible && m_vertical_tabs_expanded && (window_controls_on_left() != vertical_tabs_are_on_right());+ return m_window_controls_visible && m_vertical_tabs_expanded && (window_controls_are_on_left() != vertical_tabs_are_on_right());}// The Ladybird button keeps clear of the controls held by the expanded sidebar.@@ -4437,16 +4457,16 @@ int TabWidget::vertical_tabs_header_spacing() const// The open sidebar needs room for its window controls and header buttons even at its narrowest.int TabWidget::minimum_vertical_tabs_expanded_width() const{- auto has_window_controls = use_native_macos_window_controls() || (m_window_controls_visible && window_controls_on_left() != vertical_tabs_are_on_right());- if (!m_ladybird_buttons || (!has_window_controls && !m_everything_in_sidebar))- return VERTICAL_TABS_MIN_EXPANDED_WIDTH;- if (!use_native_macos_window_controls() && has_window_controls && vertical_tabs_are_on_right()) {- auto top_row_width = (2 * vertical_tabs_side_margin(true)) + SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN- + VERTICAL_TABS_TOGGLE_BUTTON_SIZE + SIDEBAR_TOGGLE_MINIMUM_GAP- + m_ladybird_button->sizeHint().width() + m_ladybird_buttons->layout()->spacing() + m_all_tabs_button->sizeHint().width()- + TOOLBAR_HORIZONTAL_MARGIN + m_window_controls->sizeHint().width();+ if (m_ladybird_buttons && vertical_tabs_are_on_right()) {+ auto top_row_width = vertical_tabs_side_margin(true) + SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN+ + m_all_tabs_button->sizeHint().width() + m_toolbar->trailing_sidebar_slot().layout()->spacing()+ + COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE.width() + m_toolbar->trailing_sidebar_slot_right_inset(m_window_controls_visible);return max(VERTICAL_TABS_MIN_EXPANDED_WIDTH, top_row_width);}++ auto has_window_controls = use_native_macos_window_controls() || (m_window_controls_visible && window_controls_are_on_left() != vertical_tabs_are_on_right());+ if (!m_ladybird_buttons || (!has_window_controls && !m_everything_in_sidebar))+ return VERTICAL_TABS_MIN_EXPANDED_WIDTH;// NB: With everything in the sidebar, the navigation buttons sit after the Ladybird button instead.auto after_ladybird_button = m_everything_in_sidebar? WindowToolbar::navigation_buttons_width_in_sidebar()@@ -4507,9 +4527,11 @@ void TabWidget::rebuild_layout()m_tab_bar->set_vertical_tabs_position(m_vertical_tabs_position);m_tab_bar->set_pinned_tabs_in_rows(m_vertical_tabs_hover_expanded && !m_vertical_tabs_expanded);m_tab_bar->set_tab_layout(current_tab_layout());+ if constexpr (!use_native_macos_window_controls())+ set_window_control_button_order(*m_window_controls, window_controls_are_on_left());m_vertical_tabs_expanded_width = clamp(m_vertical_tabs_expanded_width, minimum_vertical_tabs_expanded_width(), VERTICAL_TABS_MAX_EXPANDED_WIDTH);update_toolbar_window_controls_visibility();- m_toolbar->set_arrangement(toolbar_is_in_sidebar() ? ToolbarArrangement::Sidebar : ToolbarArrangement::Row, SIDEBAR_CONTENT_INSET - vertical_tabs_side_margin(true));+ m_toolbar->set_arrangement(toolbar_is_in_sidebar() ? ToolbarArrangement::Sidebar : ToolbarArrangement::Row, window_controls_are_on_left(), SIDEBAR_CONTENT_INSET - vertical_tabs_side_margin(true));place_all_tabs_and_sidebar_toggle();if (m_tab_bar->tab_layout() != TabLayout::Horizontal) {@@ -4565,7 +4587,7 @@ void TabWidget::rebuild_layout()update_tab_button_visibility();update_tab_chrome_visibility();update_tab_layout();- place_collapsed_sidebar_buttons();+ place_toolbar_sidebar_buttons();m_main_layout->activate();place_toolbar_over_page_column();}@@ -4774,14 +4796,34 @@ void TabWidget::place_sidebar_toggle_in_corner()m_vertical_tabs_toggle_button->raise();}-// With everything in the open sidebar, the all-tabs button starts its footer, after the toggle in the corner. It sits by-// the Ladybird button everywhere else.+// With everything in the open sidebar, the all-tabs button starts its footer. On the right it stays beside the sidebar+// toggle, and everywhere else it sits beside the Ladybird button.void TabWidget::place_all_tabs_and_sidebar_toggle(){+ if (m_tab_bar->tab_layout() != TabLayout::Horizontal && vertical_tabs_are_on_right()) {+ auto& slot = m_toolbar->trailing_sidebar_slot();+ auto* slot_layout = static_cast<QBoxLayout*>(slot.layout());++ if (m_all_tabs_button->parentWidget() != &slot) {+ m_all_tabs_button->setParent(&slot);+ slot_layout->insertWidget(0, m_all_tabs_button, 0, Qt::AlignVCenter);+ }++ if (m_vertical_tabs_toggle_button->parentWidget() != &slot) {+ m_vertical_tabs_toggle_button->setParent(&slot);+ slot_layout->insertWidget(1, m_vertical_tabs_toggle_button, 0, Qt::AlignVCenter);+ }++ m_vertical_tabs_toggle_button->set_size(COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE);+ m_vertical_tabs_toggle_button->show();+ m_all_tabs_button->show();+ return;+ }+if (sidebar_toggle_stays_in_corner()) {if (m_vertical_tabs_toggle_button->parentWidget() != m_vertical_tab_bar_column)m_vertical_tabs_toggle_button->setParent(m_vertical_tab_bar_column);- m_vertical_tabs_toggle_button->setFixedSize(COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE);+ m_vertical_tabs_toggle_button->set_size(COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE);m_vertical_tabs_toggle_button->show();place_sidebar_toggle_in_corner();auto toggle_right = m_vertical_tabs_toggle_button->geometry().right() + 1;@@ -4807,11 +4849,19 @@ void TabWidget::place_all_tabs_and_sidebar_toggle()m_all_tabs_button->show();}-void TabWidget::place_collapsed_sidebar_buttons()+void TabWidget::place_toolbar_sidebar_buttons(){- auto collapsed = m_tab_bar_visible && m_tab_bar->tab_layout() != TabLayout::Horizontal && !m_vertical_tabs_expanded;+ auto is_vertical = m_tab_bar->tab_layout() != TabLayout::Horizontal;+ auto on_right = is_vertical && vertical_tabs_are_on_right();+auto& slot = m_toolbar->sidebar_slot();- if (!collapsed) {+ auto& trailing_slot = m_toolbar->trailing_sidebar_slot();+ if (!on_right || !m_vertical_tabs_expanded)+ m_toolbar->restore_trailing_sidebar_slot();++ trailing_slot.setVisible(m_tab_bar_visible && on_right);++ if (!m_tab_bar_visible || !is_vertical || (m_vertical_tabs_expanded && !on_right)) {slot.hide();return;}@@ -4822,14 +4872,17 @@ void TabWidget::place_collapsed_sidebar_buttons()m_ladybird_button->set_tile_vertical_offset(0);slot_layout->insertWidget(0, m_ladybird_buttons, 0, Qt::AlignVCenter);}- if (!sidebar_toggle_stays_in_corner()) {++ if (!sidebar_toggle_stays_in_corner() && !on_right) {if (m_vertical_tabs_toggle_button->parentWidget() != &slot) {m_vertical_tabs_toggle_button->setParent(&slot);- m_vertical_tabs_toggle_button->setFixedSize(COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE);+ m_vertical_tabs_toggle_button->set_size(COLLAPSED_VERTICAL_TABS_TOGGLE_BUTTON_SIZE);slot_layout->insertWidget(1, m_vertical_tabs_toggle_button, 0, Qt::AlignVCenter);}+m_vertical_tabs_toggle_button->show();}+m_ladybird_buttons->show();slot.show();}@@ -4856,25 +4909,26 @@ void TabWidget::rebuild_layout_for_vertical_tabs()// collapsed sidebar, and the sidebar's toggle at the edge toward the page. With everything in the sidebar, the// navigation buttons are at that edge, the all-tabs button is in the footer, and the toggle is in its corner.//- // On the right, the window controls follow the all-tabs button. Without controls, the all-tabs button keeps as- // clear of the window's edge as the toggle is of the page.- auto trailing_margin = vertical_tabs_are_on_right() && vertical_tabs_hold_window_controls() ? 0 : SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN;+ // On the right, the app button stays in the toolbar. The tab buttons keep the toolbar's inset from the window's+ // right edge, so neither moves when the sidebar toggles.+ auto trailing_room = m_toolbar->trailing_sidebar_slot_right_inset(m_window_controls_visible) - vertical_tabs_side_margin(true);+ if (vertical_tabs_hold_window_controls())+ trailing_room -= m_window_controls->sizeHint().width();+ auto trailing_margin = vertical_tabs_are_on_right() ? (vertical_tabs_hold_window_controls() ? 0 : trailing_room) : SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN;top_row_layout->setContentsMargins(vertical_tabs_are_on_right() ? SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN : 0, 0, trailing_margin, 0);top_row_layout->addStrut(WindowToolbar::toolbar_height(should_show_window_controls_in_tab_toolbar()));- if (!sidebar_toggle_stays_in_corner()) {+ if (!sidebar_toggle_stays_in_corner() && !vertical_tabs_are_on_right()) {m_vertical_tabs_toggle_button->setParent(m_vertical_tab_bar_column);// NB: The button was smaller while it sat in the collapsed sidebar's slot.- m_vertical_tabs_toggle_button->setFixedSize(VERTICAL_TABS_TOGGLE_BUTTON_SIZE, VERTICAL_TABS_TOGGLE_BUTTON_SIZE);+ m_vertical_tabs_toggle_button->set_size({ VERTICAL_TABS_TOGGLE_BUTTON_SIZE, VERTICAL_TABS_TOGGLE_BUTTON_SIZE });m_vertical_tabs_toggle_button->show();}if (vertical_tabs_are_on_right()) {- if (!sidebar_toggle_stays_in_corner())- top_row_layout->addWidget(m_vertical_tabs_toggle_button, 0, Qt::AlignVCenter);- top_row_layout->addSpacing(SIDEBAR_TOGGLE_MINIMUM_GAP);top_row_layout->addStretch(1);- top_row_layout->addWidget(m_ladybird_buttons, 0, Qt::AlignVCenter);+ auto& buttons = m_toolbar->trailing_sidebar_slot();+ top_row_layout->addWidget(&buttons, 0, Qt::AlignVCenter);if (vertical_tabs_hold_window_controls()) {- top_row_layout->addSpacing(TOOLBAR_HORIZONTAL_MARGIN);+ top_row_layout->addSpacing(trailing_room);if (m_vertical_tabs_toggling)top_row_layout->addSpacing(m_window_controls->sizeHint().width());else@@ -4909,15 +4963,19 @@ void TabWidget::rebuild_layout_for_vertical_tabs()}} else {// The collapsed rail holds only tabs. The Ladybird and all-tabs buttons and the sidebar's toggle move to the- // toolbar, after the window controls (see place_collapsed_sidebar_buttons()). Its tabs start as far below the+ // toolbar, after the window controls (see place_toolbar_sidebar_buttons()). Its tabs start as far below the// toolbar as the open sidebar's start below its top row.m_vertical_tab_bar_column_layout->addSpacing(VERTICAL_TABS_TOP_MARGIN - VERTICAL_TAB_BAR_END_ROOM);}if (m_vertical_tabs_expanded) {- m_ladybird_buttons->setParent(m_vertical_tab_bar_column);- m_ladybird_button->set_tile_vertical_offset(0);- m_ladybird_buttons->show();+ if (!vertical_tabs_are_on_right()) {+ m_ladybird_buttons->setParent(m_vertical_tab_bar_column);+ m_ladybird_button->set_tile_vertical_offset(0);+ m_ladybird_buttons->show();+ }+m_vertical_tab_bar_column_layout->addLayout(top_row_layout);+if (toolbar_is_in_sidebar() && !toggle_moves_toolbar()) {// Below its top row, the sidebar holds the toolbar's navigation buttons and address field.m_vertical_tab_bar_column_layout->addWidget(m_toolbar);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 3abb8d370a5..27e5ec4755c 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -53,6 +53,7 @@ class QWheelEvent;namespace Ladybird {class AllTabsPopover;+class ChromeHeaderButton;class LadybirdButton;class SandboxOffBar;@@ -380,6 +381,7 @@ private:bool vertical_tabs_effectively_expanded() const;bool cursor_is_over_vertical_tabs() const;bool vertical_tabs_are_on_right() const;+ bool window_controls_are_on_left() const;int vertical_tabs_layout_width() const;bool should_show_window_controls_in_tab_toolbar() const;bool vertical_tabs_hold_window_controls() const;@@ -393,7 +395,7 @@ private:bool sidebar_toggle_stays_in_corner() const;void place_all_tabs_and_sidebar_toggle();void place_sidebar_toggle_in_corner();- void place_collapsed_sidebar_buttons();+ void place_toolbar_sidebar_buttons();void float_sidebar_buttons_while_toggling();bool slides_page_with_toggling_sidebar() const;void slide_page_with_toggling_sidebar();@@ -449,9 +451,9 @@ private:bool m_all_tabs_entries_update_is_pending { false };Vector<SessionWindowId> m_recently_closed_unit_ids;LadybirdButton* m_ladybird_button { nullptr };- // The Ladybird button and the all-tabs button after it, which move together.+ // The Ladybird button, with the all-tabs button when both are on the left.QWidget* m_ladybird_buttons { nullptr };- QToolButton* m_vertical_tabs_toggle_button { nullptr };+ ChromeHeaderButton* m_vertical_tabs_toggle_button { nullptr };QToolButton* m_minimize_window_button { nullptr };QToolButton* m_maximize_window_button { nullptr };QToolButton* m_close_window_button { nullptr };diff --git a/UI/Qt/WindowControlButton.cpp b/UI/Qt/WindowControlButton.cppindex b0f3064f602..6ad5e50b4f4 100644--- a/UI/Qt/WindowControlButton.cpp+++ b/UI/Qt/WindowControlButton.cpp@@ -219,6 +219,14 @@ bool window_controls_on_left()return use_native_macos_window_controls() || desktop_window_buttons().on_left;}+void set_window_control_button_order(QWidget& container, bool on_left)+{+ // Mirror the desktop's button order when moving the controls to the other side.+ auto* layout = static_cast<QBoxLayout*>(container.layout());+ layout->setDirection(on_left != window_controls_on_left() ? QBoxLayout::RightToLeft : QBoxLayout::LeftToRight);+ layout->activate();+}+WindowControlButtons create_window_control_buttons(QWidget& parent, char const* object_name, QSize icon_size, QSize button_size){auto* container = new QWidget(&parent);diff --git a/UI/Qt/WindowControlButton.h b/UI/Qt/WindowControlButton.hindex 6ddbf728e11..c637da57719 100644--- a/UI/Qt/WindowControlButton.h+++ b/UI/Qt/WindowControlButton.h@@ -60,6 +60,7 @@ struct WindowControlButtons {};bool window_controls_on_left();+void set_window_control_button_order(QWidget&, bool on_left);WindowControlButtons create_window_control_buttons(QWidget& parent, char const* object_name, QSize icon_size, QSize button_size);QWidget* create_window_controls_spacer(QWidget& parent, char const* object_name, QSize size);diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cppindex cda78b671e0..5495afbf294 100644--- a/UI/Qt/WindowToolbar.cpp+++ b/UI/Qt/WindowToolbar.cpp@@ -754,7 +754,7 @@ private:// focus ring takes the place of some of the toolbar's margin.static int toolbar_left_margin(bool has_custom_window_controls){- return has_custom_window_controls && window_controls_on_left() ? 0 : TOOLBAR_HORIZONTAL_MARGIN;+ return has_custom_window_controls ? 0 : TOOLBAR_HORIZONTAL_MARGIN;}static constexpr int toolbar_right_margin(bool has_custom_window_controls)@@ -1162,6 +1162,7 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent): QWidget(parent), WebView::SettingsObserver(Application::settings()), m_is_private(is_private)+ , m_window_controls_on_left(window_controls_on_left()){auto& application = ApplicationActions::the();@@ -1293,6 +1294,14 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)sidebar_slot_layout->addSpacing(SIDEBAR_SLOT_SEPARATOR_MARGIN);m_sidebar_slot->hide();+ m_trailing_sidebar_slot = new QWidget(m_toolbar);+ m_trailing_sidebar_slot->setObjectName("LadybirdTrailingSidebarSlot");+ m_trailing_sidebar_slot->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);+ auto* trailing_sidebar_slot_layout = new QHBoxLayout(m_trailing_sidebar_slot);+ trailing_sidebar_slot_layout->setContentsMargins(0, 0, 0, 0);+ trailing_sidebar_slot_layout->setSpacing(TOOLBAR_SPACING);+ m_trailing_sidebar_slot->hide();+m_sidebar_footer = new QWidget(this);m_sidebar_footer->setObjectName("LadybirdSidebarFooter");m_sidebar_footer->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);@@ -1349,6 +1358,24 @@ void WindowToolbar::size_navigation_buttons(QSize size, int spacing)m_navigation_buttons->layout()->setSpacing(spacing);}+void WindowToolbar::restore_trailing_sidebar_slot()+{+ if (m_arrangement != ToolbarArrangement::Row || m_trailing_sidebar_slot->parentWidget() == m_toolbar)+ return;+ auto* row_layout = static_cast<QBoxLayout*>(m_toolbar->layout());+ auto index = m_window_controls_on_left ? row_layout->count() : row_layout->indexOf(m_window_controls_separator);+ row_layout->insertWidget(index, m_trailing_sidebar_slot, 0, Qt::AlignVCenter);+}++int WindowToolbar::trailing_sidebar_slot_right_inset(bool window_controls_visible) const+{+ auto has_trailing_controls = !use_native_macos_window_controls() && !m_window_controls_on_left && window_controls_visible;+ auto inset = toolbar_right_margin(has_trailing_controls);+ if (has_trailing_controls)+ inset += m_window_controls->sizeHint().width() + m_window_controls_separator->width() + (2 * TOOLBAR_SPACING);+ return inset;+}+void WindowToolbar::lay_out_as_row(){size_navigation_buttons(TOOLBAR_BUTTON_SIZE, TOOLBAR_SPACING);@@ -1357,7 +1384,7 @@ void WindowToolbar::lay_out_as_row()toolbar_layout->setSpacing(TOOLBAR_SPACING);toolbar_layout->setContentsMargins(TOOLBAR_HORIZONTAL_MARGIN, 0, toolbar_right_margin(false), 0);- if (window_controls_on_left()) {+ if (m_window_controls_on_left) {toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);if constexpr (!use_native_macos_window_controls())toolbar_layout->addWidget(m_window_controls_separator, 0, Qt::AlignVCenter);@@ -1369,7 +1396,8 @@ void WindowToolbar::lay_out_as_row()toolbar_layout->addWidget(m_downloads_button, 0, Qt::AlignVCenter);if (m_feedback_button)toolbar_layout->addWidget(m_feedback_button, 0, Qt::AlignVCenter);- if (!window_controls_on_left()) {+ toolbar_layout->addWidget(m_trailing_sidebar_slot, 0, Qt::AlignVCenter);+ if (!m_window_controls_on_left) {toolbar_layout->addWidget(m_window_controls_separator, 0, Qt::AlignVCenter);toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);}@@ -1398,6 +1426,7 @@ void WindowToolbar::lay_out_in_sidebar()// NB: What the sidebar has no room for stays hidden, as widgets left out of a layout would show where they last were.m_sidebar_slot->hide();+ m_trailing_sidebar_slot->hide();m_window_controls->hide();m_window_controls_separator->hide();@@ -1578,12 +1607,15 @@ bool WindowToolbar::eventFilter(QObject* watched, QEvent* event)return false;}-void WindowToolbar::set_arrangement(ToolbarArrangement arrangement, int sidebar_inset)+void WindowToolbar::set_arrangement(ToolbarArrangement arrangement, bool window_controls_on_left, int sidebar_inset){- if (m_arrangement == arrangement && m_sidebar_inset == sidebar_inset)+ if (m_arrangement == arrangement && m_sidebar_inset == sidebar_inset && m_window_controls_on_left == window_controls_on_left)return;m_arrangement = arrangement;m_sidebar_inset = sidebar_inset;+ m_window_controls_on_left = window_controls_on_left;+ if constexpr (!use_native_macos_window_controls())+ set_window_control_button_order(*m_window_controls, window_controls_on_left);// NB: Deleting the layout leaves the widgets it held in place, ready for the next one.delete m_toolbar->layout();@@ -1805,8 +1837,7 @@ void WindowToolbar::set_window_controls_visible(bool visible)m_window_controls_separator->setVisible(has_custom_window_controls);m_window_controls->setVisible(has_native_window_controls || has_custom_window_controls);m_toolbar->setFixedHeight(toolbar_height(visible));- auto on_left = window_controls_on_left();- m_toolbar->layout()->setContentsMargins(toolbar_left_margin(has_custom_window_controls), 0, toolbar_right_margin(has_custom_window_controls && !on_left), 0);+ m_toolbar->layout()->setContentsMargins(toolbar_left_margin(has_custom_window_controls && m_window_controls_on_left), 0, toolbar_right_margin(has_custom_window_controls && !m_window_controls_on_left), 0);m_toolbar->layout()->invalidate();}@@ -1816,7 +1847,7 @@ int WindowToolbar::lead_beside_collapsed_sidebar(QWidget const& ladybird_buttons{auto toolbar_spacing = m_toolbar->layout()->spacing();auto lead = 0;- if (window_controls_on_left() && !m_window_controls->isHidden()) {+ if (m_window_controls_on_left && !m_window_controls->isHidden()) {lead += m_window_controls->width() + toolbar_spacing;if constexpr (!use_native_macos_window_controls())lead += m_window_controls_separator->width() + toolbar_spacing;@@ -1837,7 +1868,7 @@ void WindowToolbar::set_leading_room(int room)if (m_arrangement == ToolbarArrangement::Sidebar)return;auto has_custom_window_controls = !use_native_macos_window_controls() && m_window_controls_visible;- auto left_margin = toolbar_left_margin(has_custom_window_controls) + room;+ auto left_margin = toolbar_left_margin(has_custom_window_controls && m_window_controls_on_left) + room;auto margins = m_toolbar->layout()->contentsMargins();if (margins.left() == left_margin)return;diff --git a/UI/Qt/WindowToolbar.h b/UI/Qt/WindowToolbar.hindex 342c074ee84..9c01fb5c431 100644--- a/UI/Qt/WindowToolbar.h+++ b/UI/Qt/WindowToolbar.h@@ -63,9 +63,12 @@ public:void bind(Tab*);void release_location_edit(Tab&);- // While the sidebar is collapsed, the toolbar holds the Ladybird button and the sidebar's toggle, after the window- // controls, here.+ // While the sidebar is collapsed, the toolbar holds the Ladybird button and the left sidebar's toggle here.QWidget& sidebar_slot() { return *m_sidebar_slot; }+ // The right sidebar's all-tabs button and toggle sit before any right-side window controls.+ QWidget& trailing_sidebar_slot() { return *m_trailing_sidebar_slot; }+ void restore_trailing_sidebar_slot();+ int trailing_sidebar_slot_right_inset(bool window_controls_visible) const;QWidget& window_controls() { return *m_window_controls; }void set_window_controls_visible(bool);int lead_beside_collapsed_sidebar(QWidget const& ladybird_buttons, QSize sidebar_toggle_size) const;@@ -76,7 +79,7 @@ public:ToolbarArrangement arrangement() const { return m_arrangement; }// The sidebar's own margin plus the given inset keeps the toolbar's contents clear of the sidebar's edges.- void set_arrangement(ToolbarArrangement, int sidebar_inset = 0);+ void set_arrangement(ToolbarArrangement, bool window_controls_on_left, int sidebar_inset = 0);QWidget& sidebar_footer() { return *m_sidebar_footer; }QWidget& navigation_buttons() { return *m_navigation_buttons; }static int navigation_buttons_width_in_sidebar();@@ -148,6 +151,7 @@ private:QWidget* m_field_slot { nullptr };QWidget* m_suggestions_area { nullptr };bool m_window_controls_visible { false };+ bool m_window_controls_on_left { false };int m_sidebar_inset { 0 };int m_sidebar_footer_leading_room { 0 };qreal m_contents_opacity { 1 };@@ -159,6 +163,7 @@ private:PerformanceMonitorWidget* m_performance_monitor { nullptr };QWidget* m_window_controls_separator { nullptr };QWidget* m_sidebar_slot { nullptr };+ QWidget* m_trailing_sidebar_slot { nullptr };QWidget* m_window_controls { nullptr };QToolButton* m_minimize_window_button { nullptr };QToolButton* m_maximize_window_button { nullptr };