SystemState reads the generation before the appearance

This commit is contained in:
aiongg
2026-11-13 17:44:40 +00:00
parent 304030b65b
commit 83e75d696a
3 changed files with 9 additions and 3 deletions
+2 -1
View File
@@ -171,7 +171,8 @@ impl Watcher {
self.shared.get()
}
/// Rises each time the theme, [`Watcher::contrast`] or [`Watcher::reduced_motion`] changes, before the wake
/// callback runs; a layout or icon theme change leaves it. Read the preferences again when it moved.
/// callback runs; a layout or icon theme change leaves it. Read the preferences again when it moved,
/// after reading this: a value is stored before the generation rises.
pub fn generation(&self) -> u64 {
self.shared.generation.load(Ordering::Acquire)
}
+2 -1
View File
@@ -100,7 +100,8 @@ impl SystemReader {
/// Rises each time a preference [`SystemReader::read`] answers from changes, as its source
/// reports it: the watcher's theme, contrast or reduced motion, or a reported value. Read
/// again when it moved. On the web the browser's queries raise it in no case.
/// again when it moved. On the web the browser's queries raise it in no case. Read it before
/// [`SystemReader::read`]: the watcher stores a value before it raises the generation.
pub fn generation(&self) -> u64 {
self.watcher.as_ref().map_or(0, Watcher::generation) + self.reported.generation.load(Ordering::Acquire)
}
+5 -1
View File
@@ -29,7 +29,11 @@ pub struct SystemState {
/// What the OS reports on `ctx` now: the host's reader (`InstallSpec::system`), with the colour scheme egui's
/// integration reports (`Event::SystemTheme`) where the reader's own watcher has none.
pub fn system_appearance(ctx: &Context) -> SystemState {
Service::<Source>::run(ctx, |source| SystemState { appearance: source.0.read().into(), generation: source.0.generation() })
Service::<Source>::run(ctx, |source| {
// Generation first: a change landing between the two reads then shows again at the next read.
let generation = source.0.generation();
SystemState { appearance: source.0.read().into(), generation }
})
}
pub(crate) fn install(ctx: &Context, reader: SystemReader) {