.pragma library .import "popoutCatalog.js" as PopoutCatalog // Explicit projections only. Never serialize a service, output, or caller string. function choice(value, allowed) { return allowed.indexOf(value) >= 0 ? value : "unknown"; } function number(value) { return typeof value === "number" && Number.isFinite(value) ? value : 0; } function rect(value) { return { "x": number(value.x), "y": number(value.y), "width": number(value.width), "height": number(value.height) }; } function name(value) { if (value === "") return ""; return typeof value === "string" && Object.prototype.hasOwnProperty.call(PopoutCatalog.entries, value) ? value : "unknown"; } function phase(value) { return choice(value, ["closed", "opening", "open", "closing"]); } function nextOperationId(current) { return current >= 2147483647 ? 1 : current + 1; } function transition(event, surfaces) { return { "version": 1, "kind": "popup-transition", "operationId": number(surfaces.operationId), "event": choice(event, ["opening", "opened", "switched", "closed"]), "name": name(surfaces.popoutName), "phase": phase(surfaces.popoutPhase) }; } function popup(surfaces) { return { "operationId": number(surfaces.operationId), "name": name(surfaces.popoutName), "phase": phase(surfaces.popoutPhase), "open": surfaces.popoutOpen === true, "closing": surfaces.popoutClosing === true, "orientation": choice(surfaces.orientation, ["horizontal", "vertical"]), "progress": number(surfaces.popoutProgress), "anchor": rect(surfaces.popoutAnchor), "card": rect(surfaces.popupCardFrame(surfaces.popoutProgress).currentRect), "viewport": { "width": number(surfaces.screenWidth), "height": number(surfaces.screenHeight), "barHeight": number(surfaces.barHeight) } }; } function snapshot(surfaces, screens, services) { const displays = []; for (let i = 0; i < screens.length; i++) { const screen = screens[i]; const display = rect(screen); display.scale = number(screen.devicePixelRatio); displays.push(display); } return { "version": 1, "popup": popup(surfaces), "displays": displays, "services": { "niri": { "available": services.niri.available === true, "ready": services.niri.ready === true, "windowCount": number(services.niri.windows.length), "workspaceCount": number(services.niri.workspaces.length) }, "audio": { "ready": services.audio.pipewireReady === true }, "network": { "enabled": services.network.wifiEnabled === true, "scanning": services.network.scanning === true }, "vault": { "status": choice(services.vault.status, ["needs-setup", "locked", "loading", "unlocked", "syncing", "sync-failure", "stale-cache", "second-factor", "authentication-failure", "unavailable-vault"]), "lockPending": services.vault.lockPending === true }, "noko": { "ready": services.noko.ready === true, "phase": choice(services.noko.overlayState, ["", "capturing", "transcribing", "finished"]), "installing": services.noko.installing === true } } }; }