Skip to content

Commit 316df56

Browse files
committed
Add inhibit idle to window config, add tests
1 parent 311ca6b commit 316df56

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed

niri-config/src/appearance.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,12 @@ pub enum BlockOutFrom {
622622
ScreenCapture,
623623
}
624624

625+
#[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq, Eq)]
626+
pub enum InhibitIdle {
627+
Always,
628+
Fullscreen,
629+
}
630+
625631
#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
626632
pub struct BorderRule {
627633
#[knuffel(child)]

niri-config/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,36 @@ mod tests {
587587
.unwrap()
588588
}
589589

590+
#[test]
591+
fn inhibit() {
592+
let parsed = do_parse(
593+
r##"
594+
window-rule {
595+
inhibit-idle "fullscreen"
596+
}
597+
window-rule {
598+
inhibit-idle "always"
599+
}
600+
window-rule {
601+
inhibit-idle null
602+
}
603+
window-rule {
604+
}
605+
"##,
606+
);
607+
608+
assert!(matches!(
609+
parsed.window_rules[0].inhibit_idle,
610+
Some(Some(InhibitIdle::Fullscreen))
611+
));
612+
assert!(matches!(
613+
parsed.window_rules[1].inhibit_idle,
614+
Some(Some(InhibitIdle::Always))
615+
));
616+
assert!(matches!(parsed.window_rules[2].inhibit_idle, Some(None)));
617+
assert!(matches!(parsed.window_rules[3].inhibit_idle, None));
618+
}
619+
590620
#[test]
591621
fn parse() {
592622
let parsed = do_parse(
@@ -1795,6 +1825,7 @@ mod tests {
17951825
),
17961826
scroll_factor: None,
17971827
tiled_state: None,
1828+
inhibit_idle: None,
17981829
},
17991830
],
18001831
layer_rules: [

niri-config/src/window_rule.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use niri_ipc::ColumnDisplay;
33
use crate::appearance::{BlockOutFrom, BorderRule, CornerRadius, ShadowRule, TabIndicatorRule};
44
use crate::layout::DefaultPresetSize;
55
use crate::utils::RegexEq;
6-
use crate::FloatOrInt;
6+
use crate::{FloatOrInt, InhibitIdle};
77

88
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
99
pub struct WindowRule {
@@ -72,6 +72,8 @@ pub struct WindowRule {
7272
pub scroll_factor: Option<FloatOrInt<0, 100>>,
7373
#[knuffel(child, unwrap(argument))]
7474
pub tiled_state: Option<bool>,
75+
#[knuffel(child, unwrap(argument))]
76+
pub inhibit_idle: Option<Option<InhibitIdle>>,
7577
}
7678

7779
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]

src/niri.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use anyhow::{bail, ensure, Context};
1515
use calloop::futures::Scheduler;
1616
use niri_config::debug::PreviewRender;
1717
use niri_config::{
18-
Config, FloatOrInt, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode,
18+
Config, FloatOrInt, InhibitIdle, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode,
1919
WorkspaceReference, Xkb,
2020
};
2121
use smithay::backend::allocator::Fourcc;
@@ -4147,7 +4147,17 @@ impl Niri {
41474147
with_states(surface, |states| {
41484148
surface_primary_scanout_output(surface, states).is_some()
41494149
})
4150-
});
4150+
})
4151+
|| self
4152+
.layout
4153+
.windows()
4154+
.into_iter()
4155+
.any(|a| match a.1.rules().inhibit_idle {
4156+
Some(InhibitIdle::Always) => true,
4157+
Some(InhibitIdle::Fullscreen) => a.1.is_fullscreen(),
4158+
None => false,
4159+
});
4160+
41514161
self.idle_notifier_state.set_is_inhibited(is_inhibited);
41524162
}
41534163

src/window/mod.rs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::{max, min};
33
use niri_config::utils::MergeWith as _;
44
use niri_config::window_rule::{Match, WindowRule};
55
use niri_config::{
6-
BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, PresetSize, ShadowRule,
6+
BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, InhibitIdle, PresetSize, ShadowRule,
77
TabIndicatorRule,
88
};
99
use niri_ipc::ColumnDisplay;
@@ -119,6 +119,9 @@ pub struct ResolvedWindowRules {
119119

120120
/// Override whether to set the Tiled xdg-toplevel state on the window.
121121
pub tiled_state: Option<bool>,
122+
123+
/// Whether to inhibit idle for this window.
124+
pub inhibit_idle: Option<InhibitIdle>,
122125
}
123126

124127
impl<'a> WindowRef<'a> {
@@ -174,6 +177,75 @@ impl<'a> WindowRef<'a> {
174177
}
175178

176179
impl ResolvedWindowRules {
180+
pub const fn empty() -> Self {
181+
Self {
182+
default_width: None,
183+
default_height: None,
184+
default_column_display: None,
185+
default_floating_position: None,
186+
open_on_output: None,
187+
open_on_workspace: None,
188+
open_maximized: None,
189+
open_fullscreen: None,
190+
open_floating: None,
191+
open_focused: None,
192+
min_width: None,
193+
min_height: None,
194+
max_width: None,
195+
max_height: None,
196+
focus_ring: BorderRule {
197+
off: false,
198+
on: false,
199+
width: None,
200+
active_color: None,
201+
inactive_color: None,
202+
urgent_color: None,
203+
active_gradient: None,
204+
inactive_gradient: None,
205+
urgent_gradient: None,
206+
},
207+
border: BorderRule {
208+
off: false,
209+
on: false,
210+
width: None,
211+
active_color: None,
212+
inactive_color: None,
213+
urgent_color: None,
214+
active_gradient: None,
215+
inactive_gradient: None,
216+
urgent_gradient: None,
217+
},
218+
shadow: ShadowRule {
219+
off: false,
220+
on: false,
221+
offset: None,
222+
softness: None,
223+
spread: None,
224+
draw_behind_window: None,
225+
color: None,
226+
inactive_color: None,
227+
},
228+
tab_indicator: TabIndicatorRule {
229+
active_color: None,
230+
inactive_color: None,
231+
urgent_color: None,
232+
active_gradient: None,
233+
inactive_gradient: None,
234+
urgent_gradient: None,
235+
},
236+
draw_border_with_background: None,
237+
opacity: None,
238+
geometry_corner_radius: None,
239+
clip_to_geometry: None,
240+
baba_is_float: None,
241+
block_out_from: None,
242+
variable_refresh_rate: None,
243+
scroll_factor: None,
244+
tiled_state: None,
245+
inhibit_idle: None,
246+
}
247+
}
248+
177249
pub fn compute(rules: &[WindowRule], window: WindowRef, is_at_startup: bool) -> Self {
178250
let _span = tracy_client::span!("ResolvedWindowRules::compute");
179251

@@ -296,6 +368,9 @@ impl ResolvedWindowRules {
296368
if let Some(x) = rule.tiled_state {
297369
resolved.tiled_state = Some(x);
298370
}
371+
if let Some(x) = rule.inhibit_idle {
372+
resolved.inhibit_idle = x;
373+
}
299374
}
300375

301376
resolved.open_on_output = open_on_output.map(|x| x.to_owned());

0 commit comments

Comments
 (0)