Fix CI: recordings keep to 60 fps, the battery has room for its time left
Deploy to the handset / build-and-deploy (push) Successful in 2m3s
CI / test (push) Successful in 3m5s

- Recorder: a 12 ms gap let through 83 frames a second. Frames now come due every 60th of a
  second, with room for a 60 Hz screen's jitter.
- Battery: the handset change shrank it to 76 px everywhere, too narrow for the time left. It is
  104 px again, and 76 only on a compact panel.
- Tests: recording is timed from its first frame, the failed launch doesn't depend on the apps
  installed, and the scene test waits for notices and clocks to settle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 23:20:00 -08:00
1 parent 4e6a8005dd
commit d1d1bb398c
6 files changed
+63 -14

No files matched your search

+12 -3
View File
@@ -1385,8 +1385,17 @@ test "compose_scene hands the host a scene only when something changed" {
} }
None => abort("the first scene must be drawn") None => abort("the first scene must be drawn")
} }
// Nothing happened: nothing to draw. // Nothing happens: soon there is nothing to draw. (A startup notice may go away or a clock turn
assert_true(comp.compose_scene() is None) // meanwhile; on a busy machine that takes a few scenes.)
let settles = fn() {
for _ in 0..<20 {
if comp.compose_scene() is None {
return true
}
}
false
}
assert_true(settles())
assert_false(comp.frame_changed) assert_false(comp.frame_changed)
// A new window changes the scene, then it settles again. // A new window changes the scene, then it settles again.
ignore(open_and_configure_client(comp, socket_path, "A", "a")) ignore(open_and_configure_client(comp, socket_path, "A", "a"))
@@ -1394,7 +1403,7 @@ test "compose_scene hands the host a scene only when something changed" {
Some(sg) => assert_eq(sg.windows.length(), 1) Some(sg) => assert_eq(sg.windows.length(), 1)
None => abort("a new window must change the scene") None => abort("a new window must change the scene")
} }
assert_true(comp.compose_scene() is None) assert_true(settles())
// The switcher overlay is part of the scene too. // The switcher overlay is part of the scene too.
comp.handle_input(@nested.InputEvent::Key(56U, true), 1U) comp.handle_input(@nested.InputEvent::Key(56U, true), 1U)
ignore(open_and_configure_client(comp, socket_path, "B", "b")) ignore(open_and_configure_client(comp, socket_path, "B", "b"))
+1
View File
@@ -17,6 +17,7 @@ fn wait_notice(comp : @host.ChandraCompositor, ms : Int) -> Array[String] {
///| ///|
test "a launch that fails shows the command, the exit status and what it printed" { test "a launch that fails shows the command, the exit status and what it printed" {
let comp = new_comp("launch-fail") let comp = new_comp("launch-fail")
comp.shell.apps.clear() // an installed Kwi would be called by its name
// What V's Flatpak kwi did: bwrap can't set up the sandbox, prints why and exits 1. // What V's Flatpak kwi did: bwrap can't set up the sandbox, prints why and exits 1.
let cmd = "echo starting; for i in 1 2 3; do echo \"bwrap: Can't find source path /run/user/1000/doc/by-app/org.kde.kwi: No such file or directory\" >&2; done; exit 1" let cmd = "echo starting; for i in 1 2 3; do echo \"bwrap: Can't find source path /run/user/1000/doc/by-app/org.kde.kwi: No such file or directory\" >&2; done; exit 1"
assert_true(comp.shell.start_app("org.kde.kwi", cmd)) assert_true(comp.shell.start_app("org.kde.kwi", cmd))
+39 -10
View File
@@ -36,8 +36,9 @@ pub(all) struct Recording {
/// itself; a host with a frame recorder keeps its own). /// itself; a host with a frame recorder keeps its own).
mut pending : Bytes mut pending : Bytes
mut sent : Int mut sent : Int
/// When the last frame was taken, and the pointer position drawn into it. /// When the next frame is due (monotonic microseconds), and the pointer position drawn into the
mut last_grab : UInt64 /// last one.
mut due_us : UInt64
mut grab_px : Int mut grab_px : Int
mut grab_py : Int mut grab_py : Int
/// A drawn frame not recorded yet (too soon after the last one, or the queue was full). /// A drawn frame not recorded yet (too soon after the last one, or the queue was full).
@@ -47,11 +48,39 @@ pub(all) struct Recording {
mut frames : Int mut frames : Int
} }
///| Frames a second recorded at most, and the gap that makes. ///| Frames a second recorded at most.
let rec_fps : Int = 60 let rec_fps : Int = 60
///| How early a frame may come, in microseconds: a screen's frames at 60 Hz jitter by a few ms.
let rec_early_us : UInt64 = 4667UL
///| When the next frame is due after one taken at `now` (microseconds) that was itself due at `due`:
/// a 60th of a second on. One taken early doesn't bring the next forward, so the average stays
/// within `rec_fps`; one taken late starts the count over, so a stall isn't made up in a burst.
fn rec_next_due(due : UInt64, now : UInt64) -> UInt64 {
(if due > now { due } else { now }) + 1000000UL / rec_fps.to_uint64()
}
///| ///|
let rec_gap_ms : UInt64 = 12UL test "recording takes at most 60 frames a second, and all of a jittery 60 Hz screen's" {
let run = fn(times : Array[UInt64]) {
let mut due = 0UL
let mut n = 0
for t in times {
if t + rec_early_us >= due {
due = rec_next_due(due, t)
n = n + 1
}
}
n
}
// A changed picture every 5 ms for ten seconds.
let n = run(Array::makei(2000, i => 1000000UL + i.to_uint64() * 5000UL))
assert_true(n >= 595 && n <= 601)
// A 60 Hz screen, every other frame 3 ms late: none is dropped.
let jittery = Array::makei(600, i => 1000000UL + i.to_uint64() * 16667UL + (if i % 2 == 1 { 3000UL } else { 0UL }))
assert_eq(run(jittery), 600)
}
///| Screen recording done by the host that draws the screen: `grab` copies a rectangle of the ///| Screen recording done by the host that draws the screen: `grab` copies a rectangle of the
/// screen (with the pointer at a screen position when asked) into the host's queue, stamped with /// screen (with the pointer at a screen position when asked) into the host's queue, stamped with
@@ -191,7 +220,7 @@ fn ChandraCompositor::start_recording(self : ChandraCompositor, r : @scene.Rect)
header_sent: 0, header_sent: 0,
pending: Bytes::from_array([]), pending: Bytes::from_array([]),
sent: 0, sent: 0,
last_grab: 0UL, due_us: 0UL,
grab_px: -1, grab_px: -1,
grab_py: -1, grab_py: -1,
dirty: true, dirty: true,
@@ -218,7 +247,7 @@ fn ChandraCompositor::end_recording(self : ChandraCompositor, error : String?) -
if streaming && error is None { if streaming && error is None {
// One more frame with the time now, so the last picture lasts until the stop. // One more frame with the time now, so the last picture lasts until the stop.
rec.dirty = true rec.dirty = true
rec.last_grab = 0UL rec.due_us = 0UL
self.take_recording_frame(rec, @sys.monotonic_ms()) self.take_recording_frame(rec, @sys.monotonic_ms())
match self.frame_recorder { match self.frame_recorder {
Some(host) => Some(host) =>
@@ -379,11 +408,11 @@ pub fn ChandraCompositor::recording_frame_drawn(self : ChandraCompositor) -> Uni
} }
} }
///| Take the screen's current frame into the recording, unless the last one was taken less than ///| Take the screen's current frame into the recording, unless it would make more than
/// a 60th of a second ago or the previous frame is still going out (it stays `dirty` then, and /// `rec_fps` a second or the previous frame is still going out (it stays `dirty` then, and
/// `recording_tick` takes it as soon as it can). /// `recording_tick` takes it as soon as it can).
fn ChandraCompositor::take_recording_frame(self : ChandraCompositor, rec : Recording, now : UInt64) -> Unit { fn ChandraCompositor::take_recording_frame(self : ChandraCompositor, rec : Recording, now : UInt64) -> Unit {
if rec.last_grab > 0UL && now - rec.last_grab < rec_gap_ms { if now * 1000UL + rec_early_us < rec.due_us {
return return
} }
let px = self.ptr_x.to_int() let px = self.ptr_x.to_int()
@@ -413,7 +442,7 @@ fn ChandraCompositor::take_recording_frame(self : ChandraCompositor, rec : Recor
} }
if taken { if taken {
rec.dirty = false rec.dirty = false
rec.last_grab = now rec.due_us = rec_next_due(rec.due_us, now * 1000UL)
rec.grab_px = px rec.grab_px = px
rec.grab_py = py rec.grab_py = py
rec.frames = rec.frames + 1 rec.frames = rec.frames + 1
+8
View File
@@ -224,6 +224,14 @@ test "super+alt+r records the screen to a video with ffmpeg; the REC pill stops
chord(comp, [125U, 56U], 64U | 8U, 19U, 1U) chord(comp, [125U, 56U], 64U | 8U, 19U, 1U)
assert_true(comp.recording()) assert_true(comp.recording())
assert_eq(comp.recording_rect(), Some(@scene.Rect::new(0, 0, 1280, 720))) assert_eq(comp.recording_rect(), Some(@scene.Rect::new(0, 0, 1280, 720)))
// ffmpeg starts first: until it listens no frame is taken.
let t_start = @sys.monotonic_ms()
while comp.recorded_frames() == 0 && @sys.monotonic_ms() - t_start < 9000UL {
comp.step()
ignore(comp.compose_frame())
@sys.sleep_ms(5)
}
assert_true(comp.recorded_frames() > 0)
// Run the loop for a little over a second, the pointer moving all the while: each step a // Run the loop for a little over a second, the pointer moving all the while: each step a
// changed picture, so frames are taken as often as the recorder allows. // changed picture, so frames are taken as often as the recorder allows.
let t0 = @sys.monotonic_ms() let t0 = @sys.monotonic_ms()
+2
View File
@@ -240,6 +240,8 @@ fn DesktopShell::panel_slots(self : DesktopShell) -> Array[@panel.SlotIn] {
w.module_id == "rotate" || w.module_id == "rotate" ||
w.module_id == "osk") { w.module_id == "osk") {
36 36
} else if compact && w.module_id == "battery" {
76 // the percentage, without the time left
} else { } else {
base_w base_w
} }
+1 -1
View File
@@ -38,7 +38,7 @@ pub let critical_percent : Int = 10
///| ///|
pub fn info() -> (String, String, Int, Int, Int) { pub fn info() -> (String, String, Int, Int, Int) {
// id, name, preferred w, preferred h, min w // id, name, preferred w, preferred h, min w
("org.chandra.battery", "Battery", 76, 34, 34) ("org.chandra.battery", "Battery", 104, 34, 34)
} }
///| ///|