forge
Explore
Log in

Don't you dare go Hollow

Add live-reload for output mode

Browse files at this commit

1f9abaaa58b4517cea35921791d2bad03cbd0ef3Ivan MolodetskikhParent: eb4946c
README.mdmodified+1 -1
@@ -165,7 +165,7 @@ Please use the default configuration file as the starting point for your custom
165 165
166 Niri will live-reload many of the configuration settings, like key binds or gaps, as you change the config file.166 Niri will live-reload many of the configuration settings, like key binds or gaps, as you change the config file.
167 Though, some settings are still missing live-reload support.167 Though, some settings are still missing live-reload support.
168-Notably, output modes will only apply when the output is reconnected.168+Notably, input device libinput settings will only apply when the input device is reconnected.
169 169
170 [PaperWM]: https://github.com/paperwm/PaperWM170 [PaperWM]: https://github.com/paperwm/PaperWM
171 [mako]: https://github.com/emersion/mako171 [mako]: https://github.com/emersion/mako
src/backend/tty.rsmodified+74 -7
@@ -47,6 +47,7 @@ use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_
47 use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;47 use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
48 48
49 use super::RenderResult;49 use super::RenderResult;
50+use crate::frame_clock::FrameClock;
50 use crate::niri::{RedrawState, State};51 use crate::niri::{RedrawState, State};
51 use crate::render_helpers::AsGlesRenderer;52 use crate::render_helpers::AsGlesRenderer;
52 use crate::utils::get_monotonic_time;53 use crate::utils::get_monotonic_time;
@@ -1177,8 +1178,10 @@ impl Tty {
1177 let mut to_disconnect = vec![];1178 let mut to_disconnect = vec![];
1178 let mut to_connect = vec![];1179 let mut to_connect = vec![];
1179 1180
1180- for (node, device) in &self.devices {1181+ for (&node, device) in &mut self.devices {
1181- for surface in device.surfaces.values() {1182+ for surface in device.surfaces.values_mut() {
1183+ let crtc = surface.compositor.crtc();
1184+
1182 let config = self1185 let config = self
1183 .config1186 .config
1184 .borrow()1187 .borrow()
@@ -1187,14 +1190,78 @@ impl Tty {
1187 .find(|o| o.name == surface.name)1190 .find(|o| o.name == surface.name)
1188 .cloned()1191 .cloned()
1189 .unwrap_or_default();1192 .unwrap_or_default();
1190-
1191 if config.off {1193 if config.off {
1192- let crtc = surface.compositor.crtc();1194+ to_disconnect.push((node, crtc));
1193- to_disconnect.push((*node, crtc));1195+ continue;
1194 }1196 }
1197+
1198+ // Check if we need to change the mode.
1199+ let connector = surface
1200+ .compositor
1201+ .current_connectors()
1202+ .into_iter()
1203+ .next()
1204+ .unwrap();
1205+ let Some(connector) = device.drm_scanner.connectors().get(&connector) else {
1206+ error!("missing enabled connector in drm_scanner");
1207+ continue;
1208+ };
1209+
1210+ let Some((mode, fallback)) = pick_mode(connector, config.mode) else {
1211+ error!("couldn't pick mode for enabled connector");
1212+ continue;
1213+ };
1214+
1215+ if surface.compositor.current_mode() == mode {
1216+ continue;
1217+ }
1218+
1219+ let output = niri
1220+ .global_space
1221+ .outputs()
1222+ .find(|output| {
1223+ let tty_state: &TtyOutputState = output.user_data().get().unwrap();
1224+ tty_state.node == node && tty_state.crtc == crtc
1225+ })
1226+ .cloned();
1227+ let Some(output) = output else {
1228+ error!("missing output for crtc: {crtc:?}");
1229+ continue;
1230+ };
1231+ let Some(output_state) = niri.output_state.get_mut(&output) else {
1232+ error!("missing state for output {:?}", surface.name);
1233+ continue;
1234+ };
1235+
1236+ if fallback {
1237+ let target = config.mode.unwrap();
1238+ warn!(
1239+ "output {:?}: configured mode {}x{}{} could not be found, \
1240+ falling back to preferred",
1241+ surface.name,
1242+ target.width,
1243+ target.height,
1244+ if let Some(refresh) = target.refresh {
1245+ format!("@{refresh}")
1246+ } else {
1247+ String::new()
1248+ },
1249+ );
1250+ }
1251+
1252+ debug!("output {:?}: picking mode: {mode:?}", surface.name);
1253+ if let Err(err) = surface.compositor.use_mode(mode) {
1254+ warn!("error changing mode: {err:?}");
1255+ continue;
1256+ }
1257+
1258+ let wl_mode = Mode::from(mode);
1259+ output.change_current_state(Some(wl_mode), None, None, None);
1260+ output.set_preferred(wl_mode);
1261+ output_state.frame_clock = FrameClock::new(Some(refresh_interval(mode)));
1262+ niri.output_resized(output);
1195 }1263 }
1196 1264
1197- // Check if any disabled connectors need to be enabled.
1198 for (connector, crtc) in device.drm_scanner.crtcs() {1265 for (connector, crtc) in device.drm_scanner.crtcs() {
1199 // Check if connected.1266 // Check if connected.
1200 if connector.state() != connector::State::Connected {1267 if connector.state() != connector::State::Connected {
@@ -1222,7 +1289,7 @@ impl Tty {
1222 .unwrap_or_default();1289 .unwrap_or_default();
1223 1290
1224 if !config.off {1291 if !config.off {
1225- to_connect.push((*node, connector.clone(), crtc));1292+ to_connect.push((node, connector.clone(), crtc));
1226 }1293 }
1227 }1294 }
1228 }1295 }