mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
WindowServer: Add support for default MenuItem
This allows marking a MenuItem as a default action, e.g. in a context menu for an action that reflects what e.g. a double click would perform. Also enhance the window menu to mark the close action as the default, and when double clicked perform that action. Fixes #1289
This commit is contained in:
parent
684b04e02a
commit
fc4e01a3c9
10 changed files with 194 additions and 32 deletions
|
@ -370,10 +370,35 @@ void WindowFrame::on_mouse_event(const MouseEvent& event)
|
|||
if (m_window.type() != WindowType::Normal && m_window.type() != WindowType::Notification)
|
||||
return;
|
||||
|
||||
if (m_window.type() == WindowType::Normal && event.type() == Event::MouseDown && (event.button() == MouseButton::Left || event.button() == MouseButton::Right) && title_bar_icon_rect().contains(event.position())) {
|
||||
if (m_window.type() == WindowType::Normal && title_bar_icon_rect().contains(event.position())) {
|
||||
wm.move_to_front_and_make_active(m_window);
|
||||
m_window.popup_window_menu(title_bar_rect().bottom_left().translated(rect().location()));
|
||||
return;
|
||||
if (event.type() == Event::MouseDown && (event.button() == MouseButton::Left || event.button() == MouseButton::Right)) {
|
||||
// Manually start a potential double click. Since we're opening
|
||||
// a menu, we will only receive the MouseDown event, so we
|
||||
// need to record that fact. If the user subsequently clicks
|
||||
// on the same area, the menu will get closed, and we will
|
||||
// receive a MouseUp event, but because windows have changed
|
||||
// we don't get a MouseDoubleClick event. We can however record
|
||||
// this click, and when we receive the MouseUp event check if
|
||||
// it would have been considered a double click, if it weren't
|
||||
// for the fact that we opened and closed a window in the meanwhile
|
||||
auto& wm = WindowManager::the();
|
||||
wm.start_menu_doubleclick(m_window, event);
|
||||
|
||||
m_window.popup_window_menu(title_bar_rect().bottom_left().translated(rect().location()), WindowMenuDefaultAction::Close);
|
||||
return;
|
||||
} else if (event.type() == Event::MouseUp && event.button() == MouseButton::Left) {
|
||||
// Since the MouseDown event opened a menu, another MouseUp
|
||||
// from the second click outside the menu wouldn't be considered
|
||||
// a double click, so let's manually check if it would otherwise
|
||||
// have been be considered to be one
|
||||
auto& wm = WindowManager::the();
|
||||
if (wm.is_menu_doubleclick(m_window, event)) {
|
||||
// It is a double click, so perform activate the default item
|
||||
m_window.window_menu_activate_default();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This is slightly hackish, but expand the title bar rect by two pixels downwards,
|
||||
|
@ -394,7 +419,8 @@ void WindowFrame::on_mouse_event(const MouseEvent& event)
|
|||
}
|
||||
if (event.type() == Event::MouseDown) {
|
||||
if (m_window.type() == WindowType::Normal && event.button() == MouseButton::Right) {
|
||||
m_window.popup_window_menu(event.position().translated(rect().location()));
|
||||
auto default_action = m_window.is_maximized() ? WindowMenuDefaultAction::Restore : WindowMenuDefaultAction::Maximize;
|
||||
m_window.popup_window_menu(event.position().translated(rect().location()), default_action);
|
||||
return;
|
||||
}
|
||||
if (m_window.is_movable() && event.button() == MouseButton::Left)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue