forge
Explore
Log in

Don't you dare go Hollow

Implement is-window-cast-target window rule matcher

Browse files at this commit

29b7a41692b9773ac939c2b18fe9dbf6735cfef1Ivan MolodetskikhParent: 2167536
niri-config/src/lib.rsmodified+5 -0
@@ -1210,6 +1210,8 @@ pub struct Match {
1210 #[knuffel(property)]1210 #[knuffel(property)]
1211 pub is_floating: Option<bool>,1211 pub is_floating: Option<bool>,
1212 #[knuffel(property)]1212 #[knuffel(property)]
1213+ pub is_window_cast_target: Option<bool>,
1214+ #[knuffel(property)]
1213 pub at_startup: Option<bool>,1215 pub at_startup: Option<bool>,
1214 }1216 }
1215 1217
@@ -3948,6 +3950,7 @@ mod tests {
3948 is_focused: None,3950 is_focused: None,
3949 is_active_in_column: None,3951 is_active_in_column: None,
3950 is_floating: None,3952 is_floating: None,
3953+ is_window_cast_target: None,
3951 at_startup: None,3954 at_startup: None,
3952 }],3955 }],
3953 excludes: vec![3956 excludes: vec![
@@ -3958,6 +3961,7 @@ mod tests {
3958 is_focused: None,3961 is_focused: None,
3959 is_active_in_column: None,3962 is_active_in_column: None,
3960 is_floating: None,3963 is_floating: None,
3964+ is_window_cast_target: None,
3961 at_startup: None,3965 at_startup: None,
3962 },3966 },
3963 Match {3967 Match {
@@ -3967,6 +3971,7 @@ mod tests {
3967 is_focused: Some(false),3971 is_focused: Some(false),
3968 is_active_in_column: None,3972 is_active_in_column: None,
3969 is_floating: None,3973 is_floating: None,
3974+ is_window_cast_target: None,
3970 at_startup: None,3975 at_startup: None,
3971 },3976 },
3972 ],3977 ],
src/niri.rsmodified+22 -3
@@ -642,13 +642,18 @@ impl State {
642 self.niri.refresh_idle_inhibit();642 self.niri.refresh_idle_inhibit();
643 self.refresh_pointer_contents();643 self.refresh_pointer_contents();
644 foreign_toplevel::refresh(self);644 foreign_toplevel::refresh(self);
645+
646+ #[cfg(feature = "xdp-gnome-screencast")]
647+ self.niri.refresh_mapped_cast_outputs();
648+ // Should happen before refresh_window_rules(), but after anything that can start or stop
649+ // screencasts.
650+ #[cfg(feature = "xdp-gnome-screencast")]
651+ self.niri.refresh_mapped_cast_window_rules();
652+
645 self.niri.refresh_window_rules();653 self.niri.refresh_window_rules();
646 self.refresh_ipc_outputs();654 self.refresh_ipc_outputs();
647 self.ipc_refresh_layout();655 self.ipc_refresh_layout();
648 self.ipc_refresh_keyboard_layout_index();656 self.ipc_refresh_keyboard_layout_index();
649-
650- #[cfg(feature = "xdp-gnome-screencast")]
651- self.niri.refresh_mapped_cast_outputs();
652 }657 }
653 658
654 fn notify_blocker_cleared(&mut self) {659 fn notify_blocker_cleared(&mut self) {
@@ -3256,6 +3261,20 @@ impl Niri {
3256 }3261 }
3257 }3262 }
3258 3263
3264+ #[cfg(feature = "xdp-gnome-screencast")]
3265+ pub fn refresh_mapped_cast_window_rules(&mut self) {
3266+ // O(N^2) but should be fine since there aren't many casts usually.
3267+ self.layout.with_windows_mut(|mapped, _| {
3268+ let id = mapped.id().get();
3269+ // Find regardless of cast.is_active.
3270+ let value = self
3271+ .casts
3272+ .iter()
3273+ .any(|cast| cast.target == (CastTarget::Window { id }));
3274+ mapped.set_is_window_cast_target(value);
3275+ });
3276+ }
3277+
3259 #[cfg(feature = "xdp-gnome-screencast")]3278 #[cfg(feature = "xdp-gnome-screencast")]
3260 pub fn refresh_mapped_cast_outputs(&mut self) {3279 pub fn refresh_mapped_cast_outputs(&mut self) {
3261 use std::collections::hash_map::Entry;3280 use std::collections::hash_map::Entry;
src/window/mapped.rsmodified+17 -0
@@ -80,6 +80,9 @@ pub struct Mapped {
80 /// Whether this window is floating.80 /// Whether this window is floating.
81 is_floating: bool,81 is_floating: bool,
82 82
83+ /// Whether this window is a target of a window cast.
84+ is_window_cast_target: bool,
85+
83 /// Whether this window should ignore opacity set through window rules.86 /// Whether this window should ignore opacity set through window rules.
84 ignore_opacity_window_rule: bool,87 ignore_opacity_window_rule: bool,
85 88
@@ -188,6 +191,7 @@ impl Mapped {
188 is_focused: false,191 is_focused: false,
189 is_active_in_column: true,192 is_active_in_column: true,
190 is_floating: false,193 is_floating: false,
194+ is_window_cast_target: false,
191 ignore_opacity_window_rule: false,195 ignore_opacity_window_rule: false,
192 block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),196 block_out_buffer: RefCell::new(SolidColorBuffer::new((0., 0.), [0., 0., 0., 1.])),
193 animate_next_configure: false,197 animate_next_configure: false,
@@ -260,6 +264,10 @@ impl Mapped {
260 self.is_floating264 self.is_floating
261 }265 }
262 266
267+ pub fn is_window_cast_target(&self) -> bool {
268+ self.is_window_cast_target
269+ }
270+
263 pub fn toggle_ignore_opacity_window_rule(&mut self) {271 pub fn toggle_ignore_opacity_window_rule(&mut self) {
264 self.ignore_opacity_window_rule = !self.ignore_opacity_window_rule;272 self.ignore_opacity_window_rule = !self.ignore_opacity_window_rule;
265 }273 }
@@ -273,6 +281,15 @@ impl Mapped {
273 self.need_to_recompute_rules = true;281 self.need_to_recompute_rules = true;
274 }282 }
275 283
284+ pub fn set_is_window_cast_target(&mut self, value: bool) {
285+ if self.is_window_cast_target == value {
286+ return;
287+ }
288+
289+ self.is_window_cast_target = value;
290+ self.need_to_recompute_rules = true;
291+ }
292+
276 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {293 fn render_snapshot(&self, renderer: &mut GlesRenderer) -> LayoutElementRenderSnapshot {
277 let _span = tracy_client::span!("Mapped::render_snapshot");294 let _span = tracy_client::span!("Mapped::render_snapshot");
278 295
src/window/mod.rsmodified+13 -0
@@ -146,6 +146,13 @@ impl<'a> WindowRef<'a> {
146 WindowRef::Mapped(mapped) => mapped.is_floating(),146 WindowRef::Mapped(mapped) => mapped.is_floating(),
147 }147 }
148 }148 }
149+
150+ pub fn is_window_cast_target(self) -> bool {
151+ match self {
152+ WindowRef::Unmapped(_) => false,
153+ WindowRef::Mapped(mapped) => mapped.is_window_cast_target(),
154+ }
155+ }
149 }156 }
150 157
151 impl ResolvedWindowRules {158 impl ResolvedWindowRules {
@@ -446,5 +453,11 @@ fn window_matches(window: WindowRef, role: &XdgToplevelSurfaceRoleAttributes, m:
446 }453 }
447 }454 }
448 455
456+ if let Some(is_window_cast_target) = m.is_window_cast_target {
457+ if window.is_window_cast_target() != is_window_cast_target {
458+ return false;
459+ }
460+ }
461+
449 true462 true
450 }463 }
wiki/Configuration:-Window-Rules.mdmodified+37 -0
@@ -34,6 +34,7 @@ window-rule {
34 match is-focused=false34 match is-focused=false
35 match is-active-in-column=true35 match is-active-in-column=true
36 match is-floating=true36 match is-floating=true
37+ match is-window-cast-target=true
37 match at-startup=true38 match at-startup=true
38 39
39 // Properties that apply once upon window opening.40 // Properties that apply once upon window opening.
@@ -239,6 +240,42 @@ window-rule {
239 }240 }
240 ```241 ```
241 242
243+#### `is-window-cast-target`
244+
245+<sup>Since: next release</sup>
246+
247+Can be `true` or `false`.
248+Matches `true` for windows that are target of an ongoing window screencast.
249+
250+```kdl
251+// Indicate screencasted windows with red colors.
252+window-rule {
253+ match is-window-cast-target=true
254+
255+ focus-ring {
256+ active-color "#f38ba8"
257+ inactive-color "#7d0d2d"
258+ }
259+
260+ border {
261+ inactive-color "#7d0d2d"
262+ }
263+
264+ shadow {
265+ color "#7d0d2d70"
266+ }
267+
268+ tab-indicator {
269+ active-color "#f38ba8"
270+ inactive-color "#7d0d2d"
271+ }
272+}
273+```
274+
275+Example:
276+
277+![](https://github.com/user-attachments/assets/375b381e-3a87-4e94-8676-44404971d893)
278+
242 #### `at-startup`279 #### `at-startup`
243 280
244 <sup>Since: 0.1.6</sup>281 <sup>Since: 0.1.6</sup>