From 2de843143d692d19687071cf27692626208a0102 Mon Sep 17 00:00:00 2001 From: Andy Kopra Date: Sun, 11 Oct 2026 19:10:25 +0200 Subject: [PATCH] Trace window focus, blur and visibility in pen input From the development repository at 0304046. Co-Authored-By: Claude Opus 4.8 --- client/js/pen_input.js | 17 ++++++++++++++++- tests/test_end_to_end.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/js/pen_input.js b/client/js/pen_input.js index b382ee6..962959b 100644 --- a/client/js/pen_input.js +++ b/client/js/pen_input.js @@ -178,7 +178,8 @@ export function attachPenInput(surface, target) { /** @param {PointerEvent} event @returns {string} The press, for the trace. */ function describe(event) { const where = event.target === surface ? '' : ` on ${describeTarget(event.target)}`; - return `${event.pointerType} ${event.pointerId} buttons ${event.buttons} pressure ${event.pressure.toFixed(2)}${where}`; + const focus = document.hasFocus() ? 'in front' : 'behind'; + return `${event.pointerType} ${event.pointerId} buttons ${event.buttons} pressure ${event.pressure.toFixed(2)} (${focus})${where}`; } surface.addEventListener('pointerdown', (event) => { @@ -314,6 +315,20 @@ export function attachPenInput(surface, target) { // The side button of a pen asks for a context menu. surface.addEventListener('contextmenu', (event) => event.preventDefault()); + // The window's focus, blur and the tab's visibility, traced into the + // Session log but acting on nothing yet (2026-10-11): Andy's pages + // sometimes gained a lone dot when he clicked the page to bring the + // browser to the front from the terminal, with the Pen chosen. A + // press that only raised the window should draw nothing, but whether + // the browser reports the focus before that press or after it, and + // whether the document is focused when the press arrives, must be + // learned on his machine before the rule is written (a window focus + // is faked by the test harness on every tab switch, so it cannot be + // learned here). The press trace already carries "in front"/"behind". + window.addEventListener('focus', () => trace('window: focus')); + window.addEventListener('blur', () => trace('window: blur')); + document.addEventListener('visibilitychange', () => trace(`visibility: ${document.visibilityState}`)); + // Safari on iOS: cancelling pointerdown leaves the touch's own // behaviour (selection, the magnifier, the callout) to WebKit; only a // cancelled touchstart stops it. The text field is a child of the diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index fa185bc..3c40c5b 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -781,7 +781,7 @@ class EndToEndTest(unittest.TestCase): # and a release of the pen, after the browser's name. shown = firefox.run("return document.getElementById('event_log').textContent;") self.assertRegex(shown, r"^\d\d:\d\d:\d\d\.\d\d\d Browser: Mozilla") - self.assertRegex(shown, r"\n\S+ press pen \d+ buttons 1 pressure \d\.\d\d, pen\n") + self.assertRegex(shown, r"\n\S+ press pen \d+ buttons 1 pressure \d\.\d\d \((?:in front|behind)\), pen\n") self.assertRegex(shown, r"\n\S+ pointerup pen \d+, \d+ points") firefox.run("document.getElementById('session_close').click();") self.assertFalse(firefox.run("return document.getElementById('session_dialog').open;"))