From 80554dc9140ee763e9b133fa52984db3f4aeadf8 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 3 Jun 2026 13:59:02 -0400 Subject: [PATCH] LibWebView+UI/Qt: Move the vertical tab width to LibWebView settings Let's store this alongside all other vertical tab settings. --- Libraries/LibWebView/Settings.cpp | 5 +++++ Libraries/LibWebView/Settings.h | 1 + Libraries/LibWebView/WebUI/SettingsUI.cpp | 6 ++++-- UI/Qt/Settings.cpp | 12 ------------ UI/Qt/Settings.h | 3 --- UI/Qt/TabBar.cpp | 10 +++++++--- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp index 7e3a227b29..8b61504a20 100644 --- a/Libraries/LibWebView/Settings.cpp +++ b/Libraries/LibWebView/Settings.cpp @@ -26,6 +26,7 @@ static constexpr auto TAB_SETTINGS_KEY = "tabs"sv; static constexpr auto VERTICAL_TABS_ENABLED_KEY = "verticalTabsEnabled"sv; static constexpr auto VERTICAL_TABS_EXPANDED_KEY = "verticalTabsExpanded"sv; static constexpr auto VERTICAL_TABS_EXPAND_ON_HOVER_KEY = "verticalTabsExpandOnHover"sv; +static constexpr auto VERTICAL_TABS_EXPANDED_WIDTH_KEY = "verticalTabsExpandedWidth"sv; static constexpr auto SHOW_BOOKMARKS_BAR_KEY = "showBookmarksBar"sv; static constexpr auto DEFAULT_SHOW_BOOKMARKS_BAR = true; @@ -296,6 +297,8 @@ JsonValue Settings::serialize_json() const tab_settings.set(VERTICAL_TABS_ENABLED_KEY, m_tab_settings.vertical_tabs_enabled); tab_settings.set(VERTICAL_TABS_EXPANDED_KEY, m_tab_settings.vertical_tabs_expanded); tab_settings.set(VERTICAL_TABS_EXPAND_ON_HOVER_KEY, m_tab_settings.vertical_tabs_expand_on_hover); + if (m_tab_settings.vertical_tabs_expanded_width.has_value()) + tab_settings.set(VERTICAL_TABS_EXPANDED_WIDTH_KEY, *m_tab_settings.vertical_tabs_expanded_width); settings.set(TAB_SETTINGS_KEY, move(tab_settings)); settings.set(SHOW_BOOKMARKS_BAR_KEY, m_show_bookmarks_bar); @@ -427,6 +430,8 @@ TabSettings Settings::parse_tab_settings(JsonValue const& settings) tab_settings.vertical_tabs_expanded = *vertical_tabs_expanded; if (auto vertical_tabs_expand_on_hover = settings.as_object().get_bool(VERTICAL_TABS_EXPAND_ON_HOVER_KEY); vertical_tabs_expand_on_hover.has_value()) tab_settings.vertical_tabs_expand_on_hover = *vertical_tabs_expand_on_hover; + if (auto vertical_tabs_expanded_width = settings.as_object().get_integer(VERTICAL_TABS_EXPANDED_WIDTH_KEY); vertical_tabs_expanded_width.has_value()) + tab_settings.vertical_tabs_expanded_width = *vertical_tabs_expanded_width; return tab_settings; } diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h index 7faef08bd6..6730ca1f3b 100644 --- a/Libraries/LibWebView/Settings.h +++ b/Libraries/LibWebView/Settings.h @@ -26,6 +26,7 @@ struct TabSettings { bool vertical_tabs_enabled { false }; bool vertical_tabs_expanded { true }; bool vertical_tabs_expand_on_hover { false }; + Optional vertical_tabs_expanded_width; }; struct BrowsingBehavior { diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp index c046f67401..c0d6f97075 100644 --- a/Libraries/LibWebView/WebUI/SettingsUI.cpp +++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp @@ -176,9 +176,11 @@ void SettingsUI::set_tab_settings(JsonValue const& tab_settings) { auto& settings = WebView::Application::settings(); auto parsed_tab_settings = Settings::parse_tab_settings(tab_settings); + auto const& current_tab_settings = settings.tab_settings(); - // Collapsed/expanded vertical tabs are not controlled by the settings UI. Don't overwrite it. - parsed_tab_settings.vertical_tabs_expanded = settings.tab_settings().vertical_tabs_expanded; + // Collapsed/expanded vertical tabs and their width are not controlled by the settings UI. Don't overwrite them. + parsed_tab_settings.vertical_tabs_expanded = current_tab_settings.vertical_tabs_expanded; + parsed_tab_settings.vertical_tabs_expanded_width = current_tab_settings.vertical_tabs_expanded_width; settings.set_tab_settings(parsed_tab_settings); load_current_settings(); diff --git a/UI/Qt/Settings.cpp b/UI/Qt/Settings.cpp index 9126ff0f04..d61355df90 100644 --- a/UI/Qt/Settings.cpp +++ b/UI/Qt/Settings.cpp @@ -73,16 +73,4 @@ void Settings::set_show_menubar(bool show_menubar) emit show_menubar_changed(show_menubar); } -Optional Settings::vertical_tabs_expanded_width() -{ - if (m_qsettings->contains("vertical_tabs_expanded_width")) - return m_qsettings->value("vertical_tabs_expanded_width").toInt(); - return {}; -} - -void Settings::set_vertical_tabs_expanded_width(int width) -{ - m_qsettings->setValue("vertical_tabs_expanded_width", width); -} - } diff --git a/UI/Qt/Settings.h b/UI/Qt/Settings.h index c9c7e1a84f..d2a4dccc19 100644 --- a/UI/Qt/Settings.h +++ b/UI/Qt/Settings.h @@ -45,9 +45,6 @@ public: bool show_menubar(); void set_show_menubar(bool show_menubar); - Optional vertical_tabs_expanded_width(); - void set_vertical_tabs_expanded_width(int); - signals: void show_menubar_changed(bool show_menubar); diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp index 5be0dd6c31..7bf3107f2c 100644 --- a/UI/Qt/TabBar.cpp +++ b/UI/Qt/TabBar.cpp @@ -16,7 +16,6 @@ # include #endif #include -#include #include #include #include @@ -1116,7 +1115,7 @@ TabWidget::TabWidget(QWidget* parent) if (auto* top_level_window = window(); top_level_window != this) top_level_window->installEventFilter(this); - m_vertical_tabs_expanded_width = Settings::the()->vertical_tabs_expanded_width().value_or(VERTICAL_TABS_DEFAULT_EXPANDED_WIDTH); + m_vertical_tabs_expanded_width = Application::settings().tab_settings().vertical_tabs_expanded_width.value_or(VERTICAL_TABS_DEFAULT_EXPANDED_WIDTH); m_vertical_tabs_expanded_width = clamp_vertical_tabs_expanded_width(m_vertical_tabs_expanded_width); m_tab_bar = new TabBar(this); @@ -1717,7 +1716,12 @@ void TabWidget::apply_vertical_tabs_expanded_width(int width) void TabWidget::persist_vertical_tabs_expanded_width() { - Settings::the()->set_vertical_tabs_expanded_width(m_vertical_tabs_expanded_width); + auto tab_settings = Application::settings().tab_settings(); + + using ValueType = decltype(tab_settings.vertical_tabs_expanded_width)::ValueType; + tab_settings.vertical_tabs_expanded_width = clamp(m_vertical_tabs_expanded_width, 0, NumericLimits::max()); + + Application::settings().set_tab_settings(tab_settings); } void TabWidget::set_resize_handle_property(char const* property, bool enabled)