Store output name in CastTarget

Will be useful in the next commit to avoid fetching it every time.
This commit is contained in:
Ivan Molodetskikh
2026-01-12 18:25:31 +03:00
parent 570ea119ba
commit 6f92b3296a
3 changed files with 31 additions and 14 deletions
+1 -2
View File
@@ -2235,8 +2235,7 @@ impl State {
Some(name) => self.niri.output_by_name_match(&name), Some(name) => self.niri.output_by_name_match(&name),
}; };
if let Some(output) = output { if let Some(output) = output {
let output = output.downgrade(); self.set_dynamic_cast_target(CastTarget::output(output));
self.set_dynamic_cast_target(CastTarget::Output(output));
} }
} }
Action::ClearDynamicCastTarget => { Action::ClearDynamicCastTarget => {
+22 -3
View File
@@ -571,8 +571,27 @@ pub enum CenterCoords {
pub enum CastTarget { pub enum CastTarget {
// Dynamic cast before selecting anything. // Dynamic cast before selecting anything.
Nothing, Nothing,
Output(WeakOutput), Output {
Window { id: u64 }, output: WeakOutput,
/// Cached name of the output.
name: String,
},
Window {
id: u64,
},
}
impl CastTarget {
pub fn output(output: &Output) -> Self {
Self::Output {
output: output.downgrade(),
name: output.name(),
}
}
pub fn matches_output(&self, weak: &WeakOutput) -> bool {
matches!(self, CastTarget::Output { output, .. } if output == weak)
}
} }
/// Pending update to a window's focus timestamp. /// Pending update to a window's focus timestamp.
@@ -2797,7 +2816,7 @@ impl Niri {
RedrawState::WaitingForEstimatedVBlankAndQueued(token) => self.event_loop.remove(token), RedrawState::WaitingForEstimatedVBlankAndQueued(token) => self.event_loop.remove(token),
} }
self.stop_casts_for_target(CastTarget::Output(output.downgrade())); self.stop_casts_for_target(CastTarget::output(output));
self.remove_screencopy_output(output); self.remove_screencopy_output(output);
+8 -9
View File
@@ -156,8 +156,8 @@ impl State {
}); });
return; return;
} }
CastTarget::Output(weak) => { CastTarget::Output { output, .. } => {
if let Some(output) = weak.upgrade() { if let Some(output) = output.upgrade() {
self.niri.queue_redraw(&output); self.niri.queue_redraw(&output);
} }
return; return;
@@ -260,7 +260,7 @@ impl State {
// Leave refresh as is when clearing. Chances are, the next refresh will match it, // Leave refresh as is when clearing. Chances are, the next refresh will match it,
// then we'll avoid reconfiguring. // then we'll avoid reconfiguring.
CastTarget::Nothing => (), CastTarget::Nothing => (),
CastTarget::Output(output) => { CastTarget::Output { output, .. } => {
if let Some(output) = output.upgrade() { if let Some(output) = output.upgrade() {
refresh = Some(output.current_mode().unwrap().refresh as u32); refresh = Some(output.current_mode().unwrap().refresh as u32);
} }
@@ -316,8 +316,8 @@ impl State {
// We don't stop dynamic casts on missing output/window. // We don't stop dynamic casts on missing output/window.
let (size, refresh) = match target { let (size, refresh) = match target {
CastTarget::Nothing => panic!("dynamic cast starting target must not be Nothing"), CastTarget::Nothing => panic!("dynamic cast starting target must not be Nothing"),
CastTarget::Output(weak) => { CastTarget::Output { output, .. } => {
let Some(output) = weak.upgrade() else { let Some(output) = output.upgrade() else {
return; return;
}; };
cast_params_for_output(&output) cast_params_for_output(&output)
@@ -404,7 +404,7 @@ impl State {
}; };
let (size, refresh) = cast_params_for_output(output); let (size, refresh) = cast_params_for_output(output);
(CastTarget::Output(output.downgrade()), size, refresh, false) (CastTarget::output(output), size, refresh, false)
} }
StreamTargetId::Window { id } StreamTargetId::Window { id }
if id == self.niri.casting.dynamic_cast_id_for_portal.get() => if id == self.niri.casting.dynamic_cast_id_for_portal.get() =>
@@ -538,8 +538,7 @@ impl Niri {
) { ) {
let _span = tracy_client::span!("Niri::render_for_screen_cast"); let _span = tracy_client::span!("Niri::render_for_screen_cast");
let target = CastTarget::Output(output.downgrade()); let weak = output.downgrade();
let size = output.current_mode().unwrap().size; let size = output.current_mode().unwrap().size;
let transform = output.current_transform(); let transform = output.current_transform();
let size = transform.transform_size(size); let size = transform.transform_size(size);
@@ -558,7 +557,7 @@ impl Niri {
continue; continue;
} }
if cast.target != target { if !cast.target.matches_output(&weak) {
continue; continue;
} }