feature: add on-demand vrr (#586)
Browse files at this commit10 changed files +201 -66
- niri-config/src/lib.rs +26 -4
- niri-ipc/src/lib.rs +25 -11
- src/backend/mod.rs +7 -0
- src/backend/tty.rs +50 -38
- src/frame_clock.rs +4 -0
- src/niri.rs +46 -7
- src/protocols/output_management.rs +5 -5
- src/window/mod.rs +7 -0
- wiki/Configuration:-Outputs.md +10 -1
- wiki/Configuration:-Window-Rules.md +21 -0
niri-config/src/lib.rsmodified+26 -4
| @@ -324,11 +324,25 @@ pub struct Output { | ||
| 324 | 324 | #[knuffel(child, unwrap(argument, str))] |
| 325 | 325 | pub mode: Option<ConfiguredMode>, |
| 326 | 326 | #[knuffel(child)] |
| 327 | - pub variable_refresh_rate: bool, | |
| 327 | + pub variable_refresh_rate: Option<Vrr>, | |
| 328 | 328 | #[knuffel(child, default = DEFAULT_BACKGROUND_COLOR)] |
| 329 | 329 | pub background_color: Color, |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | +impl Output { | |
| 333 | + pub fn is_vrr_always_on(&self) -> bool { | |
| 334 | + self.variable_refresh_rate == Some(Vrr { on_demand: false }) | |
| 335 | + } | |
| 336 | + | |
| 337 | + pub fn is_vrr_on_demand(&self) -> bool { | |
| 338 | + self.variable_refresh_rate == Some(Vrr { on_demand: true }) | |
| 339 | + } | |
| 340 | + | |
| 341 | + pub fn is_vrr_always_off(&self) -> bool { | |
| 342 | + self.variable_refresh_rate.is_none() | |
| 343 | + } | |
| 344 | +} | |
| 345 | + | |
| 332 | 346 | impl Default for Output { |
| 333 | 347 | fn default() -> Self { |
| 334 | 348 | Self { |
| @@ -338,7 +352,7 @@ impl Default for Output { | ||
| 338 | 352 | transform: Transform::Normal, |
| 339 | 353 | position: None, |
| 340 | 354 | mode: None, |
| 341 | - variable_refresh_rate: false, | |
| 355 | + variable_refresh_rate: None, | |
| 342 | 356 | background_color: DEFAULT_BACKGROUND_COLOR, |
| 343 | 357 | } |
| 344 | 358 | } |
| @@ -352,6 +366,12 @@ pub struct Position { | ||
| 352 | 366 | pub y: i32, |
| 353 | 367 | } |
| 354 | 368 | |
| 369 | +#[derive(knuffel::Decode, Debug, Clone, PartialEq, Default)] | |
| 370 | +pub struct Vrr { | |
| 371 | + #[knuffel(property, default = false)] | |
| 372 | + pub on_demand: bool, | |
| 373 | +} | |
| 374 | + | |
| 355 | 375 | // MIN and MAX generics are only used during parsing to check the value. |
| 356 | 376 | #[derive(Debug, Default, Clone, Copy, PartialEq)] |
| 357 | 377 | pub struct FloatOrInt<const MIN: i32, const MAX: i32>(pub f64); |
| @@ -896,6 +916,8 @@ pub struct WindowRule { | ||
| 896 | 916 | pub clip_to_geometry: Option<bool>, |
| 897 | 917 | #[knuffel(child, unwrap(argument))] |
| 898 | 918 | pub block_out_from: Option<BlockOutFrom>, |
| 919 | + #[knuffel(child, unwrap(argument))] | |
| 920 | + pub variable_refresh_rate: Option<bool>, | |
| 899 | 921 | } |
| 900 | 922 | |
| 901 | 923 | // Remember to update the PartialEq impl when adding fields! |
| @@ -2705,7 +2727,7 @@ mod tests { | ||
| 2705 | 2727 | transform "flipped-90" |
| 2706 | 2728 | position x=10 y=20 |
| 2707 | 2729 | mode "1920x1080@144" |
| 2708 | - variable-refresh-rate | |
| 2730 | + variable-refresh-rate on-demand=true | |
| 2709 | 2731 | background-color "rgba(25, 25, 102, 1.0)" |
| 2710 | 2732 | } |
| 2711 | 2733 | |
| @@ -2889,7 +2911,7 @@ mod tests { | ||
| 2889 | 2911 | height: 1080, |
| 2890 | 2912 | refresh: Some(144.), |
| 2891 | 2913 | }), |
| 2892 | - variable_refresh_rate: true, | |
| 2914 | + variable_refresh_rate: Some(Vrr { on_demand: true }), | |
| 2893 | 2915 | background_color: Color::from_rgba8_unpremul(25, 25, 102, 255), |
| 2894 | 2916 | }]), |
| 2895 | 2917 | layout: Layout { |
niri-ipc/src/lib.rsmodified+25 -11
| @@ -352,18 +352,11 @@ pub enum OutputAction { | ||
| 352 | 352 | #[cfg_attr(feature = "clap", command(subcommand))] |
| 353 | 353 | position: PositionToSet, |
| 354 | 354 | }, |
| 355 | - /// Toggle variable refresh rate. | |
| 355 | + /// Set the variable refresh rate mode. | |
| 356 | 356 | Vrr { |
| 357 | - /// Whether to enable variable refresh rate. | |
| 358 | - #[cfg_attr( | |
| 359 | - feature = "clap", | |
| 360 | - arg( | |
| 361 | - value_name = "ON|OFF", | |
| 362 | - action = clap::ArgAction::Set, | |
| 363 | - value_parser = clap::builder::BoolishValueParser::new(), | |
| 364 | - ), | |
| 365 | - )] | |
| 366 | - enable: bool, | |
| 357 | + /// Variable refresh rate mode to set. | |
| 358 | + #[cfg_attr(feature = "clap", command(flatten))] | |
| 359 | + vrr: VrrToSet, | |
| 367 | 360 | }, |
| 368 | 361 | } |
| 369 | 362 | |
| @@ -425,6 +418,27 @@ pub struct ConfiguredPosition { | ||
| 425 | 418 | pub y: i32, |
| 426 | 419 | } |
| 427 | 420 | |
| 421 | +/// Output VRR to set. | |
| 422 | +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] | |
| 423 | +#[cfg_attr(feature = "clap", derive(clap::Args))] | |
| 424 | +#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] | |
| 425 | +pub struct VrrToSet { | |
| 426 | + /// Whether to enable variable refresh rate. | |
| 427 | + #[cfg_attr( | |
| 428 | + feature = "clap", | |
| 429 | + arg( | |
| 430 | + value_name = "ON|OFF", | |
| 431 | + action = clap::ArgAction::Set, | |
| 432 | + value_parser = clap::builder::BoolishValueParser::new(), | |
| 433 | + hide_possible_values = true, | |
| 434 | + ), | |
| 435 | + )] | |
| 436 | + pub vrr: bool, | |
| 437 | + /// Only enable when the output shows a window matching the variable-refresh-rate window rule. | |
| 438 | + #[cfg_attr(feature = "clap", arg(long))] | |
| 439 | + pub on_demand: bool, | |
| 440 | +} | |
| 441 | + | |
| 428 | 442 | /// Connected output. |
| 429 | 443 | #[derive(Debug, Serialize, Deserialize, Clone)] |
| 430 | 444 | #[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] |
src/backend/mod.rsmodified+7 -0
| @@ -153,6 +153,13 @@ impl Backend { | ||
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | + pub fn set_output_on_demand_vrr(&mut self, niri: &mut Niri, output: &Output, enable_vrr: bool) { | |
| 157 | + match self { | |
| 158 | + Backend::Tty(tty) => tty.set_output_on_demand_vrr(niri, output, enable_vrr), | |
| 159 | + Backend::Winit(_) => (), | |
| 160 | + } | |
| 161 | + } | |
| 162 | + | |
| 156 | 163 | pub fn on_output_config_changed(&mut self, niri: &mut Niri) { |
| 157 | 164 | match self { |
| 158 | 165 | Backend::Tty(tty) => tty.on_output_config_changed(niri), |
src/backend/tty.rsmodified+50 -38
| @@ -180,6 +180,7 @@ struct TtyOutputState { | ||
| 180 | 180 | struct Surface { |
| 181 | 181 | name: String, |
| 182 | 182 | compositor: GbmDrmCompositor, |
| 183 | + connector: connector::Handle, | |
| 183 | 184 | dmabuf_feedback: Option<SurfaceDmabufFeedback>, |
| 184 | 185 | gamma_props: Option<GammaProps>, |
| 185 | 186 | /// Gamma change to apply upon session resume. |
| @@ -426,18 +427,6 @@ impl Tty { | ||
| 426 | 427 | } |
| 427 | 428 | |
| 428 | 429 | // Restore VRR. |
| 429 | - let Some(connector) = | |
| 430 | - surface.compositor.pending_connectors().into_iter().next() | |
| 431 | - else { | |
| 432 | - error!("surface pending connectors is empty"); | |
| 433 | - continue; | |
| 434 | - }; | |
| 435 | - let Some(connector) = device.drm_scanner.connectors().get(&connector) | |
| 436 | - else { | |
| 437 | - error!("missing enabled connector in drm_scanner"); | |
| 438 | - continue; | |
| 439 | - }; | |
| 440 | - | |
| 441 | 430 | let output = niri |
| 442 | 431 | .global_space |
| 443 | 432 | .outputs() |
| @@ -457,7 +446,7 @@ impl Tty { | ||
| 457 | 446 | |
| 458 | 447 | try_to_change_vrr( |
| 459 | 448 | &device.drm, |
| 460 | - connector, | |
| 449 | + surface.connector, | |
| 461 | 450 | *crtc, |
| 462 | 451 | surface, |
| 463 | 452 | output_state, |
| @@ -832,15 +821,13 @@ impl Tty { | ||
| 832 | 821 | let mut vrr_enabled = false; |
| 833 | 822 | if let Some(capable) = is_vrr_capable(&device.drm, connector.handle()) { |
| 834 | 823 | if capable { |
| 835 | - let word = if config.variable_refresh_rate { | |
| 836 | - "enabling" | |
| 837 | - } else { | |
| 838 | - "disabling" | |
| 839 | - }; | |
| 824 | + // Even if on-demand, we still disable it until later checks. | |
| 825 | + let vrr = config.is_vrr_always_on(); | |
| 826 | + let word = if vrr { "enabling" } else { "disabling" }; | |
| 840 | 827 | |
| 841 | - match set_vrr_enabled(&device.drm, crtc, config.variable_refresh_rate) { | |
| 828 | + match set_vrr_enabled(&device.drm, crtc, vrr) { | |
| 842 | 829 | Ok(enabled) => { |
| 843 | - if enabled != config.variable_refresh_rate { | |
| 830 | + if enabled != vrr { | |
| 844 | 831 | warn!("failed {} VRR", word); |
| 845 | 832 | } |
| 846 | 833 | |
| @@ -851,13 +838,13 @@ impl Tty { | ||
| 851 | 838 | } |
| 852 | 839 | } |
| 853 | 840 | } else { |
| 854 | - if config.variable_refresh_rate { | |
| 841 | + if !config.is_vrr_always_off() { | |
| 855 | 842 | warn!("cannot enable VRR because connector is not vrr_capable"); |
| 856 | 843 | } |
| 857 | 844 | |
| 858 | 845 | // Try to disable it anyway to work around a bug where resetting DRM state causes |
| 859 | 846 | // vrr_capable to be reset to 0, potentially leaving VRR_ENABLED at 1. |
| 860 | - let res = set_vrr_enabled(&device.drm, crtc, config.variable_refresh_rate); | |
| 847 | + let res = set_vrr_enabled(&device.drm, crtc, false); | |
| 861 | 848 | if matches!(res, Ok(true)) { |
| 862 | 849 | warn!("error disabling VRR"); |
| 863 | 850 | |
| @@ -865,7 +852,7 @@ impl Tty { | ||
| 865 | 852 | vrr_enabled = true; |
| 866 | 853 | } |
| 867 | 854 | } |
| 868 | - } else if config.variable_refresh_rate { | |
| 855 | + } else if !config.is_vrr_always_off() { | |
| 869 | 856 | warn!("cannot enable VRR because connector is not vrr_capable"); |
| 870 | 857 | } |
| 871 | 858 | |
| @@ -1017,6 +1004,7 @@ impl Tty { | ||
| 1017 | 1004 | |
| 1018 | 1005 | let surface = Surface { |
| 1019 | 1006 | name: output_name.clone(), |
| 1007 | + connector: connector.handle(), | |
| 1020 | 1008 | compositor, |
| 1021 | 1009 | dmabuf_feedback, |
| 1022 | 1010 | gamma_props, |
| @@ -1661,6 +1649,33 @@ impl Tty { | ||
| 1661 | 1649 | } |
| 1662 | 1650 | } |
| 1663 | 1651 | |
| 1652 | + pub fn set_output_on_demand_vrr(&mut self, niri: &mut Niri, output: &Output, enable_vrr: bool) { | |
| 1653 | + let _span = tracy_client::span!("Tty::set_output_on_demand_vrr"); | |
| 1654 | + | |
| 1655 | + let output_state = niri.output_state.get_mut(output).unwrap(); | |
| 1656 | + output_state.on_demand_vrr_enabled = enable_vrr; | |
| 1657 | + if output_state.frame_clock.vrr() == enable_vrr { | |
| 1658 | + return; | |
| 1659 | + } | |
| 1660 | + for (&node, device) in self.devices.iter_mut() { | |
| 1661 | + for (&crtc, surface) in device.surfaces.iter_mut() { | |
| 1662 | + let tty_state: &TtyOutputState = output.user_data().get().unwrap(); | |
| 1663 | + if tty_state.node == node && tty_state.crtc == crtc { | |
| 1664 | + try_to_change_vrr( | |
| 1665 | + &device.drm, | |
| 1666 | + surface.connector, | |
| 1667 | + crtc, | |
| 1668 | + surface, | |
| 1669 | + output_state, | |
| 1670 | + enable_vrr, | |
| 1671 | + ); | |
| 1672 | + self.refresh_ipc_outputs(niri); | |
| 1673 | + return; | |
| 1674 | + } | |
| 1675 | + } | |
| 1676 | + } | |
| 1677 | + } | |
| 1678 | + | |
| 1664 | 1679 | pub fn on_output_config_changed(&mut self, niri: &mut Niri) { |
| 1665 | 1680 | let _span = tracy_client::span!("Tty::on_output_config_changed"); |
| 1666 | 1681 | |
| @@ -1675,9 +1690,7 @@ impl Tty { | ||
| 1675 | 1690 | let mut to_connect = vec![]; |
| 1676 | 1691 | |
| 1677 | 1692 | for (&node, device) in &mut self.devices { |
| 1678 | - for surface in device.surfaces.values_mut() { | |
| 1679 | - let crtc = surface.compositor.crtc(); | |
| 1680 | - | |
| 1693 | + for (&crtc, surface) in device.surfaces.iter_mut() { | |
| 1681 | 1694 | let config = self |
| 1682 | 1695 | .config |
| 1683 | 1696 | .borrow() |
| @@ -1691,12 +1704,8 @@ impl Tty { | ||
| 1691 | 1704 | } |
| 1692 | 1705 | |
| 1693 | 1706 | // Check if we need to change the mode. |
| 1694 | - let Some(connector) = surface.compositor.pending_connectors().into_iter().next() | |
| 1707 | + let Some(connector) = device.drm_scanner.connectors().get(&surface.connector) | |
| 1695 | 1708 | else { |
| 1696 | - error!("surface pending connectors is empty"); | |
| 1697 | - continue; | |
| 1698 | - }; | |
| 1699 | - let Some(connector) = device.drm_scanner.connectors().get(&connector) else { | |
| 1700 | 1709 | error!("missing enabled connector in drm_scanner"); |
| 1701 | 1710 | continue; |
| 1702 | 1711 | }; |
| @@ -1707,8 +1716,9 @@ impl Tty { | ||
| 1707 | 1716 | }; |
| 1708 | 1717 | |
| 1709 | 1718 | let change_mode = surface.compositor.pending_mode() != mode; |
| 1710 | - let change_vrr = surface.vrr_enabled != config.variable_refresh_rate; | |
| 1711 | - if !change_mode && !change_vrr { | |
| 1719 | + let change_always_vrr = surface.vrr_enabled != config.is_vrr_always_on(); | |
| 1720 | + let is_on_demand_vrr = config.is_vrr_on_demand(); | |
| 1721 | + if !change_mode && !change_always_vrr && !is_on_demand_vrr { | |
| 1712 | 1722 | continue; |
| 1713 | 1723 | } |
| 1714 | 1724 | |
| @@ -1729,14 +1739,16 @@ impl Tty { | ||
| 1729 | 1739 | continue; |
| 1730 | 1740 | }; |
| 1731 | 1741 | |
| 1732 | - if change_vrr { | |
| 1742 | + if (is_on_demand_vrr && surface.vrr_enabled != output_state.on_demand_vrr_enabled) | |
| 1743 | + || (!is_on_demand_vrr && change_always_vrr) | |
| 1744 | + { | |
| 1733 | 1745 | try_to_change_vrr( |
| 1734 | 1746 | &device.drm, |
| 1735 | - connector, | |
| 1747 | + connector.handle(), | |
| 1736 | 1748 | crtc, |
| 1737 | 1749 | surface, |
| 1738 | 1750 | output_state, |
| 1739 | - config.variable_refresh_rate, | |
| 1751 | + !surface.vrr_enabled, | |
| 1740 | 1752 | ); |
| 1741 | 1753 | } |
| 1742 | 1754 | |
| @@ -2388,7 +2400,7 @@ pub fn set_gamma_for_crtc( | ||
| 2388 | 2400 | |
| 2389 | 2401 | fn try_to_change_vrr( |
| 2390 | 2402 | device: &DrmDevice, |
| 2391 | - connector: &connector::Info, | |
| 2403 | + connector: connector::Handle, | |
| 2392 | 2404 | crtc: crtc::Handle, |
| 2393 | 2405 | surface: &mut Surface, |
| 2394 | 2406 | output_state: &mut crate::niri::OutputState, |
| @@ -2396,7 +2408,7 @@ fn try_to_change_vrr( | ||
| 2396 | 2408 | ) { |
| 2397 | 2409 | let _span = tracy_client::span!("try_to_change_vrr"); |
| 2398 | 2410 | |
| 2399 | - if is_vrr_capable(device, connector.handle()) == Some(true) { | |
| 2411 | + if is_vrr_capable(device, connector) == Some(true) { | |
| 2400 | 2412 | let word = if enable_vrr { "enabling" } else { "disabling" }; |
| 2401 | 2413 | |
| 2402 | 2414 | match set_vrr_enabled(device, crtc, enable_vrr) { |
src/frame_clock.rsmodified+4 -0
| @@ -40,6 +40,10 @@ impl FrameClock { | ||
| 40 | 40 | self.last_presentation_time = None; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + pub fn vrr(&self) -> bool { | |
| 44 | + self.vrr | |
| 45 | + } | |
| 46 | + | |
| 43 | 47 | pub fn presented(&mut self, presentation_time: Duration) { |
| 44 | 48 | if presentation_time.is_zero() { |
| 45 | 49 | // Not interested in these. |
src/niri.rsmodified+46 -7
| @@ -299,6 +299,7 @@ pub struct OutputState { | ||
| 299 | 299 | pub global: GlobalId, |
| 300 | 300 | pub frame_clock: FrameClock, |
| 301 | 301 | pub redraw_state: RedrawState, |
| 302 | + pub on_demand_vrr_enabled: bool, | |
| 302 | 303 | // After the last redraw, some ongoing animations still remain. |
| 303 | 304 | pub unfinished_animations_remain: bool, |
| 304 | 305 | /// Last sequence received in a vblank event. |
| @@ -1202,8 +1203,14 @@ impl State { | ||
| 1202 | 1203 | } |
| 1203 | 1204 | } |
| 1204 | 1205 | } |
| 1205 | - niri_ipc::OutputAction::Vrr { enable } => { | |
| 1206 | - config.variable_refresh_rate = enable; | |
| 1206 | + niri_ipc::OutputAction::Vrr { vrr } => { | |
| 1207 | + config.variable_refresh_rate = if vrr.vrr { | |
| 1208 | + Some(niri_config::Vrr { | |
| 1209 | + on_demand: vrr.on_demand, | |
| 1210 | + }) | |
| 1211 | + } else { | |
| 1212 | + None | |
| 1213 | + } | |
| 1207 | 1214 | } |
| 1208 | 1215 | } |
| 1209 | 1216 | } |
| @@ -2005,6 +2012,7 @@ impl Niri { | ||
| 2005 | 2012 | let state = OutputState { |
| 2006 | 2013 | global, |
| 2007 | 2014 | redraw_state: RedrawState::Idle, |
| 2015 | + on_demand_vrr_enabled: false, | |
| 2008 | 2016 | unfinished_animations_remain: false, |
| 2009 | 2017 | frame_clock: FrameClock::new(refresh_interval, vrr), |
| 2010 | 2018 | last_drm_sequence: None, |
| @@ -3089,6 +3097,8 @@ impl Niri { | ||
| 3089 | 3097 | lock_state => self.lock_state = lock_state, |
| 3090 | 3098 | } |
| 3091 | 3099 | |
| 3100 | + self.refresh_on_demand_vrr(backend, output); | |
| 3101 | + | |
| 3092 | 3102 | // Send the frame callbacks. |
| 3093 | 3103 | // |
| 3094 | 3104 | // FIXME: The logic here could be a bit smarter. Currently, during an animation, the |
| @@ -3118,6 +3128,39 @@ impl Niri { | ||
| 3118 | 3128 | }); |
| 3119 | 3129 | } |
| 3120 | 3130 | |
| 3131 | + pub fn refresh_on_demand_vrr(&mut self, backend: &mut Backend, output: &Output) { | |
| 3132 | + let _span = tracy_client::span!("Niri::refresh_on_demand_vrr"); | |
| 3133 | + let Some(on_demand) = self | |
| 3134 | + .config | |
| 3135 | + .borrow() | |
| 3136 | + .outputs | |
| 3137 | + .find(&output.name()) | |
| 3138 | + .map(|output| output.is_vrr_on_demand()) | |
| 3139 | + else { | |
| 3140 | + warn!("error getting output config for {}", output.name()); | |
| 3141 | + return; | |
| 3142 | + }; | |
| 3143 | + if !on_demand { | |
| 3144 | + return; | |
| 3145 | + } | |
| 3146 | + | |
| 3147 | + let current = self.layout.windows_for_output(output).any(|mapped| { | |
| 3148 | + mapped.rules().variable_refresh_rate == Some(true) && { | |
| 3149 | + let mut visible = false; | |
| 3150 | + mapped.window.with_surfaces(|surface, states| { | |
| 3151 | + if !visible | |
| 3152 | + && surface_primary_scanout_output(surface, states).as_ref() == Some(output) | |
| 3153 | + { | |
| 3154 | + visible = true; | |
| 3155 | + } | |
| 3156 | + }); | |
| 3157 | + visible | |
| 3158 | + } | |
| 3159 | + }); | |
| 3160 | + | |
| 3161 | + backend.set_output_on_demand_vrr(self, output, current); | |
| 3162 | + } | |
| 3163 | + | |
| 3121 | 3164 | pub fn update_primary_scanout_output( |
| 3122 | 3165 | &self, |
| 3123 | 3166 | output: &Output, |
| @@ -3181,13 +3224,9 @@ impl Niri { | ||
| 3181 | 3224 | let offscreen_id = offscreen_id.as_ref(); |
| 3182 | 3225 | |
| 3183 | 3226 | win.with_surfaces(|surface, states| { |
| 3184 | - states | |
| 3185 | - .data_map | |
| 3186 | - .insert_if_missing_threadsafe(Mutex::<PrimaryScanoutOutput>::default); | |
| 3187 | 3227 | let surface_primary_scanout_output = states |
| 3188 | 3228 | .data_map |
| 3189 | - .get::<Mutex<PrimaryScanoutOutput>>() | |
| 3190 | - .unwrap(); | |
| 3229 | + .get_or_insert_threadsafe(Mutex::<PrimaryScanoutOutput>::default); | |
| 3191 | 3230 | surface_primary_scanout_output |
| 3192 | 3231 | .lock() |
| 3193 | 3232 | .unwrap() |
src/protocols/output_management.rsmodified+5 -5
| @@ -3,7 +3,7 @@ use std::collections::HashMap; | ||
| 3 | 3 | use std::iter::zip; |
| 4 | 4 | use std::mem; |
| 5 | 5 | |
| 6 | -use niri_config::FloatOrInt; | |
| 6 | +use niri_config::{FloatOrInt, Vrr}; | |
| 7 | 7 | use niri_ipc::Transform; |
| 8 | 8 | use smithay::reexports::wayland_protocols_wlr::output_management::v1::server::{ |
| 9 | 9 | zwlr_output_configuration_head_v1, zwlr_output_configuration_v1, zwlr_output_head_v1, |
| @@ -693,9 +693,9 @@ where | ||
| 693 | 693 | new_config.scale = Some(FloatOrInt(scale)); |
| 694 | 694 | } |
| 695 | 695 | zwlr_output_configuration_head_v1::Request::SetAdaptiveSync { state } => { |
| 696 | - let enabled = match state { | |
| 697 | - WEnum::Value(AdaptiveSyncState::Enabled) => true, | |
| 698 | - WEnum::Value(AdaptiveSyncState::Disabled) => false, | |
| 696 | + let vrr = match state { | |
| 697 | + WEnum::Value(AdaptiveSyncState::Enabled) => Some(Vrr { on_demand: false }), | |
| 698 | + WEnum::Value(AdaptiveSyncState::Disabled) => None, | |
| 699 | 699 | _ => { |
| 700 | 700 | warn!("SetAdaptativeSync: unknown requested adaptative sync"); |
| 701 | 701 | conf_head.post_error( |
| @@ -705,7 +705,7 @@ where | ||
| 705 | 705 | return; |
| 706 | 706 | } |
| 707 | 707 | }; |
| 708 | - new_config.variable_refresh_rate = enabled; | |
| 708 | + new_config.variable_refresh_rate = vrr; | |
| 709 | 709 | } |
| 710 | 710 | _ => unreachable!(), |
| 711 | 711 | } |
src/window/mod.rsmodified+7 -0
| @@ -72,6 +72,9 @@ pub struct ResolvedWindowRules { | ||
| 72 | 72 | |
| 73 | 73 | /// Whether to block out this window from certain render targets. |
| 74 | 74 | pub block_out_from: Option<BlockOutFrom>, |
| 75 | + | |
| 76 | + /// Whether to enable VRR on this window's primary output if it is on-demand. | |
| 77 | + pub variable_refresh_rate: Option<bool>, | |
| 75 | 78 | } |
| 76 | 79 | |
| 77 | 80 | impl<'a> WindowRef<'a> { |
| @@ -132,6 +135,7 @@ impl ResolvedWindowRules { | ||
| 132 | 135 | geometry_corner_radius: None, |
| 133 | 136 | clip_to_geometry: None, |
| 134 | 137 | block_out_from: None, |
| 138 | + variable_refresh_rate: None, | |
| 135 | 139 | } |
| 136 | 140 | } |
| 137 | 141 | |
| @@ -231,6 +235,9 @@ impl ResolvedWindowRules { | ||
| 231 | 235 | if let Some(x) = rule.block_out_from { |
| 232 | 236 | resolved.block_out_from = Some(x); |
| 233 | 237 | } |
| 238 | + if let Some(x) = rule.variable_refresh_rate { | |
| 239 | + resolved.variable_refresh_rate = Some(x); | |
| 240 | + } | |
| 234 | 241 | } |
| 235 | 242 | |
| 236 | 243 | resolved.open_on_output = open_on_output.map(|x| x.to_owned()); |
wiki/Configuration:-Outputs.mdmodified+10 -1
| @@ -12,7 +12,7 @@ output "eDP-1" { | ||
| 12 | 12 | scale 2.0 |
| 13 | 13 | transform "90" |
| 14 | 14 | position x=1280 y=0 |
| 15 | - variable-refresh-rate | |
| 15 | + variable-refresh-rate // on-demand=true | |
| 16 | 16 | background-color "#003300" |
| 17 | 17 | } |
| 18 | 18 | |
| @@ -147,6 +147,15 @@ output "HDMI-A-1" { | ||
| 147 | 147 | } |
| 148 | 148 | ``` |
| 149 | 149 | |
| 150 | +<sup>Since: 0.1.9</sup> You can also set the `on-demand=true` property, which will only enable VRR when this output shows a window matching the `variable-refresh-rate` window rule. | |
| 151 | +This is helpful to avoid various issues with VRR, since it can be disabled most of the time, and only enabled for specific windows, like games or video players. | |
| 152 | + | |
| 153 | +```kdl | |
| 154 | +output "HDMI-A-1" { | |
| 155 | + variable-refresh-rate on-demand=true | |
| 156 | +} | |
| 157 | +``` | |
| 158 | + | |
| 150 | 159 | ### `background-color` |
| 151 | 160 | |
| 152 | 161 | <sup>Since: 0.1.8</sup> |
wiki/Configuration:-Window-Rules.mdmodified+21 -0
| @@ -47,6 +47,7 @@ window-rule { | ||
| 47 | 47 | opacity 0.5 |
| 48 | 48 | block-out-from "screencast" |
| 49 | 49 | // block-out-from "screen-capture" |
| 50 | + variable-refresh-rate true | |
| 50 | 51 | |
| 51 | 52 | focus-ring { |
| 52 | 53 | // off |
| @@ -391,6 +392,26 @@ window-rule { | ||
| 391 | 392 | } |
| 392 | 393 | ``` |
| 393 | 394 | |
| 395 | +#### `variable-refresh-rate` | |
| 396 | + | |
| 397 | +<sup>Since: 0.1.9</sup> | |
| 398 | + | |
| 399 | +If set to true, whenever this window displays on an output with on-demand VRR, it will enable VRR on that output. | |
| 400 | + | |
| 401 | +```kdl | |
| 402 | +// Configure some output with on-demand VRR. | |
| 403 | +output "HDMI-A-1" { | |
| 404 | + variable-refresh-rate on-demand=true | |
| 405 | +} | |
| 406 | + | |
| 407 | +// Enable on-demand VRR when mpv displays on the output. | |
| 408 | +window-rule { | |
| 409 | + match app-id="^mpv$" | |
| 410 | + | |
| 411 | + variable-refresh-rate true | |
| 412 | +} | |
| 413 | +``` | |
| 414 | + | |
| 394 | 415 | #### `draw-border-with-background` |
| 395 | 416 | |
| 396 | 417 | Override whether the border and the focus ring draw with a background. |