Files
ZebraticandClaude Opus 5.5 7dc52a4a2e Launcher: splash intro, new icon set, consoles, Lutris, Steam accounts, overlay
- Splash: Summit's icon rises in over an amber glow, the name follows, then it
  fades into the app (about a second, no keys taken, off when motion is off)
- install.sh: after installing icons, rebuild KDE's sycoca and send
  KIconLoader.iconChanged so a running Plasma shows the updated icon
- New app icon (SVG + rendered PNG sizes, render.sh), used by the packages and
  the engine's window
- Lutris scan, consoles (Remote Play via chiaki-ng frame tap, capture cards),
  Steam account switching, running-game tracking, window mode, artwork
- Library UI: add dialog, profile editor, accounts, "now playing" screen
- Engine: in-game overlay/HUD, overlay key, global key fixes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 01:53:49 +01:00

110 lines
5.2 KiB
Python

"""The key that opens and closes Summit's overlay (framegen/menu.py): Insert unless the launcher's Settings page
(ui.toml `overlay_key`) or `run.py --overlay-key` says otherwise.
Insert Home F10 Ctrl+Shift+O Alt+F1
A key on its own is fine when it types nothing and games rarely use it (Insert, Home, End, Delete, Page Up/Down,
Pause, Scroll Lock, the F keys); a letter, digit, Space or Tab needs Ctrl, Alt or Super with it, or the game would
lose that key. Esc, Enter, Backspace and the arrows are never the overlay's key: they move about inside it, and Esc
belongs to the game.
parse() gives the key in one spelling; x11(), glfw_key() and windows() turn it into what each way of listening wants
(framegen/globalkeys.py over a game on Linux, the video window's own keys, framegen/hotkeys.py on Windows).
"""
from __future__ import annotations
from dataclasses import dataclass
DEFAULT = "Insert"
MODS = ("Ctrl", "Alt", "Shift", "Super") # in the order they're shown
_MOD_ALIASES = {"ctrl": "Ctrl", "control": "Ctrl", "alt": "Alt", "shift": "Shift", "super": "Super", "win": "Super",
"windows": "Super", "meta": "Super", "logo": "Super"}
# Keys that can be the overlay's key on their own: name -> (X keysym name, GLFW key name)
ALONE = {"Insert": ("Insert", "INSERT"), "Home": ("Home", "HOME"), "End": ("End", "END"),
"Delete": ("Delete", "DELETE"), "PageUp": ("Prior", "PAGE_UP"), "PageDown": ("Next", "PAGE_DOWN"),
"Pause": ("Pause", "PAUSE"), "ScrollLock": ("Scroll_Lock", "SCROLL_LOCK")}
ALONE |= {f"F{n}": (f"F{n}", f"F{n}") for n in range(1, 25)}
# Keys that need Ctrl, Alt or Super with them
WITH_MOD = {"Space": ("space", "SPACE"), "Tab": ("Tab", "TAB")}
WITH_MOD |= {chr(c): (chr(c).lower(), chr(c)) for c in range(ord("A"), ord("Z") + 1)}
WITH_MOD |= {str(d): (str(d), str(d)) for d in range(10)}
_KEY_ALIASES = {"ins": "Insert", "del": "Delete", "pgup": "PageUp", "pgdn": "PageDown", "pagedn": "PageDown",
"prior": "PageUp", "next": "PageDown", "break": "Pause", "scroll_lock": "ScrollLock",
"scrlk": "ScrollLock"}
NEVER = {"esc": "Esc", "escape": "Esc", "enter": "Enter", "return": "Enter", "backspace": "Backspace", "up": "Up",
"down": "Down", "left": "Left", "right": "Right"}
@dataclass(frozen=True)
class Key:
mods: tuple[str, ...] # of MODS, in that order
key: str # a name in ALONE or WITH_MOD
name: str # as shown and saved: "Insert", "Ctrl+Shift+O"
def parse(text: str) -> Key:
"""The key from its name, in any case and with or without spaces ("insert", "ctrl + shift + o"). ValueError,
saying what's wrong, for one that can't be the overlay's key."""
parts = [p.strip() for p in (text or "").split("+") if p.strip()]
if not parts:
raise ValueError("no key")
mods: list[str] = []
key = None
for p in parts:
low = p.lower()
if low in _MOD_ALIASES:
if _MOD_ALIASES[low] in mods:
raise ValueError(f"{_MOD_ALIASES[low]} twice")
mods.append(_MOD_ALIASES[low])
continue
if key is not None:
raise ValueError("more than one key besides Ctrl, Alt, Shift and Super")
if low in NEVER:
raise ValueError(f"{NEVER[low]} moves about inside the overlay (and Esc is the game's): pick another key")
low = _KEY_ALIASES.get(low, p).lower()
key = next((k for k in (*ALONE, *WITH_MOD) if k.lower() == low), None)
if key is None:
raise ValueError(f"unknown key {p!r}")
if key is None:
raise ValueError("Ctrl, Alt, Shift or Super needs a key with it")
if key in WITH_MOD and not {"Ctrl", "Alt", "Super"} & set(mods):
raise ValueError(f"{key} needs Ctrl, Alt or Super with it, or the game would lose that key")
mods_ = tuple(m for m in MODS if m in mods)
return Key(mods_, key, "+".join((*mods_, key)))
def pick(text: str | None) -> tuple[Key, str]:
"""The key to use for `text` (None or "": the default), and a note when `text` couldn't be used ("" if it
could): the default is used then, so the overlay always has a key."""
if not (text or "").strip():
return parse(DEFAULT), ""
try:
return parse(text), ""
except ValueError as e:
return parse(DEFAULT), f"the overlay key {text!r} can't be used ({e}); using {DEFAULT}"
def x11(k: Key) -> str:
"""As framegen/globalkeys.py takes it: "ctrl+shift+o", "Insert" (the key as its X keysym name)."""
sym = (ALONE.get(k.key) or WITH_MOD[k.key])[0]
return "+".join((*(m.lower() for m in k.mods), sym))
def glfw_key(k: Key, glfw) -> tuple[int, int]:
"""(GLFW's key, its modifier bits) for the video window's own key callback."""
name = (ALONE.get(k.key) or WITH_MOD[k.key])[1]
bits = {"Ctrl": glfw.MOD_CONTROL, "Alt": glfw.MOD_ALT, "Shift": glfw.MOD_SHIFT, "Super": glfw.MOD_SUPER}
mods = 0
for m in k.mods:
mods |= bits[m]
return getattr(glfw, "KEY_" + name), mods
def windows(k: Key) -> str | None:
"""As framegen/hotkeys.py writes it ("Ctrl+Alt+M", "Insert"), or None for a key it has no name for."""
from .hotkeys import KEYS
if k.key not in KEYS:
return None
return "+".join((*("Win" if m == "Super" else m for m in k.mods), k.key))