Skip to content

Truly independent web browser

UI/Qt: Run the window controls to the window's edge

Andreas Kling995179bdad42
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 3c712025941..514ca25e6d3 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -68,6 +68,7 @@ static constexpr auto TAB_CLOSE_BUTTON_POSITION = QTabBar::RightSide;
static constexpr int LADYBIRD_MENU_WIDTH = 280;
static constexpr int WINDOW_RESIZE_BORDER_WIDTH = 6;
static constexpr int WINDOW_RESIZE_CORNER_WIDTH = WINDOW_RESIZE_BORDER_WIDTH * 2;
+static constexpr int MENU_BAR_LEADING_ROOM = 8;
#if defined(AK_OS_MACOS)
// NB: AppKit puts the traffic lights 10 px in, so they move this far to sit NATIVE_MACOS_WINDOW_CONTROLS_INSET in.
static constexpr int NATIVE_WINDOW_CONTROL_X_OFFSET = NATIVE_MACOS_WINDOW_CONTROLS_INSET - 10;
@@ -1313,6 +1314,13 @@ void BrowserWindow::create_menu_bar_window_controls()
m_menu_bar_close_window_button = window_control_buttons.close;
menuBar()->setCornerWidget(m_menu_bar_window_controls, Qt::TopRightCorner);
+ // NB: A menu bar insets its corner widgets by its leading padding, so the room before the first menu comes from
+ // a corner widget of its own, and the window controls can reach the window's edge.
+ auto* leading_room = new QWidget(menuBar());
+ auto* leading_room_layout = new QHBoxLayout(leading_room);
+ leading_room_layout->setContentsMargins(MENU_BAR_LEADING_ROOM, 0, 0, 0);
+ menuBar()->setCornerWidget(leading_room, Qt::TopLeftCorner);
+
connect(m_menu_bar_minimize_window_button, &QToolButton::clicked, this, [this] {
showMinimized();
});
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index e2e4ef4bacb..827ee74a2fa 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -381,7 +381,7 @@ QMenuBar#LadybirdMenuBar {{
color: {5};
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 {0}, stop:1 {1});
border: 0;
- padding: 0 4px 0 8px;
+ padding: 0 4px 0 0;
spacing: 2px;
}}
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index 5d36852f5c8..7a9f67a0b42 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -95,6 +95,8 @@ static constexpr int HORIZONTAL_WINDOW_ITEM_CENTER = 18;
static constexpr int HORIZONTAL_WINDOW_CONTROL_HEIGHT = 2 * (HORIZONTAL_WINDOW_ITEM_CENTER - (HORIZONTAL_TAB_STRIP_HEIGHT - HORIZONTAL_TAB_HEIGHT));
// The first item on the strip is as far from the window's edge as the traffic lights are from its corner on macOS.
static constexpr int HORIZONTAL_TAB_STRIP_LEADING_MARGIN = use_native_macos_window_controls() ? NATIVE_MACOS_WINDOW_CONTROLS_INSET : 13;
+// The window controls run to the window's edge.
+static constexpr int HORIZONTAL_TAB_STRIP_TRAILING_MARGIN = use_native_macos_window_controls() ? 8 : 0;
// Horizontal tabs shrink until they are just wide enough for their favicon, and past that the strip scrolls. Below the
// padded width, a tab gives up the room around its card and its content, until only its favicon is left.
static constexpr int HORIZONTAL_TAB_MIN_WIDTH = 20;
@@ -4151,7 +4153,7 @@ void TabWidget::rebuild_layout_for_horizontal_tabs()
{
m_tab_bar_row->setMinimumHeight(HORIZONTAL_TAB_STRIP_HEIGHT);
m_tab_bar_row_layout->setSpacing(0);
- m_tab_bar_row_layout->setContentsMargins(HORIZONTAL_TAB_STRIP_LEADING_MARGIN, HORIZONTAL_TAB_STRIP_HEIGHT - HORIZONTAL_TAB_HEIGHT, 8, 0);
+ m_tab_bar_row_layout->setContentsMargins(HORIZONTAL_TAB_STRIP_LEADING_MARGIN, HORIZONTAL_TAB_STRIP_HEIGHT - HORIZONTAL_TAB_HEIGHT, HORIZONTAL_TAB_STRIP_TRAILING_MARGIN, 0);
set_dynamic_property_if_needed(*m_new_tab_button, VERTICAL_TABS_EXPANDED_PROPERTY, false);
set_dynamic_property_if_needed(*m_new_tab_button, VERTICAL_TABS_BUTTON_PROPERTY, true);
@@ -4362,8 +4364,6 @@ void TabWidget::rebuild_layout_for_vertical_tabs()
set_dynamic_property_if_needed(*m_vertical_tab_bar_column, VERTICAL_TABS_POSITION_PROPERTY, vertical_tabs_position_property_value(m_vertical_tabs_position));
m_vertical_tab_bar_column_layout->setSpacing(0);
- if (auto* window_controls_layout = m_window_controls->layout())
- window_controls_layout->setContentsMargins(0, 0, 0, 0);
update_vertical_tabs_column_margins();
update_vertical_tabs_button_layout();
diff --git a/UI/Qt/WindowControlButton.cpp b/UI/Qt/WindowControlButton.cpp
index d8eb06eaa6c..c53cbda9498 100644
--- a/UI/Qt/WindowControlButton.cpp
+++ b/UI/Qt/WindowControlButton.cpp
@@ -32,6 +32,8 @@ namespace Ladybird {
// A round button is a 24 px circle at the end of its button, with a little room before it.
static constexpr int ROUND_BUTTON_SIZE = 24;
static constexpr int ROUND_BUTTON_LEADING_GAP = 6;
+// Square buttons run to the window's edge, but a circle keeps clear of it.
+static constexpr int ROUND_BUTTONS_TRAILING_GAP = 8;
// Its glyph is drawn in a 10 px box, with a heavier line than the hairlines of the square buttons.
static constexpr qreal ROUND_BUTTON_GLYPH_SIZE = 10;
static constexpr qreal ROUND_BUTTON_GLYPH_STROKE_WIDTH = 1.5;
@@ -171,6 +173,8 @@ WindowControlButtons create_window_control_buttons(QWidget& parent, char const*
close->setVisible(desktop_buttons.close);
for (auto* button : { minimize, maximize, close })
button->set_round(desktop_buttons.round);
+ if (desktop_buttons.round)
+ layout->setContentsMargins(0, 0, ROUND_BUTTONS_TRAILING_GAP, 0);
return { container, minimize, maximize, close };
}
diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cpp
index f271b8a11f0..737a610bce8 100644
--- a/UI/Qt/WindowToolbar.cpp
+++ b/UI/Qt/WindowToolbar.cpp
@@ -540,13 +540,12 @@ static constexpr int TOOLBAR_LOCATION_EDIT_MARGIN = 6;
// The address field's focus ring reaches 3 px past its edge. With the toolbar's spacing, this room also puts the
// downloads button 6 px after the field.
static constexpr int TOOLBAR_LOCATION_FOCUS_RING_ROOM = 4;
-static constexpr int TOOLBAR_WINDOW_CONTROLS_RIGHT_MARGIN = 4;
-// NB: Unless window controls follow it, the address field ends the toolbar, and the room for its focus ring takes the
-// place of some of the toolbar's margin.
+// NB: Window controls run to the window's edge. Without them, the address field ends the toolbar, and the room for its
+// focus ring takes the place of some of the toolbar's margin.
static constexpr int toolbar_right_margin(bool has_custom_window_controls)
{
- return has_custom_window_controls ? TOOLBAR_WINDOW_CONTROLS_RIGHT_MARGIN : TOOLBAR_HORIZONTAL_MARGIN - TOOLBAR_LOCATION_FOCUS_RING_ROOM;
+ return has_custom_window_controls ? 0 : TOOLBAR_HORIZONTAL_MARGIN - TOOLBAR_LOCATION_FOCUS_RING_ROOM;
}
static constexpr int DOWNLOADS_POPOVER_WIDTH = 380;
static constexpr int DOWNLOADS_POPOVER_MAX_HEIGHT = 360;