From f92afdf20ecf105a0e65faa2df1707e070832c5b Mon Sep 17 00:00:00 2001 From: Compot Developer Date: Mon, 12 Oct 2026 17:32:15 +0000 Subject: [PATCH] fix: Escape also closes a menu opened by touch A menu opened by touch has no focused view, so key events never reached its layout and Escape did not close it (found while testing #60). In touch mode the layout now takes focus; with a remote, focus stays on the menu items as before. --- .../main/java/com/openipc/decoder/MenuManager.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/android/app/src/main/java/com/openipc/decoder/MenuManager.java b/android/app/src/main/java/com/openipc/decoder/MenuManager.java index d917d272..742f1013 100644 --- a/android/app/src/main/java/com/openipc/decoder/MenuManager.java +++ b/android/app/src/main/java/com/openipc/decoder/MenuManager.java @@ -110,6 +110,7 @@ void showMenu(View anchor, boolean quadEnabled, int mActive, String version, int margin = dp(12); mMenuPopup.showAtLocation(anchor, Gravity.TOP | Gravity.START, margin, margin); mMenuPopup.setOnDismissListener(() -> mMenuPopup = null); + focusForKeys(mMenuLayout); return; } @@ -126,6 +127,7 @@ public boolean dispatchKeyEvent(KeyEvent event) { } }; layout.setOrientation(LinearLayout.VERTICAL); + layout.setFocusableInTouchMode(true); PopupWindow popup = new PopupWindow(layout, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true); @@ -133,6 +135,7 @@ public boolean dispatchKeyEvent(KeyEvent event) { popup.showAtLocation(anchor, Gravity.TOP | Gravity.START, margin, margin); mMenuPopup = popup; popup.setOnDismissListener(() -> mMenuPopup = null); + focusForKeys(layout); LinearLayout camRow = new LinearLayout(activity); camRow.setOrientation(LinearLayout.HORIZONTAL); @@ -247,6 +250,15 @@ private void updateCachedMenu(boolean quadEnabled, int mActive, String[] mHosts) } } + /** + * A menu opened by touch has no focused view, so keys never reach the layout and Escape + * did not close it. In touch mode the layout itself takes focus; with a remote, focus + * stays on the menu items as before. + */ + private static void focusForKeys(View layout) { + if (layout.isInTouchMode()) layout.requestFocus(); + } + private TextView createItem(String title) { TextView text = new TextView(activity); text.setText(title);