diff options
| -rw-r--r-- | shutdown/SessionView.cpp | 3 | ||||
| -rw-r--r-- | tests/test_unity_window_view.cpp | 17 | ||||
| -rw-r--r-- | unity-shared/UnityWindowView.cpp | 6 |
3 files changed, 23 insertions, 3 deletions
diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index d8a7f6f79..93e77c996 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -296,7 +296,8 @@ nux::Area* View::FindKeyFocusArea(unsigned etype, unsigned long key_code, unsign { nux::InputArea* focused = nux::GetWindowCompositor().GetKeyFocusArea(); - if (!focused || !focused->IsMouseInside()) + // Let's reset the focused area if we're in keyboard-navigation mode. + if (focused && focused->IsChildOf(buttons_layout_) && !focused->IsMouseInside()) return this; } diff --git a/tests/test_unity_window_view.cpp b/tests/test_unity_window_view.cpp index 9ee7a7fc2..85fdac335 100644 --- a/tests/test_unity_window_view.cpp +++ b/tests/test_unity_window_view.cpp @@ -125,7 +125,6 @@ TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose) TEST_F(TestUnityWindowView, WindowManagerCloseKeyRequestsClose) { view.closable = true; - ASSERT_NE(view.close_button_, nullptr); auto& close_key = WindowManager::Default().close_window_key; close_key = std::make_pair(nux::KEY_MODIFIER_ALT, g_random_int()); @@ -140,7 +139,6 @@ TEST_F(TestUnityWindowView, WindowManagerCloseKeyRequestsClose) TEST_F(TestUnityWindowView, WindowManagerCloseKeyRequestsCloseWithCaps) { view.closable = true; - ASSERT_NE(view.close_button_, nullptr); auto& close_key = WindowManager::Default().close_window_key; close_key = std::make_pair(nux::KEY_MODIFIER_ALT, g_random_int()); @@ -153,6 +151,21 @@ TEST_F(TestUnityWindowView, WindowManagerCloseKeyRequestsCloseWithCaps) EXPECT_TRUE(close_requested); } +TEST_F(TestUnityWindowView, EscapeKeyRequestsClose) +{ + view.closable = true; + + bool close_requested = false; + view.request_close.connect([&close_requested] { close_requested = true; }); + + view.FindKeyFocusArea(nux::NUX_KEYDOWN, NUX_VK_ESCAPE, 0); + EXPECT_TRUE(close_requested); + + close_requested = false; + view.closable = false; + EXPECT_FALSE(close_requested); +} + TEST_F(TestUnityWindowView, QueueDrawsOnCloseTextureUpdate) { view.closable = true; diff --git a/unity-shared/UnityWindowView.cpp b/unity-shared/UnityWindowView.cpp index 89df8c5f9..ac1241556 100644 --- a/unity-shared/UnityWindowView.cpp +++ b/unity-shared/UnityWindowView.cpp @@ -94,6 +94,12 @@ nux::Area* UnityWindowView::FindKeyFocusArea(unsigned etype, unsigned long key_c request_close.emit(); return nullptr; } + + if (key_code == NUX_VK_ESCAPE) + { + request_close.emit(); + return nullptr; + } } return View::FindKeyFocusArea(etype, key_code, modifiers); |
