WindowServer: Remove "system menu" concept from WindowServer

This commit is contained in:
Andreas Kling 2021-03-25 23:08:34 +01:00
parent 619a223800
commit 327866520a
Notes: sideshowbarker 2024-07-18 21:05:19 +09:00
9 changed files with 19 additions and 148 deletions

View File

@ -834,19 +834,6 @@ OwnPtr<Messages::WindowServer::StartDragResponse> ClientConnection::handle(const
return make<Messages::WindowServer::StartDragResponse>(true);
}
OwnPtr<Messages::WindowServer::SetSystemMenuResponse> ClientConnection::handle(const Messages::WindowServer::SetSystemMenu& message)
{
auto it = m_menus.find(message.menu_id());
if (it == m_menus.end()) {
did_misbehave("SetSystemMenu called with invalid menu ID");
return {};
}
auto& menu = it->value;
MenuManager::the().set_system_menu(menu);
return make<Messages::WindowServer::SetSystemMenuResponse>();
}
OwnPtr<Messages::WindowServer::SetSystemThemeResponse> ClientConnection::handle(const Messages::WindowServer::SetSystemTheme& message)
{
bool success = WindowManager::the().update_theme(message.theme_path(), message.theme_name());

View File

@ -145,7 +145,6 @@ private:
virtual OwnPtr<Messages::WindowServer::SetWindowIconBitmapResponse> handle(const Messages::WindowServer::SetWindowIconBitmap&) override;
virtual void handle(const Messages::WindowServer::WM_SetWindowTaskbarRect&) override;
virtual OwnPtr<Messages::WindowServer::StartDragResponse> handle(const Messages::WindowServer::StartDrag&) override;
virtual OwnPtr<Messages::WindowServer::SetSystemMenuResponse> handle(const Messages::WindowServer::SetSystemMenu&) override;
virtual OwnPtr<Messages::WindowServer::SetSystemThemeResponse> handle(const Messages::WindowServer::SetSystemTheme&) override;
virtual OwnPtr<Messages::WindowServer::GetSystemThemeResponse> handle(const Messages::WindowServer::GetSystemTheme&) override;
virtual OwnPtr<Messages::WindowServer::SetWindowBaseSizeAndSizeIncrementResponse> handle(const Messages::WindowServer::SetWindowBaseSizeAndSizeIncrement&) override;

View File

@ -122,7 +122,7 @@ int Menu::content_width() const
if (widest_shortcut)
widest_item += padding_between_text_and_shortcut() + widest_shortcut;
return max(widest_item, rect_in_global_menubar().width()) + horizontal_padding() + frame_thickness() * 2;
return max(widest_item, rect_in_window_menubar().width()) + horizontal_padding() + frame_thickness() * 2;
}
void Menu::redraw()

View File

@ -74,11 +74,6 @@ public:
callback(item);
}
Gfx::IntRect text_rect_in_global_menubar() const { return m_text_rect_in_global_menubar; }
void set_text_rect_in_global_menubar(const Gfx::IntRect& rect) { m_text_rect_in_global_menubar = rect; }
Gfx::IntRect rect_in_global_menubar() const { return m_rect_in_global_menubar; }
void set_rect_in_global_menubar(const Gfx::IntRect& rect) { m_rect_in_global_menubar = rect; }
Gfx::IntRect text_rect_in_window_menubar() const { return m_text_rect_in_window_menubar; }
void set_text_rect_in_window_menubar(const Gfx::IntRect& rect) { m_text_rect_in_window_menubar = rect; }
Gfx::IntRect rect_in_window_menubar() const { return m_rect_in_window_menubar; }
@ -153,8 +148,6 @@ private:
ClientConnection* m_client { nullptr };
int m_menu_id { 0 };
String m_name;
Gfx::IntRect m_rect_in_global_menubar;
Gfx::IntRect m_text_rect_in_global_menubar;
Gfx::IntRect m_rect_in_window_menubar;
Gfx::IntRect m_text_rect_in_window_menubar;
MenuBar* m_menubar { nullptr };

View File

