- ESC no longer triggers the emergency stop (an ESC in another app stopped the run at 20:29); stopping only via ctrl-opt-cmd-S or the stop button - a table whose program runs counts as open even when its window is not visible (other desktop, Cockpit without screen recording): no reopening, no giving up, correct table count; teardown and closing a full table work over the channel - Cockpit checks and requests the screen recording permission - gapless tiling (sicht/kacheln.py): tables fill the full height, the Cockpit bar takes the rest and never goes below its minimum width; own animated resize no longer stored as minimum - earlier today: top-up safety net, leave after the hand (sit out next hand), tournament lock, waitlist left on close, Cockpit start lock, warning throttle, preflop raise-war reading, Bomb Pot practice, tournament break and level-up on the stage - teacher core for the streamer mode (betrieb/lehrer.py, betrieb/grund_lesen.py) and its plan
82 lines
3.9 KiB
Swift
82 lines
3.9 KiB
Swift
import Foundation
|
|
import AppKit
|
|
import ApplicationServices
|
|
import Carbon.HIToolbox
|
|
import CockpitKern
|
|
|
|
/// Tasten, die ueberall wirken - auch wenn die Tische vorn sind und der Laeufer die Maus hat.
|
|
///
|
|
/// ⌃⌥⌘S Not-Aus systemweiter Hotkey, braucht keine Freigabe
|
|
/// ⌃⌥⌘C Leiste ↔ Pille systemweiter Hotkey
|
|
/// ⌃⌥⌘H Cockpit ein/aus systemweiter Hotkey
|
|
///
|
|
/// ESC ist kein Not-Aus mehr (5.11.2026: ein ESC in einem anderen Programm hielt den Laeufer
|
|
/// versehentlich an) - anhalten nur noch mit Absicht: ⌃⌥⌘S oder der Not-Aus-Knopf.
|
|
@MainActor
|
|
final class Tasten {
|
|
enum Kuerzel: UInt32 { case notAus = 1, form = 2, sichtbar = 3 }
|
|
|
|
private static var handler: [UInt32: () -> Void] = [:]
|
|
private var refs: [EventHotKeyRef] = []
|
|
|
|
func kuerzel(_ k: Kuerzel, _ aktion: @escaping () -> Void) {
|
|
let taste: Int = switch k { case .notAus: kVK_ANSI_S; case .form: kVK_ANSI_C; case .sichtbar: kVK_ANSI_H }
|
|
var ref: EventHotKeyRef?
|
|
let id = EventHotKeyID(signature: OSType(0x5046_434B), id: k.rawValue) // "PFCK"
|
|
let status = RegisterEventHotKey(UInt32(taste), UInt32(controlKey | optionKey | cmdKey), id,
|
|
GetApplicationEventTarget(), 0, &ref)
|
|
guard status == noErr, let ref else { return }
|
|
refs.append(ref)
|
|
Self.handler[k.rawValue] = aktion
|
|
}
|
|
|
|
func starten() {
|
|
var art = EventTypeSpec(eventClass: OSType(kEventClassKeyboard), eventKind: UInt32(kEventHotKeyPressed))
|
|
InstallEventHandler(GetApplicationEventTarget(), { _, ereignis, _ in
|
|
var id = EventHotKeyID()
|
|
GetEventParameter(ereignis, EventParamName(kEventParamDirectObject), EventParamType(typeEventHotKeyID),
|
|
nil, MemoryLayout<EventHotKeyID>.size, nil, &id)
|
|
let n = id.id
|
|
MainActor.assumeIsolated { Tasten.handler[n]?() }
|
|
return noErr
|
|
}, 1, &art, nil, nil)
|
|
eingriffBeobachten()
|
|
}
|
|
|
|
// ---- Eingriff: deine Maus/Tastatur hat Vorrang ------------------------------------------
|
|
//
|
|
// macOS vermerkt an jedem Ereignis, welcher Prozess es erzeugt hat. Eingaben kommen von
|
|
// keinem Prozess (Absender 0), die Klicks des Bots von seinem Python-Prozess. Klicks ins
|
|
// Cockpit selbst sieht der globale Wächter nicht - das Cockpit zu bedienen hält den Laeufer nicht an.
|
|
private var eingriffMonitor: Any?
|
|
private var eingriffZuletzt = Date.distantPast
|
|
private var eingriffProtokolliert = 0
|
|
|
|
func eingriffBeobachten() {
|
|
if let m = eingriffMonitor { NSEvent.removeMonitor(m) }
|
|
let arten: NSEvent.EventTypeMask = [.leftMouseDown, .rightMouseDown, .otherMouseDown, .keyDown, .scrollWheel]
|
|
eingriffMonitor = NSEvent.addGlobalMonitorForEvents(matching: arten) { [weak self] e in
|
|
let absender = e.cgEvent?.getIntegerValueField(.eventSourceUnixProcessID) ?? -1
|
|
MainActor.assumeIsolated { self?.eingabe(absender: absender, art: e.type) }
|
|
}
|
|
}
|
|
|
|
private func eingabe(absender: Int64, art: NSEvent.EventType) {
|
|
if eingriffProtokolliert < 12 {
|
|
eingriffProtokolliert += 1
|
|
Protokoll.schreiben("Eingabe gesehen: Absender \(absender), Art \(art.rawValue)")
|
|
}
|
|
guard absender == 0, Date().timeIntervalSince(eingriffZuletzt) > 0.3 else { return }
|
|
eingriffZuletzt = Date()
|
|
try? FileManager.default.createDirectory(at: Orte.scratch, withIntermediateDirectories: true)
|
|
try? Data("\(Date().timeIntervalSince1970)".utf8).write(to: Orte.eingriff)
|
|
}
|
|
|
|
/// Neu scharf machen: ein globaler Waechter, angelegt ohne Bedienungshilfen, bleibt taub -
|
|
/// auch wenn die Freigabe spaeter kommt. Darum nach jeder erteilten Freigabe neu anlegen.
|
|
func neuScharf() {
|
|
eingriffBeobachten()
|
|
Protokoll.schreiben("Eingriff-Wächter neu angelegt (Bedienungshilfen: \(AXIsProcessTrusted()))")
|
|
}
|
|
}
|