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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! MXC — the Myx Color Protocol.
//!
//! Myx derives a 16-token semantic palette from album art on every track change.
//! Without MXC that palette dies inside the process. MXC makes it a **published
//! local resource**: Myx opens a Unix socket, writes newline-delimited JSON, and
//! any process that wants album-reactive color subscribes. Myx has zero
//! knowledge of its consumers.
//!
//! The protocol is deliberately small: **one socket, one message shape, full
//! state every time, snapshot on connect.**
//!
//! Spec: `~/Jawz/notes/tech/myx-color-protocol.md` (v0.1.0).
//!
//! This module is the *protocol* half — pure data types and pure color math,
//! no I/O. The publisher (`UnixListener`, fan-out, dedupe) is a separate
//! concern so that these types stay trivially portable to consumers.
//!
//! ## Layout
//!
//! - [`wire`] — the serde types that define the byte-level contract.
//! - [`contrast`] — WCAG relative luminance and the `on_*` foreground picker.
//! - [`cli`] — `myx theme get|watch`, the reference consumer, kept here so the
//! protocol and the tool that reads it cannot drift apart.
//!
//! ## Why the contrast math lives here
//!
//! Every surveyed media-theming project reimplements luminance clamping, and
//! most do it wrong (see spec §3.3). Publishing `is_dark` and `contrast`
//! *once, correctly* means no consumer has to. That is a protocol
//! responsibility, not a consumer one.
pub use Contrast;
pub use ;
use PathBuf;
/// Protocol major version. Bumped only for breaking changes — removing or
/// renaming a color token, changing hex format, or changing framing.
///
/// Additive changes (new optional envelope fields, new [`OriginKind`] values,
/// new `on_*` keys) do NOT bump this. Consumers ignore what they don't know.
pub const PROTOCOL_VERSION: u32 = 1;
/// Socket path: `$XDG_RUNTIME_DIR/myx/theme.sock`.
///
/// Falls back to `/tmp/myx-$UID/theme.sock` when `XDG_RUNTIME_DIR` is unset
/// (bare TTY logins, some minimal containers). The fallback is uid-scoped so
/// two users on one box never collide.
/// Minimal `getuid` shim so the fallback path doesn't pull in a `libc`
/// dependency for one call.
unsafe
unsafe
/// Unix epoch milliseconds, for the `ts` envelope field.
///
/// Saturates to `0` if the clock is before the epoch rather than panicking —
/// a bad clock must never take down the player.