Add live-reload for output on/off
Browse files at this commit5f440f7be3245ad2d357b49d2d2948bb931f661aParent: 6644cc13 changed files +74 -0
- src/backend/mod.rs +7 -0
- src/backend/tty.rs +65 -0
- src/niri.rs +2 -0
src/backend/mod.rsmodified+7 -0
| @@ -136,6 +136,13 @@ impl Backend { | |||
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | + pub fn on_output_config_changed(&mut self, niri: &mut Niri) { | ||
| 140 | + match self { | ||
| 141 | + Backend::Tty(tty) => tty.on_output_config_changed(niri), | ||
| 142 | + Backend::Winit(_) => (), | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + | ||
| 139 | pub fn tty(&mut self) -> &mut Tty { | 146 | pub fn tty(&mut self) -> &mut Tty { |
| 140 | if let Self::Tty(v) = self { | 147 | if let Self::Tty(v) = self { |
| 141 | v | 148 | v |
src/backend/tty.rsmodified+65 -0
| @@ -1220,6 +1220,71 @@ impl Tty { | |||
| 1220 | } | 1220 | } |
| 1221 | } | 1221 | } |
| 1222 | } | 1222 | } |
| 1223 | + | ||
| 1224 | + pub fn on_output_config_changed(&mut self, niri: &mut Niri) { | ||
| 1225 | + let mut to_disconnect = vec![]; | ||
| 1226 | + let mut to_connect = vec![]; | ||
| 1227 | + | ||
| 1228 | + for (node, device) in &self.devices { | ||
| 1229 | + for surface in device.surfaces.values() { | ||
| 1230 | + let config = self | ||
| 1231 | + .config | ||
| 1232 | + .borrow() | ||
| 1233 | + .outputs | ||
| 1234 | + .iter() | ||
| 1235 | + .find(|o| o.name == surface.name) | ||
| 1236 | + .cloned() | ||
| 1237 | + .unwrap_or_default(); | ||
| 1238 | + | ||
| 1239 | + if config.off { | ||
| 1240 | + let crtc = surface.compositor.crtc(); | ||
| 1241 | + to_disconnect.push((*node, crtc)); | ||
| 1242 | + } | ||
| 1243 | + } | ||
| 1244 | + | ||
| 1245 | + // Check if any disabled connectors need to be enabled. | ||
| 1246 | + for (connector, crtc) in device.drm_scanner.crtcs() { | ||
| 1247 | + // Check if connected. | ||
| 1248 | + if connector.state() != connector::State::Connected { | ||
| 1249 | + continue; | ||
| 1250 | + } | ||
| 1251 | + | ||
| 1252 | + // Check if already enabled. | ||
| 1253 | + if device.surfaces.contains_key(&crtc) { | ||
| 1254 | + continue; | ||
| 1255 | + } | ||
| 1256 | + | ||
| 1257 | + let output_name = format!( | ||
| 1258 | + "{}-{}", | ||
| 1259 | + connector.interface().as_str(), | ||
| 1260 | + connector.interface_id(), | ||
| 1261 | + ); | ||
| 1262 | + | ||
| 1263 | + let config = self | ||
| 1264 | + .config | ||
| 1265 | + .borrow() | ||
| 1266 | + .outputs | ||
| 1267 | + .iter() | ||
| 1268 | + .find(|o| o.name == output_name) | ||
| 1269 | + .cloned() | ||
| 1270 | + .unwrap_or_default(); | ||
| 1271 | + | ||
| 1272 | + if !config.off { | ||
| 1273 | + to_connect.push((*node, connector.clone(), crtc)); | ||
| 1274 | + } | ||
| 1275 | + } | ||
| 1276 | + } | ||
| 1277 | + | ||
| 1278 | + for (node, crtc) in to_disconnect { | ||
| 1279 | + self.connector_disconnected(niri, node, crtc); | ||
| 1280 | + } | ||
| 1281 | + | ||
| 1282 | + for (node, connector, crtc) in to_connect { | ||
| 1283 | + if let Err(err) = self.connector_connected(niri, node, connector, crtc) { | ||
| 1284 | + warn!("error connecting connector: {err:?}"); | ||
| 1285 | + } | ||
| 1286 | + } | ||
| 1287 | + } | ||
| 1223 | } | 1288 | } |
| 1224 | 1289 | ||
| 1225 | fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { | 1290 | fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> { |
src/niri.rsmodified+2 -0
| @@ -615,6 +615,8 @@ impl State { | |||
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | self.niri.reposition_outputs(None); | 617 | self.niri.reposition_outputs(None); |
| 618 | + | ||
| 619 | + self.backend.on_output_config_changed(&mut self.niri); | ||
| 618 | } | 620 | } |
| 619 | 621 | ||
| 620 | self.niri.queue_redraw_all(); | 622 | self.niri.queue_redraw_all(); |