v0.08: prevent minimize — toolbar self-restores, Chromium watchdog

This commit is contained in:
2026-05-22 20:22:03 +00:00
parent d4041582f0
commit ff58ec0fd4
+40 -1
View File
@@ -513,6 +513,11 @@ class KioskOverlay(QWidget):
screen = QApplication.instance().primaryScreen() screen = QApplication.instance().primaryScreen()
screen.geometryChanged.connect(self._on_screen_resize) screen.geometryChanged.connect(self._on_screen_resize)
# Watchdog: if Chromium ever gets minimised, map it back every 2 s.
self._watchdog = QTimer()
self._watchdog.timeout.connect(self._restore_chromium)
self._watchdog.start(2000)
def _on_screen_resize(self, rect): def _on_screen_resize(self, rect):
global SCREEN_W, SCREEN_H global SCREEN_W, SCREEN_H
w, h = rect.width(), rect.height() w, h = rect.width(), rect.height()
@@ -528,6 +533,41 @@ class KioskOverlay(QWidget):
def _resize_chrome(self): def _resize_chrome(self):
self.cdp.resize_window(0, TOP_H, SCREEN_W, SCREEN_H - TOP_H) self.cdp.resize_window(0, TOP_H, SCREEN_W, SCREEN_H - TOP_H)
def changeEvent(self, event):
"""Un-minimise the toolbar the instant it gets iconified."""
from PyQt5.QtCore import QEvent
if event.type() == QEvent.WindowStateChange:
if self.windowState() & Qt.WindowMinimized:
QTimer.singleShot(50, self._self_restore)
super().changeEvent(event)
def _self_restore(self):
self.setWindowState(Qt.WindowNoState)
self.show()
self.raise_()
def _restore_chromium(self):
"""Watchdog: restore Chromium if it was minimised (_NET_WM_STATE_HIDDEN)."""
try:
result = subprocess.run(
["xdotool", "search", "--class", "chromium"],
capture_output=True, text=True, timeout=2
)
for wid in result.stdout.strip().split():
if not wid:
continue
state = subprocess.run(
["xprop", "-id", wid, "_NET_WM_STATE"],
capture_output=True, text=True, timeout=1
)
if "_NET_WM_STATE_HIDDEN" in state.stdout:
subprocess.run(
["xdotool", "windowmap", wid],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
except Exception:
pass
def _build_toolbar(self): def _build_toolbar(self):
bar = QWidget(); bar.setFixedHeight(TOOLBAR_H) bar = QWidget(); bar.setFixedHeight(TOOLBAR_H)
bar.setStyleSheet(f"background:{TOOLBAR_COLOR};") bar.setStyleSheet(f"background:{TOOLBAR_COLOR};")
@@ -681,7 +721,6 @@ def launch_chrome():
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
# Detect actual screen resolution at runtime # Detect actual screen resolution at runtime
global SCREEN_W, SCREEN_H
_geo = app.primaryScreen().geometry() _geo = app.primaryScreen().geometry()
SCREEN_W, SCREEN_H = _geo.width(), _geo.height() SCREEN_W, SCREEN_H = _geo.width(), _geo.height()
app.setApplicationName("SeniorNet") app.setApplicationName("SeniorNet")