mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 13:27:35 +00:00
WindowServer: Move some event code from WSWindowManager to WSMenuBarKeeper.
This commit is contained in:
parent
ede598589a
commit
ef1bfcb9d8
4 changed files with 41 additions and 40 deletions
|
@ -104,5 +104,41 @@ void WSMenuBarKeeper::refresh()
|
||||||
|
|
||||||
void WSMenuBarKeeper::event(CEvent& event)
|
void WSMenuBarKeeper::event(CEvent& event)
|
||||||
{
|
{
|
||||||
|
if (event.type() == WSEvent::MouseMove || event.type() == WSEvent::MouseUp || event.type() == WSEvent::MouseDown || event.type() == WSEvent::MouseWheel) {
|
||||||
|
auto& mouse_event = static_cast<WSMouseEvent&>(event);
|
||||||
|
WSWindowManager::the().for_each_active_menubar_menu([&](WSMenu& menu) {
|
||||||
|
if (menu.rect_in_menubar().contains(mouse_event.position())) {
|
||||||
|
handle_menu_mouse_event(menu, mouse_event);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
return CObject::event(event);
|
return CObject::event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSMenuBarKeeper::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& event)
|
||||||
|
{
|
||||||
|
auto& wm = WSWindowManager::the();
|
||||||
|
bool is_hover_with_any_menu_open = event.type() == WSMouseEvent::MouseMove && wm.current_menu() && (wm.current_menu()->menubar() || wm.current_menu() == wm.system_menu());
|
||||||
|
bool is_mousedown_with_left_button = event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left;
|
||||||
|
bool should_open_menu = &menu != wm.current_menu() && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
|
||||||
|
|
||||||
|
if (should_open_menu) {
|
||||||
|
if (wm.current_menu() == &menu)
|
||||||
|
return;
|
||||||
|
wm.close_current_menu();
|
||||||
|
if (!menu.is_empty()) {
|
||||||
|
auto& menu_window = menu.ensure_menu_window();
|
||||||
|
menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
|
||||||
|
menu_window.set_visible(true);
|
||||||
|
}
|
||||||
|
wm.set_current_menu(&menu);
|
||||||
|
refresh();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left) {
|
||||||
|
wm.close_current_menu();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ private:
|
||||||
WSWindow& window() { return *m_window; }
|
WSWindow& window() { return *m_window; }
|
||||||
const WSWindow& window() const { return *m_window; }
|
const WSWindow& window() const { return *m_window; }
|
||||||
|
|
||||||
|
void handle_menu_mouse_event(WSMenu&, const WSMouseEvent&);
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void tick_clock();
|
void tick_clock();
|
||||||
|
|
||||||
|
|
|
@ -385,31 +385,6 @@ void WSWindowManager::pick_new_active_window()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindowManager::handle_menu_mouse_event(WSMenu& menu, const WSMouseEvent& event)
|
|
||||||
{
|
|
||||||
bool is_hover_with_any_menu_open = event.type() == WSMouseEvent::MouseMove && m_current_menu && (m_current_menu->menubar() || m_current_menu == m_system_menu);
|
|
||||||
bool is_mousedown_with_left_button = event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left;
|
|
||||||
bool should_open_menu = &menu != current_menu() && (is_hover_with_any_menu_open || is_mousedown_with_left_button);
|
|
||||||
|
|
||||||
if (should_open_menu) {
|
|
||||||
if (current_menu() == &menu)
|
|
||||||
return;
|
|
||||||
close_current_menu();
|
|
||||||
if (!menu.is_empty()) {
|
|
||||||
auto& menu_window = menu.ensure_menu_window();
|
|
||||||
menu_window.move_to({ menu.rect_in_menubar().x(), menu.rect_in_menubar().bottom() + 2 });
|
|
||||||
menu_window.set_visible(true);
|
|
||||||
}
|
|
||||||
m_current_menu = menu.make_weak_ptr();
|
|
||||||
m_menubar_keeper.refresh();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.type() == WSMouseEvent::MouseDown && event.button() == MouseButton::Left) {
|
|
||||||
close_current_menu();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSWindowManager::close_current_menu()
|
void WSWindowManager::close_current_menu()
|
||||||
{
|
{
|
||||||
if (m_current_menu && m_current_menu->menu_window())
|
if (m_current_menu && m_current_menu->menu_window())
|
||||||
|
@ -418,17 +393,6 @@ void WSWindowManager::close_current_menu()
|
||||||
m_menubar_keeper.refresh();
|
m_menubar_keeper.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSWindowManager::handle_menubar_mouse_event(const WSMouseEvent& event)
|
|
||||||
{
|
|
||||||
for_each_active_menubar_menu([&](WSMenu& menu) {
|
|
||||||
if (menu.rect_in_menubar().contains(event.position())) {
|
|
||||||
handle_menu_mouse_event(menu, event);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void WSWindowManager::start_window_drag(WSWindow& window, const WSMouseEvent& event)
|
void WSWindowManager::start_window_drag(WSWindow& window, const WSMouseEvent& event)
|
||||||
{
|
{
|
||||||
#ifdef DRAG_DEBUG
|
#ifdef DRAG_DEBUG
|
||||||
|
@ -718,10 +682,9 @@ void WSWindowManager::process_mouse_event(WSMouseEvent& event, WSWindow*& hovere
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menubar_rect().contains(event.position())) {
|
if (menubar_rect().contains(event.position())) {
|
||||||
handle_menubar_mouse_event(event);
|
m_menubar_keeper.event(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_current_menu && m_current_menu->menu_window()) {
|
if (m_current_menu && m_current_menu->menu_window()) {
|
||||||
auto& window = *m_current_menu->menu_window();
|
auto& window = *m_current_menu->menu_window();
|
||||||
bool event_is_inside_current_menu = window.rect().contains(event.position());
|
bool event_is_inside_current_menu = window.rect().contains(event.position());
|
||||||
|
|
|
@ -80,6 +80,7 @@ public:
|
||||||
void set_current_menubar(WSMenuBar*);
|
void set_current_menubar(WSMenuBar*);
|
||||||
WSMenu* current_menu() { return m_current_menu.ptr(); }
|
WSMenu* current_menu() { return m_current_menu.ptr(); }
|
||||||
void set_current_menu(WSMenu*);
|
void set_current_menu(WSMenu*);
|
||||||
|
WSMenu* system_menu() { return m_system_menu.ptr(); }
|
||||||
|
|
||||||
const WSCursor& active_cursor() const;
|
const WSCursor& active_cursor() const;
|
||||||
const WSCursor& arrow_cursor() const { return *m_arrow_cursor; }
|
const WSCursor& arrow_cursor() const { return *m_arrow_cursor; }
|
||||||
|
@ -106,6 +107,7 @@ public:
|
||||||
void close_menubar(WSMenuBar&);
|
void close_menubar(WSMenuBar&);
|
||||||
Color menu_selection_color() const { return m_menu_selection_color; }
|
Color menu_selection_color() const { return m_menu_selection_color; }
|
||||||
int menubar_menu_margin() const;
|
int menubar_menu_margin() const;
|
||||||
|
void close_current_menu();
|
||||||
|
|
||||||
void set_resolution(int width, int height);
|
void set_resolution(int width, int height);
|
||||||
|
|
||||||
|
@ -149,7 +151,6 @@ private:
|
||||||
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& hovered_window);
|
bool process_ongoing_window_resize(const WSMouseEvent&, WSWindow*& hovered_window);
|
||||||
bool process_ongoing_window_drag(WSMouseEvent&, WSWindow*& hovered_window);
|
bool process_ongoing_window_drag(WSMouseEvent&, WSWindow*& hovered_window);
|
||||||
void handle_menu_mouse_event(WSMenu&, const WSMouseEvent&);
|
void handle_menu_mouse_event(WSMenu&, const WSMouseEvent&);
|
||||||
void handle_menubar_mouse_event(const WSMouseEvent&);
|
|
||||||
void handle_close_button_mouse_event(WSWindow&, const WSMouseEvent&);
|
void handle_close_button_mouse_event(WSWindow&, const WSMouseEvent&);
|
||||||
void start_window_drag(WSWindow&, const WSMouseEvent&);
|
void start_window_drag(WSWindow&, const WSMouseEvent&);
|
||||||
void handle_client_request(const WSAPIClientRequest&);
|
void handle_client_request(const WSAPIClientRequest&);
|
||||||
|
@ -167,7 +168,6 @@ private:
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
void for_each_window(Callback);
|
void for_each_window(Callback);
|
||||||
|
|
||||||
void close_current_menu();
|
|
||||||
virtual void event(CEvent&) override;
|
virtual void event(CEvent&) override;
|
||||||
void paint_window_frame(const WSWindow&);
|
void paint_window_frame(const WSWindow&);
|
||||||
void tell_wm_listener_about_window(WSWindow& listener, WSWindow&);
|
void tell_wm_listener_about_window(WSWindow& listener, WSWindow&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue