From c60b95b519a9c834a861b74043051450aca50e2d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Nov 2026 05:28:25 +0000 Subject: [PATCH] Give lock, PIN, WiFi and dialog windows keyboard focus when they open Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013wi3ZQveYdjfcrEsyazq32 --- kiosk-app/main.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kiosk-app/main.js b/kiosk-app/main.js index 14fd168..ddd064b 100644 --- a/kiosk-app/main.js +++ b/kiosk-app/main.js @@ -282,6 +282,7 @@ function showLockoutScreen(mode){ // The boot screen takes the separate boot code when one is set. const codeType=(lockoutMode==='boot'&&bootPassword)?bootCodeType:lockoutCodeType; lockoutWindow.loadFile(path.join(__dirname,'lockscreen.html'),{query:{type:codeType,mode:lockoutMode}}); + grabKeyboardFocus(lockoutWindow); lockoutWindow.on('closed',()=>{ lockoutWindow=null; @@ -880,6 +881,27 @@ function returnToHome(){ markActivity(); } +// Make a freshly opened dialog/lock window take the physical keyboard. +// Without this, under a bare window manager (openbox) the new window can +// show up but keyboard focus stays on the page behind it, so a PIN or +// password could only be entered by touch / the on-screen keyboard. +function grabKeyboardFocus(win){ + const take=()=>{ + if(!win||win.isDestroyed())return; + try{ + win.show(); + win.focus(); + win.webContents.focus(); + }catch(e){ + console.log('[FOCUS] Could not focus window:',e.message); + } + }; + win.once('ready-to-show',take); + win.webContents.once('did-finish-load',take); + // Window managers can hand focus elsewhere just after mapping the window. + setTimeout(take,300); +} + function showInactivityPrompt(){ if(promptWindow&&!promptWindow.isDestroyed())return; @@ -894,6 +916,7 @@ function showInactivityPrompt(){ }); promptWindow.loadFile(path.join(__dirname,'inactivity-prompt-extended.html')); + grabKeyboardFocus(promptWindow); promptWindow.on('closed',()=>{ promptWindow=null; @@ -961,6 +984,7 @@ function showPauseDialog(){ }); pauseWindow.loadFile(path.join(__dirname,'pause-dialog.html')); + grabKeyboardFocus(pauseWindow); pauseWindow.on('closed',()=>{ if(pauseWindowTimer){clearTimeout(pauseWindowTimer);pauseWindowTimer=null;} @@ -1161,6 +1185,7 @@ function showPinEntry(){ }); pinWindow.loadFile(path.join(__dirname,'pin-entry.html')); + grabKeyboardFocus(pinWindow); pinWindow.on('closed',()=>{ if(pinWindowTimer){clearTimeout(pinWindowTimer);pinWindowTimer=null;} pinWindow=null; @@ -1282,6 +1307,7 @@ function showWifiWindow(){ }); wifiWindow.setMenu(null); wifiWindow.loadFile(path.join(__dirname,'wifi.html')); + grabKeyboardFocus(wifiWindow); wifiWindow.on('closed',()=>{ if(wifiIdleTimer){clearTimeout(wifiIdleTimer);wifiIdleTimer=null;} wifiWindow=null;