<message>Delete obsolete one-shot scripts for setting screen rotation and wallpaper, as well as related Python and shell scripts. Update the first-boot configuration to streamline the provisioning process by removing references to these scripts. This cleanup enhances maintainability and focuses on the essential steps required for the first boot experience, ensuring a more efficient setup for users.
107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
# 5 taps in the top-right corner of the screen close Chromium (kiosk).
|
|
# Run from session autostart. Requires: python3, PyGObject (Gtk), Wayland or X11.
|
|
|
|
import logging
|
|
import subprocess
|
|
import sys
|
|
|
|
LOG_TAG = "five-tap"
|
|
logging.basicConfig(
|
|
stream=sys.stderr,
|
|
level=logging.DEBUG,
|
|
format=f"{LOG_TAG}: %(message)s",
|
|
)
|
|
log = logging.getLogger(LOG_TAG)
|
|
|
|
try:
|
|
import gi
|
|
gi.require_version("Gdk", "3.0")
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gdk, Gtk, GLib
|
|
except Exception as e:
|
|
log.error("need PyGObject Gtk: %s", e)
|
|
sys.exit(1)
|
|
|
|
CORNER_SIZE = 80
|
|
TAP_WINDOW_SEC = 2.0
|
|
CHROMIUM_KILL_CMD = ["pkill", "-f", "chromium"]
|
|
|
|
|
|
def get_screen_size():
|
|
display = Gdk.Display.get_default()
|
|
if not display:
|
|
log.warning("no display found, using fallback 800x1280")
|
|
return 800, 1280
|
|
monitor = display.get_monitor(0) if display.get_n_monitors() else None
|
|
if monitor:
|
|
geom = monitor.get_geometry()
|
|
log.info("screen size: %dx%d", geom.width, geom.height)
|
|
return geom.width, geom.height
|
|
log.warning("no monitor found, using fallback 800x1280")
|
|
return 800, 1280
|
|
|
|
|
|
def on_button_press(widget, event, data):
|
|
count, reset_timer = data
|
|
count[0] += 1
|
|
log.debug("tap %d of 5 at (%.0f, %.0f)", count[0], event.x_root, event.y_root)
|
|
if reset_timer[0]:
|
|
GLib.source_remove(reset_timer[0])
|
|
if count[0] >= 5:
|
|
count[0] = 0
|
|
log.info("5 taps reached — killing chromium")
|
|
try:
|
|
result = subprocess.run(CHROMIUM_KILL_CMD, timeout=2, capture_output=True)
|
|
log.info("pkill returncode=%d", result.returncode)
|
|
except Exception as e:
|
|
log.error("pkill failed: %s", e)
|
|
if reset_timer[0]:
|
|
GLib.source_remove(reset_timer[0])
|
|
reset_timer[0] = None
|
|
return
|
|
def reset():
|
|
log.debug("tap count reset (%.1fs timeout)", TAP_WINDOW_SEC)
|
|
count[0] = 0
|
|
reset_timer[0] = None
|
|
return False
|
|
reset_timer[0] = GLib.timeout_add(int(TAP_WINDOW_SEC * 1000), reset)
|
|
return False
|
|
|
|
|
|
def main():
|
|
win = Gtk.Window()
|
|
win.set_decorated(False)
|
|
win.set_resizable(False)
|
|
win.set_default_size(CORNER_SIZE, CORNER_SIZE)
|
|
win.set_skip_taskbar_hint(True)
|
|
win.set_skip_pager_hint(True)
|
|
win.set_keep_above(True)
|
|
win.set_opacity(0.01)
|
|
win.set_accept_focus(False)
|
|
win.set_focus_on_map(False)
|
|
# Allow closing from compositor / taskbar
|
|
win.connect("destroy", Gtk.main_quit)
|
|
# Count 5 taps
|
|
count = [0]
|
|
reset_timer = [None]
|
|
win.connect("button-press-event", on_button_press, (count, reset_timer))
|
|
# Touch events often come as button-press with button=1
|
|
win.set_events(
|
|
win.get_events()
|
|
| Gdk.EventMask.BUTTON_PRESS_MASK
|
|
| Gdk.EventMask.TOUCH_MASK
|
|
)
|
|
win.realize()
|
|
w, h = get_screen_size()
|
|
x = max(0, w - CORNER_SIZE)
|
|
win.move(x, 0)
|
|
log.info("window %dx%d positioned at x=%d y=0", CORNER_SIZE, CORNER_SIZE, x)
|
|
win.show_all()
|
|
log.info("listening for taps (5 within %.1fs to kill chromium)", TAP_WINDOW_SEC)
|
|
Gtk.main()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|