diff --git a/src/kits/interface/MenuWindow.cpp b/src/kits/interface/MenuWindow.cpp index b84495eec8..a3cce07b77 100644 --- a/src/kits/interface/MenuWindow.cpp +++ b/src/kits/interface/MenuWindow.cpp @@ -55,6 +55,7 @@ BMenuWindow::AttachMenu(BMenu *menu) if (menu != NULL) { BMenuFrame *menuFrame = new BMenuFrame(menu); AddChild(menuFrame); + menu->MakeFocus(true); } } diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index fdfb5ef2f9..e63c0b4428 100644 --- a/src/servers/app/Desktop.cpp +++ b/src/servers/app/Desktop.cpp @@ -100,12 +100,9 @@ KeyboardFilter::_UpdateFocus(int32 key, EventTarget** _target) if (!fDesktop->LockSingleWindow()) return; + EventTarget* focus = fDesktop->KeyboardEventTarget(); bigtime_t now = system_time(); - EventTarget* focus = NULL; - if (fDesktop->FocusWindow() != NULL) - focus = &fDesktop->FocusWindow()->EventTarget(); - // TODO: this is a try to not steal focus from the current window // in case you enter some text and a window pops up you haven't // triggered yourself (like a pop-up window in your browser while @@ -1074,6 +1071,25 @@ Desktop::_UpdateFronts(bool updateFloating) } +/*! + Returns the current keyboard event target candidate - which is either the + top-most window (in case it's a menu), or the one having focus. + The window lock must be held when calling this function. +*/ +EventTarget* +Desktop::KeyboardEventTarget() +{ + WindowLayer* window = _CurrentWindows().LastWindow(); + if (window != NULL && window->Feel() == kMenuWindowFeel) + return &window->EventTarget(); + + if (FocusWindow() != NULL) + return &FocusWindow()->EventTarget(); + + return NULL; +} + + bool Desktop::_WindowHasModal(WindowLayer* window) { diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index f215729b64..9bb301e490 100644 --- a/src/servers/app/Desktop.h +++ b/src/servers/app/Desktop.h @@ -144,6 +144,7 @@ class Desktop : public MessageLooper, public ScreenOwner { int32 ViewUnderMouse(const WindowLayer* window); void SetFocusWindow(WindowLayer* window); + EventTarget* KeyboardEventTarget(); WindowLayer* FindWindowLayerByClientToken(int32 token, team_id teamID); //WindowLayer* FindWindowLayerByServerToken(int32 token);