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 {
55 HashMap<String, OwnedValue>,55 HashMap<String, OwnedValue>,
56 )> {56 )> {
57 // Construct the DBus response.57 // Construct the DBus response.
58- let mut monitors: Vec<(Monitor, LogicalMonitor)> = self58+ let mut monitors = Vec::new();
59- .ipc_outputs59+ let mut logical_monitors = Vec::new();
60- .lock()60+
61- .unwrap()61+ for output in self.ipc_outputs.lock().unwrap().values() {
62- .values()62+ // Loosely matches the check in Mutter.
63- // Take only enabled outputs.63+ let c = &output.name;
64- .filter(|output| output.current_mode.is_some() && output.logical.is_some())64+ let is_laptop_panel = is_laptop_panel(c);
65- .map(|output| {65+ let display_name = make_display_name(output, is_laptop_panel);
66- // Loosely matches the check in Mutter.66+
67- let c = &output.name;67+ let mut properties = HashMap::new();
68- let is_laptop_panel = is_laptop_panel(c);68+ properties.insert(
69- let display_name = make_display_name(output, is_laptop_panel);69+ String::from("display-name"),
70-70+ OwnedValue::from(zvariant::Str::from(display_name)),
71- let mut properties = HashMap::new();71+ );
72- properties.insert(72+ properties.insert(
73- String::from("display-name"),73+ String::from("is-builtin"),
74- OwnedValue::from(zvariant::Str::from(display_name)),74+ OwnedValue::from(is_laptop_panel),
75- );75+ );
76- properties.insert(76+
77- String::from("is-builtin"),77+ let mut modes: Vec<Mode> = output
78- OwnedValue::from(is_laptop_panel),78+ .modes
79- );79+ .iter()
80-80+ .map(|m| {
81- let mut modes: Vec<Mode> = output81+ let niri_ipc::Mode {
82- .modes82+ width,
83- .iter()83+ height,
84- .map(|m| {84+ refresh_rate,
85- let niri_ipc::Mode {85+ is_preferred,
86- width,86+ } = *m;
87- height,87+ let refresh = refresh_rate as f64 / 1000.;
88- refresh_rate,88+
89- is_preferred,89+ Mode {
90- } = *m;90+ id: format!("{width}x{height}@{refresh:.3}"),
91- let refresh = refresh_rate as f64 / 1000.;91+ width: i32::from(width),
92-92+ height: i32::from(height),
93- Mode {93+ refresh_rate: refresh,
94- id: format!("{width}x{height}@{refresh:.3}"),94+ preferred_scale: 1.,
95- width: i32::from(width),95+ supported_scales: vec![1., 2., 3.],
96- height: i32::from(height),96+ properties: HashMap::from([(
97- refresh_rate: refresh,97+ String::from("is-preferred"),
98- preferred_scale: 1.,98+ OwnedValue::from(is_preferred),
99- supported_scales: vec![1., 2., 3.],99+ )]),
100- properties: HashMap::from([(100+ }
101- String::from("is-preferred"),101+ })
102- OwnedValue::from(is_preferred),102+ .collect();
103- )]),103+ if let Some(mode) = output.current_mode {
104- }104+ modes[mode]
105- })
106- .collect();
107- modes[output.current_mode.unwrap()]
108 .properties105 .properties
109 .insert(String::from("is-current"), OwnedValue::from(true));106 .insert(String::from("is-current"), OwnedValue::from(true));
107+ }
110 108
111- let connector = c.clone();109+ let connector = c.clone();
112- let model = output.model.clone();110+ let model = output.model.clone();
113- let make = output.make.clone();111+ let make = output.make.clone();
114 112
115- // Serial is used for session restore, so fall back to the connector name if it's113+ // Serial is used for session restore, so fall back to the connector name if it's
116- // not available.114+ // not available.
117- let serial = output.serial.as_ref().unwrap_or(&connector).clone();115+ let serial = output.serial.as_ref().unwrap_or(&connector).clone();
118 116
119- let monitor = Monitor {117+ let names = (connector, make, model, serial);
120- names: (connector, make, model, serial),
121- modes,
122- properties,
123- };
124-
125- let logical = output.logical.as_ref().unwrap();
126 118
119+ if let Some(logical) = output.logical.as_ref() {
127 let transform = match logical.transform {120 let transform = match logical.transform {
128 niri_ipc::Transform::Normal => 0,121 niri_ipc::Transform::Normal => 0,
129 niri_ipc::Transform::_90 => 1,122 niri_ipc::Transform::_90 => 1,
@@ -135,24 +128,28 @@ impl DisplayConfig {
135 niri_ipc::Transform::Flipped270 => 7,128 niri_ipc::Transform::Flipped270 => 7,
136 };129 };
137 130
138- let logical_monitor = LogicalMonitor {131+ logical_monitors.push(LogicalMonitor {
139 x: logical.x,132 x: logical.x,
140 y: logical.y,133 y: logical.y,
141 scale: logical.scale,134 scale: logical.scale,
142 transform,135 transform,
143 is_primary: false,136 is_primary: false,
144- monitors: vec![monitor.names.clone()],137+ monitors: vec![names.clone()],
145 properties: HashMap::new(),138 properties: HashMap::new(),
146- };139+ });
140+ }
147 141
148- (monitor, logical_monitor)142+ monitors.push(Monitor {
149- })143+ names,
150- .collect();144+ modes,
145+ properties,
146+ });
147+ }
151 148
152 // Sort by connector.149 // 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));
154 152
155- let (monitors, logical_monitors) = monitors.into_iter().unzip();
156 let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]);153 let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]);
157 Ok((0, monitors, logical_monitors, properties))154 Ok((0, monitors, logical_monitors, properties))
158 }155 }