Smoother animations without a GPU: faster rasteriser, frame pacing, software/hardware mode
CI / test (push) Failing after 3m2s
CI / test (push) Failing after 3m2s
Measured headless at 1920x1080 with CHANDRA_FRAME_TRACE (new: one log line per drawn frame): - Overview open: 46 -> 62 fps, worst frame gap 69 -> 36 ms, raster 14 -> 5 ms a frame. - Live Starfield: 19 -> 30 fps (its target), raster 49 -> 13 ms, CPU 97% -> 46%. Rasteriser (MoonBit host; circles and previews also in the Rust host): - Blending works on two channels at a time in 16-bit lanes with an exact /255: same pixels, about 3x quicker on big translucent fills (the overview's dim, the starfield's nebulae). - Filled circles are drawn as row spans, rings skip their empty middle (a sqrt per pixel of the bounding box before). Same pixels; a Rust test checks it against the old loop. - Window previews gliding in the overview are sampled straight from the preview at each frame's size instead of filtered and cached at a size used once; the MoonBit host also gets the one-large-size cache and 4096 px draw limit the Rust host had (it kept every size and didn't draw previews past 1024 px). - Image scaling sums each output row's columns once, with 32-bit sums and division. Frame pacing: frames are drawn only when the output can take them (no page flip in flight on KMS; the previous frame shown nested and on X11), with a frame every 250 ms for an output that never gets ready. The KMS loop runs at 125 Hz, so animations used to rasterise frames that were never shown. Software or hardware mode (compositor/shell/render_mode.mbt, docs/rendering.md): detected from the DRM render nodes' drivers (and NVIDIA's proprietary driver, LIBGL_ALWAYS_SOFTWARE), overridden by CHANDRA_RENDER=software|hardware or Settings > Session "Lighter animations" (state.edn :render, saved only when it differs from what was detected). Software mode remakes changing previews every 200 ms instead of 100 ms and caps desktop modules at ~30 fps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkTQp5uN5FtwpzrXUA
This commit is contained in:
16 files changed
+719
-97
No files matched your search
+58
-36
@@ -179,7 +179,11 @@ pub fn run(args : Array[String]) -> Int {
|
||||
let login = drm || login
|
||||
comp.sync_system_theme = login // the login session sets apps' dark/light preference
|
||||
comp.login_session = login // and power actions (suspend, power off) act on the machine
|
||||
// GPU or not (CHANDRA_RENDER overrides): without one the desktop asks less of the CPU.
|
||||
let (rmode, rwhy) = @shell.detect_render_mode()
|
||||
comp.shell.set_render_detected(rmode, rwhy)
|
||||
comp.restore_state() // and the layout mode and recent apps from the last session
|
||||
@sys.log(comp.shell.render_summary())
|
||||
comp.shell.screen_w = width
|
||||
// Screenshots and recordings read the host's framebuffer (it draws the desktop).
|
||||
comp.frame_source = Some(fn() { Some(@raster.read_frame(comp.output_w, comp.output_h)) })
|
||||
@@ -239,6 +243,10 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
let mut frames = 0
|
||||
let idle = IdleClock::new()
|
||||
// CHANDRA_FRAME_TRACE=1: one log line per drawn frame (when, and how long composing and
|
||||
// rasterising took), for measuring how smooth animations are.
|
||||
let trace = @sys.getenv("CHANDRA_FRAME_TRACE").length() > 0
|
||||
let pacer = Pacer::{ last_ms: 0UL }
|
||||
// A changed frame waits here until the display can take it (no page flip in flight).
|
||||
let mut need_present = true
|
||||
// --profile: every 3 s print how long each frame part took on average.
|
||||
@@ -274,15 +282,15 @@ pub fn run(args : Array[String]) -> Int {
|
||||
k.set_cursor_shape(comp.desired_cursor())
|
||||
// The host draws; only a changed desktop is sent, and the frame is shown by the host
|
||||
// straight from its framebuffer.
|
||||
let changed = match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
true
|
||||
}
|
||||
None => false
|
||||
// Draw only when the display can take the frame (no page flip in flight): a frame
|
||||
// drawn meanwhile would never be seen, and drawing it costs a whole frame's CPU.
|
||||
let changed = if k.frame_ready() || comp.screen_off || pacer.overdue() {
|
||||
draw_frame(comp, trace, pacer)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
if changed {
|
||||
need_present = true
|
||||
}
|
||||
if need_present && k.frame_ready() {
|
||||
k.present_frame()
|
||||
@@ -361,15 +369,10 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
n.set_cursor_shape(comp.desired_cursor())
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
// As on a display: draw when the host compositor can take the frame.
|
||||
if (n.frame_ready() || pacer.overdue()) && draw_frame(comp, trace, pacer) {
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
if need_present && n.frame_ready() {
|
||||
n.present_frame(width, height)
|
||||
@@ -407,15 +410,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
comp.handle_input(ev, now_ms)
|
||||
}
|
||||
x.set_cursor_shape(comp.desired_cursor())
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
if (x.frame_ready() || pacer.overdue()) && draw_frame(comp, trace, pacer) {
|
||||
need_present = true
|
||||
busy = true
|
||||
}
|
||||
if need_present && x.frame_ready() {
|
||||
x.present_frame(width, height)
|
||||
@@ -426,15 +423,9 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
None => {
|
||||
comp.handle_gfx_events(gfx_surface)
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (@sys.monotonic_ms() - r0)
|
||||
need_present = serve && gfx_out.length() > 0
|
||||
busy = true
|
||||
}
|
||||
None => ()
|
||||
if draw_frame(comp, trace, pacer) {
|
||||
need_present = serve && gfx_out.length() > 0
|
||||
busy = true
|
||||
}
|
||||
// No display: --serve keeps a PNG of the latest frame for looking at a live compositor.
|
||||
if serve && gfx_out.length() > 0 && frames % 30 == 0 && need_present {
|
||||
@@ -479,6 +470,37 @@ pub fn run(args : Array[String]) -> Int {
|
||||
}
|
||||
}
|
||||
|
||||
///| When the last frame was drawn: an output that never says it is ready again (a hidden nested
|
||||
/// window gets no frame callbacks) still gets a frame now and then, so screenshots, recordings
|
||||
/// and clients waiting on frame callbacks carry on.
|
||||
struct Pacer {
|
||||
mut last_ms : UInt64
|
||||
}
|
||||
|
||||
///|
|
||||
fn Pacer::overdue(self : Pacer) -> Bool {
|
||||
@sys.monotonic_ms() - self.last_ms >= 250UL
|
||||
}
|
||||
|
||||
///| Compose the desktop and hand a changed frame to the host to draw. True when it changed.
|
||||
fn draw_frame(comp : @host.ChandraCompositor, trace : Bool, pacer : Pacer) -> Bool {
|
||||
let c0 = @sys.monotonic_ms()
|
||||
pacer.last_ms = c0
|
||||
match comp.compose_scene() {
|
||||
Some(sg) => {
|
||||
let r0 = @sys.monotonic_ms()
|
||||
@raster.submit(sg)
|
||||
let r1 = @sys.monotonic_ms()
|
||||
comp.prof_raster_ms = comp.prof_raster_ms + (r1 - r0)
|
||||
if trace {
|
||||
@sys.log("frame " + r1.to_string() + " compose " + (r0 - c0).to_string() + " raster " + (r1 - r0).to_string())
|
||||
}
|
||||
true
|
||||
}
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
///| How long an idle main loop may sleep. Nothing on screen changes without a client, the seat or
|
||||
/// the display waking the loop, except what follows the wall clock (clocks, the desktop card,
|
||||
/// system stats, notices), which changes on whole seconds. So an idle loop sleeps until just
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
"chandra/desktop/compositor/renderer" @renderer,
|
||||
"chandra/desktop/compositor/gfx" @gfx,
|
||||
"chandra/desktop/compositor/host" @host,
|
||||
"chandra/desktop/compositor/shell" @shell,
|
||||
"chandra/desktop/compositor/nested" @nested,
|
||||
"chandra/desktop/compositor/x11" @x11,
|
||||
"chandra/desktop/compositor/kms" @kms,
|
||||
|
||||
@@ -1694,8 +1694,11 @@ test "open_settings opens the settings module on the tab asked for" {
|
||||
assert_eq(pr.h, 40 + (1 + 4 + 6) * 28 + 6)
|
||||
assert_true(comp.shell.open_settings(Session))
|
||||
ignore(comp.compose_frame())
|
||||
// The four settings, then Face unlock (a heading; chandra-face isn't installed in tests).
|
||||
assert_eq(comp.shell.slot_popup_rect(slot).h, 40 + 6 * 28 + 6)
|
||||
// The five settings, then Face unlock (a heading; chandra-face isn't installed in tests).
|
||||
assert_eq(comp.shell.slot_popup_rect(slot).h, 40 + 7 * 28 + 6)
|
||||
assert_true(
|
||||
comp.shell.slot_popup_texts(slot).iter().any(t => t.0.has_prefix("Lighter animations (")),
|
||||
)
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
/// those whose title or app id don't match fade out.
|
||||
///
|
||||
/// The previews are the Alt+Tab switcher's (switcher.mbt: `switcher_thumb`), made only while
|
||||
/// the overview is up and remade at most every `THUMB_REFRESH_MS` for windows that keep drawing.
|
||||
/// the overview is up and remade at most every `preview_refresh_ms` for windows that keep drawing.
|
||||
/// Nothing is redrawn for the overview once it settles unless a window draws or the pointer
|
||||
/// moves onto another window.
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
///|
|
||||
test "a real GPU's render node means hardware; display-only drivers and none mean software" {
|
||||
assert_eq(@shell.classify_render(["i915"], false, false).0, @shell.RenderMode::Hardware)
|
||||
assert_eq(@shell.classify_render(["simpledrm", "amdgpu"], false, false).0, @shell.RenderMode::Hardware)
|
||||
assert_eq(@shell.classify_render(["virtio_gpu"], false, false).0, @shell.RenderMode::Software)
|
||||
assert_eq(@shell.classify_render(["vkms"], false, false).1, "no GPU (only vkms)")
|
||||
assert_eq(@shell.classify_render([], false, false), (@shell.RenderMode::Software, "no GPU found"))
|
||||
// NVIDIA's proprietary driver without nvidia-drm loaded has no render node, but it is a GPU.
|
||||
assert_eq(@shell.classify_render([], true, false).0, @shell.RenderMode::Hardware)
|
||||
// LIBGL_ALWAYS_SOFTWARE: apps draw in software whatever the hardware.
|
||||
assert_eq(@shell.classify_render(["i915"], true, true).0, @shell.RenderMode::Software)
|
||||
assert_eq(@shell.uevent_driver("MAJOR=226\nDRIVER=amdgpu\nPCI_ID=1002:73BF\n"), "amdgpu")
|
||||
assert_eq(@shell.uevent_driver("MAJOR=226\n"), "")
|
||||
assert_eq(@shell.RenderMode::parse(" Software\n"), Some(@shell.RenderMode::Software))
|
||||
assert_eq(@shell.RenderMode::parse("gpu"), Some(@shell.RenderMode::Hardware))
|
||||
assert_eq(@shell.RenderMode::parse("fast"), None)
|
||||
}
|
||||
|
||||
///|
|
||||
test "the Lighter animations switch overrides detection and is saved only when it differs" {
|
||||
let comp = new_comp("rendermode")
|
||||
comp.shell.persist = true
|
||||
write_state_edn("{}\n")
|
||||
comp.shell.set_render_detected(@shell.RenderMode::Hardware, "GPU: i915")
|
||||
comp.restore_state()
|
||||
assert_false(comp.shell.software_render())
|
||||
assert_eq(comp.shell.preview_refresh_ms(), 100UL)
|
||||
assert_eq(comp.shell.desktop_min_frame_ms(), 16)
|
||||
// On: software, remembered.
|
||||
comp.shell.set_session_setting(4, true)
|
||||
assert_true(comp.shell.software_render())
|
||||
assert_eq(comp.shell.preview_refresh_ms(), 200UL)
|
||||
assert_eq(comp.shell.desktop_min_frame_ms(), 33)
|
||||
assert_true(read_state_edn().contains(":render :software"))
|
||||
assert_true(comp.shell.render_summary().contains("chosen in Settings"))
|
||||
// Back to what was detected: nothing saved.
|
||||
comp.shell.set_session_setting(4, false)
|
||||
assert_false(comp.shell.software_render())
|
||||
assert_false(read_state_edn().contains(":render"))
|
||||
// A saved choice is read back; on a machine where it matches detection it is dropped.
|
||||
write_state_edn("{:render :software}\n")
|
||||
comp.restore_state()
|
||||
assert_true(comp.shell.software_render())
|
||||
comp.shell.set_render_detected(@shell.RenderMode::Software, "no GPU found")
|
||||
comp.restore_state()
|
||||
assert_true(comp.shell.software_render())
|
||||
assert_eq(comp.shell.render_choice, None)
|
||||
comp.close()
|
||||
}
|
||||
@@ -154,7 +154,7 @@ pub(all) struct SwitcherThumb {
|
||||
|
||||
///| How often a preview of a window that keeps redrawing (a video) is made again: scaling a
|
||||
/// full-screen buffer down takes a couple of ms, too much for every frame of every window.
|
||||
const THUMB_REFRESH_MS : UInt64 = 100UL
|
||||
/// Every 100 ms, or 200 ms with software rendering (`DesktopShell::preview_refresh_ms`).
|
||||
|
||||
///| True while the switcher is up and a preview waits for its next refresh (the main loop
|
||||
/// keeps its frame pace for it).
|
||||
@@ -219,7 +219,7 @@ fn ChandraCompositor::switcher_thumb(self : ChandraCompositor, id : UInt64, box_
|
||||
let now = @sys.monotonic_ms()
|
||||
match old {
|
||||
Some(t) if t.w == tw && t.h == th && t.handle != 0U &&
|
||||
(!t.stale || now - t.made_ms < THUMB_REFRESH_MS) => return (t.handle, tw, th)
|
||||
(!t.stale || now - t.made_ms < self.shell.preview_refresh_ms()) => return (t.handle, tw, th)
|
||||
_ => ()
|
||||
}
|
||||
let reuse = match old {
|
||||
|
||||
@@ -323,6 +323,9 @@ fn DesktopShell::desktop_tick(self : DesktopShell, now : UInt64) -> Unit {
|
||||
let ms = (now - self.desk_t0).to_int()
|
||||
let r = d.pl.desktop_tick(ms)
|
||||
let r = if r > max_frame_delay { max_frame_delay } else { r }
|
||||
// Software rendering: at most ~30 frames a second, however often the module asks.
|
||||
let min = self.desktop_min_frame_ms()
|
||||
let r = if r > 0 && r < min { min } else { r }
|
||||
self.desk_next = if r > 0 { now + r.to_uint64() } else { 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
///| Software or hardware rendering: whether this machine has a GPU that apps can draw with.
|
||||
///
|
||||
/// Chandra itself always draws the desktop on the CPU (the host's rasteriser), so the GPU never
|
||||
/// makes the compositor's own frames cheaper. What it changes is how much CPU is left over: with
|
||||
/// a GPU, apps (browsers, video, games) draw there; without one they draw with llvmpipe or their
|
||||
/// own software paths on the same cores as Chandra. So in software mode the desktop asks for
|
||||
/// less: window previews are remade less often while they are on screen, and a desktop module
|
||||
/// (Live Starfield) gets at most 30 frames a second.
|
||||
///
|
||||
/// Detected at start (`detect_render_mode`): a DRM render node whose driver drives a real GPU
|
||||
/// (i915, xe, amdgpu, radeon, nouveau, nvidia, Arm and other SoC GPUs) means hardware; none, or
|
||||
/// only virtual/display-only ones (simpledrm, vkms, virtio_gpu, qxl, bochs, vmwgfx, ...), or
|
||||
/// LIBGL_ALWAYS_SOFTWARE=1 mean software. Overrides, strongest first: the CHANDRA_RENDER
|
||||
/// environment variable (`software` or `hardware`), then Settings > Session "Lighter
|
||||
/// animations", saved in state.edn as `:render :software` or `:render :hardware` only when it
|
||||
/// differs from what was detected.
|
||||
|
||||
///|
|
||||
pub(all) enum RenderMode {
|
||||
Software
|
||||
Hardware
|
||||
} derive(Eq, Show, Debug)
|
||||
|
||||
///| The name state.edn and CHANDRA_RENDER use.
|
||||
pub fn RenderMode::name(self : RenderMode) -> String {
|
||||
match self {
|
||||
Software => "software"
|
||||
Hardware => "hardware"
|
||||
}
|
||||
}
|
||||
|
||||
///| "software" / "hardware" (any case, also "sw" / "hw", "gpu" / "cpu").
|
||||
pub fn RenderMode::parse(s : String) -> RenderMode? {
|
||||
match s.trim(chars=" \n\t").to_lower().to_string() {
|
||||
"software" | "sw" | "cpu" => Some(Software)
|
||||
"hardware" | "hw" | "gpu" => Some(Hardware)
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
///| DRM drivers that only scan out or emulate a display: a render node from one of these is no
|
||||
/// GPU to draw with.
|
||||
let software_drm_drivers : Array[String] = [
|
||||
"simpledrm", "simple-framebuffer", "efifb", "vesafb", "vkms", "vgem", "virtio_gpu", "virtio-gpu",
|
||||
"qxl", "bochs", "bochs-drm", "cirrus", "cirrus-qemu", "vboxvideo", "vmwgfx", "hyperv_drm", "udl",
|
||||
"gud", "ast", "mgag200", "xen-front",
|
||||
]
|
||||
|
||||
///| The driver named by a sysfs `uevent` file's DRIVER= line ("" when it has none).
|
||||
pub fn uevent_driver(text : String) -> String {
|
||||
for line in text.split("\n") {
|
||||
let l = line.to_string()
|
||||
if l.has_prefix("DRIVER=") {
|
||||
return l[7:].to_string()
|
||||
}
|
||||
}
|
||||
""
|
||||
}
|
||||
|
||||
///| Hardware or software from the DRM render nodes' drivers (render node drivers as found, in
|
||||
/// order), the NVIDIA proprietary driver being loaded, and LIBGL_ALWAYS_SOFTWARE. Also why, for
|
||||
/// the log and Settings.
|
||||
pub fn classify_render(
|
||||
drivers : Array[String],
|
||||
nvidia : Bool,
|
||||
libgl_software : Bool,
|
||||
) -> (RenderMode, String) {
|
||||
if libgl_software {
|
||||
return (Software, "LIBGL_ALWAYS_SOFTWARE is set")
|
||||
}
|
||||
for d in drivers {
|
||||
if d.length() > 0 && !software_drm_drivers.contains(d) {
|
||||
return (Hardware, "GPU: " + d)
|
||||
}
|
||||
}
|
||||
if nvidia {
|
||||
return (Hardware, "GPU: nvidia")
|
||||
}
|
||||
match drivers.iter().find_first(d => d.length() > 0) {
|
||||
Some(d) => (Software, "no GPU (only " + d + ")")
|
||||
None => (Software, "no GPU found")
|
||||
}
|
||||
}
|
||||
|
||||
///| Look at this machine: see `classify_render`.
|
||||
pub fn detect_render_mode() -> (RenderMode, String) {
|
||||
let drivers : Array[String] = []
|
||||
for n = 128; n < 136; n = n + 1 {
|
||||
let b = @sys.read_proc_bytes("/sys/class/drm/renderD" + n.to_string() + "/device/uevent")
|
||||
if b.length() > 0 {
|
||||
drivers.push(uevent_driver(bytes_text(b)))
|
||||
}
|
||||
}
|
||||
let nvidia = @sys.read_proc_bytes("/proc/driver/nvidia/version").length() > 0
|
||||
let libgl = @sys.getenv("LIBGL_ALWAYS_SOFTWARE")
|
||||
classify_render(drivers, nvidia, libgl.length() > 0 && libgl != "0" && libgl != "false")
|
||||
}
|
||||
|
||||
///|
|
||||
fn bytes_text(b : Bytes) -> String {
|
||||
let sb = StringBuilder()
|
||||
for c in b {
|
||||
sb.write_char(Int::unsafe_to_char(c.to_int()))
|
||||
}
|
||||
sb.to_string()
|
||||
}
|
||||
|
||||
///| Set the detected mode (and why) at start; CHANDRA_RENDER, when set, replaces it.
|
||||
pub fn DesktopShell::set_render_detected(self : DesktopShell, mode : RenderMode, why : String) -> Unit {
|
||||
match RenderMode::parse(@sys.getenv("CHANDRA_RENDER")) {
|
||||
Some(m) => {
|
||||
self.render_detected = m
|
||||
self.render_why = "CHANDRA_RENDER=" + m.name()
|
||||
self.render_forced = true
|
||||
}
|
||||
None => {
|
||||
self.render_detected = mode
|
||||
self.render_why = why
|
||||
self.render_forced = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| The mode in effect: CHANDRA_RENDER, else the Settings choice, else what was detected.
|
||||
pub fn DesktopShell::render_mode(self : DesktopShell) -> RenderMode {
|
||||
if self.render_forced {
|
||||
return self.render_detected
|
||||
}
|
||||
match self.render_choice {
|
||||
Some(m) => m
|
||||
None => self.render_detected
|
||||
}
|
||||
}
|
||||
|
||||
///| True when the desktop should ask less of the CPU (no GPU).
|
||||
pub fn DesktopShell::software_render(self : DesktopShell) -> Bool {
|
||||
self.render_mode() == Software
|
||||
}
|
||||
|
||||
///| One line for the log: the mode and where it came from.
|
||||
pub fn DesktopShell::render_summary(self : DesktopShell) -> String {
|
||||
let from = if self.render_forced {
|
||||
self.render_why
|
||||
} else if self.render_choice is Some(_) {
|
||||
"chosen in Settings; detected " + self.render_detected.name() + ", " + self.render_why
|
||||
} else {
|
||||
self.render_why
|
||||
}
|
||||
"rendering: " + self.render_mode().name() + " (" + from + ")"
|
||||
}
|
||||
|
||||
///| Choose software (true) or hardware rendering in Settings: remembered only when it differs
|
||||
/// from what was detected.
|
||||
pub fn DesktopShell::choose_software_render(self : DesktopShell, on : Bool) -> Unit {
|
||||
let m = if on { Software } else { Hardware }
|
||||
self.render_choice = if m == self.render_detected { None } else { Some(m) }
|
||||
}
|
||||
|
||||
///| The Settings switch's label: what it does and what was found.
|
||||
fn DesktopShell::render_setting_label(self : DesktopShell) -> String {
|
||||
let found = if self.render_forced {
|
||||
self.render_why
|
||||
} else {
|
||||
match self.render_detected {
|
||||
Software => "no GPU found"
|
||||
Hardware => "GPU found"
|
||||
}
|
||||
}
|
||||
"Lighter animations (" + found + ")"
|
||||
}
|
||||
|
||||
///| How often (ms) a window preview that keeps changing is remade while it is on screen.
|
||||
pub fn DesktopShell::preview_refresh_ms(self : DesktopShell) -> UInt64 {
|
||||
if self.software_render() {
|
||||
200UL
|
||||
} else {
|
||||
100UL
|
||||
}
|
||||
}
|
||||
|
||||
///| The shortest time (ms) between a desktop module's frames.
|
||||
pub fn DesktopShell::desktop_min_frame_ms(self : DesktopShell) -> Int {
|
||||
if self.software_render() {
|
||||
33
|
||||
} else {
|
||||
16
|
||||
}
|
||||
}
|
||||
@@ -280,6 +280,13 @@ pub(all) struct DesktopShell {
|
||||
/// Chandra's own password dialog answers polkit (run0, pkexec, ...); off: the system's polkit
|
||||
/// agent does. Saved as state.edn `:auth-agent :system` when off.
|
||||
mut native_auth_agent : Bool
|
||||
/// Software or hardware rendering (render_mode.mbt): what was detected at start (or
|
||||
/// CHANDRA_RENDER, then `render_forced`), why, and the Settings choice when it differs
|
||||
/// (state.edn `:render`).
|
||||
mut render_detected : RenderMode
|
||||
mut render_why : String
|
||||
mut render_forced : Bool
|
||||
mut render_choice : RenderMode?
|
||||
/// Dark mode (the configured theme) or light (Moon Day); saved as `:theme :light` when off.
|
||||
mut dark_mode : Bool
|
||||
/// Power: minutes without input before the login session turns the screen off / suspends
|
||||
@@ -445,6 +452,10 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
net: None,
|
||||
remember_windows: true,
|
||||
native_auth_agent: true,
|
||||
render_detected: Hardware,
|
||||
render_why: "not detected",
|
||||
render_forced: false,
|
||||
render_choice: None,
|
||||
dark_mode: true,
|
||||
screen_off_min: default_screen_off_min,
|
||||
suspend_min: default_suspend_min,
|
||||
|
||||
@@ -51,6 +51,8 @@ pub(all) struct SavedState {
|
||||
terminal : String?
|
||||
/// From `:auth-agent`: true for :chandra, false for :system.
|
||||
native_auth_agent : Bool?
|
||||
/// From `:render`: :software or :hardware chosen in Settings (absent: as detected).
|
||||
render : RenderMode?
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -64,7 +66,7 @@ let layout_names : Array[String] = ["tiling", "monocle", "floating"]
|
||||
///| The keys this build owns; everything else in the file is kept as it is.
|
||||
let owned_keys : Array[String] = [
|
||||
"layout", "recent", "desktop-card", "windows", "wallpaper", "restore-session", "remember-windows",
|
||||
"theme", "power", "shortcuts", "terminal", "auth-agent",
|
||||
"theme", "power", "shortcuts", "terminal", "auth-agent", "render",
|
||||
]
|
||||
|
||||
///| How state.edn names each wallpaper, in `@libshell.wallpaper_names` order.
|
||||
@@ -113,6 +115,7 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
shortcuts: [],
|
||||
terminal: None,
|
||||
native_auth_agent: None,
|
||||
render: None,
|
||||
}
|
||||
}
|
||||
let entries = read_state_file()
|
||||
@@ -228,6 +231,10 @@ pub fn DesktopShell::load_state(self : DesktopShell) -> SavedState {
|
||||
Some(Text(t)) if t.length() > 0 => Some(t)
|
||||
_ => None
|
||||
},
|
||||
render: match lookup_key(entries, "render") {
|
||||
Some(Keyword(k)) | Some(Text(k)) => RenderMode::parse(k)
|
||||
_ => None
|
||||
},
|
||||
native_auth_agent: match lookup_key(entries, "auth-agent") {
|
||||
Some(Keyword("system")) => Some(false)
|
||||
Some(Keyword("chandra")) => Some(true)
|
||||
@@ -288,6 +295,10 @@ pub fn DesktopShell::apply_state(self : DesktopShell, st : SavedState) -> Unit {
|
||||
Some(b) => self.native_auth_agent = b
|
||||
None => ()
|
||||
}
|
||||
self.render_choice = match st.render {
|
||||
Some(m) if m != self.render_detected => Some(m)
|
||||
_ => None
|
||||
}
|
||||
match st.terminal {
|
||||
Some(t) => {
|
||||
self.terminal = t
|
||||
@@ -388,6 +399,10 @@ pub fn DesktopShell::save_state(self : DesktopShell) -> Unit {
|
||||
if !self.native_auth_agent {
|
||||
entries.insert(2, (@edn.Value::Keyword("auth-agent"), @edn.Value::Keyword("system")))
|
||||
}
|
||||
match self.render_choice {
|
||||
Some(m) => entries.insert(2, (@edn.Value::Keyword("render"), @edn.Value::Keyword(m.name())))
|
||||
None => ()
|
||||
}
|
||||
if !self.dark_mode {
|
||||
entries.insert(2, (@edn.Value::Keyword("theme"), @edn.Value::Keyword("light")))
|
||||
}
|
||||
|
||||
@@ -684,7 +684,7 @@ fn DesktopShell::publish_host_data(self : DesktopShell) -> Unit {
|
||||
}
|
||||
if self.any_cap("session-settings") {
|
||||
let st = @wasm.Table::new()
|
||||
for n in session_setting_names {
|
||||
for n in self.session_setting_labels() {
|
||||
st.str(n)
|
||||
st.end_row()
|
||||
}
|
||||
@@ -759,14 +759,24 @@ pub fn DesktopShell::set_wallpaper(self : DesktopShell, i : Int) -> Unit {
|
||||
///| The session settings the session settings module lists, in index order.
|
||||
let session_setting_names : Array[String] = [
|
||||
"Reopen windows at login", "Remember window positions", "Dark mode", "Chandra password dialog",
|
||||
render_setting_name,
|
||||
]
|
||||
|
||||
///| The rendering switch (its label is made by `render_setting_label`).
|
||||
let render_setting_name : String = "Lighter animations"
|
||||
|
||||
///| The session settings' labels as listed (the rendering one says what was detected).
|
||||
fn DesktopShell::session_setting_labels(self : DesktopShell) -> Array[String] {
|
||||
session_setting_names.map(n => if n == render_setting_name { self.render_setting_label() } else { n })
|
||||
}
|
||||
|
||||
///| Which session settings are on: bit i for `session_setting_names[i]`.
|
||||
fn DesktopShell::session_settings_bits(self : DesktopShell) -> Int {
|
||||
(if self.restore_session { 1 } else { 0 }) |
|
||||
(if self.remember_windows { 2 } else { 0 }) |
|
||||
(if self.dark_mode { 4 } else { 0 }) |
|
||||
(if self.native_auth_agent { 8 } else { 0 })
|
||||
(if self.native_auth_agent { 8 } else { 0 }) |
|
||||
(if self.software_render() { 16 } else { 0 })
|
||||
}
|
||||
|
||||
///| Turn session setting `i` on or off (ignored when out of range) and remember it in state.edn.
|
||||
@@ -784,6 +794,7 @@ pub fn DesktopShell::set_session_setting(self : DesktopShell, i : Int, on : Bool
|
||||
self.native_auth_agent = on
|
||||
self.actions.push(AuthAgentChanged)
|
||||
}
|
||||
4 => self.choose_software_render(on)
|
||||
_ => return
|
||||
}
|
||||
@wasm.publish_session_settings(self.session_settings_bits())
|
||||
|
||||
Reference in new issue
Block a user