fix: keep the system print dialog in front of the window that rendered it
The render helper sat on top of the Print dialog, so the dialog could not be reached and nothing could be printed. Two causes. The daemon could not see window titles at all — the tree walk never collected them — and both windows arrive close enough together to be configured in the same pass, in whatever order the tree lists them. Configuring a window focuses it, so whichever was done last ended up in front, and that was not reliably the dialog. The dialog is now recognised by its exact title and configured last, and if a Chrome popup takes focus while it exists, focus is handed straight back. Focus is only ever reclaimed from another popup: clicking the main browser or the dock is the teacher's business and is left alone. A title match, narrowly, and only for this one known dialog. Creation order still decides which Chrome window is the browser; nothing else is classified by what it happens to be called. Nothing auto-closes the helper. After Print is cancelled it stays, and the sticky dock X still closes it. Proven by looking rather than by state. The render window is given a saturated background in the fixture so a screenshot answers "which window is in front" unambiguously: Print opens in front, the helper is then deliberately raised over it and Print comes back in front, cancelling Print leaves the helper visible with the dock X still offering it, and that X closes exactly the helper and leaves the main browser untouched. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0e91b4cbd3
commit
aadb1b8819
@@ -174,6 +174,59 @@ chrome = {8: window(8, "one", hidden=True)}
|
||||
check("a minimised popup is not adopted",
|
||||
hidden.update([8], chrome) is None)
|
||||
|
||||
print()
|
||||
print("4b. the print dialog stays in front")
|
||||
|
||||
def win(identifier, title, focused=False, hidden=False):
|
||||
w = window(identifier, title, focused=focused, hidden=hidden)
|
||||
w["name"] = title
|
||||
return w
|
||||
|
||||
check("the dialog is recognised by its exact title",
|
||||
script.is_print_dialog({"name": "Print"}))
|
||||
check("the render window is not",
|
||||
not script.is_print_dialog({"name": "Printable Document - Google Chrome"}))
|
||||
check("nothing else is", not script.is_print_dialog({"name": "Print Preview"}))
|
||||
check("a missing title is not", not script.is_print_dialog({}))
|
||||
|
||||
commands.clear()
|
||||
# The render window has raised itself over the dialog.
|
||||
chrome = {5: win(5, "main"), 8: win(8, "Printable Document", focused=True),
|
||||
9: win(9, "Print")}
|
||||
script.keep_print_in_front([8, 9], chrome)
|
||||
check("focus is taken back for the dialog",
|
||||
commands == ["[con_id=9] focus"], commands)
|
||||
|
||||
commands.clear()
|
||||
chrome = {5: win(5, "main"), 8: win(8, "Printable Document"), 9: win(9, "Print", focused=True)}
|
||||
script.keep_print_in_front([8, 9], chrome)
|
||||
check("nothing happens while the dialog already has focus", commands == [], commands)
|
||||
|
||||
commands.clear()
|
||||
chrome = {5: win(5, "main", focused=True), 8: win(8, "Printable Document"),
|
||||
9: win(9, "Print")}
|
||||
script.keep_print_in_front([8, 9], chrome)
|
||||
check("focus is never stolen from the main browser", commands == [], commands)
|
||||
|
||||
commands.clear()
|
||||
chrome = {5: win(5, "main"), 8: win(8, "Printable Document")}
|
||||
script.keep_print_in_front([8], chrome)
|
||||
check("nothing happens when there is no dialog", commands == [], commands)
|
||||
|
||||
commands.clear()
|
||||
chrome = {8: win(8, "Printable Document", focused=True), 9: win(9, "Print", hidden=True)}
|
||||
script.keep_print_in_front([8, 9], chrome)
|
||||
check("a minimised dialog is left alone", commands == [], commands)
|
||||
|
||||
# Both arriving together: whichever is configured last ends up in front,
|
||||
# so the dialog has to be last.
|
||||
order = sorted([8, 9], key=lambda i: script.is_print_dialog(
|
||||
{8: {"name": "Printable Document"}, 9: {"name": "Print"}}[i]))
|
||||
check("the dialog is configured after the render window", order == [8, 9], order)
|
||||
order = sorted([9, 8], key=lambda i: script.is_print_dialog(
|
||||
{8: {"name": "Printable Document"}, 9: {"name": "Print"}}[i]))
|
||||
check("even when the tree lists it first", order == [8, 9], order)
|
||||
|
||||
print()
|
||||
print("5. the state the dock reads")
|
||||
work = Path(tempfile.mkdtemp())
|
||||
|
||||
Reference in New Issue
Block a user