fix: put the popup close button in the dock, and clear the printer location

Three things, none of them redesigns.

The close affordance for a secondary Chrome window was a separate
layer-shell surface anchored to that window's corner, repositioned by a
five-per-second poll. Any position change tore the surface down and
built another, so on real hardware it chased the window and flickered.
Removed entirely: the GTK button process, the geometry maths that placed
it, the --close-button mode that spawned it, and the poll loop that
drove it. The window helper no longer imports GTK at all.

The behaviour underneath it was right and is kept. The first Chrome
top-level is the classroom browser, tiled and borderless; later ones
float centred at about three quarters of the output. Creation order is
the only thing that can tell them apart — confirmed on a real session,
where every Chrome top-level shares app_id, shell, PID and a null
transient_for, and sway exposes no window properties for Wayland
toplevels at all. Titles are still not used. It now follows sway's own
window events instead of polling, so dragging a popup costs nothing.

Close moved into the dock, which was already on screen and does not
move, so it cannot chase anything. It appears only while a secondary
window is focused and runs kill on that one container. The helper
publishes which window that is; the dock watches the file rather than
polling. A stock sway title bar has no close button, so restoring the
border would not have solved this either.

Two bugs found by looking rather than by testing state. Chrome
renegotiates the size of a popup opened with explicit dimensions after
the resize returns, which left windows centred for a width they no
longer had; placement now settles and repeats once, at creation only, so
dragging is still free. And the dock's Close button came up empty
because show_all does not recurse into a no-show-all widget.

