1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

WindowServer+LibGfx: Remove code for drawing the old-style menu bar

This commit is contained in:
Andreas Kling 2021-03-31 23:22:06 +02:00
parent 19c578024b
commit 0e798234c7
12 changed files with 6 additions and 79 deletions

View file

@ -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

View file

@ -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); }

View file

@ -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);

View file

@ -147,7 +147,6 @@ enum class PathRole {
InactiveWindowShadow,
ActiveWindowShadow,
TaskBarShadow,
MenuBarShadow,
MenuShadow,
TooltipShadow,
__Count,

View file

@ -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);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Shannon Booth <shannon.ml.booth@gmail.com>
* All rights reserved.
*
@ -26,14 +26,10 @@
*/
#include <AK/Badge.h>
#include <AK/Debug.h>
#include <AK/QuickSort.h>
#include <LibGfx/Painter.h>
#include <WindowServer/ClientConnection.h>
#include <WindowServer/MenuManager.h>
#include <WindowServer/Screen.h>
#include <WindowServer/WindowManager.h>
#include <unistd.h>
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>, 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();

View file

@ -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<Menu*>&);
const Window& window() const { return *m_window; }
virtual void event(Core::Event&) override;
void handle_mouse_event(MouseEvent&);
void draw();
RefPtr<Window> m_window;
WeakPtr<Menu> m_current_menu;
WeakPtr<Window> m_previous_input_window;
Vector<WeakPtr<Menu>> m_open_menu_stack;
@ -96,8 +83,6 @@ private:
RefPtr<Core::Timer> m_search_timer;
StringBuilder m_current_search;
bool m_needs_window_resize { false };
int m_theme_index { 0 };
WeakPtr<Menu> m_hovered_menu;

View file

@ -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;
});

View file

@ -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:

View file

@ -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();

View file

@ -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)

View file

@ -35,7 +35,6 @@ enum class WindowType {
WindowSwitcher,
Taskbar,
Tooltip,
Menubar,
MenuApplet,
Notification,
Desktop,