mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Add live-reload for output on/off
This commit is contained in:
@@ -136,6 +136,13 @@ impl Backend {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_output_config_changed(&mut self, niri: &mut Niri) {
|
||||
match self {
|
||||
Backend::Tty(tty) => tty.on_output_config_changed(niri),
|
||||
Backend::Winit(_) => (),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tty(&mut self) -> &mut Tty {
|
||||
if let Self::Tty(v) = self {
|
||||
v
|
||||
|
||||
@@ -1220,6 +1220,71 @@ impl Tty {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_output_config_changed(&mut self, niri: &mut Niri) {
|
||||
let mut to_disconnect = vec![];
|
||||
let mut to_connect = vec![];
|
||||
|
||||
for (node, device) in &self.devices {
|
||||
for surface in device.surfaces.values() {
|
||||
let config = self
|
||||
.config
|
||||
.borrow()
|
||||
.outputs
|
||||
.iter()
|
||||
.find(|o| o.name == surface.name)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
if config.off {
|
||||
let crtc = surface.compositor.crtc();
|
||||
to_disconnect.push((*node, crtc));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any disabled connectors need to be enabled.
|
||||
for (connector, crtc) in device.drm_scanner.crtcs() {
|
||||
// Check if connected.
|
||||
if connector.state() != connector::State::Connected {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if already enabled.
|
||||
if device.surfaces.contains_key(&crtc) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let output_name = format!(
|
||||
"{}-{}",
|
||||
connector.interface().as_str(),
|
||||
connector.interface_id(),
|
||||
);
|
||||
|
||||
let config = self
|
||||
.config
|
||||
.borrow()
|
||||
.outputs
|
||||
.iter()
|
||||
.find(|o| o.name == output_name)
|
||||
.cloned()
|
||||
.unwrap_or_default();
|
||||
|
||||
if !config.off {
|
||||
to_connect.push((*node, connector.clone(), crtc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (node, crtc) in to_disconnect {
|
||||
self.connector_disconnected(niri, node, crtc);
|
||||
}
|
||||
|
||||
for (node, connector, crtc) in to_connect {
|
||||
if let Err(err) = self.connector_connected(niri, node, connector, crtc) {
|
||||
warn!("error connecting connector: {err:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn primary_node_from_config(config: &Config) -> Option<(DrmNode, DrmNode)> {
|
||||
|
||||
@@ -615,6 +615,8 @@ impl State {
|
||||
}
|
||||
|
||||
self.niri.reposition_outputs(None);
|
||||
|
||||
self.backend.on_output_config_changed(&mut self.niri);
|
||||
}
|
||||
|
||||
self.niri.queue_redraw_all();
|
||||
|
||||
Reference in New Issue
Block a user