Skip to content

Truly independent web browser

UI/Qt: Lighten the tab strip of an inactive window

Andreas Kling4b5d382edae4
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index b9ab710bdc8..dee4a79aade 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -19,6 +19,7 @@
#include <QPainterPath>
#include <QPalette>
#include <QStyleHints>
+#include <QWidget>
namespace Ladybird::ChromeStyle {
@@ -124,10 +125,19 @@ QColor mix(QColor const& from, QColor const& to, double amount)
}
// The tab strip is darker than the toolbar below it, whose color the selected tab shares, so the selected tab stands out.
-QColor chrome_tab_strip_background(QPalette const& palette)
+WindowActivity window_activity(QWidget const& widget)
+{
+ return widget.isActiveWindow() ? WindowActivity::Active : WindowActivity::Inactive;
+}
+
+QColor chrome_tab_strip_background(QPalette const& palette, WindowActivity activity)
{
auto dark = is_dark(palette);
- return mix(chrome_window(palette), material_color_anchors(dark).tab_strip, dark ? 0.70 : 0.68);
+ auto color = mix(chrome_window(palette), material_color_anchors(dark).tab_strip, dark ? 0.70 : 0.68);
+ // An inactive window's tab strip is lifted toward the toolbar, so the window recedes behind the active one.
+ if (activity == WindowActivity::Inactive)
+ color = mix(color, chrome_background(palette), 0.4);
+ return color;
}
// In dark mode, the chrome is lifted from near black toward a cool slate rather than a plain gray.
@@ -1210,6 +1220,7 @@ QString tab_widget_style_sheet(QPalette const& palette)
auto dark = is_dark(palette);
auto tab_strip_background = chrome_tab_strip_background(palette);
auto background = style_sheet_color(tab_strip_background);
+ auto inactive_background = style_sheet_color(chrome_tab_strip_background(palette, WindowActivity::Inactive));
auto hover = style_sheet_color(chrome_control_surface_hover(palette));
auto pressed = style_sheet_color(chrome_control_surface_pressed(palette));
auto control_border = style_sheet_color(chrome_control_border(palette));
@@ -1256,6 +1267,11 @@ QToolButton#LadybirdVerticalTabsToggleButton {{
padding: 0;
}}
+QWidget#LadybirdTabStrip[windowInactive="true"],
+QWidget#LadybirdVerticalTabBar[windowInactive="true"] {{
+ background: {9};
+}}
+
QWidget#LadybirdVerticalTabsResizeHandle {{
background: transparent;
border: 0;
@@ -1389,7 +1405,7 @@ QWidget#LadybirdVerticalTabsContentSeparator {{
)"
#endif
,
- background, hover, pressed, control_border, text, close_hover, close_text, sidebar_separator, sidebar_separator_hover);
+ background, hover, pressed, control_border, text, close_hover, close_text, sidebar_separator, sidebar_separator_hover, inactive_background);
}
QString autocomplete_popup_style_sheet(QPalette const& palette)
diff --git a/UI/Qt/ChromeStyle.h b/UI/Qt/ChromeStyle.h
index 8088c248958..2be27ef6823 100644
--- a/UI/Qt/ChromeStyle.h
+++ b/UI/Qt/ChromeStyle.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/Optional.h>
+#include <AK/Types.h>
#include <QColor>
#include <QString>
@@ -15,6 +16,7 @@ class QFont;
class QPainter;
class QPainterPath;
class QPalette;
+class QWidget;
namespace Ladybird::ChromeStyle {
@@ -25,7 +27,13 @@ bool is_dark(QPalette const&);
QColor mix(QColor const& from, QColor const& to, double amount);
QColor chrome_text(QPalette const&);
QColor chrome_button_text(QPalette const&);
-QColor chrome_tab_strip_background(QPalette const&);
+enum class WindowActivity : u8 {
+ Active,
+ Inactive,
+};
+WindowActivity window_activity(QWidget const&);
+
+QColor chrome_tab_strip_background(QPalette const&, WindowActivity = WindowActivity::Active);
QColor chrome_background(QPalette const&);
QColor chrome_surface(QPalette const&);
QColor chrome_surface_recessed(QPalette const&);
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 1f1922f23f0..08ec3444c69 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1880,7 +1880,7 @@ void Tab::paintEvent(QPaintEvent*)
inside.addEllipse(curve_left, height() - (2 * radius), 2 * radius, 2 * radius);
painter.setRenderHint(QPainter::Antialiasing, true);
- painter.fillPath(corner.subtracted(inside), ChromeStyle::chrome_tab_strip_background(palette));
+ painter.fillPath(corner.subtracted(inside), ChromeStyle::chrome_tab_strip_background(palette, ChromeStyle::window_activity(*this)));
}
#endif
@@ -1934,6 +1934,10 @@ void Tab::hide_hover_label()
bool Tab::event(QEvent* event)
{
+ // The sidebar's color, which the frame around the page bends around, follows the window's activity.
+ if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowDeactivate)
+ update();
+
if (event->type() == QEvent::PaletteChange && is_loaded()) {
update_chrome_style();
recreate_toolbar_icons();
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index c4155dd30c5..308eb9d4a43 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -148,6 +148,7 @@ static constexpr auto FULL_WIDTH_TOOLBAR_PROPERTY = "fullWidthToolbar";
static constexpr auto VERTICAL_TABS_EXPANDED_PROPERTY = "verticalTabsExpanded";
static constexpr auto VERTICAL_TABS_BUTTON_PROPERTY = "verticalTabsButton";
static constexpr auto VERTICAL_TABS_POSITION_PROPERTY = "verticalTabsPosition";
+static constexpr auto WINDOW_INACTIVE_PROPERTY = "windowInactive";
static constexpr auto VERTICAL_TABS_RESIZE_HANDLE_HOVERED_PROPERTY = "hovered";
static constexpr auto VERTICAL_TABS_RESIZE_HANDLE_ACTIVE_PROPERTY = "active";
@@ -365,10 +366,12 @@ static QColor tab_hover_surface(QPalette const& palette, qreal hover_progress)
return color;
}
-static QColor horizontal_tab_separator(QPalette const& palette)
+static QColor horizontal_tab_separator(QWidget const& widget)
{
+ auto const& palette = widget.palette();
auto dark = ChromeStyle::is_dark(palette);
- return ChromeStyle::mix(ChromeStyle::chrome_tab_strip_background(palette), ChromeStyle::chrome_text(palette), dark ? 0.18 : 0.25);
+ auto background = ChromeStyle::chrome_tab_strip_background(palette, ChromeStyle::window_activity(widget));
+ return ChromeStyle::mix(background, ChromeStyle::chrome_text(palette), dark ? 0.18 : 0.25);
}
static QRectF collapsed_vertical_tab_shape_rect(QRectF const& rect)
@@ -900,6 +903,10 @@ void TabBar::tabLayoutChange()
bool TabBar::event(QEvent* event)
{
+ // The separators between tabs are mixed from the tab strip's color, which follows the window's activity.
+ if (event->type() == QEvent::WindowActivate || event->type() == QEvent::WindowDeactivate)
+ update();
+
// The swirl stops while the tab bar is hidden, so it has to start again for tabs still loading when it is shown.
if (event->type() == QEvent::Show)
update_loading_swirl_animation();
@@ -1009,7 +1016,7 @@ void TabBar::paintEvent(QPaintEvent*)
QRectF separator_rect { separator_x, separator_center_y - (HORIZONTAL_TAB_SEPARATOR_HEIGHT / 2.0), HORIZONTAL_TAB_SEPARATOR_WIDTH, HORIZONTAL_TAB_SEPARATOR_HEIGHT };
painter.save();
painter.setOpacity(separator_opacity);
- painter.fillRect(separator_rect, horizontal_tab_separator(palette()));
+ painter.fillRect(separator_rect, horizontal_tab_separator(*this));
painter.restore();
}
}
@@ -2674,6 +2681,11 @@ bool TabWidget::event(QEvent* event)
update_chrome_style();
} else if (type == QEvent::WindowStateChange) {
update_window_button_icons();
+ } else if (type == QEvent::WindowActivate || type == QEvent::WindowDeactivate) {
+ // The tab strip and the sidebar are lighter while the window is inactive.
+ auto inactive = type == QEvent::WindowDeactivate;
+ set_dynamic_property_if_needed(*m_tab_bar_row, WINDOW_INACTIVE_PROPERTY, inactive);
+ set_dynamic_property_if_needed(*m_vertical_tab_bar_column, WINDOW_INACTIVE_PROPERTY, inactive);
} else if (type == QEvent::Leave) {
defer_update_vertical_tabs_hover_expanded();
}