@ -54,8 +54,6 @@ MenuManager::MenuManager()
s_the = this;
m_needs_window_resize = true;
set_current_menubar(nullptr);
m_window = Window::construct(*this, WindowType::Menubar);
m_window->set_rect(menubar_rect());
@ -95,24 +93,6 @@ void MenuManager::draw()
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());
for_each_active_menubar_menu([&](Menu& menu) {
auto text_rect = menu.text_rect_in_global_menubar();
Color text_color = palette.window_text();
if (is_open(menu) && &menu == m_current_menu_bar_menu) {
painter.fill_rect(menu.rect_in_global_menubar(), palette.menu_selection());
painter.draw_rect(menu.rect_in_global_menubar(), palette.menu_selection().darkened());
text_color = palette.menu_selection_text();
text_rect.move_by(1, 1);
}
painter.draw_text(
text_rect,
menu.name(),
menu.title_font(),
Gfx::TextAlignment::CenterLeft,
text_color);
return IterationDecision::Continue;
});
AppletManager::the().draw();
}
@ -126,6 +106,8 @@ void MenuManager::refresh()
void MenuManager::event(Core::Event& event)
{
auto& wm = WindowManager::the();
if (static_cast<Event&>(event).is_mouse_event()) {
handle_mouse_event(static_cast<MouseEvent&>(event));
return;
@ -173,8 +155,10 @@ void MenuManager::event(Core::Event& event)
m_current_menu->set_hovered_item(-1);
else {
auto* target_menu = previous_menu(m_current_menu);
if (target_menu)
open_menu(*target_menu, true);
if (target_menu) {
target_menu->ensure_menu_window().move_to(target_menu->rect_in_window_menubar().bottom_left().translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
open_menu(*target_menu, false);
}
}
}
close_everyone_not_in_lineage(*m_current_menu);
@ -185,10 +169,11 @@ void MenuManager::event(Core::Event& event)
auto hovered_item = m_current_menu->hovered_item();
if (hovered_item && hovered_item->is_submenu())
m_current_menu->descend_into_submenu_at_hovered_item();
else if (m_open_menu_stack.size() <= 1) {
else if (m_open_menu_stack.size() <= 1 && wm.window_with_active_menu()) {
auto* target_menu = next_menu(m_current_menu);
if (target_menu) {
open_menu(*target_menu, true);
target_menu->ensure_menu_window().move_to(target_menu->rect_in_window_menubar().bottom_left().translated(wm.window_with_active_menu()->frame().rect().location()).translated(wm.window_with_active_menu()->frame().menubar_rect().location()));
open_menu(*target_menu, false);
close_everyone_not_in_lineage(*target_menu);
}
}
@ -214,20 +199,6 @@ void MenuManager::event(Core::Event& event)
void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
{
auto* active_window = WindowManager::the().active_window();
bool handled_menubar_event = false;
for_each_active_menubar_menu([&](Menu& menu) {
if (menu.rect_in_global_menubar().contains(mouse_event.position())) {
handled_menubar_event = &menu == m_system_menu || !active_window || !active_window->is_modal();
if (handled_menubar_event)
handle_menu_mouse_event(menu, mouse_event);
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
if (handled_menubar_event)
return;
if (has_open_menu()) {
auto* topmost_menu = m_open_menu_stack.last().ptr();
VERIFY(topmost_menu);
@ -289,27 +260,6 @@ void MenuManager::handle_mouse_event(MouseEvent& mouse_event)
AppletManager::the().dispatch_event(static_cast<Event&>(mouse_event));
}
void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
{
bool is_hover_with_any_menu_open = event.type() == MouseEvent::MouseMove
&& has_open_menu() && m_current_menu_bar_menu
&& (m_open_menu_stack.first()->menubar() || m_open_menu_stack.first() == m_system_menu.ptr());
bool is_mousedown_with_left_button = event.type() == MouseEvent::MouseDown && event.button() == MouseButton::Left;
bool should_open_menu = (&menu != m_current_menu || !m_current_menu_bar_menu) && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
if (is_mousedown_with_left_button)
m_bar_open = !m_bar_open;
if (should_open_menu && m_bar_open) {
close_everyone();
open_menu(menu, true);
return;
}
if (!m_bar_open && m_current_menu_bar_menu)
close_everyone();
}
void MenuManager::set_needs_window_resize()
{
m_needs_window_resize = true;
@ -419,13 +369,8 @@ void MenuManager::open_menu(Menu& menu, bool from_menu_bar, bool as_current_menu
if (!menu.is_empty()) {
menu.redraw_if_theme_changed();
bool should_update_position = from_menu_bar;
if (!menu.menu_window()) {
should_update_position = true;
if (!menu.menu_window())
menu.ensure_menu_window();
}
if (should_update_position)
menu.menu_window()->move_to({ menu.rect_in_global_menubar().x(), menu.rect_in_global_menubar().bottom() + 2 });
menu.menu_window()->set_visible(true);
}
@ -497,33 +442,14 @@ Gfx::IntRect MenuManager::menubar_rect() const
return { 0, 0, Screen::the().rect().width(), 19 };
}
void MenuManager::set_current_menubar(MenuBar*)
{
Gfx::IntPoint next_menu_location { MenuManager::menubar_menu_margin() / 2, 0 };
for_each_active_menubar_menu([&](Menu& menu) {
int text_width = menu.title_font().width(menu.name());
menu.set_rect_in_global_menubar({ next_menu_location.x() - MenuManager::menubar_menu_margin() / 2, 0, text_width + MenuManager::menubar_menu_margin(), menubar_rect().height() - 1 });
Gfx::IntRect text_rect { next_menu_location.translated(0, 1), { text_width, menubar_rect().height() - 3 } };
menu.set_text_rect_in_global_menubar(text_rect);
next_menu_location.move_by(menu.rect_in_global_menubar().width(), 0);
return IterationDecision::Continue;
});
refresh();
}
void MenuManager::set_system_menu(Menu& menu)
{
m_system_menu = menu;
set_current_menubar(nullptr);
}
Menu* MenuManager::previous_menu(Menu* current)
{
auto& wm = WindowManager::the();
if (!wm.window_with_active_menu())
return nullptr;
Menu* found = nullptr;
Menu* previous = nullptr;
for_each_active_menubar_menu([&](Menu& menu) {
wm.window_with_active_menu()->menubar()->for_each_menu([&](Menu& menu) {
if (current == &menu) {
found = previous;
return IterationDecision::Break;
@ -538,7 +464,10 @@ Menu* MenuManager::next_menu(Menu* current)
{
Menu* found = nullptr;
bool is_next = false;
for_each_active_menubar_menu([&](Menu& menu) {
auto& wm = WindowManager::the();
if (!wm.window_with_active_menu())
return nullptr;
wm.window_with_active_menu()->menubar()->for_each_menu([&](Menu& menu) {
if (is_next) {
found = &menu;
return IterationDecision::Break;

View File

@ -59,8 +59,6 @@ public:
void clear_current_menu();
void open_menu(Menu&, bool from_menu_bar, bool as_current_menu = true);
void set_current_menubar(MenuBar*);
void close_bar();
void close_everyone();
void close_everyone_not_in_lineage(Menu&);
@ -68,22 +66,10 @@ public:
void close_all_menus_from_client(Badge<ClientConnection>, ClientConnection&);
Menu* system_menu() { return m_system_menu; }
void set_system_menu(Menu&);
int theme_index() const { return m_theme_index; }
Window& window() { return *m_window; }
template<typename Callback>
void for_each_active_menubar_menu(Callback callback)
{
if (system_menu()) {
if (callback(*system_menu()) == IterationDecision::Break)
return;
}
}
Menu* previous_menu(Menu* current);
Menu* next_menu(Menu* current);

View File

@ -1155,9 +1155,6 @@ Gfx::IntRect WindowManager::arena_rect_for_type(WindowType type) const
void WindowManager::event(Core::Event& event)
{
if (static_cast<Event&>(event).is_mouse_event()) {
if (event.type() != Event::MouseMove)
m_previous_event_is_key_down_logo = false;
Window* hovered_window = nullptr;
process_mouse_event(static_cast<MouseEvent&>(event), hovered_window);
set_hovered_window(hovered_window);
@ -1187,20 +1184,6 @@ void WindowManager::event(Core::Event& event)
return;
}
if (key_event.type() == Event::KeyDown && key_event.key() == Key_Super) {
m_previous_event_is_key_down_logo = true;
} else if (m_previous_event_is_key_down_logo) {
m_previous_event_is_key_down_logo = false;
if (!m_dnd_client && key_event.type() == Event::KeyUp && key_event.key() == Key_Super) {
if (MenuManager::the().has_open_menu()) {
MenuManager::the().close_everyone();
} else {
MenuManager::the().open_menu(*MenuManager::the().system_menu(), true);
}
return;
}
}
if (MenuManager::the().current_menu()) {
MenuManager::the().dispatch_event(event);
return;
@ -1371,8 +1354,6 @@ void WindowManager::set_active_window(Window* window, bool make_input)
Core::EventLoop::current().post_event(*m_active_window, make<Event>(Event::WindowActivated));
m_active_window->invalidate(true, true);
tell_wm_listeners_window_state_changed(*m_active_window);
} else {
MenuManager::the().set_current_menubar(nullptr);
}
// Window shapes may have changed (e.g. shadows for inactive/active windows)

View File

@ -360,8 +360,6 @@ private:
String m_dnd_text;
RefPtr<Core::MimeData> m_dnd_mime_data;
RefPtr<Gfx::Bitmap> m_dnd_bitmap;
bool m_previous_event_is_key_down_logo { false };
};
template<typename Callback>

View File

@ -10,8 +10,6 @@ endpoint WindowServer = 2
AddMenuToMenubar(i32 menubar_id, i32 menu_id) => ()
SetSystemMenu(i32 menu_id) => ()
AddMenuItem(
i32 menu_id,
i32 identifier,