diff --git a/docs/wiki/Configuration:-Window-Rules.md b/docs/wiki/Configuration:-Window-Rules.md
index 48a57492..0d7e820f 100644
--- a/docs/wiki/Configuration:-Window-Rules.md
+++ b/docs/wiki/Configuration:-Window-Rules.md
@@ -668,6 +668,18 @@ window-rule {
}
```
+Since: next release You can set `variable-refresh-rate` to `"fullscreen-only"` to activate on-demand VRR only when this window is fullscreen on this output.
+The window must cover the entire screen (when niri hides the top layer-shell layer).
+
+This mode will work even when there are overlays over the fullscreen window.
+
+```kdl
+// Enable on-demand VRR when any window is fullscreen.
+window-rule {
+ variable-refresh-rate "fullscreen-only"
+}
+```
+
#### `default-column-display`
Since: 25.02
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index 80b2cff5..b8989e8d 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -909,6 +909,7 @@ mod tests {
default-column-display "tabbed"
default-floating-position x=100 y=-200 relative-to="bottom-left"
on-xdg-activate "ignore"
+ variable-refresh-rate "fullscreen-only"
focus-ring {
off
@@ -1900,7 +1901,9 @@ mod tests {
clip_to_geometry: None,
baba_is_float: None,
block_out_from: None,
- variable_refresh_rate: None,
+ variable_refresh_rate: Some(
+ FullscreenOnly,
+ ),
default_column_display: Some(
Tabbed,
),
diff --git a/niri-config/src/window_rule.rs b/niri-config/src/window_rule.rs
index acc9e2e5..b3543f92 100644
--- a/niri-config/src/window_rule.rs
+++ b/niri-config/src/window_rule.rs
@@ -1,3 +1,4 @@
+use knuffel::errors::DecodeError;
use niri_ipc::ColumnDisplay;
use crate::appearance::{
@@ -68,7 +69,7 @@ pub struct WindowRule {
#[knuffel(child, unwrap(argument))]
pub block_out_from: Option,
#[knuffel(child, unwrap(argument))]
- pub variable_refresh_rate: Option,
+ pub variable_refresh_rate: Option,
#[knuffel(child, unwrap(argument, str))]
pub default_column_display: Option,
#[knuffel(child)]
@@ -85,6 +86,16 @@ pub struct WindowRule {
pub popups: PopupsRule,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum VrrRule {
+ /// No effect on VRR.
+ Off,
+ /// Enable VRR when the window is visible.
+ On,
+ /// Enable VRR when the window is the current fullscreen window.
+ FullscreenOnly,
+}
+
/// Rules for popup surfaces.
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
pub struct PopupsRule {
@@ -172,3 +183,37 @@ pub enum RelativeTo {
Left,
Right,
}
+
+impl knuffel::DecodeScalar for VrrRule {
+ fn raw_decode(
+ val: &knuffel::span::Spanned,
+ _ctx: &mut knuffel::decode::Context,
+ ) -> Result> {
+ const ERROR: &str = "expected `true`, `\"fullscreen-only\"`, or `false`";
+ match &**val {
+ knuffel::ast::Literal::Bool(b) => Ok(if *b { VrrRule::On } else { VrrRule::Off }),
+ knuffel::ast::Literal::String(s) => match &s[..] {
+ // Also accept bool strings to reduce confusion.
+ "true" => Ok(VrrRule::On),
+ "false" => Ok(VrrRule::Off),
+ "fullscreen-only" => Ok(VrrRule::FullscreenOnly),
+ _ => Err(DecodeError::conversion(val, ERROR)),
+ },
+ _ => Err(DecodeError::conversion(val, ERROR)),
+ }
+ }
+
+ fn type_check(
+ type_name: &Option>,
+ ctx: &mut knuffel::decode::Context,
+ ) {
+ if let Some(typ) = type_name {
+ ctx.emit_error(DecodeError::TypeName {
+ span: typ.span().clone(),
+ found: Some((**typ).clone()),
+ expected: knuffel::errors::ExpectedType::no_type(),
+ rust_type: stringify!(VrrRule),
+ });
+ }
+ }
+}
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 761d226b..3befce14 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -1641,14 +1641,18 @@ impl Monitor {
(InsertWorkspace::NewAt(last_idx + 1), dummy)
}
- pub fn render_above_top_layer(&self) -> bool {
+ pub fn fullscreen_window_above_top_layer(&self) -> Option<&W> {
// Render above the top layer only if the view is stationary.
if self.workspace_switch.is_some() || self.overview_progress.is_some() {
- return false;
+ return None;
}
let ws = &self.workspaces[self.active_workspace_idx];
- ws.render_above_top_layer()
+ ws.fullscreen_window_above_top_layer()
+ }
+
+ pub fn render_above_top_layer(&self) -> bool {
+ self.fullscreen_window_above_top_layer().is_some()
}
pub fn render_insert_hint_between_workspaces(
diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs
index ed85342e..4f462c65 100644
--- a/src/layout/scrolling.rs
+++ b/src/layout/scrolling.rs
@@ -2943,19 +2943,22 @@ impl ScrollingSpace {
true
}
- pub fn render_above_top_layer(&self) -> bool {
+ pub fn fullscreen_window_above_top_layer(&self) -> Option<&W> {
// Render above the top layer if we're on a fullscreen window and the view is stationary.
if self.columns.is_empty() {
- return false;
+ return None;
}
if !self.view_offset.is_static() {
- return false;
+ return None;
}
- self.columns[self.active_column_idx]
- .sizing_mode()
- .is_fullscreen()
+ let col = &self.columns[self.active_column_idx];
+ if !col.sizing_mode().is_fullscreen() {
+ return None;
+ }
+
+ Some(col.tiles[col.active_tile_idx].window())
}
pub fn render(
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 4da404de..effa38b2 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -1715,8 +1715,8 @@ impl Workspace {
)
}
- pub fn render_above_top_layer(&self) -> bool {
- self.scrolling.render_above_top_layer()
+ pub fn fullscreen_window_above_top_layer(&self) -> Option<&W> {
+ self.scrolling.fullscreen_window_above_top_layer()
}
pub fn is_floating_visible(&self) -> bool {
@@ -1724,7 +1724,7 @@ impl Workspace {
matches!(
self.floating_is_active,
FloatingActive::Yes | FloatingActive::NoButRaised
- ) || !self.render_above_top_layer()
+ ) || self.fullscreen_window_above_top_layer().is_none()
}
pub fn store_unmap_snapshot_if_empty(
diff --git a/src/niri.rs b/src/niri.rs
index 17f4c1bb..d7d180a0 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -15,6 +15,7 @@ use anyhow::{bail, ensure, Context};
use calloop::futures::Scheduler;
use niri_config::debug::PreviewRender;
use niri_config::output::MaxBpc;
+use niri_config::window_rule::VrrRule;
use niri_config::{
Config, FloatOrInt, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode,
WorkspaceReference, Xkb,
@@ -5016,19 +5017,34 @@ impl Niri {
return;
}
- let current = self.layout.windows_for_output(output).any(|mapped| {
- mapped.rules().variable_refresh_rate == Some(true) && {
- let mut visible = false;
- mapped.window.with_surfaces(|surface, states| {
- if !visible
- && surface_primary_scanout_output(surface, states).as_ref() == Some(output)
- {
- visible = true;
- }
- });
- visible
- }
- });
+ // Check for fullscreen-only VRR first as that's cheaper.
+ let mon = self.layout.monitor_for_output(output).unwrap();
+ // We allow the overlay layer and floating windows for this check
+ // so VRR keeps working with overlays.
+ let current = mon
+ .fullscreen_window_above_top_layer()
+ .is_some_and(|mapped| {
+ mapped.rules().variable_refresh_rate == Some(VrrRule::FullscreenOnly)
+ });
+
+ let current = current
+ || self.layout.windows_for_output(output).any(|mapped| {
+ mapped.rules().variable_refresh_rate == Some(VrrRule::On) && {
+ let mut visible = false;
+ mapped.window.with_surfaces(|surface, states| {
+ if visible {
+ // Skip checking.
+ return;
+ }
+
+ if surface_primary_scanout_output(surface, states).as_ref() == Some(output)
+ {
+ visible = true;
+ }
+ });
+ visible
+ }
+ });
backend.set_output_on_demand_vrr(self, output, current);
}
diff --git a/src/window/mod.rs b/src/window/mod.rs
index 771f0d95..c6a24b1d 100644
--- a/src/window/mod.rs
+++ b/src/window/mod.rs
@@ -1,7 +1,7 @@
use std::cmp::{max, min};
use niri_config::utils::MergeWith as _;
-use niri_config::window_rule::{Match, OnXdgActivate, WindowRule};
+use niri_config::window_rule::{Match, OnXdgActivate, VrrRule, WindowRule};
use niri_config::{
BackgroundEffect, BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, PresetSize,
ResolvedPopupsRules, ShadowRule, TabIndicatorRule,
@@ -115,7 +115,7 @@ pub struct ResolvedWindowRules {
pub block_out_from: Option,
/// Whether to enable VRR on this window's primary output if it is on-demand.
- pub variable_refresh_rate: Option,
+ pub variable_refresh_rate: Option,
/// Multiplier for all scroll events sent to this window.
pub scroll_factor: Option,