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:
co-authored by
Claude Opus 5
parent
a1d8150d7c
commit
f65c814eff
+101
-1
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import math
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
@@ -11,7 +12,7 @@ import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
gi.require_version("GtkLayerShell", "0.1")
|
||||
|
||||
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, GtkLayerShell
|
||||
from gi.repository import Gio, Gtk, Gdk, GdkPixbuf, GLib, GtkLayerShell
|
||||
|
||||
sys.path.insert(0, "/usr/local/lib/ekklesia-classroom")
|
||||
|
||||
@@ -76,6 +77,11 @@ BUSY_SPINNER_SIZE = 38
|
||||
THROBBER_FRAMES = 24
|
||||
THROBBER_INTERVAL_MS = 80
|
||||
|
||||
# Which secondary Chrome window the Close button acts on, published by
|
||||
# classroom-chrome-windows. A file rather than a socket because the dock
|
||||
# only ever reads it, and Gio can watch it without a poll.
|
||||
CLOSE_TARGET_NAME = "chrome-close-target"
|
||||
|
||||
BUSY_POLL_MS = 500
|
||||
|
||||
# Long enough for a cold Chrome start on classroom hardware, short enough
|
||||
@@ -231,6 +237,8 @@ class ClassroomShell(Gtk.Window):
|
||||
self.dvd_image = None
|
||||
self.disc_ready = None
|
||||
self.buttons = {}
|
||||
self.close_target = None
|
||||
self.close_monitor = None
|
||||
|
||||
GtkLayerShell.init_for_window(self)
|
||||
GtkLayerShell.set_layer(
|
||||
@@ -355,8 +363,100 @@ class ClassroomShell(Gtk.Window):
|
||||
0,
|
||||
)
|
||||
|
||||
# Only ever on screen while a secondary browser window is focused,
|
||||
# so the ordinary dock is exactly what it has always been.
|
||||
close = self.make_button(
|
||||
"close",
|
||||
custom_icon("close.svg", scaled(BROWSER_ICON_SIZE, self.scale))
|
||||
or themed_icon("window-close-symbolic"),
|
||||
self.close_secondary,
|
||||
)
|
||||
close.set_no_show_all(True)
|
||||
close.set_visible(False)
|
||||
|
||||
# show_all() does not recurse into a no-show-all widget, so the
|
||||
# icon has to be shown by hand or the button appears empty when
|
||||
# it is finally revealed.
|
||||
self.buttons["close"]["image"].show()
|
||||
|
||||
dock.pack_start(close, False, False, 0)
|
||||
|
||||
self.watch_close_target()
|
||||
|
||||
return dock
|
||||
|
||||
# -- the close affordance for secondary browser windows ---------
|
||||
#
|
||||
# The button lives here rather than on the window because a surface
|
||||
# anchored to a moving window chases it and flickers. The dock does
|
||||
# not move.
|
||||
|
||||
def watch_close_target(self):
|
||||
directory = Path(
|
||||
os.environ.get("XDG_RUNTIME_DIR") or "/tmp"
|
||||
) / "ekklesia-classroom"
|
||||
|
||||
try:
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
self.close_path = directory / CLOSE_TARGET_NAME
|
||||
|
||||
# Watching the directory rather than the file: the state is
|
||||
# published by rename, so the file itself is replaced.
|
||||
self.close_monitor = Gio.File.new_for_path(
|
||||
str(directory)
|
||||
).monitor_directory(Gio.FileMonitorFlags.NONE, None)
|
||||
|
||||
self.close_monitor.connect(
|
||||
"changed",
|
||||
self.on_close_target_changed,
|
||||
)
|
||||
except (OSError, GLib.Error) as error:
|
||||
print(
|
||||
f"classroom-dock: not watching for browser popups: {error}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
self.close_path = None
|
||||
return
|
||||
|
||||
self.refresh_close_target()
|
||||
|
||||
def on_close_target_changed(self, monitor, changed, other, event):
|
||||
if changed is not None and changed.get_basename() != CLOSE_TARGET_NAME:
|
||||
return
|
||||
|
||||
self.refresh_close_target()
|
||||
|
||||
def refresh_close_target(self):
|
||||
target = None
|
||||
|
||||
if self.close_path is not None:
|
||||
try:
|
||||
text = self.close_path.read_text().strip()
|
||||
except OSError:
|
||||
text = ""
|
||||
|
||||
if text.isdigit():
|
||||
target = int(text)
|
||||
|
||||
if target == self.close_target:
|
||||
return
|
||||
|
||||
self.close_target = target
|
||||
|
||||
entry = self.buttons.get("close")
|
||||
|
||||
if entry is not None:
|
||||
entry["button"].set_visible(target is not None)
|
||||
|
||||
def close_secondary(self, *_):
|
||||
if self.close_target is None or sway is None:
|
||||
return
|
||||
|
||||
# Closes exactly this container. Never the main browser, and
|
||||
# never a Chrome process.
|
||||
sway.command(f"[con_id={self.close_target}] kill")
|
||||
|
||||
def make_button(self, name, image, callback):
|
||||
button = Gtk.Button()
|
||||
button.set_relief(Gtk.ReliefStyle.NONE)
|
||||
|
||||
Reference in New Issue
Block a user