mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
WindowServer: Reset menu position when opened by the menu bar
Also, only mark the menu bar item as opened if a menu was actually opened through the menu bar. These changes allow a menu to be used both in the menu bar as well as a context menu. Fixes #5469
This commit is contained in:
parent
bd318dcdcd
commit
35363a972a
4 changed files with 19 additions and 21 deletions
|
@ -323,7 +323,7 @@ void Menu::descend_into_submenu_at_hovered_item()
|
||||||
ASSERT(hovered_item());
|
ASSERT(hovered_item());
|
||||||
auto submenu = hovered_item()->submenu();
|
auto submenu = hovered_item()->submenu();
|
||||||
ASSERT(submenu);
|
ASSERT(submenu);
|
||||||
MenuManager::the().open_menu(*submenu, false);
|
MenuManager::the().open_menu(*submenu, false, false);
|
||||||
submenu->set_hovered_item(0);
|
submenu->set_hovered_item(0);
|
||||||
ASSERT(submenu->hovered_item()->type() != MenuItem::Separator);
|
ASSERT(submenu->hovered_item()->type() != MenuItem::Separator);
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ void Menu::do_popup(const Gfx::IntPoint& position, bool make_input)
|
||||||
|
|
||||||
window.move_to(adjusted_pos);
|
window.move_to(adjusted_pos);
|
||||||
window.set_visible(true);
|
window.set_visible(true);
|
||||||
MenuManager::the().open_menu(*this, make_input);
|
MenuManager::the().open_menu(*this, false, make_input);
|
||||||
WindowManager::the().did_popup_a_menu({});
|
WindowManager::the().did_popup_a_menu({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ void MenuManager::draw()
|
||||||
|
|
||||||
for_each_active_menubar_menu([&](Menu& menu) {
|
for_each_active_menubar_menu([&](Menu& menu) {
|
||||||
Color text_color = palette.window_text();
|
Color text_color = palette.window_text();
|
||||||
if (is_open(menu)) {
|
if (is_open(menu) && &menu == m_current_menu_bar_menu) {
|
||||||
painter.fill_rect(menu.rect_in_menubar(), palette.menu_selection());
|
painter.fill_rect(menu.rect_in_menubar(), palette.menu_selection());
|
||||||
painter.draw_rect(menu.rect_in_menubar(), palette.menu_selection().darkened());
|
painter.draw_rect(menu.rect_in_menubar(), palette.menu_selection().darkened());
|
||||||
text_color = palette.menu_selection_text();
|
text_color = palette.menu_selection_text();
|
||||||
|
@ -173,7 +173,7 @@ void MenuManager::event(Core::Event& event)
|
||||||
else {
|
else {
|
||||||
auto* target_menu = previous_menu(m_current_menu);
|
auto* target_menu = previous_menu(m_current_menu);
|
||||||
if (target_menu)
|
if (target_menu)
|
||||||
open_menu(*target_menu);
|
open_menu(*target_menu, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
close_everyone_not_in_lineage(*m_current_menu);
|
close_everyone_not_in_lineage(*m_current_menu);
|
||||||
|
@ -187,7 +187,7 @@ void MenuManager::event(Core::Event& event)
|
||||||
else if (m_open_menu_stack.size() <= 1) {
|
else if (m_open_menu_stack.size() <= 1) {
|
||||||
auto* target_menu = next_menu(m_current_menu);
|
auto* target_menu = next_menu(m_current_menu);
|
||||||
if (target_menu) {
|
if (target_menu) {
|
||||||
open_menu(*target_menu);
|
open_menu(*target_menu, true);
|
||||||
close_everyone_not_in_lineage(*target_menu);
|
close_everyone_not_in_lineage(*target_menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,14 +294,14 @@ void MenuManager::handle_menu_mouse_event(Menu& menu, const MouseEvent& event)
|
||||||
&& has_open_menu()
|
&& has_open_menu()
|
||||||
&& (m_open_menu_stack.first()->menubar() || m_open_menu_stack.first() == m_system_menu.ptr());
|
&& (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 is_mousedown_with_left_button = event.type() == MouseEvent::MouseDown && event.button() == MouseButton::Left;
|
||||||
bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
|
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)
|
if (is_mousedown_with_left_button)
|
||||||
m_bar_open = !m_bar_open;
|
m_bar_open = !m_bar_open;
|
||||||
|
|
||||||
if (should_open_menu && m_bar_open) {
|
if (should_open_menu && m_bar_open) {
|
||||||
close_everyone();
|
close_everyone();
|
||||||
open_menu(menu);
|
open_menu(menu, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,17 +383,11 @@ void MenuManager::close_menu_and_descendants(Menu& menu)
|
||||||
close_menus(menus_to_close);
|
close_menus(menus_to_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuManager::toggle_menu(Menu& menu)
|
void MenuManager::open_menu(Menu& menu, bool from_menu_bar, bool as_current_menu)
|
||||||
{
|
{
|
||||||
if (is_open(menu)) {
|
if (from_menu_bar)
|
||||||
close_menu_and_descendants(menu);
|
m_current_menu_bar_menu = &menu;
|
||||||
return;
|
|
||||||
}
|
|
||||||
open_menu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuManager::open_menu(Menu& menu, bool as_current_menu)
|
|
||||||
{
|
|
||||||
if (is_open(menu)) {
|
if (is_open(menu)) {
|
||||||
if (as_current_menu || current_menu() != &menu) {
|
if (as_current_menu || current_menu() != &menu) {
|
||||||
// This menu is already open. If requested, or if the current
|
// This menu is already open. If requested, or if the current
|
||||||
|
@ -405,10 +399,13 @@ void MenuManager::open_menu(Menu& menu, bool as_current_menu)
|
||||||
|
|
||||||
if (!menu.is_empty()) {
|
if (!menu.is_empty()) {
|
||||||
menu.redraw_if_theme_changed();
|
menu.redraw_if_theme_changed();
|
||||||
|
bool should_update_position = from_menu_bar;
|
||||||
if (!menu.menu_window()) {
|
if (!menu.menu_window()) {
|
||||||
auto& menu_window = menu.ensure_menu_window();
|
should_update_position = true;
|
||||||
menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
|
menu.ensure_menu_window();
|
||||||
}
|
}
|
||||||
|
if (should_update_position)
|
||||||
|
menu.menu_window()->move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
|
||||||
menu.menu_window()->set_visible(true);
|
menu.menu_window()->set_visible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +425,7 @@ void MenuManager::clear_current_menu()
|
||||||
{
|
{
|
||||||
Menu* previous_current_menu = m_current_menu;
|
Menu* previous_current_menu = m_current_menu;
|
||||||
m_current_menu = nullptr;
|
m_current_menu = nullptr;
|
||||||
|
m_current_menu_bar_menu = nullptr;
|
||||||
if (previous_current_menu) {
|
if (previous_current_menu) {
|
||||||
// When closing the last menu, restore the previous active input window
|
// When closing the last menu, restore the previous active input window
|
||||||
auto& wm = WindowManager::the();
|
auto& wm = WindowManager::the();
|
||||||
|
|
|
@ -57,8 +57,7 @@ public:
|
||||||
Menu* current_menu() { return m_current_menu.ptr(); }
|
Menu* current_menu() { return m_current_menu.ptr(); }
|
||||||
void set_current_menu(Menu*);
|
void set_current_menu(Menu*);
|
||||||
void clear_current_menu();
|
void clear_current_menu();
|
||||||
void open_menu(Menu&, bool as_current_menu = true);
|
void open_menu(Menu&, bool from_menu_bar, bool as_current_menu = true);
|
||||||
void toggle_menu(Menu&);
|
|
||||||
|
|
||||||
MenuBar* current_menubar() { return m_current_menubar.ptr(); }
|
MenuBar* current_menubar() { return m_current_menubar.ptr(); }
|
||||||
void set_current_menubar(MenuBar*);
|
void set_current_menubar(MenuBar*);
|
||||||
|
@ -108,6 +107,7 @@ private:
|
||||||
RefPtr<Window> m_window;
|
RefPtr<Window> m_window;
|
||||||
|
|
||||||
WeakPtr<Menu> m_current_menu;
|
WeakPtr<Menu> m_current_menu;
|
||||||
|
WeakPtr<Menu> m_current_menu_bar_menu;
|
||||||
WeakPtr<Window> m_previous_input_window;
|
WeakPtr<Window> m_previous_input_window;
|
||||||
Vector<WeakPtr<Menu>> m_open_menu_stack;
|
Vector<WeakPtr<Menu>> m_open_menu_stack;
|
||||||
|
|
||||||
|
|
|
@ -1178,7 +1178,7 @@ void WindowManager::event(Core::Event& event)
|
||||||
if (MenuManager::the().has_open_menu()) {
|
if (MenuManager::the().has_open_menu()) {
|
||||||
MenuManager::the().close_everyone();
|
MenuManager::the().close_everyone();
|
||||||
} else {
|
} else {
|
||||||
MenuManager::the().open_menu(*MenuManager::the().system_menu());
|
MenuManager::the().open_menu(*MenuManager::the().system_menu(), true);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue