run --enhance: a failing engine leaves the game running; a 0 width/height is never sent as a monitor mode
If the engine exits with an error (no window found, the Wayland share dialog cancelled, a capture tool missing), the game now goes on without Enhance and summit run says so; a normal engine exit still stops both. Checked on Plasma 6.8 with --window class:nothing. Found there too: --width 0 --height 0 made summit run 'kscreen-doctor output.HDMI-A-1.mode.0x0@60' (kscreen-doctor refused it; the monitor stayed as it was); zeros now mean not set. The stand-in test window can go fullscreen on a named monitor.
This commit is contained in:
1 parent
e9d6aa6f8a
commit
d3d2cae0e7
4 files changed
+37
-5
No files matched your search
@@ -277,6 +277,7 @@ fn main() -> Result<()> {
|
||||
engine::Ended::Game if detached => out!("the game's window closed; the engine ended ({})", eng_proc.wait()?),
|
||||
engine::Ended::Game => out!("the game exited; the engine was stopped"),
|
||||
engine::Ended::Engine => out!("the engine exited ({}); the game was stopped", eng_proc.wait()?),
|
||||
engine::Ended::EngineFailed => out!("Enhance could not run ({}; the engine's last lines above say why): the game went on without it", eng_proc.wait()?),
|
||||
}
|
||||
status
|
||||
} else {
|
||||
|
||||
@@ -39,7 +39,9 @@ fn c(a: &[&str]) -> Cmd { a.iter().map(|s| s.to_string()).collect() }
|
||||
/// instead of pretending.
|
||||
pub fn plan(session: Session, desktop: Desktop, p: &Profile) -> Vec<Cmd> {
|
||||
let Some(mon) = p.monitor.as_deref() else { return vec![] };
|
||||
let mode = match (p.width, p.height) { (Some(w), Some(h)) => Some((w, h)), _ => None };
|
||||
// 0 means not set (`summit profile set --width 0`): never a mode to ask a monitor for
|
||||
let mode = match (p.width, p.height) { (Some(w), Some(h)) if w > 0 && h > 0 => Some((w, h)), _ => None };
|
||||
let p = &Profile { refresh_hz: p.refresh_hz.filter(|r| *r > 0.0), width: mode.map(|m| m.0), height: mode.map(|m| m.1), ..p.clone() };
|
||||
match (session, desktop) {
|
||||
(Session::Wayland, Desktop::Kde) => {
|
||||
// One call: kscreen-doctor applies all of its arguments as one configuration.
|
||||
@@ -204,6 +206,7 @@ pub fn outputs(session: Session, desktop: Desktop) -> Result<Vec<Output>, String
|
||||
/// None when the profile changes no mode, or the monitor's current mode is unknown.
|
||||
pub fn restore_profile(outs: &[Output], p: &Profile) -> Option<Profile> {
|
||||
let mon = p.monitor.as_deref()?;
|
||||
let p = &Profile { width: p.width.filter(|w| *w > 0), height: p.height.filter(|h| *h > 0), refresh_hz: p.refresh_hz.filter(|r| *r > 0.0), ..p.clone() };
|
||||
if p.width.is_none() && p.refresh_hz.is_none() { return None; }
|
||||
let (w, h, r) = outs.iter().find(|o| o.name == mon)?.current?;
|
||||
if p.width == Some(w) && p.height == Some(h) && p.refresh_hz.is_none_or(|x| (x - r).abs() < 0.01) { return None; }
|
||||
@@ -270,6 +273,14 @@ mod tests {
|
||||
let p = plan(Session::X11, Desktop::Other, &prof());
|
||||
assert_eq!(p[0].join(" "), "xrandr --output HDMI-A-1 --mode 3840x2160 --rate 60");
|
||||
}
|
||||
#[test] fn zero_size_is_not_a_mode() {
|
||||
let p = Profile { monitor: Some("HDMI-A-1".into()), width: Some(0), height: Some(0), refresh_hz: Some(60.0), ..Default::default() };
|
||||
assert_eq!(plan(Session::Wayland, Desktop::Kde, &p), vec![vec!["kscreen-doctor", "output.HDMI-A-1.enable"]]);
|
||||
assert_eq!(plan(Session::X11, Desktop::Other, &p)[0].join(" "), "xrandr --output HDMI-A-1 --rate 60");
|
||||
let o = parse_kscreen_json(KSCREEN_REAL);
|
||||
assert!(plan_for(Session::Wayland, Desktop::Kde, &p, &o).is_empty(), "the output is on and no mode is asked for");
|
||||
assert_eq!(restore_profile(&o, &Profile { refresh_hz: None, ..p }), None);
|
||||
}
|
||||
#[test] fn gnome_wayland_honestly_empty() { assert!(plan(Session::Wayland, Desktop::Gnome, &prof()).is_empty()); }
|
||||
const XRANDR: &str = "Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
|
||||
Virtual-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
|
||||
|
||||
@@ -131,7 +131,10 @@ pub fn extra_args(env: Option<&str>) -> Vec<String> {
|
||||
/// Which of the two processes of `summit run --enhance` ended first, or `Stopped`: `should_stop` said so (summit
|
||||
/// itself got SIGTERM, SIGINT or SIGHUP) and both were stopped.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Ended { Game, Engine, Stopped }
|
||||
pub enum Ended { Game, Engine, Stopped,
|
||||
/// The engine failed (a non-zero exit: no capture, the share dialog cancelled, a crash): the game was left
|
||||
/// running, without Enhance, and waited for.
|
||||
EngineFailed }
|
||||
|
||||
/// Wait until the game or the engine exits, then stop the other one: SIGTERM first (the engine closes its window and
|
||||
/// prints its summary; a game saves), SIGKILL if it is still there after `grace`. Returns who ended first and the
|
||||
@@ -151,7 +154,9 @@ pub fn supervise(game: &mut std::process::Child, engine: &mut std::process::Chil
|
||||
if !handed_off && game.try_wait()?.is_some() {
|
||||
if detached { handed_off = true; } else { return Ok(Ended::Game); }
|
||||
}
|
||||
if engine.try_wait()?.is_some() { return Ok(if handed_off { Ended::Game } else { Ended::Engine }); }
|
||||
if let Some(st) = engine.try_wait()? {
|
||||
return Ok(if handed_off { Ended::Game } else if st.success() { Ended::Engine } else { Ended::EngineFailed });
|
||||
}
|
||||
std::thread::sleep(poll);
|
||||
}
|
||||
};
|
||||
@@ -164,6 +169,7 @@ pub fn supervise(game: &mut std::process::Child, engine: &mut std::process::Chil
|
||||
_ if handed_off => {}
|
||||
Ended::Game => stop(engine, grace)?,
|
||||
Ended::Engine => stop(game, grace)?,
|
||||
Ended::EngineFailed => { let (st, _) = wait_or_stop(game, grace, should_stop)?; return Ok((first, st)); }
|
||||
}
|
||||
Ok((first, game.wait()?))
|
||||
}
|
||||
@@ -331,6 +337,15 @@ mod tests {
|
||||
assert_eq!(who, Ended::Engine);
|
||||
assert!(!status.success(), "the game was terminated, not left running");
|
||||
}
|
||||
#[test] fn supervise_leaves_the_game_running_when_the_engine_fails() {
|
||||
// e.g. the Wayland share dialog was cancelled: the game goes on without Enhance
|
||||
let (mut game, mut eng) = (sh("sleep 0.6; exit 5"), sh("exit 1"));
|
||||
let t = std::time::Instant::now();
|
||||
let (who, status) = supervise(&mut game, &mut eng, std::time::Duration::from_secs(5), false, &|| false).unwrap();
|
||||
assert_eq!(who, Ended::EngineFailed);
|
||||
assert_eq!(status.code(), Some(5), "the game ran to its own end");
|
||||
assert!(t.elapsed() >= std::time::Duration::from_millis(500));
|
||||
}
|
||||
#[test] fn supervise_detached_waits_for_the_engine() {
|
||||
// the launcher command returns at once; the engine (the game's window) goes on, and is not stopped
|
||||
let (mut game, mut eng) = (sh("exit 0"), sh("sleep 0.6"));
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
moving bars, that prints each key it gets and each focus change, so a test can tell whether the game still has the
|
||||
keyboard with the engine's picture over it.
|
||||
|
||||
python devtools/wayland_standin.py [--seconds 60] [--size 1280x720] [--title "Summit stand-in"]
|
||||
python devtools/wayland_standin.py [--seconds 60] [--size 1280x720] [--title "Summit stand-in"] [--fullscreen DP-1]
|
||||
"""
|
||||
import argparse
|
||||
import sys
|
||||
@@ -17,6 +17,7 @@ def main() -> int:
|
||||
ap.add_argument("--seconds", type=float, default=60)
|
||||
ap.add_argument("--size", default="1280x720")
|
||||
ap.add_argument("--title", default="Summit stand-in (native Wayland)")
|
||||
ap.add_argument("--fullscreen", default="", metavar="MONITOR", help="fullscreen on the monitor of that name")
|
||||
a = ap.parse_args()
|
||||
w, h = map(int, a.size.split("x"))
|
||||
glfw.init_hint(glfw.PLATFORM, glfw.PLATFORM_WAYLAND)
|
||||
@@ -24,7 +25,11 @@ def main() -> int:
|
||||
print("glfw init failed", flush=True)
|
||||
return 1
|
||||
print("platform:", "wayland" if glfw.get_platform() == glfw.PLATFORM_WAYLAND else glfw.get_platform(), flush=True)
|
||||
win = glfw.create_window(w, h, a.title, None, None)
|
||||
mon = next((m for m in glfw.get_monitors() if a.fullscreen and a.fullscreen in glfw.get_monitor_name(m).decode()), None)
|
||||
if mon is not None:
|
||||
mode = glfw.get_video_mode(mon)
|
||||
w, h = mode.size.width, mode.size.height
|
||||
win = glfw.create_window(w, h, a.title, mon, None)
|
||||
glfw.make_context_current(win)
|
||||
glfw.swap_interval(1)
|
||||
keys = []
|
||||
|
||||
Reference in new issue
Block a user