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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Display profile provider — per-display refresh/HDR/color/scale.
//!
//! Builds on the existing [`crate::display::DisplayMonitor`]. Each connected
//! display is exposed as its own profile group with the actively-applied
//! mode + HDR/scale settings.
use super::{ProfileGroup, ProfileProvider, Setting, SettingRisk, SettingValue, Subsystem};
pub struct DisplayProfileProvider {
_private: (),
}
impl DisplayProfileProvider {
pub fn new() -> Self {
Self { _private: () }
}
}
impl Default for DisplayProfileProvider {
fn default() -> Self {
Self::new()
}
}
impl ProfileProvider for DisplayProfileProvider {
fn subsystem(&self) -> Subsystem {
Subsystem::Display
}
fn snapshot(&mut self) -> Vec<ProfileGroup> {
let mut groups = super::edid::scan_edid_groups();
let monitor = match crate::display::DisplayMonitor::new() {
Ok(m) => m,
Err(_) => return groups,
};
for d in monitor.displays() {
let label = d.name.clone().unwrap_or_else(|| d.id.clone());
let mut g = ProfileGroup::new(
Subsystem::Display,
&label,
if d.is_primary {
"Primary display"
} else {
"Display"
},
"DisplayMonitor",
);
if let Some(mfg) = &d.manufacturer {
g.push(Setting::info(
"manufacturer",
"Manufacturer",
SettingValue::Text(mfg.clone()),
));
}
// Two of the three displays here report a connection the reader
// cannot classify, and `{:?}` printed the literal word "Unknown" as
// the value. The ontology already turns that into an absence with a
// reason --- `push_str_as` refuses the word --- and this surface was
// publishing it as though it were a kind of connector. Dropped
// instead, the way every other row here behaves when it has nothing.
let connection = format!("{:?}", d.connection);
if !connection.eq_ignore_ascii_case("unknown") {
g.push(Setting::info(
"connection",
"Connection",
SettingValue::Text(connection),
));
}
// "0x0" was published here as a resolution. A mode that was not
// read gets no row, the same as the aspect ratio below.
if let (Some(w), Some(h)) = (d.width, d.height) {
g.push(Setting::info(
"resolution",
"Resolution",
SettingValue::Text(format!("{w}x{h}")),
));
}
if let Some(ratio) = d.aspect_ratio() {
g.push(Setting::info(
"aspect_ratio",
"Aspect Ratio",
SettingValue::Text(ratio),
));
}
// The Linux and macOS readers do not parse a rate at all, so this
// row said "0 Hz" on both platforms for every display.
if let Some(hz) = d.refresh_rate {
g.push(
Setting::info(
"refresh_rate_hz",
"Refresh Rate",
SettingValue::Float(hz as f64),
)
.with_unit("Hz")
.with_risk(SettingRisk::Safe)
.with_source("DisplayMonitor"),
);
}
g.push(
Setting::info(
"hdr_mode",
"HDR Mode",
SettingValue::Text(format!("{:?}", d.hdr)),
)
.with_risk(SettingRisk::Safe),
);
if let Some(b) = d.brightness {
g.push(
Setting::info("brightness", "Brightness", SettingValue::Float(b as f64))
.with_unit("%")
.with_risk(SettingRisk::Safe),
);
}
if let Some(s) = d.scale_factor {
g.push(
Setting::info("scale_factor", "DPI Scale", SettingValue::Float(s))
.with_risk(SettingRisk::Safe),
);
}
if let Some(bpp) = d.bits_per_pixel {
g.push(Setting::info(
"bpp",
"Bits Per Pixel",
SettingValue::Uint(bpp as u64),
));
}
if let (Some(w), Some(h)) = (d.physical_width_mm, d.physical_height_mm) {
g.push(Setting::info(
"physical_mm",
"Physical Size",
SettingValue::Text(format!("{}×{} mm", w, h)),
));
}
g.push(Setting::info(
"is_primary",
"Primary",
SettingValue::Bool(d.is_primary),
));
groups.push(g);
}
groups
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn smoke() {
let mut p = DisplayProfileProvider::new();
let _ = p.snapshot();
}
}