1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT
//! The process-wide environment revision bumped by an OS change notification.
//!
//! # Why a counter and not a callback
//!
//! The library does not own the host's event loop, so it cannot be *pushed* a callback on a
//! thread it is not running. What it can be given is a value it compares against the one it saw
//! last, which is the same shape [`crate::platform::Platform::display_generation`] and the asset
//! watcher already use. A backend that receives a native notification (macOS
//! `NSDistributedNotificationCenter`, Windows `WM_SETTINGCHANGE`, GTK's `notify::` signals)
//! calls [`bump`]; the style layer's bounded poll then sees a different revision and re-reads the
//! facts immediately instead of waiting for its interval.
//!
//! # Why this is separate from a backend's own revision
//!
//! A backend's [`Platform::environment_generation`] is derived from values it can read — which is
//! the honest fallback when there is no notification source, but it cannot distinguish "the user
//! changed the setting and changed it back between two reads" from "nothing happened". A pushed
//! notification can. Keeping the pushed revision here means every backend, including the ones
//! that derive instead of listen, gains the same hook without a field on each implementation.
//!
//! [`Platform::environment_generation`]: crate::platform::Platform::environment_generation
use ;
/// Notifications observed since process start. Zero means none, which is also the value that says
/// "this backend cannot report changes" on [`Platform::environment_generation`], so the two
/// meanings are compatible: before a notification there is nothing to report.
static NOTIFIED: AtomicU64 = new;
/// Records one host notification and returns the new revision.
/// The number of notifications observed so far.
/// Serialises tests that advance the process-wide counter.
///
/// # Why the tests need this
///
/// The counter is one value for the whole process, and `cargo test` runs the test threads in
/// parallel. A test that reads `generation()`, acts, and asserts a delta is only meaningful while
/// no other test bumps in between — and the environment-fact cache tests deliberately bump to
/// prove a notification invalidates a reading. One lock owned by this module (the owner of the
/// counter) is the smallest thing that makes both assertions deterministic.
pub
/// Folds the notification revision into a backend's own revision.
///
/// A backend revision of `0` means "not derived here"; the notification count is then the whole
/// answer, and stays `0` until the host actually notifies. A non-zero backend revision is mixed
/// with the notification count so a push changes the returned value even when the derived values
/// have not changed yet (AppKit updates its cached appearance a moment after posting, for
/// example).