The printer's Location is now blank. CUPS prints it under the queue name
in every dialog, so "Ekklesia Classroom" was a second line the teacher
had to read past; the identity is one word. The already-configured check
includes Location, so a machine set up before this is corrected rather
than left as close enough.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
ekklesia
2026-09-06 20:24:51 -05:00
co-authored by Claude Opus 5
parent a1d8150d7c
commit f65c814eff
18 changed files with 1144 additions and 100 deletions
+188
View File
@@ -0,0 +1,188 @@
#!/bin/bash
set -uo pipefail
# Secondary Chrome windows: which window is which, how a popup is placed,
# and which one the dock offers to close.
#
# tests/test-classroom-chrome-windows.sh
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PYTHONPATH="$ROOT/lib" python3 - "$ROOT" <<'PY'
import importlib.machinery
import importlib.util
import json
import os
import sys
import tempfile
from pathlib import Path
from classroom_chrome import ChromeRoles, chrome_windows
root = Path(sys.argv[1])
path = root / "scripts/classroom-chrome-windows"
loader = importlib.machinery.SourceFileLoader("classroom_chrome_windows", str(path))
spec = importlib.util.spec_from_loader(loader.name, loader)
script = importlib.util.module_from_spec(spec)
loader.exec_module(script)
source = path.read_text()
dock_source = (root / "scripts/classroom-dock").read_text()
passed = failed = 0
def check(label, condition, detail=""):
global passed, failed
if condition:
print(f" ok {label}")
passed += 1
else:
print(f" FAIL {label}")
if detail:
print(f" {detail}")
failed += 1
def window(identifier, title, floating=False, hidden=False, focused=False):
return {
"id": identifier,
"app_id": "google-chrome",
"class": "",
"instance": "",
"pid": 4242,
"name": title,
"focused": focused,
"floating": floating,
"hidden": hidden,
}
print("1. creation order decides which window is the browser")
roles = ChromeRoles()
main = window(5, "Main browser - Google Chrome")
popup = window(8, "about:blank - Google Chrome")
change = roles.update([main])
check("the first Chrome window is the browser", change["primary"] == 5)
check("it is not a popup", change["new_secondary"] == [])
change = roles.update([main, popup])
check("a later Chrome window is a popup", change["new_secondary"] == [8])
check("the browser stays the browser", change["primary"] == 5)
renamed_main = window(5, "Something else entirely")
renamed_popup = window(8, "A different page title")
change = roles.update([renamed_main, renamed_popup])
check("titles never change a role",
change["primary"] == 5 and not change["new_secondary"])
check("a shared PID never confuses roles",
len(chrome_windows([renamed_main, renamed_popup])) == 2)
print()
print("2. several popups at once")
third = window(9, "Third window")
change = roles.update([main, popup, third])
check("a third top-level is also a popup", change["new_secondary"] == [9])
change = roles.update([main, popup])
check("closing one leaves the other a popup", roles.secondary == [8])
check("the closed one is reported", change["removed"] == [9])
print()
print("3. how a popup is placed")
commands = []
script.command = lambda argument: commands.append(argument)
script.SETTLE_SECONDS = 0
script.configure_secondary(8)
check("floats exactly one container", commands[0] == "[con_id=8] floating enable")
check("borderless, like the main browser", commands[1] == "[con_id=8] border none")
check("about three quarters of the output",
"width 76 ppt height 76 ppt" in commands[2], commands)
check("centred", commands[3] == "[con_id=8] move position center")
check("focused", commands[4] == "[con_id=8] focus")
# Chrome resizes a popup after the fact, so the placement is repeated
# once the size has settled or the window ends up off to one side.
check("placed again after Chrome settles",
commands[-1] == "[con_id=8] move position center"
and "width 76 ppt" in commands[-2], commands)
check("placed exactly twice, never on a loop",
commands.count("[con_id=8] move position center") == 2, commands)
check("never matches all Chrome windows at once",
all("app_id" not in item for item in commands))
commands.clear()
script.configure_primary(8)
check("a promoted window goes back to tiled",
commands[0] == "[con_id=8] floating disable")
check("and borderless", commands[1] == "[con_id=8] border none")
print()
print("4. which popup the dock offers to close")
chrome = {5: window(5, "main", focused=True), 8: window(8, "popup")}
check("none while the main browser is focused",
script.focused_secondary([8], chrome) is None)
chrome = {5: window(5, "main"), 8: window(8, "popup", focused=True)}
check("the focused popup", script.focused_secondary([8], chrome) == 8)
chrome = {8: window(8, "one"), 9: window(9, "two", focused=True)}
check("the focused one of several", script.focused_secondary([8, 9], chrome) == 9)
chrome = {8: window(8, "one", hidden=True, focused=True)}
check("never a minimised one", script.focused_secondary([8], chrome) is None)
check("nothing focused means nothing to close",
script.focused_secondary([8], {8: window(8, "p")}) is None)
print()
print("5. the state the dock reads")
work = Path(tempfile.mkdtemp())
state = work / "chrome-close-target"
script.publish(9, state)
check("publishes the container id", state.read_text().strip() == "9")
check("published by rename, not left half written",
not (work / "chrome-close-target.tmp").exists())
script.publish(None, state)
check("empty when there is nothing to close", state.read_text().strip() == "")
print()
print("6. the dock owns the button, not the window")
check("no layer-shell surface in the window helper",
"GtkLayerShell" not in source)
check("no second GTK process spawned for a button",
"Gtk.main" not in source and "show_close_button" not in source)
check("no geometry maths chasing a window",
"output_rect" not in source and "button_margins" not in source)
check("the dock has a close action", '"close"' in dock_source)
check("the dock closes exactly one container",
'[con_id={self.close_target}] kill' in dock_source)
check("the dock never kills Chrome processes",
"pkill" not in dock_source and "killall" not in dock_source)
check("the dock watches rather than polls for it",
"monitor_directory" in dock_source)
print()
print("7. driven by Sway events, not a poll")
check("subscribes to window events", '"-t", "subscribe"' in source)
check("ignores title churn",
"title" not in script.INTERESTING and "new" in script.INTERESTING)
check("reacts to focus and movement",
{"focus", "move", "close"} <= set(script.INTERESTING))
check("no polling loop constant", "POLL_SECONDS" not in source)
print()
print("8. the session still starts it")
config = (root / "config/sway/config").read_text()
check("started with the session",
"exec --no-startup-id /usr/local/bin/classroom-chrome-windows" in config)
check("no broad Chrome floating rule",
not any("floating enable" in line and "google-chrome" in line
for line in config.splitlines()))
print()
print(f"passed: {passed} failed: {failed}")
sys.exit(1 if failed else 0)
PY
+157 -21
View File
@@ -35,18 +35,119 @@ check_absent() {
fi
}
mkdir -p "$WORK/bin"
mkdir -p "$WORK/bin" "$WORK/state"
for command in lpadmin cupsenable cupsaccept; do
cat > "$WORK/bin/$command" <<'SHIM'
cat > "$WORK/bin/lpadmin" <<'SHIM'
#!/bin/bash
echo "$(basename "$0") $*" >> "$CUPS_LOG"
SHIM
echo "lpadmin $*" >> "$CUPS_LOG"
if [[ "$1" == "-x" ]]; then
rm -f "$CUPS_STATE/legacy"
exit 0
fi
if [[ "$1" == "-d" ]]; then
echo "$2" > "$CUPS_STATE/default"
exit 0
fi
queue=""
uri=""
description=""
location=""
location_given=false
printout=""
color=""
model=false
while [[ $# -gt 0 ]]; do
case "$1" in
-p) queue="$2"; shift 2 ;;
-v) uri="$2"; shift 2 ;;
-m) model=true; shift 2 ;;
-D) description="$2"; shift 2 ;;
-L) location="$2"; location_given=true; shift 2 ;;
-o)
[[ "$2" == PrintoutMode=* ]] && printout="${2#*=}"
[[ "$2" == ColorModel=* ]] && color="${2#*=}"
shift 2
;;
*) shift ;;
esac
done
[[ -n "$queue" ]] || exit 0
[[ -z "$uri" ]] || echo "$uri" > "$CUPS_STATE/uri"
[[ -z "$description" ]] || echo "$description" > "$CUPS_STATE/description"
[[ "$location_given" == false ]] || printf '%s' "$location" > "$CUPS_STATE/location"
# Match CUPS on Trixie: PPD choices sent while selecting the model are not
# retained. The production helper must set them in a follow-up request.
if [[ "$model" == false ]]; then
[[ -z "$printout" ]] || echo "$printout" > "$CUPS_STATE/printout"
[[ -z "$color" ]] || echo "$color" > "$CUPS_STATE/color"
fi
touch "$CUPS_STATE/queue"
SHIM
cat > "$WORK/bin/cupsenable" <<'SHIM'
#!/bin/bash
echo "cupsenable $*" >> "$CUPS_LOG"
touch "$CUPS_STATE/enabled"
SHIM
cat > "$WORK/bin/cupsaccept" <<'SHIM'
#!/bin/bash
echo "cupsaccept $*" >> "$CUPS_LOG"
touch "$CUPS_STATE/accepting"
SHIM
cat > "$WORK/bin/lpstat" <<'SHIM'
#!/bin/bash
[[ "${FAKE_CUPS_RUNNING:-true}" == "true" ]]
case "$1" in
-r)
[[ "${FAKE_CUPS_RUNNING:-true}" == "true" ]]
;;
-v)
[[ -f "$CUPS_STATE/queue" ]] || exit 1
echo "device for Elmer: $(cat "$CUPS_STATE/uri")"
;;
-a)
[[ -f "$CUPS_STATE/accepting" ]] || exit 1
echo "Elmer accepting requests since now"
;;
-d)
[[ -f "$CUPS_STATE/default" ]] || exit 1
echo "system default destination: $(cat "$CUPS_STATE/default")"
;;
-l)
[[ -f "$CUPS_STATE/queue" ]] || exit 1
echo "printer Elmer is idle. enabled since now"
echo " Description: $(cat "$CUPS_STATE/description")"
echo " Location: $(cat "$CUPS_STATE/location" 2>/dev/null || true)"
;;
-p)
if [[ "$2" == "Classroom_Color" ]]; then
[[ -f "$CUPS_STATE/legacy" ]] || exit 1
echo "printer Classroom_Color is idle. enabled since now"
else
[[ -f "$CUPS_STATE/queue" ]] || exit 1
enabled=disabled
[[ -f "$CUPS_STATE/enabled" ]] && enabled=enabled
echo "printer Elmer is idle. $enabled since now"
fi
;;
esac
SHIM
cat > "$WORK/bin/lpoptions" <<'SHIM'
#!/bin/bash
[[ -f "$CUPS_STATE/queue" ]] || exit 1
printout="$(cat "$CUPS_STATE/printout")"
color="$(cat "$CUPS_STATE/color")"
echo "PrintoutMode/Printout Mode: Draft *${printout} High"
echo "ColorModel/Color Mode: Gray *${color}"
SHIM
cat > "$WORK/bin/lpinfo" <<'SHIM'
@@ -58,37 +159,71 @@ else
fi
SHIM
cat > "$WORK/bin/systemctl" <<'SHIM'
#!/bin/bash
echo "systemctl $*" >> "$SERVICE_LOG"
SHIM
chmod +x "$WORK/bin"/*
export PATH="$WORK/bin:$PATH"
export CUPS_LOG="$WORK/cups.log"
export SERVICE_LOG="$WORK/services.log"
export CUPS_STATE="$WORK/state"
export CLASSROOM_PRINTER_SETUP_TESTING=true
run() {
"$SCRIPT" "$@" 2>&1
}
echo "1. creates the explicit classroom queue"
echo "1. provisions the site printer exactly"
: > "$CUPS_LOG"
out="$(run 10.20.30.40)"
: > "$SERVICE_LOG"
touch "$CUPS_STATE/legacy"
out="$(run)"
log="$(cat "$CUPS_LOG")"
check "uses AppSocket by IP" "-v socket://10.20.30.40:9100" "$log"
services="$(cat "$SERVICE_LOG")"
check "uses the verified site AppSocket URI" "-v socket://10.10.0.155:9100" "$log"
check "creates the Elmer queue" "lpadmin -p Elmer" "$log"
check "description is Elmer" "-D Elmer" "$log"
check "uses Trixie's generic color PCL 6 driver" \
"Generic-PCL_6_PCL_XL_Printer-pxlcolor.ppd" "$log"
check "uses one stable queue name" "lpadmin -p Classroom_Color" "$log"
check "enables the queue" "cupsenable Classroom_Color" "$log"
check "accepts jobs" "cupsaccept Classroom_Color" "$log"
check "defaults the queue" "lpadmin -d Classroom_Color" "$log"
check "reports offline-safe behavior" "may remain offline" "$out"
check "forces normal quality" "-o PrintoutMode=Normal" "$log"
check "forces color" "-o ColorModel=Color" "$log"
check "sets driver defaults after selecting the PPD" \
"lpadmin -p Elmer -o PrintoutMode=Normal -o ColorModel=Color" "$log"
check "enables Elmer" "cupsenable Elmer" "$log"
check "accepts jobs" "cupsaccept Elmer" "$log"
check "defaults Elmer" "lpadmin -d Elmer" "$log"
check "removes the legacy queue" "lpadmin -x Classroom_Color" "$log"
check "disables Avahi service and socket" "disable --now avahi-daemon.socket avahi-daemon.service" "$services"
check "masks Avahi service and socket" "mask avahi-daemon.socket avahi-daemon.service" "$services"
check "reports color defaults" "PrintoutMode=Normal, ColorModel=Color" "$out"
# The teacher-facing identity is just "Elmer". CUPS prints Location under
# the queue name in every print dialog, so it has to be empty.
check "passes an empty Location to CUPS" "-D Elmer -L" "$log"
check "no location text is written" "0" \
"$(grep -c 'Ekklesia Classroom' "$CUPS_LOG")"
check "the queue is left with no location" "" \
"$(cat "$CUPS_STATE/location" 2>/dev/null)"
echo
echo "2. repeated setup updates the same queue"
run 10.20.30.40 >/dev/null
configs="$(grep -c '^lpadmin -p Classroom_Color' "$CUPS_LOG")"
check "two runs configured the same queue twice" "2" "$configs"
check_absent "no generated queue suffix" "Classroom_Color_" "$(cat "$CUPS_LOG")"
echo "2. a correct repeated run is a quick no-op"
: > "$CUPS_LOG"
out="$(run)"
check "reports already configured" "Elmer is already correctly configured" "$out"
check "does not rewrite the queue" "0" "$(wc -l < "$CUPS_LOG")"
echo
echo "3. explicit URIs and non-default setup"
echo "2b. a machine configured the old way is corrected"
printf 'Ekklesia Classroom' > "$CUPS_STATE/location"
: > "$CUPS_LOG"
out="$(run)"
check "notices the stale location" "configuring Elmer" "$out"
check "clears it" "" "$(cat "$CUPS_STATE/location" 2>/dev/null)"
check "and then settles" "Elmer is already correctly configured" "$(run)"
echo
echo "3. explicit URI remains available for administration"
: > "$CUPS_LOG"
run --no-default ipp://printer.example.test/ipp/print >/dev/null
log="$(cat "$CUPS_LOG")"
@@ -104,7 +239,8 @@ else
fi
export FAKE_DRIVER_PRESENT=false
if out="$(run 10.20.30.40)"; then
rm -f "$CUPS_STATE/queue"
if out="$(run)"; then
check "missing driver fails" "failure" "unexpected success"
else
check "missing driver is explained" "generic color PCL 6 driver is not installed" "$out"
+25 -3
View File
@@ -15,6 +15,9 @@ postinst = (root / "packaging/debian/postinst").read_text()
provision = (root / "scripts/classroom-provision").read_text()
units = "\n".join(path.read_text() for path in (root / "systemd").rglob("*.service"))
canary = (root / "update_canary.sh").read_text()
validation_script = (root / "tools/validate-trixie-release.sh").read_text()
sway = (root / "config/sway/config").read_text()
build = (root / "tools/build-release.sh").read_text()
policy = json.loads(
(root / "config/chrome/policies/managed/ekklesia-classroom.json").read_text()
)
@@ -56,12 +59,31 @@ print("3. printing service behavior")
check("CUPS service and socket are enabled", "systemctl enable cups.socket cups.service || true" in postinst)
check("CUPS start is best effort", "systemctl start cups.socket || true" in postinst)
check("automatic remote queue browsing is disabled", "systemctl disable --now cups-browsed.service || true" in postinst)
check("printer setup is never a boot service", "classroom-printer-setup" not in units)
check("printer setup is never provisioning", "classroom-printer-setup" not in provision)
check("Avahi service and socket are disabled", "systemctl disable --now avahi-daemon.socket avahi-daemon.service || true" in postinst)
check("Avahi service and socket are masked", "systemctl mask avahi-daemon.socket avahi-daemon.service || true" in postinst)
check("printer setup is not a blocking boot dependency", "classroom-printer-setup" not in units)
check("printer setup runs automatically in provisioning", "/usr/local/bin/classroom-printer-setup" in provision)
check("printer provisioning is bounded", "--kill-after=5s 30s" in provision)
check("Chrome uses the system print dialog", policy.get("DisablePrintPreview") is True)
print()
print("4. canary release gate")
print("4. secondary Chrome windows")
check("stateful Chrome helper starts with Sway", "/usr/local/bin/classroom-chrome-windows" in sway)
check("Chrome helper is packaged", '"$ROOT/scripts/classroom-chrome-windows"' in build)
check("Chrome role module is packaged", '"$ROOT/lib/classroom_chrome.py"' in build)
check("no broad Chrome floating rule", not any(
"google-chrome" in line and "floating enable" in line
for line in sway.splitlines()
))
print()
print("5. bounded Trixie validation")
check("container has an outer deadline", "720s" in validation_script)
check("package installs have deadlines", "candidate-install 360" in validation_script)
check("container service startup is suppressed", "/usr/sbin/policy-rc.d" in validation_script and "exit 101" in validation_script)
print()
print("6. canary release gate")
validation = canary.index('"$ROOT/tools/validate-trixie-release.sh"')
package_copy = canary.index('cp "$package_path"')
first_rsync = canary.index("rsync -av")