From 0219459ba09dcf3a0755b2bee9bc761033fb59cf Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Sat, 21 Jan 2006 09:23:59 +0000 Subject: [PATCH] Added a small time hysteresis: submenus are only opened if the user keeps the mouse there for a while. I'd like feedback on this git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16015 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/Menu.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index fbe0d566b5..bd944e3ebb 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -1108,17 +1108,31 @@ BMenu::_track(int *action, long start) ulong buttons; BMenuItem *item = NULL; int localAction = MENU_ACT_NONE; + + bigtime_t startTime = system_time(); + bigtime_t clickTime = 0; + get_click_speed(&clickTime); do { if (!LockLooper()) break; + bigtime_t snoozeAmount = 50000; BPoint location; GetMouse(&location, &buttons); item = HitTestItems(location, B_ORIGIN); if (item != NULL) { - if (item != fSelected) + if (item != fSelected) { + SelectItem(item, -1); + startTime = system_time(); + snoozeAmount = 20000; + } else if (system_time() > clickTime + startTime && item->Submenu() + && item->Submenu()->Window() == NULL) { + // Open the submenu if it's not opened yet, but only if + // the mouse pointer stayed over there for some time + // (hysteresis) SelectItem(item); + } } else { if (OverSuper(location)) { UnlockLooper(); @@ -1128,7 +1142,8 @@ BMenu::_track(int *action, long start) SelectItem(NULL); } - if (fSelected != NULL && fSelected->Submenu() != NULL) { + if (fSelected != NULL && fSelected->Submenu() != NULL + && fSelected->Submenu()->Window() != NULL) { UnlockLooper(); int submenuAction = MENU_ACT_NONE; @@ -1145,7 +1160,7 @@ BMenu::_track(int *action, long start) UnlockLooper(); - snooze(50000); + snooze(snoozeAmount); } while (buttons != 0); if (localAction == MENU_ACT_NONE) {