Store output name in CastTarget
Browse files at this commit6f92b3296a9fc67dbce5a88708c2ed2dfabe4927Parent: 570ea113 changed files +31 -14
- src/input/mod.rs +1 -2
- src/niri.rs +22 -3
- src/screencasting/mod.rs +8 -9
src/input/mod.rsmodified+1 -2
| @@ -2235,8 +2235,7 @@ impl State { | |||
| 2235 | Some(name) => self.niri.output_by_name_match(&name), | 2235 | Some(name) => self.niri.output_by_name_match(&name), |
| 2236 | }; | 2236 | }; |
| 2237 | if let Some(output) = output { | 2237 | if let Some(output) = output { |
| 2238 | - let output = output.downgrade(); | 2238 | + self.set_dynamic_cast_target(CastTarget::output(output)); |
| 2239 | - self.set_dynamic_cast_target(CastTarget::Output(output)); | ||
| 2240 | } | 2239 | } |
| 2241 | } | 2240 | } |
| 2242 | Action::ClearDynamicCastTarget => { | 2241 | Action::ClearDynamicCastTarget => { |
src/niri.rsmodified+22 -3
| @@ -571,8 +571,27 @@ pub enum CenterCoords { | |||
| 571 | pub enum CastTarget { | 571 | pub enum CastTarget { |
| 572 | // Dynamic cast before selecting anything. | 572 | // Dynamic cast before selecting anything. |
| 573 | Nothing, | 573 | Nothing, |
| 574 | - Output(WeakOutput), | 574 | + Output { |
| 575 | - Window { id: u64 }, | 575 | + output: WeakOutput, |
| 576 | + /// Cached name of the output. | ||
| 577 | + name: String, | ||
| 578 | + }, | ||
| 579 | + Window { | ||
| 580 | + id: u64, | ||
| 581 | + }, | ||
| 582 | +} | ||
| 583 | + | ||
| 584 | +impl CastTarget { | ||
| 585 | + pub fn output(output: &Output) -> Self { | ||
| 586 | + Self::Output { | ||
| 587 | + output: output.downgrade(), | ||
| 588 | + name: output.name(), | ||
| 589 | + } | ||
| 590 | + } | ||
| 591 | + | ||
| 592 | + pub fn matches_output(&self, weak: &WeakOutput) -> bool { | ||
| 593 | + matches!(self, CastTarget::Output { output, .. } if output == weak) | ||
| 594 | + } | ||
| 576 | } | 595 | } |
| 577 | 596 | ||
| 578 | /// Pending update to a window's focus timestamp. | 597 | /// Pending update to a window's focus timestamp. |
| @@ -2797,7 +2816,7 @@ impl Niri { | |||
| 2797 | RedrawState::WaitingForEstimatedVBlankAndQueued(token) => self.event_loop.remove(token), | 2816 | RedrawState::WaitingForEstimatedVBlankAndQueued(token) => self.event_loop.remove(token), |
| 2798 | } | 2817 | } |
| 2799 | 2818 | ||
| 2800 | - self.stop_casts_for_target(CastTarget::Output(output.downgrade())); | 2819 | + self.stop_casts_for_target(CastTarget::output(output)); |
| 2801 | 2820 | ||
| 2802 | self.remove_screencopy_output(output); | 2821 | self.remove_screencopy_output(output); |
| 2803 | 2822 | ||
src/screencasting/mod.rsmodified+8 -9
| @@ -156,8 +156,8 @@ impl State { | |||
| 156 | }); | 156 | }); |
| 157 | return; | 157 | return; |
| 158 | } | 158 | } |
| 159 | - CastTarget::Output(weak) => { | 159 | + CastTarget::Output { output, .. } => { |
| 160 | - if let Some(output) = weak.upgrade() { | 160 | + if let Some(output) = output.upgrade() { |
| 161 | self.niri.queue_redraw(&output); | 161 | self.niri.queue_redraw(&output); |
| 162 | } | 162 | } |
| 163 | return; | 163 | return; |
| @@ -260,7 +260,7 @@ impl State { | |||
| 260 | // Leave refresh as is when clearing. Chances are, the next refresh will match it, | 260 | // Leave refresh as is when clearing. Chances are, the next refresh will match it, |
| 261 | // then we'll avoid reconfiguring. | 261 | // then we'll avoid reconfiguring. |
| 262 | CastTarget::Nothing => (), | 262 | CastTarget::Nothing => (), |
| 263 | - CastTarget::Output(output) => { | 263 | + CastTarget::Output { output, .. } => { |
| 264 | if let Some(output) = output.upgrade() { | 264 | if let Some(output) = output.upgrade() { |
| 265 | refresh = Some(output.current_mode().unwrap().refresh as u32); | 265 | refresh = Some(output.current_mode().unwrap().refresh as u32); |
| 266 | } | 266 | } |
| @@ -316,8 +316,8 @@ impl State { | |||
| 316 | // We don't stop dynamic casts on missing output/window. | 316 | // We don't stop dynamic casts on missing output/window. |
| 317 | let (size, refresh) = match target { | 317 | let (size, refresh) = match target { |
| 318 | CastTarget::Nothing => panic!("dynamic cast starting target must not be Nothing"), | 318 | CastTarget::Nothing => panic!("dynamic cast starting target must not be Nothing"), |
| 319 | - CastTarget::Output(weak) => { | 319 | + CastTarget::Output { output, .. } => { |
| 320 | - let Some(output) = weak.upgrade() else { | 320 | + let Some(output) = output.upgrade() else { |
| 321 | return; | 321 | return; |
| 322 | }; | 322 | }; |
| 323 | cast_params_for_output(&output) | 323 | cast_params_for_output(&output) |
| @@ -404,7 +404,7 @@ impl State { | |||
| 404 | }; | 404 | }; |
| 405 | 405 | ||
| 406 | let (size, refresh) = cast_params_for_output(output); | 406 | let (size, refresh) = cast_params_for_output(output); |
| 407 | - (CastTarget::Output(output.downgrade()), size, refresh, false) | 407 | + (CastTarget::output(output), size, refresh, false) |
| 408 | } | 408 | } |
| 409 | StreamTargetId::Window { id } | 409 | StreamTargetId::Window { id } |
| 410 | if id == self.niri.casting.dynamic_cast_id_for_portal.get() => | 410 | if id == self.niri.casting.dynamic_cast_id_for_portal.get() => |
| @@ -538,8 +538,7 @@ impl Niri { | |||
| 538 | ) { | 538 | ) { |
| 539 | let _span = tracy_client::span!("Niri::render_for_screen_cast"); | 539 | let _span = tracy_client::span!("Niri::render_for_screen_cast"); |
| 540 | 540 | ||
| 541 | - let target = CastTarget::Output(output.downgrade()); | 541 | + let weak = output.downgrade(); |
| 542 | - | ||
| 543 | let size = output.current_mode().unwrap().size; | 542 | let size = output.current_mode().unwrap().size; |
| 544 | let transform = output.current_transform(); | 543 | let transform = output.current_transform(); |
| 545 | let size = transform.transform_size(size); | 544 | let size = transform.transform_size(size); |
| @@ -558,7 +557,7 @@ impl Niri { | |||
| 558 | continue; | 557 | continue; |
| 559 | } | 558 | } |
| 560 | 559 | ||
| 561 | - if cast.target != target { | 560 | + if !cast.target.matches_output(&weak) { |
| 562 | continue; | 561 | continue; |
| 563 | } | 562 | } |
| 564 | 563 | ||