summaryrefslogtreecommitdiff
path: root/Servers/WindowServer
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-11-11 12:54:23 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-11-11 13:13:08 +0100
commit5e61fd0e67f0ae3e77435d1aea2bcba1b37cf320 (patch)
tree901719e9a268c4a608179ec0ae0bcd07466f52da /Servers/WindowServer
parentcbecad0a776e0b9a7d5e116740fb70f7ebbba813 (diff)
downloadserenity-5e61fd0e67f0ae3e77435d1aea2bcba1b37cf320.zip
WindowManager: Simplify menu bar open/close logic
Let the global menu bar be either "open" or "closed". Clicking on one of the menus in the menu bar toggles the state. This ends up simpler and more intuitive than what we had before.
Diffstat (limited to 'Servers/WindowServer')
-rw-r--r--Servers/WindowServer/WSMenu.cpp2
-rw-r--r--Servers/WindowServer/WSMenuManager.cpp18
-rw-r--r--Servers/WindowServer/WSMenuManager.h4
-rw-r--r--Servers/WindowServer/WSWindowManager.cpp2
4 files changed, 18 insertions, 8 deletions
diff --git a/Servers/WindowServer/WSMenu.cpp b/Servers/WindowServer/WSMenu.cpp
index 8349316f34..6cb797e459 100644
--- a/Servers/WindowServer/WSMenu.cpp
+++ b/Servers/WindowServer/WSMenu.cpp
@@ -242,7 +242,7 @@ void WSMenu::did_activate(WSMenuItem& item)
if (on_item_activation)
on_item_activation(item);
- WSWindowManager::the().menu_manager().close_everyone();
+ WSWindowManager::the().menu_manager().close_bar();
WSAPI_ServerMessage message;
message.type = WSAPI_ServerMessage::Type::MenuItemActivated;
diff --git a/Servers/WindowServer/WSMenuManager.cpp b/Servers/WindowServer/WSMenuManager.cpp
index e6f6ba73f8..efae9eb5fa 100644
--- a/Servers/WindowServer/WSMenuManager.cpp
+++ b/Servers/WindowServer/WSMenuManager.cpp
@@ -145,7 +145,10 @@ void WSMenuManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& ev
bool is_mousedown_with_left_button = event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left;
bool should_open_menu = &menu != m_current_menu && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
- if (should_open_menu) {
+ if (is_mousedown_with_left_button)
+ m_bar_open = !m_bar_open;
+
+ if (should_open_menu && m_bar_open) {
if (m_current_menu == &menu)
return;
close_everyone();
@@ -158,11 +161,9 @@ void WSMenuManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& ev
refresh();
return;
}
- if (event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left) {
+
+ if (!m_bar_open)
close_everyone();
- set_current_menu(nullptr);
- return;
- }
}
void WSMenuManager::set_needs_window_resize()
@@ -177,6 +178,7 @@ void WSMenuManager::close_everyone()
menu->menu_window()->set_visible(false);
}
m_open_menu_stack.clear();
+ m_current_menu = nullptr;
refresh();
}
@@ -240,3 +242,9 @@ void WSMenuManager::set_current_menu(WSMenu* menu, bool is_submenu)
m_open_menu_stack.append(menu->make_weak_ptr());
}
}
+
+void WSMenuManager::close_bar()
+{
+ close_everyone();
+ m_bar_open = false;
+}
diff --git a/Servers/WindowServer/WSMenuManager.h b/Servers/WindowServer/WSMenuManager.h
index 37079ba956..2ae7e492ae 100644
--- a/Servers/WindowServer/WSMenuManager.h
+++ b/Servers/WindowServer/WSMenuManager.h
@@ -26,6 +26,7 @@ public:
WSMenu* current_menu() { return m_current_menu.ptr(); }
void set_current_menu(WSMenu*, bool is_submenu = false);
+ void close_bar();
void close_everyone();
void close_everyone_not_in_lineage(WSMenu&);
void close_menu_and_descendants(WSMenu&);
@@ -49,5 +50,6 @@ private:
WeakPtr<WSMenu> m_current_menu;
Vector<WeakPtr<WSMenu>> m_open_menu_stack;
- bool m_needs_window_resize;
+ bool m_needs_window_resize { false };
+ bool m_bar_open { false };
};
diff --git a/Servers/WindowServer/WSWindowManager.cpp b/Servers/WindowServer/WSWindowManager.cpp
index eedda378ed..0072cfbfbe 100644
--- a/Servers/WindowServer/WSWindowManager.cpp
+++ b/Servers/WindowServer/WSWindowManager.cpp
@@ -731,7 +731,7 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& hovere
if (topmost_menu->hovered_item())
topmost_menu->clear_hovered_item();
if (event.type() == WSEvent::MouseDown || event.type() == WSEvent::MouseUp)
- m_menu_manager.close_everyone();
+ m_menu_manager.close_bar();
if (event.type() == WSEvent::MouseMove) {
for (auto& menu : m_menu_manager.open_menu_stack()) {
if (!menu)