Truly independent web browser
UI/Qt: Reveal the window controls in the page's corner on demand
Andreas Klingeeb0bf6648cd
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 2766bb9719c..f16e2a8a2f2 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -135,7 +135,7 @@ All sizes are in logical pixels.| Header | Traffic lights, Ladybird button, all tabs, then empty space, then the hide-sidebar toggle at the sidebar's right edge. With the sidebar collapsed, the toolbar starts the same way: traffic lights, Ladybird button, all tabs, show-sidebar toggle. || Background | `sidebar` token: the strip color in light, the toolbar color in dark and private. The page must never sit directly against near-black chrome. || Sidebar on the right | Only the sidebar moves: tab list, rail and the hide/show toggle, which sits at the sidebar's inner edge (facing the page). The traffic lights, Ladybird button and All tabs button stay top left, at the start of the toolbar row, exactly as in collapsed mode. Rail badges keep their corners (× top left, speaker bottom right). Dragging a tab out of the sidebar goes sideways toward the page. On Windows, the sidebar header holds the minimize, maximize and close buttons, with the toggle to their left. Settings → Appearance → Layout shows "Sidebar on: Left / Right" below the layout cards, only while Tabs on the side is selected. |-| Everything in the sidebar | A third tab layout (Arc/Zen style): no toolbar row; the page runs to the top of the window. The sidebar holds, top to bottom: the top row (traffic lights, Ladybird button, then back, forward and reload at the right end, 26 × 28 each so they fit), the full-width address field directly below it, 4 px down (domain only while idle; the full URL when focused), pinned tabs, the tab list and new tab, and a bottom bar with the sidebar toggle and All tabs on the left and Feedback and Downloads on the right. This is the one layout where All tabs and the toggle leave the top row: keeping the top row to one quiet line, like Arc and Zen, is worth more here than matching the other layouts. Same `sidebar` color and opaque chrome as the normal sidebar: no inset page card, no gradients, no translucency. The page meets the sidebar at the `divider` line. Focus alone never grows the field: focused and empty (a new tab, startup, ⌘L on a blank tab) it stays sidebar width with its focus ring. It grows into the suggestions surface (see Suggestions), 600 px wide over the page, only once there are rows to show. If the text is cleared and no rows are left, it shrinks back. Esc, Return or a click outside also shrink it back to the sidebar field. The panel is never shown empty. Collapsing the sidebar falls back to the normal collapsed layout (toolbar row plus rail), except that the sidebar toggle stays at the bottom left of the rail, in the same place as in the open sidebar. In Settings → Appearance → Layout it is the third card, "Everything in the sidebar". |+| Everything in the sidebar | A third tab layout (Arc/Zen style): no toolbar row; the page runs to the top of the window. The sidebar holds, top to bottom: the top row (traffic lights, Ladybird button, then back, forward and reload at the right end, 26 × 28 each so they fit), the full-width address field directly below it, 4 px down (domain only while idle; the full URL when focused), pinned tabs, the tab list and new tab, and a bottom bar with the sidebar toggle and All tabs on the left and Feedback and Downloads on the right. This is the one layout where All tabs and the toggle leave the top row: keeping the top row to one quiet line, like Arc and Zen, is worth more here than matching the other layouts. Same `sidebar` color and opaque chrome as the normal sidebar: no inset page card, no gradients, no translucency. The page meets the sidebar at the `divider` line. Focus alone never grows the field: focused and empty (a new tab, startup, ⌘L on a blank tab) it stays sidebar width with its focus ring. It grows into the suggestions surface (see Suggestions), 600 px wide over the page, only once there are rows to show. If the text is cleared and no rows are left, it shrinks back. Esc, Return or a click outside also shrink it back to the sidebar field. The panel is never shown empty. Collapsing the sidebar falls back to the normal collapsed layout (toolbar row plus rail), except that the sidebar toggle stays at the bottom left of the rail, in the same place as in the open sidebar. In Settings → Appearance → Layout it is the third card, "Everything in the sidebar". On Windows and Linux, nothing holds the minimize, maximize and close buttons here, so they stay out of sight: when the pointer comes within 10 px of the window's top edge above where they go, they slide down over the page's top right corner in the `sidebar` color, with the `divider` line along their two edges on the page. The corner stays square, as they are a native surface that can't show the page through a rounded one. They slide away 300 ms after the pointer leaves them, with 16 px of leeway. A drag that ends up in the corner doesn't reveal them. |### Popovers and pagesdiff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txtindex 85730fae60b..737d27395ce 100644--- a/UI/Qt/CMakeLists.txt+++ b/UI/Qt/CMakeLists.txt@@ -57,6 +57,7 @@ add_library(ladybird_impl STATICWebContentView.cppWindowCloseCoordinator.cppWindowControlButton.cpp+ WindowControlsReveal.cppWindowScreenObserver.cppWindowToolbar.cpp)diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex 3d828509225..89fe1c3419d 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -36,6 +36,7 @@# include <UI/Qt/WaylandWindow.h>#endif#include <UI/Qt/WindowControlButton.h>+#include <UI/Qt/WindowControlsReveal.h>#include <QApplication>#include <QContextMenuEvent>@@ -3271,6 +3272,7 @@ TabWidget::TabWidget(WebView::IsPrivate is_private, QWidget* parent)m_minimize_window_button = window_control_buttons.minimize;m_maximize_window_button = window_control_buttons.maximize;m_close_window_button = window_control_buttons.close;+ m_window_controls_reveal = new WindowControlsReveal(*this, *m_page_column);}recreate_icons();@@ -3844,8 +3846,6 @@ void TabWidget::move_toolbar_with_toggling_sidebar()auto& navigation_buttons = m_toolbar->navigation_buttons();auto navigation_buttons_size = navigation_buttons.sizeHint();auto navigation_buttons_right = open_width - side_margin - SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN;- if constexpr (!use_native_macos_window_controls())- navigation_buttons_right -= m_window_controls->width();navigation_buttons.setGeometry(navigation_buttons_right - navigation_buttons_size.width(), (top_row_bottom - navigation_buttons_size.height()) / 2, navigation_buttons_size.width(), navigation_buttons_size.height());auto& footer = m_toolbar->sidebar_footer();auto footer_height = footer.sizeHint().height();@@ -4269,8 +4269,7 @@ int TabWidget::minimum_vertical_tabs_expanded_width() const+ SIDEBAR_TOGGLE_PAGE_SIDE_MARGIN + vertical_tabs_side_margin(true);if (use_native_macos_window_controls())return top_row_width;- // NB: Without the system's own window controls, they end the sidebar's top row.- return max(VERTICAL_TABS_MIN_EXPANDED_WIDTH, top_row_width + (m_window_controls_visible ? m_window_controls->sizeHint().width() : 0));+ return max(VERTICAL_TABS_MIN_EXPANDED_WIDTH, top_row_width);}// How far the opening or closing sidebar is from open, from 0 when open to 1 when collapsed.@@ -4702,9 +4701,6 @@ void TabWidget::rebuild_layout_for_vertical_tabs()} else if (!sidebar_toggle_stays_in_corner()) {top_row_layout->addWidget(m_vertical_tabs_toggle_button, 0, Qt::AlignVCenter);}- // Without a toolbar row, the window controls that aren't the system's own end the sidebar's top row.- if (!use_native_macos_window_controls() && toolbar_is_in_sidebar())- top_row_layout->addWidget(m_window_controls, 0, Qt::AlignTop);}} else {// The collapsed rail holds only tabs. The Ladybird and all-tabs buttons and the sidebar's toggle move to the@@ -5101,6 +5097,14 @@ void TabWidget::update_tab_chrome_visibility()auto show_window_controls = m_window_controls_visible&& m_tab_bar_visible&& (is_horizontal || (!use_native_macos_window_controls() && toolbar_is_in_sidebar()));+ if (m_window_controls_reveal) {+ // NB: Without a toolbar row or a tab strip, nothing holds the window controls, so they stay out of sight.+ if (show_window_controls && !is_horizontal) {+ m_window_controls_reveal->hold(*m_window_controls);+ return;+ }+ m_window_controls_reveal->release();+ }m_window_controls->setVisible(show_window_controls);}@@ -5134,6 +5138,8 @@ void TabWidget::update_chrome_style()m_vertical_tab_bar_column->setStyleSheet(style_sheet);m_vertical_tabs_content_separator->setStyleSheet(style_sheet);m_vertical_tabs_resize_handle->setStyleSheet(style_sheet);+ if (m_window_controls_reveal)+ m_window_controls_reveal->setStyleSheet(style_sheet);auto reserved_space_palette = m_vertical_tabs_reserved_space->palette();reserved_space_palette.setColor(QPalette::Window, ChromeStyle::chrome_sidebar_background(Theme::chrome_palette(*this)));m_vertical_tabs_reserved_space->setPalette(reserved_space_palette);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 679efaeea16..207409a68f8 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -56,6 +56,7 @@ class LadybirdButton;class TabPreviewPopup;class TabWidget;+class WindowControlsReveal;static constexpr int TAB_ICON_SIZE = 16;@@ -441,6 +442,7 @@ private:QToolButton* m_maximize_window_button { nullptr };QToolButton* m_close_window_button { nullptr };QWidget* m_window_controls { nullptr };+ WindowControlsReveal* m_window_controls_reveal { nullptr };WindowToolbar* m_toolbar { nullptr };BookmarksBarContainer* m_bookmarks_bar { nullptr };QWidget* m_page_column { nullptr };diff --git a/UI/Qt/WindowControlsReveal.cpp b/UI/Qt/WindowControlsReveal.cppnew file mode 100644index 00000000000..53e943fba57--- /dev/null+++ b/UI/Qt/WindowControlsReveal.cpp@@ -0,0 +1,197 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <UI/Qt/Motion.h>+#include <UI/Qt/SystemAppearance.h>+#include <UI/Qt/Theme.h>+#include <UI/Qt/WindowControlsReveal.h>++#include <QApplication>+#include <QEvent>+#include <QMouseEvent>+#include <QPainter>+#include <QTimer>+#include <QVariantAnimation>+#include <QWindow>++namespace Ladybird {++// The pointer has to come this close to the top of the page, so that what a page has in its corner stays in reach.+static constexpr int REVEAL_ZONE_HEIGHT = 10;+// The window's outline is around the page, and a pointer thrown into the corner of the window ends up on it.+static constexpr int WINDOW_EDGE_ROOM = 2;+// The pointer can stray this far from the controls for a moment without them leaving.+static constexpr int CONCEAL_MARGIN = 16;+static constexpr int CONCEAL_DELAY_MS = 300;++WindowControlsReveal::WindowControlsReveal(QWidget& parent, QWidget& page)+ : QWidget(&parent)+ , m_page(page)+{+ setObjectName("LadybirdWindowControlsReveal");+ // OPTIMIZATION: A native child that Qt creates as it is shown stacks above whatever presents the page, so the page+ // doesn't have to step aside, and be painted by Qt, each time the pointer passes through the corner.+ setAttribute(Qt::WA_DontCreateNativeAncestors);+ setAttribute(Qt::WA_NativeWindow);+ hide();++ m_conceal_timer = new QTimer(this);+ m_conceal_timer->setSingleShot(true);+ m_conceal_timer->setInterval(CONCEAL_DELAY_MS);+ connect(m_conceal_timer, &QTimer::timeout, this, [this] {+ // NB: The controls can slide in under a pointer at rest, which only tells the window that the pointer left it.+ if (!underMouse())+ set_revealed(false);+ });++ m_animation = new QVariantAnimation(this);+ connect(m_animation, &QVariantAnimation::valueChanged, this, [this](QVariant const& value) {+ // NB: Setting the next run's values reports them as of where the last run ended.+ if (m_animation->state() != QAbstractAnimation::Running)+ return;+ m_progress = value.toReal();+ place();+ });+}++void WindowControlsReveal::hold(QWidget& window_controls)+{+ if (m_window_controls == &window_controls)+ return;+ m_window_controls = &window_controls;+ window_controls.setParent(this);+ m_page.installEventFilter(this);+ qApp->installEventFilter(this);+}++void WindowControlsReveal::release()+{+ if (!m_window_controls)+ return;+ m_window_controls = nullptr;+ m_page.removeEventFilter(this);+ qApp->removeEventFilter(this);+ m_conceal_timer->stop();+ m_animation->stop();+ m_revealed = false;+ m_progress = 0;+ hide();+}++bool WindowControlsReveal::event_is_for_this_window(QObject* watched) const+{+ // NB: The pointer's events go to the windows first, which see it wherever the widgets under it don't track it.+ auto* event_window = qobject_cast<QWindow*>(watched);+ if (!event_window)+ return false;+ while (event_window->parent())+ event_window = event_window->parent();+ return event_window == window()->windowHandle();+}++bool WindowControlsReveal::eventFilter(QObject* watched, QEvent* event)+{+ switch (event->type()) {+ case QEvent::Move:+ case QEvent::Resize:+ if (watched == &m_page)+ place();+ break;+ case QEvent::MouseMove:+ if (event_is_for_this_window(watched)) {+ auto const& mouse_event = *static_cast<QMouseEvent*>(event);+ pointer_moved(mouse_event.globalPosition(), mouse_event.buttons() != Qt::NoButton);+ }+ break;+ case QEvent::Leave:+ if (m_revealed && event_is_for_this_window(watched))+ m_conceal_timer->start();+ break;+ default:+ break;+ }+ return false;+}++QRect WindowControlsReveal::rect_when_revealed() const+{+ auto size = m_window_controls->sizeHint();+ auto top_right = m_page.mapTo(parentWidget(), QPoint(m_page.width(), 0));+ return { top_right - QPoint(size.width(), 0), size };+}++void WindowControlsReveal::pointer_moved(QPointF global_position, bool button_is_down)+{+ auto position = parentWidget()->mapFromGlobal(global_position).toPoint();+ auto revealed_rect = rect_when_revealed();++ if (m_revealed) {+ if (revealed_rect.adjusted(-CONCEAL_MARGIN, -WINDOW_EDGE_ROOM, WINDOW_EDGE_ROOM, CONCEAL_MARGIN).contains(position))+ m_conceal_timer->stop();+ else if (!m_conceal_timer->isActive())+ m_conceal_timer->start();+ return;+ }++ // NB: A drag that ends up in the corner, such as a text selection, isn't headed for the window controls.+ auto reveal_zone = QRect(revealed_rect.topLeft(), QSize(revealed_rect.width(), REVEAL_ZONE_HEIGHT)).adjusted(0, -WINDOW_EDGE_ROOM, WINDOW_EDGE_ROOM, 0);+ if (!button_is_down && reveal_zone.contains(position))+ set_revealed(true);+}++void WindowControlsReveal::set_revealed(bool revealed)+{+ if (m_revealed == revealed)+ return;+ m_revealed = revealed;+ m_conceal_timer->stop();+ m_animation->stop();++ if (SystemAppearance::prefers_reduced_motion()) {+ m_progress = revealed ? 1 : 0;+ place();+ return;+ }+ m_animation->setStartValue(m_progress);+ m_animation->setEndValue(revealed ? 1.0 : 0.0);+ m_animation->setDuration(revealed ? Motion::FAST : Motion::EXIT);+ m_animation->setEasingCurve(revealed ? Motion::enter_easing() : Motion::exit_easing());+ m_animation->start();+}++// The controls slide out from under the top of the window: only their bottom shows at first, at their full size.+void WindowControlsReveal::place()+{+ if (!m_window_controls)+ return;+ auto height = qRound(rect_when_revealed().height() * m_progress);+ if (height == 0) {+ hide();+ return;+ }++ auto rect = rect_when_revealed();+ setGeometry(rect.x(), rect.y(), rect.width(), height);+ m_window_controls->setGeometry(0, height - rect.height(), rect.width(), rect.height());+ m_window_controls->show();+ if (isHidden()) {+ show();+ raise();+ }+ update();+}++// NB: The corner toward the page stays square, as a native surface can't show the page through a rounded one.+void WindowControlsReveal::paintEvent(QPaintEvent*)+{+ QPainter painter(this);+ auto const& chrome = Theme::chrome(*this);+ painter.fillRect(rect(), chrome.sidebar);+ painter.fillRect(0, 0, 1, height(), chrome.divider);+ painter.fillRect(0, height() - 1, width(), 1, chrome.divider);+}++}diff --git a/UI/Qt/WindowControlsReveal.h b/UI/Qt/WindowControlsReveal.hnew file mode 100644index 00000000000..5bb90b94a69--- /dev/null+++ b/UI/Qt/WindowControlsReveal.h@@ -0,0 +1,50 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/kmalloc.h>++#include <QPointF>+#include <QRect>+#include <QWidget>++class QTimer;+class QVariantAnimation;++namespace Ladybird {++// With everything in the sidebar, there is no toolbar or tab strip to hold the window controls, and the page runs to+// the top of the window. So they stay out of sight until the pointer reaches the top of the window over the page's far+// corner, and then slide down over the page until it leaves them.+class WindowControlsReveal final : public QWidget {+public:+ AK_ALLOC_WITH_KMALLOC;++ WindowControlsReveal(QWidget& parent, QWidget& page);++ void hold(QWidget& window_controls);+ void release();++private:+ virtual bool eventFilter(QObject* watched, QEvent* event) override;+ virtual void paintEvent(QPaintEvent*) override;++ bool event_is_for_this_window(QObject* watched) const;+ QRect rect_when_revealed() const;+ void pointer_moved(QPointF global_position, bool button_is_down);+ void set_revealed(bool);+ void place();++ QWidget& m_page;+ QWidget* m_window_controls { nullptr };+ QTimer* m_conceal_timer { nullptr };+ QVariantAnimation* m_animation { nullptr };+ bool m_revealed { false };+ qreal m_progress { 0 };+};++}