From 0e798234c7cb45012910584215783694433a7cdc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 31 Mar 2021 23:22:06 +0200 Subject: [PATCH] WindowServer+LibGfx: Remove code for drawing the old-style menu bar --- Base/res/themes/Default.ini | 1 - Userland/Libraries/LibGfx/Palette.h | 1 - Userland/Libraries/LibGfx/SystemTheme.cpp | 1 - Userland/Libraries/LibGfx/SystemTheme.h | 1 - Userland/Services/WindowServer/Menu.cpp | 5 +-- .../Services/WindowServer/MenuManager.cpp | 44 +------------------ Userland/Services/WindowServer/MenuManager.h | 15 ------- Userland/Services/WindowServer/Window.cpp | 5 ++- .../Services/WindowServer/WindowFrame.cpp | 5 --- .../Services/WindowServer/WindowManager.cpp | 2 - .../Services/WindowServer/WindowManager.h | 4 -- Userland/Services/WindowServer/WindowType.h | 1 - 12 files changed, 6 insertions(+), 79 deletions(-) diff --git a/Base/res/themes/Default.ini b/Base/res/themes/Default.ini index 7bba9cd62f..3b7ab90f77 100644 --- a/Base/res/themes/Default.ini +++ b/Base/res/themes/Default.ini @@ -75,7 +75,6 @@ TitleButtonHeight=15 [Paths] ActiveWindowShadow=/res/icons/themes/Default/frame-shadow-dark.png InactiveWindowShadow=/res/icons/themes/Default/frame-shadow-light.png -MenuBarShadow=/res/icons/themes/Default/frame-shadow-light.png MenuShadow=/res/icons/themes/Default/frame-shadow-light.png TaskBarShadow=/res/icons/themes/Default/frame-shadow-light.png TooltipShadow=/res/icons/themes/Default/frame-shadow-light.png diff --git a/Userland/Libraries/LibGfx/Palette.h b/Userland/Libraries/LibGfx/Palette.h index 9d1c65bdbd..1c87a73b33 100644 --- a/Userland/Libraries/LibGfx/Palette.h +++ b/Userland/Libraries/LibGfx/Palette.h @@ -142,7 +142,6 @@ public: String title_button_icons_path() const { return path(PathRole::TitleButtonIcons); } String active_window_shadow_path() const { return path(PathRole::ActiveWindowShadow); } String inactive_window_shadow_path() const { return path(PathRole::InactiveWindowShadow); } - String menu_bar_shadow_path() const { return path(PathRole::MenuBarShadow); } String menu_shadow_path() const { return path(PathRole::MenuShadow); } String task_bar_shadow_path() const { return path(PathRole::TaskBarShadow); } String tooltip_shadow_path() const { return path(PathRole::TooltipShadow); } diff --git a/Userland/Libraries/LibGfx/SystemTheme.cpp b/Userland/Libraries/LibGfx/SystemTheme.cpp index 7a5f61c10d..5e3fda5635 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.cpp +++ b/Userland/Libraries/LibGfx/SystemTheme.cpp @@ -122,7 +122,6 @@ Core::AnonymousBuffer load_system_theme(const String& path) DO_PATH(ActiveWindowShadow, true); DO_PATH(InactiveWindowShadow, true); DO_PATH(TaskBarShadow, true); - DO_PATH(MenuBarShadow, true); DO_PATH(MenuShadow, true); DO_PATH(TooltipShadow, true); diff --git a/Userland/Libraries/LibGfx/SystemTheme.h b/Userland/Libraries/LibGfx/SystemTheme.h index e0e97556ed..a15a6af780 100644 --- a/Userland/Libraries/LibGfx/SystemTheme.h +++ b/Userland/Libraries/LibGfx/SystemTheme.h @@ -147,7 +147,6 @@ enum class PathRole { InactiveWindowShadow, ActiveWindowShadow, TaskBarShadow, - MenuBarShadow, MenuShadow, TooltipShadow, __Count, diff --git a/Userland/Services/WindowServer/Menu.cpp b/Userland/Services/WindowServer/Menu.cpp index c0293e2440..c30a0b81e9 100644 --- a/Userland/Services/WindowServer/Menu.cpp +++ b/Userland/Services/WindowServer/Menu.cpp @@ -141,7 +141,7 @@ Window& Menu::ensure_menu_window() next_item_location.move_by(0, height); } - int window_height_available = Screen::the().height() - MenuManager::the().menubar_rect().height() - frame_thickness() * 2; + int window_height_available = Screen::the().height() - frame_thickness() * 2; int max_window_height = (window_height_available / item_height()) * item_height() + frame_thickness() * 2; int content_height = m_items.is_empty() ? 0 : (m_items.last().rect().bottom() + 1) + frame_thickness(); int window_height = min(max_window_height, content_height); @@ -592,9 +592,6 @@ void Menu::do_popup(const Gfx::IntPoint& position, bool make_input, bool as_subm adjusted_pos = adjusted_pos.translated(0, item_height()); } - if (adjusted_pos.y() < MenuManager::the().menubar_rect().height()) - adjusted_pos.set_y(MenuManager::the().menubar_rect().height()); - window.move_to(adjusted_pos); window.set_visible(true); MenuManager::the().open_menu(*this, make_input); diff --git a/Userland/Services/WindowServer/MenuManager.cpp b/Userland/Services/WindowServer/MenuManager.cpp index bea06ef708..553e2e6c2e 100644 --- a/Userland/Services/WindowServer/MenuManager.cpp +++ b/Userland/Services/WindowServer/MenuManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2020, Shannon Booth * All rights reserved. * @@ -26,14 +26,10 @@ */ #include -#include -#include -#include #include #include #include #include -#include namespace WindowServer { @@ -49,11 +45,6 @@ MenuManager& MenuManager::the() MenuManager::MenuManager() { s_the = this; - m_needs_window_resize = true; - - m_window = Window::construct(*this, WindowType::Menubar); - m_window->set_rect(menubar_rect()); - m_window->set_visible(false); m_search_timer = Core::Timer::create_single_shot(0, [this] { m_current_search.clear(); @@ -73,31 +64,8 @@ bool MenuManager::is_open(const Menu& menu) const return false; } -void MenuManager::draw() -{ - auto& wm = WindowManager::the(); - auto palette = wm.palette(); - auto menubar_rect = this->menubar_rect(); - - if (m_needs_window_resize) { - m_window->set_rect(menubar_rect); - m_needs_window_resize = false; - } - - Gfx::Painter painter(*window().backing_store()); - - painter.fill_rect(menubar_rect, palette.window()); - painter.draw_line({ 0, menubar_rect.bottom() - 1 }, { menubar_rect.right(), menubar_rect.bottom() - 1 }, palette.threed_shadow1()); - painter.draw_line({ 0, menubar_rect.bottom() }, { menubar_rect.right(), menubar_rect.bottom() }, palette.threed_shadow2()); -} - void MenuManager::refresh() { - if (!m_window) - return; - draw(); - window().invalidate(); - ClientConnection::for_each_client([&](ClientConnection& client) { client.for_each_menu([&](Menu& menu) { menu.redraw(); @@ -262,11 +230,6 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event) } } -void MenuManager::set_needs_window_resize() -{ - m_needs_window_resize = true; -} - void MenuManager::close_all_menus_from_client(Badge, ClientConnection& client) { if (!has_open_menu()) @@ -429,11 +392,6 @@ void MenuManager::set_current_menu(Menu* menu) wm.set_active_input_window(m_current_menu->menu_window()); } -Gfx::IntRect MenuManager::menubar_rect() const -{ - return { 0, 0, Screen::the().rect().width(), 19 }; -} - Menu* MenuManager::previous_menu(Menu* current) { auto& wm = WindowManager::the(); diff --git a/Userland/Services/WindowServer/MenuManager.h b/Userland/Services/WindowServer/MenuManager.h index b6ff9eb817..bdf7f076ba 100644 --- a/Userland/Services/WindowServer/MenuManager.h +++ b/Userland/Services/WindowServer/MenuManager.h @@ -49,11 +49,6 @@ public: bool is_open(const Menu&) const; bool has_open_menu() const { return !m_open_menu_stack.is_empty(); } - Gfx::IntRect menubar_rect() const; - static int menubar_menu_margin() { return 14; } - - void set_needs_window_resize(); - Menu* current_menu() { return m_current_menu.ptr(); } void set_current_menu(Menu*); void clear_current_menu(); @@ -67,8 +62,6 @@ public: int theme_index() const { return m_theme_index; } - Window& window() { return *m_window; } - Menu* previous_menu(Menu* current); Menu* next_menu(Menu* current); @@ -80,15 +73,9 @@ public: private: void close_menus(const Vector&); - const Window& window() const { return *m_window; } - virtual void event(Core::Event&) override; void handle_mouse_event(MouseEvent&); - void draw(); - - RefPtr m_window; - WeakPtr m_current_menu; WeakPtr m_previous_input_window; Vector> m_open_menu_stack; @@ -96,8 +83,6 @@ private: RefPtr m_search_timer; StringBuilder m_current_search; - bool m_needs_window_resize { false }; - int m_theme_index { 0 }; WeakPtr m_hovered_menu; diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 24642b81cf..f0967a4f5d 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -966,12 +966,15 @@ void Window::set_menubar(MenuBar* menubar) return; m_menubar = menubar; if (m_menubar) { + // FIXME: Maybe move this to the theming system? + static constexpr auto menubar_menu_margin = 14; + auto& wm = WindowManager::the(); Gfx::IntPoint next_menu_location { 0, 0 }; auto menubar_rect = Gfx::WindowTheme::current().menu_bar_rect(Gfx::WindowTheme::WindowType::Normal, rect(), wm.palette(), 1); m_menubar->for_each_menu([&](Menu& menu) { int text_width = wm.font().width(menu.name()); - menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + MenuManager::menubar_menu_margin(), menubar_rect.height() }); + menu.set_rect_in_window_menubar({ next_menu_location.x(), 0, text_width + menubar_menu_margin, menubar_rect.height() }); next_menu_location.move_by(menu.rect_in_window_menubar().width(), 0); return IterationDecision::Continue; }); diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 995b264504..a9f10125e8 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -64,13 +64,11 @@ static int s_last_title_button_icons_scale; static Gfx::Bitmap* s_active_window_shadow; static Gfx::Bitmap* s_inactive_window_shadow; -static Gfx::Bitmap* s_menu_bar_shadow; static Gfx::Bitmap* s_menu_shadow; static Gfx::Bitmap* s_task_bar_shadow; static Gfx::Bitmap* s_tooltip_shadow; static String s_last_active_window_shadow_path; static String s_last_inactive_window_shadow_path; -static String s_last_menu_bar_shadow_path; static String s_last_menu_shadow_path; static String s_last_task_bar_shadow_path; static String s_last_tooltip_shadow_path; @@ -196,7 +194,6 @@ void WindowFrame::reload_config() }; load_shadow(WindowManager::the().palette().active_window_shadow_path(), s_last_active_window_shadow_path, s_active_window_shadow); load_shadow(WindowManager::the().palette().inactive_window_shadow_path(), s_last_inactive_window_shadow_path, s_inactive_window_shadow); - load_shadow(WindowManager::the().palette().menu_bar_shadow_path(), s_last_menu_bar_shadow_path, s_menu_bar_shadow); load_shadow(WindowManager::the().palette().menu_shadow_path(), s_last_menu_shadow_path, s_menu_shadow); load_shadow(WindowManager::the().palette().task_bar_shadow_path(), s_last_task_bar_shadow_path, s_task_bar_shadow); load_shadow(WindowManager::the().palette().tooltip_shadow_path(), s_last_tooltip_shadow_path, s_tooltip_shadow); @@ -213,8 +210,6 @@ Gfx::Bitmap* WindowFrame::window_shadow() const return s_menu_shadow; case WindowType::Tooltip: return s_tooltip_shadow; - case WindowType::Menubar: - return s_menu_bar_shadow; case WindowType::Taskbar: return s_task_bar_shadow; case WindowType::AppletArea: diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 3aa0b6910b..af56821c23 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -123,7 +123,6 @@ const Gfx::Font& WindowManager::window_title_font() const bool WindowManager::set_resolution(int width, int height, int scale) { bool success = Compositor::the().set_resolution(width, height, scale); - MenuManager::the().set_needs_window_resize(); ClientConnection::for_each_client([&](ClientConnection& client) { client.notify_about_new_screen_rect(Screen::the().rect()); }); @@ -1145,7 +1144,6 @@ Gfx::IntRect WindowManager::arena_rect_for_type(WindowType type) const case WindowType::WindowSwitcher: case WindowType::Taskbar: case WindowType::Tooltip: - case WindowType::Menubar: case WindowType::MenuApplet: case WindowType::Notification: return Screen::the().rect(); diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index a83548150d..9fac9581c3 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -404,8 +404,6 @@ IterationDecision WindowManager::for_each_visible_window_from_back_to_front(Call return IterationDecision::Break; if (for_each_visible_window_of_type_from_back_to_front(WindowType::Tooltip, callback) == IterationDecision::Break) return IterationDecision::Break; - if (for_each_visible_window_of_type_from_back_to_front(WindowType::Menubar, callback) == IterationDecision::Break) - return IterationDecision::Break; if (for_each_visible_window_of_type_from_back_to_front(WindowType::Menu, callback) == IterationDecision::Break) return IterationDecision::Break; return for_each_visible_window_of_type_from_back_to_front(WindowType::WindowSwitcher, callback); @@ -441,8 +439,6 @@ IterationDecision WindowManager::for_each_visible_window_from_front_to_back(Call return IterationDecision::Break; if (for_each_visible_window_of_type_from_front_to_back(WindowType::Menu, callback) == IterationDecision::Break) return IterationDecision::Break; - if (for_each_visible_window_of_type_from_front_to_back(WindowType::Menubar, callback) == IterationDecision::Break) - return IterationDecision::Break; if (for_each_visible_window_of_type_from_front_to_back(WindowType::Tooltip, callback) == IterationDecision::Break) return IterationDecision::Break; if (for_each_visible_window_of_type_from_front_to_back(WindowType::Notification, callback) == IterationDecision::Break) diff --git a/Userland/Services/WindowServer/WindowType.h b/Userland/Services/WindowServer/WindowType.h index 308c7fd75a..f561bbd8c0 100644 --- a/Userland/Services/WindowServer/WindowType.h +++ b/Userland/Services/WindowServer/WindowType.h @@ -35,7 +35,6 @@ enum class WindowType { WindowSwitcher, Taskbar, Tooltip, - Menubar, MenuApplet, Notification, Desktop,