Wayland: an XWayland game is no longer taken for a native one (KWin 6.8 has no windowId); a new user's engine gets the replay the Settings page shows (found by the first real launcher run on the owner's desktop)

This commit is contained in:
alex committed 2026-11-24 17:22:51 +00:00
1 parent 62b012009a
commit 1214c9c182
5 files changed
+107 -14

No files matched your search

+5 -9
View File
@@ -177,11 +177,10 @@ fn main() -> Result<()> {
if let Some(o) = &out { state::path_text(o)?; }
let p = profile::load(&profile)?;
let mut args = engine::plan(&eng, &src, &p, out.is_none(), out.as_deref(), max_ticks);
// Instant replay only exists while playing on screen. Lengths come from the launcher's settings page;
// without a ui.toml the engine keeps whatever it has stored itself.
if out.is_none() && summit_core::ui::path().is_ok_and(|p| p.exists()) {
let ui = summit_core::ui::load();
args.extend(engine::clip_args(ui.replay_seconds, ui.clip_seconds));
// Instant replay only exists while playing on screen. Lengths come from the launcher's settings page
// (its defaults until the user changes them).
if out.is_none() {
args.extend(engine::ui_clip_args(&summit_core::ui::load()));
}
if out.is_none() && no_watermark { args.extend(["--watermark".to_string(), "off".to_string()]); }
args.extend(engine::extra_args(std::env::var("SUMMIT_ENGINE_ARGS").ok().as_deref()));
@@ -259,10 +258,7 @@ fn main() -> Result<()> {
let mut game = child.spawn().map_err(|e| anyhow::anyhow!("could not start {}: {e}", cmd[0]))?;
let live = engine::Live { wait_secs: wait, watermark: if no_watermark { Some(false) } else { None } };
let mut args = engine::run_enhance_plan(&eng, game.id(), window.as_deref(), &p, &live);
if summit_core::ui::path().is_ok_and(|p| p.exists()) {
let ui = summit_core::ui::load();
args.extend(engine::clip_args(ui.replay_seconds, ui.clip_seconds));
}
args.extend(engine::ui_clip_args(&summit_core::ui::load()));
args.extend(engine::extra_args(std::env::var("SUMMIT_ENGINE_ARGS").ok().as_deref()));
let py = engine::python(&eng);
out!("{} {}", py.display(), args.join(" "));
+8
View File
@@ -258,6 +258,11 @@ pub fn clips_dir() -> Option<PathBuf> {
Some(dirs::video_dir().or_else(|| dirs::home_dir().map(|h| h.join("Videos")))?.join("Summit"))
}
/// Instant replay flags from the launcher's settings (`ui::load()`: the defaults the Settings page shows when
/// there is no ui.toml yet). Not passing them then left a new user with a Settings page saying "Keep the last 1 min"
/// and an engine with replay off, so Ctrl+Alt+R saved nothing (seen on the first real install, 2026-11-24).
pub fn ui_clip_args(ui: &crate::ui::UiSettings) -> Vec<String> { clip_args(ui.replay_seconds, ui.clip_seconds) }
/// Instant replay flags for the engine, from the launcher's clip settings.
/// The engine only accepts 15, 30, 60, 180, 300 or 600 seconds, and a save is never longer than the buffer.
pub fn clip_args(replay_seconds: u32, clip_seconds: u32) -> Vec<String> {
@@ -284,6 +289,9 @@ mod tests {
}
#[test] fn clip_args_follow_the_engine_choices() {
assert_eq!(clip_args(60, 30).join(" "), "--replay 60 --clip-length 30");
// A new user has no ui.toml: the settings page shows 1 min / 30 s, and that is what the engine gets.
let none = std::env::temp_dir().join("summit-no-such-ui-toml-for-test/summit/ui.toml");
assert_eq!(ui_clip_args(&crate::ui::load_from(&none)).join(" "), "--replay 60 --clip-length 30");
assert_eq!(clip_args(30, 300).join(" "), "--replay 30 --clip-length 30");
assert!(clip_args(45, 15).is_empty());
}
+4 -3
View File
@@ -18,9 +18,10 @@ const out = [];
for (const w of workspace.windowList()) {
if (!w.normalWindow) continue;
const f = w.frameGeometry; // a window's screencast holds its title bar too
// No XWayland flag: KWin 6.8's windows have no windowId (it is undefined for XWayland windows too, checked), so
// the engine tells XWayland windows by the X server's own client list (window_portal.x_client_pids).
out.push({pid: w.pid, caption: w.caption, cls: w.resourceClass, x: f.x, y: f.y, w: f.width, h: f.height,
active: w === workspace.activeWindow, x11: w.windowId !== undefined && w.windowId !== 0,
minimized: w.minimized, output: w.output ? w.output.name : "", id: String(w.internalId)});
active: w === workspace.activeWindow, minimized: w.minimized, output: w.output ? w.output.name : "", id: String(w.internalId)});
}
callDBus("%s", "/summit/kwin", "org.summit.KWinReport", "windows", JSON.stringify(out));
"""
@@ -36,7 +37,7 @@ class KWindow:
w: int
h: int
active: bool
x11: bool # an XWayland window (framegen/window_x11.py reads those directly)
x11: bool # always False: KWin 6.8 can't say (see SCRIPT); window_portal.native_candidates asks the X server
minimized: bool
output: str # the monitor it is on, e.g. "DP-1"
id: str # KWin's own id for it (stays the same while it's open)
+21 -2
View File
@@ -310,6 +310,24 @@ class PortalWindowSource:
print(f"[window] {self.grabs} frames from PipeWire, {self.same} unchanged (left out)")
def x_client_pids(x) -> set[int]:
"""The process ids of every window on the X server's client list, however small or untitled: XWayland's windows.
(KWin 6.8's script API has no 'is this an XWayland window' flag, so a window KWin lists is native only if no
X client has its pid. A game's window may be 1x1 or untitled for its first moments: find_windows() skips those
and the engine used to take such a game for a native Wayland one, with a share dialog and a PipeWire copy.)"""
pids = set()
for xid in x.client_ids():
w = x.describe(xid)
if w is not None and w.pid:
pids.add(w.pid)
return pids
def native_candidates(kwin_windows, xpids: set[int], own_pid: int) -> list:
"""KWin's windows that are not XWayland ones (no X client has the pid) and not this process's."""
return [w for w in kwin_windows if w.pid != own_pid and w.pid not in xpids]
def open_window(query: str, wait_s: float = 0.0, sleep=time.sleep, env=os.environ):
"""--window QUERY on a Wayland session: an XWayland window that matches (window_x11, no dialog), else a native
Wayland one KWin knows (the portal), waiting up to wait_s for either. Without KWin, a window that isn't an
@@ -336,8 +354,9 @@ def open_window(query: str, wait_s: float = 0.0, sleep=time.sleep, env=os.enviro
print("[window] an XWayland window: captured through XWayland")
return X11WindowSource(target, x)
if kw is not None:
try:
native = [w for w in kw.windows() if not w.x11 and w.pid != os.getpid()]
try: # KWin's list first, the X server's second: a window that is on KWin's list is on X's by then
listed = kw.windows()
native = native_candidates(listed, x_client_pids(x) if x is not None else set(), os.getpid())
except Exception as e: # noqa: BLE001
print(f"[window] KWin didn't list its windows ({str(e)[:120]})")
native = []
+69
View File
@@ -1,9 +1,12 @@
"""Wayland window capture (framegen/window_portal.py, framegen/kwin.py): the pure parts. The portal, PipeWire and
KWin themselves were run on a Plasma 6.8 desktop (docs/WAYLAND_REPORT.md), not here."""
import json
import os
import pathlib
import sys
import pytest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from framegen import kwin
from framegen import window_portal as wp
@@ -59,3 +62,69 @@ def test_restore_token_is_kept_private_under_summit_config(tmp_path):
wp.save_token("abc-123", p)
assert wp.load_token(p) == "abc-123"
assert (pathlib.Path(p).stat().st_mode & 0o777) == 0o600
# ---- XWayland or native? (KWin 6.8 gives no flag: found on the owner's desktop, where Voidrunner, an XWayland game,
# ---- was taken for a native Wayland window and shown the share dialog)
class FakeX:
def __init__(self, windows):
self.windows = windows # xid -> XWindow
def client_ids(self):
return list(self.windows)
def describe(self, xid):
return self.windows.get(xid)
def close(self):
pass
class FakeKWin:
def __init__(self, windows):
self._w = windows
def windows(self):
return self._w
def close(self):
pass
def _kw(pid, caption="Voidrunner", w=1288, h=749):
return kwin.KWindow(pid, caption, "game", 0, 0, w, h, False, False, False, "HDMI-A-1", f"{{{pid}}}")
def _wire(monkeypatch, xwins, kwins):
from framegen import window_x11 as wx
monkeypatch.setattr(wx, "session_problem", lambda env: None)
monkeypatch.setattr(wx, "X", lambda: FakeX(xwins))
monkeypatch.setattr(wx, "find_windows", lambda x=None: [w for w in xwins.values() if w.title and w.w >= 100 and w.h >= 100])
monkeypatch.setattr(kwin, "available", lambda env=None: True)
monkeypatch.setattr(kwin, "KWin", lambda: FakeKWin(kwins))
monkeypatch.setattr(wp, "PortalWindowSource", lambda w, kw: ("portal", w.caption))
def test_native_candidates_leave_out_windows_the_x_server_has():
ks = [_kw(42), _kw(43, "native"), _kw(os.getpid(), "me")]
assert [w.pid for w in wp.native_candidates(ks, {42}, os.getpid())] == [43]
def test_a_tiny_untitled_xwayland_window_is_not_taken_for_a_native_one(monkeypatch):
# The X client list has pid 42 as a 1x1 window with no title (the game is still starting): find_windows skips it,
# but KWin already lists it. It must not be offered to the portal.
_wire(monkeypatch, {1: XWindow(1, "", "game", 42, 1, 1)}, [_kw(42)])
with pytest.raises(RuntimeError, match="no window matches"):
wp.open_window("pid:42", wait_s=0.0, sleep=lambda s: None, env={})
def test_a_window_only_kwin_knows_goes_to_the_portal(monkeypatch):
_wire(monkeypatch, {1: XWindow(1, "Editor", "kate", 10, 800, 600)}, [_kw(42)])
assert wp.open_window("pid:42", wait_s=0.0, sleep=lambda s: None, env={}) == ("portal", "Voidrunner")
def test_an_xwayland_game_is_captured_through_x(monkeypatch):
from framegen import window_x11 as wx
_wire(monkeypatch, {1: XWindow(1, "Voidrunner", "game", 42, 1280, 720)}, [_kw(42)])
monkeypatch.setattr(wx, "X11WindowSource", lambda target, x: ("x11", target.title))
assert wp.open_window("pid:42", wait_s=0.0, sleep=lambda s: None, env={}) == ("x11", "Voidrunner")