diff options
author | Andreas Kling <kling@serenityos.org> | 2021-03-28 13:36:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-28 13:40:40 +0200 |
commit | 526b4bbfdb1a60fbfec3fe64e3fc3ab9b49a221c (patch) | |
tree | 6d69ccc63d8e1756b1e936951b01df48ce67c6f8 /Userland | |
parent | ccf84a4709eaad4369e432a9707ecda3c6376334 (diff) | |
download | serenity-526b4bbfdb1a60fbfec3fe64e3fc3ab9b49a221c.zip |
WindowServer: Add ability to show/hide window menubars
This patch adds a toggle item to the window menu that controls window
menubar visibility. This is available in all windows with a menu.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WindowServer/Window.cpp | 17 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Window.h | 4 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowFrame.cpp | 8 |
3 files changed, 25 insertions, 4 deletions
diff --git a/Userland/Services/WindowServer/Window.cpp b/Userland/Services/WindowServer/Window.cpp index 0d8b2a266b..752bf55dec 100644 --- a/Userland/Services/WindowServer/Window.cpp +++ b/Userland/Services/WindowServer/Window.cpp @@ -649,6 +649,11 @@ void Window::ensure_window_menu() m_window_menu->add_item(make<MenuItem>(*m_window_menu, MenuItem::Type::Separator)); + auto menubar_visibility_item = make<MenuItem>(*m_window_menu, 4, "Menu bar"); + m_window_menu_menubar_visibility_item = menubar_visibility_item.ptr(); + menubar_visibility_item->set_checkable(true); + m_window_menu->add_item(move(menubar_visibility_item)); + auto close_item = make<MenuItem>(*m_window_menu, 3, "Close"); m_window_menu_close_item = close_item.ptr(); m_window_menu_close_item->set_icon(&close_icon()); @@ -672,6 +677,14 @@ void Window::ensure_window_menu() case 3: request_close(); break; + case 4: + frame().invalidate(); + item.set_checked(!item.is_checked()); + m_should_show_menubar = item.is_checked(); + frame().invalidate(); + Compositor::the().invalidate_occlusions(); + Compositor::the().invalidate_screen(); + break; } }; } @@ -694,6 +707,8 @@ void Window::popup_window_menu(const Gfx::IntPoint& position, WindowMenuDefaultA m_window_menu_maximize_item->set_default(default_action == WindowMenuDefaultAction::Maximize || default_action == WindowMenuDefaultAction::Restore); m_window_menu_maximize_item->set_icon(m_maximized ? &restore_icon() : &maximize_icon()); m_window_menu_close_item->set_default(default_action == WindowMenuDefaultAction::Close); + m_window_menu_menubar_visibility_item->set_enabled(menubar()); + m_window_menu_menubar_visibility_item->set_checked(menubar() && m_should_show_menubar); m_window_menu->popup(position); } @@ -964,7 +979,7 @@ void Window::set_menubar(MenuBar* menubar) void Window::invalidate_menubar() { - if (!menubar()) + if (!m_should_show_menubar || !menubar()) return; // FIXME: This invalidates way more than the menubar! frame().invalidate(); diff --git a/Userland/Services/WindowServer/Window.h b/Userland/Services/WindowServer/Window.h index 00f914ffce..4b26d6d653 100644 --- a/Userland/Services/WindowServer/Window.h +++ b/Userland/Services/WindowServer/Window.h @@ -302,6 +302,8 @@ public: void set_frameless(bool); bool is_frameless() const { return m_frameless; } + bool should_show_menubar() const { return m_should_show_menubar; } + int progress() const { return m_progress; } void set_progress(int); @@ -403,8 +405,10 @@ private: MenuItem* m_window_menu_minimize_item { nullptr }; MenuItem* m_window_menu_maximize_item { nullptr }; MenuItem* m_window_menu_close_item { nullptr }; + MenuItem* m_window_menu_menubar_visibility_item { nullptr }; int m_minimize_animation_step { -1 }; int m_progress { -1 }; + bool m_should_show_menubar { true }; }; } diff --git a/Userland/Services/WindowServer/WindowFrame.cpp b/Userland/Services/WindowServer/WindowFrame.cpp index 8bfa9c6f62..cd923128bb 100644 --- a/Userland/Services/WindowServer/WindowFrame.cpp +++ b/Userland/Services/WindowServer/WindowFrame.cpp @@ -79,7 +79,7 @@ static Gfx::IntRect frame_rect_for_window(Window& window, const Gfx::IntRect& re { if (window.is_frameless()) return rect; - int menu_row_count = window.menubar() ? 1 : 0; + int menu_row_count = (window.menubar() && window.should_show_menubar()) ? 1 : 0; return Gfx::WindowTheme::current().frame_rect_for_window(to_theme_window_type(window.type()), rect, WindowManager::the().palette(), menu_row_count); } @@ -241,7 +241,7 @@ void WindowFrame::did_set_maximized(Badge<Window>, bool maximized) Gfx::IntRect WindowFrame::menubar_rect() const { - if (!m_window.menubar()) + if (!m_window.menubar() || !m_window.should_show_menubar()) return {}; return Gfx::WindowTheme::current().menu_bar_rect(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette(), menu_row_count()); } @@ -336,7 +336,7 @@ void WindowFrame::paint_normal_frame(Gfx::Painter& painter) auto leftmost_button_rect = m_buttons.is_empty() ? Gfx::IntRect() : m_buttons.last().relative_rect(); Gfx::WindowTheme::current().paint_normal_frame(painter, window_state_for_theme(), m_window.rect(), compute_title_text(), m_window.icon(), palette, leftmost_button_rect, menu_row_count()); - if (m_window.menubar()) + if (m_window.menubar() && m_window.should_show_menubar()) paint_menubar(painter); } @@ -878,6 +878,8 @@ void WindowFrame::paint_simple_rect_shadow(Gfx::Painter& painter, const Gfx::Int int WindowFrame::menu_row_count() const { + if (!m_window.should_show_menubar()) + return 0; return m_window.menubar() ? 1 : 0; } |