hopefully does not lose keyboard control any more for users

This commit is contained in:
2026-07-26 14:09:55 +01:00
parent a7b4f04118
commit d3baa7e050
2 changed files with 58 additions and 17 deletions
+27
View File
@@ -10,6 +10,14 @@
'use strict';
// Prefix every console.log / console.error line with an ISO timestamp.
// Wrapping here means every existing log call site automatically gets a
// timestamp without needing to be touched individually.
const _origLog = console.log;
const _origError = console.error;
console.log = (...args) => _origLog(`[${new Date().toISOString()}]`, ...args);
console.error = (...args) => _origError(`[${new Date().toISOString()}]`, ...args);
const express = require('express');
const http = require('http');
const WebSocket = require('ws');
@@ -263,6 +271,25 @@ function performCssRestart(reason) {
}
containerRestarting = false;
broadcastQueueState();
// Explicitly give the newly-created CSS window keyboard focus once it
// has had time to map. Mouse clicks/movement always work after a
// restart because they target whatever window is physically under the
// cursor — but keyboard input goes to whichever window holds X11 input
// focus, which is separate state that does NOT automatically transfer
// to a freshly-relaunched window after a kill+relaunch (as opposed to a
// genuinely fresh X session on container boot). Without this, keyboard
// input can silently keep targeting a stale/dead window reference while
// everything else on the new window works fine — this was very likely
// the actual cause of "keyboard stuck, mouse/video fine" after restarts.
setTimeout(() => {
try {
execSync(`docker exec ${CONTAINER} bash -c "DISPLAY=:99 WIN=\$(xdotool search --name '' | head -1) && xdotool windowfocus --sync \$WIN" || true`);
console.log('[sig] CSS restart: focused new window');
} catch (e) {
console.error('[sig] CSS restart: failed to focus new window:', e.message);
}
}, 8000);
}, 2000);
}