forge
Explore
Log in

Don't you dare go Hollow

dbus: DisplayConfig: report disabled monitors in get_current_state

Browse files at this commit

693e0e09f79c2d1add466b15daabffd0be339ecbVal PackettParent: d52356b
This is required for gnome-control-center to be able to turn
monitors back on.
src/dbus/mutter_display_config.rsmodified+68 -71
@@ -55,75 +55,68 @@ impl DisplayConfig {
5555 HashMap<String, OwnedValue>,
5656 )> {
5757 // Construct the DBus response.
58- let mut monitors: Vec<(Monitor, LogicalMonitor)> = self
59- .ipc_outputs
60- .lock()
61- .unwrap()
62- .values()
63- // Take only enabled outputs.
64- .filter(|output| output.current_mode.is_some() && output.logical.is_some())
65- .map(|output| {
66- // Loosely matches the check in Mutter.
67- let c = &output.name;
68- let is_laptop_panel = is_laptop_panel(c);
69- let display_name = make_display_name(output, is_laptop_panel);
70-
71- let mut properties = HashMap::new();
72- properties.insert(
73- String::from("display-name"),
74- OwnedValue::from(zvariant::Str::from(display_name)),
75- );
76- properties.insert(
77- String::from("is-builtin"),
78- OwnedValue::from(is_laptop_panel),
79- );
80-
81- let mut modes: Vec<Mode> = output
82- .modes
83- .iter()
84- .map(|m| {
85- let niri_ipc::Mode {
86- width,
87- height,
88- refresh_rate,
89- is_preferred,
90- } = *m;
91- let refresh = refresh_rate as f64 / 1000.;
92-
93- Mode {
94- id: format!("{width}x{height}@{refresh:.3}"),
95- width: i32::from(width),
96- height: i32::from(height),
97- refresh_rate: refresh,
98- preferred_scale: 1.,
99- supported_scales: vec![1., 2., 3.],
100- properties: HashMap::from([(
101- String::from("is-preferred"),
102- OwnedValue::from(is_preferred),
103- )]),
104- }
105- })
106- .collect();
107- modes[output.current_mode.unwrap()]
58+ let mut monitors = Vec::new();
59+ let mut logical_monitors = Vec::new();
60+
61+ for output in self.ipc_outputs.lock().unwrap().values() {
62+ // Loosely matches the check in Mutter.
63+ let c = &output.name;
64+ let is_laptop_panel = is_laptop_panel(c);
65+ let display_name = make_display_name(output, is_laptop_panel);
66+
67+ let mut properties = HashMap::new();
68+ properties.insert(
69+ String::from("display-name"),
70+ OwnedValue::from(zvariant::Str::from(display_name)),
71+ );
72+ properties.insert(
73+ String::from("is-builtin"),
74+ OwnedValue::from(is_laptop_panel),
75+ );
76+
77+ let mut modes: Vec<Mode> = output
78+ .modes
79+ .iter()
80+ .map(|m| {
81+ let niri_ipc::Mode {
82+ width,
83+ height,
84+ refresh_rate,
85+ is_preferred,
86+ } = *m;
87+ let refresh = refresh_rate as f64 / 1000.;
88+
89+ Mode {
90+ id: format!("{width}x{height}@{refresh:.3}"),
91+ width: i32::from(width),
92+ height: i32::from(height),
93+ refresh_rate: refresh,
94+ preferred_scale: 1.,
95+ supported_scales: vec![1., 2., 3.],
96+ properties: HashMap::from([(
97+ String::from("is-preferred"),
98+ OwnedValue::from(is_preferred),
99+ )]),
100+ }
101+ })
102+ .collect();
103+ if let Some(mode) = output.current_mode {
104+ modes[mode]
108105 .properties
109106 .insert(String::from("is-current"), OwnedValue::from(true));
107+ }
110108
111- let connector = c.clone();
112- let model = output.model.clone();
113- let make = output.make.clone();
109+ let connector = c.clone();
110+ let model = output.model.clone();
111+ let make = output.make.clone();
114112
115- // Serial is used for session restore, so fall back to the connector name if it's
116- // not available.
117- let serial = output.serial.as_ref().unwrap_or(&connector).clone();
113+ // Serial is used for session restore, so fall back to the connector name if it's
114+ // not available.
115+ let serial = output.serial.as_ref().unwrap_or(&connector).clone();
118116
119- let monitor = Monitor {
120- names: (connector, make, model, serial),
121- modes,
122- properties,
123- };
124-
125- let logical = output.logical.as_ref().unwrap();
117+ let names = (connector, make, model, serial);
126118
119+ if let Some(logical) = output.logical.as_ref() {
127120 let transform = match logical.transform {
128121 niri_ipc::Transform::Normal => 0,
129122 niri_ipc::Transform::_90 => 1,
@@ -135,24 +128,28 @@ impl DisplayConfig {
135128 niri_ipc::Transform::Flipped270 => 7,
136129 };
137130
138- let logical_monitor = LogicalMonitor {
131+ logical_monitors.push(LogicalMonitor {
139132 x: logical.x,
140133 y: logical.y,
141134 scale: logical.scale,
142135 transform,
143136 is_primary: false,
144- monitors: vec![monitor.names.clone()],
137+ monitors: vec![names.clone()],
145138 properties: HashMap::new(),
146- };
139+ });
140+ }
147141
148- (monitor, logical_monitor)
149- })
150- .collect();
142+ monitors.push(Monitor {
143+ names,
144+ modes,
145+ properties,
146+ });
147+ }
151148
152149 // Sort by connector.
153- monitors.sort_unstable_by(|a, b| a.0.names.0.cmp(&b.0.names.0));
150+ monitors.sort_unstable_by(|a, b| a.names.0.cmp(&b.names.0));
151+ logical_monitors.sort_unstable_by(|a, b| a.monitors[0].0.cmp(&b.monitors[0].0));
154152
155- let (monitors, logical_monitors) = monitors.into_iter().unzip();
156153 let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]);
157154 Ok((0, monitors, logical_monitors, properties))
158155 }