forge
Explore
Log in

Don't you dare go Hollow

Make screenshot UI render target-aware

Browse files at this commit

5f23d344d5d20d238eea65cd9e7189a2baf499c8Ivan MolodetskikhParent: e43e10f
resources/default-config.kdlmodified+9 -6
@@ -402,14 +402,17 @@ animations {
402402 // To preview and set up this rule, check the preview-render option
403403 // in the debug section of the config.
404404 //
405- // WARNING: the window is NOT blocked out from the screenshot UI.
406- // If you open the screenshot UI while screencasting, blocked out windows
407- // WILL BE VISIBLE on the screencast.
405+ // WARNING: the window is NOT blocked out from third-party screenshot tools.
406+ // If you open some screenshot tool with preview while screencasting,
407+ // blocked out windows WILL BE VISIBLE on the screencast.
408+ //
409+ // The built-in screenshot UI is not affected though, you can use it safely,
410+ // and windows will remain blocked out even when screencasting it.
408411 block-out-from "screencast"
409412
410413 // You can also block out the window out of all screen captures, including
411- // the screenshot UI. This way you avoid accidentally showing the window
412- // on a screencast when opening the screenshot UI.
414+ // third-party screenshot tools. This way you avoid accidentally showing
415+ // the window on a screencast when opening a third-party screenshot preview.
413416 block-out-from "screen-capture"
414417
415418 // You can amend the window's minimum and maximum size in logical pixels.
@@ -459,7 +462,7 @@ window-rule {
459462 match app-id=r#"^org\.keepassxc\.KeePassXC$"#
460463 match app-id=r#"^org\.gnome\.World\.Secrets$"#
461464
462- // Warning: will be visible when opening the screenshot UI.
465+ // Warning: will be visible on third-party screenshot tools.
463466 block-out-from "screencast"
464467
465468 // Use this instead to block out from all screen captures.
src/niri.rsmodified+27 -21
@@ -2307,7 +2307,7 @@ impl Niri {
23072307 if self.screenshot_ui.is_open() {
23082308 elements.extend(
23092309 self.screenshot_ui
2310- .render_output(output)
2310+ .render_output(output, target)
23112311 .into_iter()
23122312 .map(OutputRenderElements::from),
23132313 );
@@ -3104,31 +3104,37 @@ impl Niri {
31043104 let size = transform.transform_size(size);
31053105
31063106 let scale = Scale::from(output.current_scale().fractional_scale());
3107- let elements = self.render::<GlesRenderer>(
3108- renderer,
3109- &output,
3110- true,
3107+ let targets = [
3108+ RenderTarget::Output,
3109+ RenderTarget::Screencast,
31113110 RenderTarget::ScreenCapture,
3112- );
3113- let elements = elements.iter().rev();
3111+ ];
3112+ let textures = targets.map(|target| {
3113+ let elements = self.render::<GlesRenderer>(renderer, &output, true, target);
3114+ let elements = elements.iter().rev();
31143115
3115- let res = render_to_texture(
3116- renderer,
3117- size,
3118- scale,
3119- Transform::Normal,
3120- Fourcc::Abgr8888,
3121- elements,
3122- );
3123- let screenshot = match res {
3124- Ok((texture, _)) => texture,
3125- Err(err) => {
3116+ let res = render_to_texture(
3117+ renderer,
3118+ size,
3119+ scale,
3120+ Transform::Normal,
3121+ Fourcc::Abgr8888,
3122+ elements,
3123+ );
3124+
3125+ if let Err(err) = &res {
31263126 warn!("error rendering output {}: {err:?}", output.name());
3127- return None;
31283127 }
3129- };
31303128
3131- Some((output, screenshot))
3129+ res
3130+ });
3131+
3132+ if textures.iter().any(|res| res.is_err()) {
3133+ return None;
3134+ }
3135+
3136+ let textures = textures.map(|res| res.unwrap().0);
3137+ Some((output, textures))
31323138 })
31333139 .collect();
31343140
src/ui/screenshot_ui.rsmodified+21 -13
@@ -19,6 +19,7 @@ use smithay::utils::{Physical, Point, Rectangle, Size, Transform};
1919
2020 use crate::niri_render_elements;
2121 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
22+use crate::render_helpers::RenderTarget;
2223
2324 const BORDER: i32 = 2;
2425
@@ -42,8 +43,9 @@ pub struct OutputData {
4243 size: Size<i32, Physical>,
4344 scale: i32,
4445 transform: Transform,
45- texture: GlesTexture,
46- texture_buffer: TextureBuffer<GlesTexture>,
46+ // Output, screencast, screen capture.
47+ texture: [GlesTexture; 3],
48+ texture_buffer: [TextureBuffer<GlesTexture>; 3],
4749 buffers: [SolidColorBuffer; 8],
4850 locations: [Point<i32, Physical>; 8],
4951 }
@@ -65,7 +67,8 @@ impl ScreenshotUi {
6567 pub fn open(
6668 &mut self,
6769 renderer: &GlesRenderer,
68- screenshots: HashMap<Output, GlesTexture>,
70+ // Output, screencast, screen capture.
71+ screenshots: HashMap<Output, [GlesTexture; 3]>,
6972 default_output: Output,
7073 ) -> bool {
7174 if screenshots.is_empty() {
@@ -110,13 +113,9 @@ impl ScreenshotUi {
110113 let output_mode = output.current_mode().unwrap();
111114 let size = transform.transform_size(output_mode.size);
112115 let scale = output.current_scale().integer_scale();
113- let texture_buffer = TextureBuffer::from_texture(
114- renderer,
115- texture.clone(),
116- scale,
117- Transform::Normal,
118- None,
119- );
116+ let texture_buffer = texture.clone().map(|texture| {
117+ TextureBuffer::from_texture(renderer, texture, scale, Transform::Normal, None)
118+ });
120119 let buffers = [
121120 SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]),
122121 SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]),
@@ -243,7 +242,11 @@ impl ScreenshotUi {
243242 }
244243 }
245244
246- pub fn render_output(&self, output: &Output) -> ArrayVec<ScreenshotUiRenderElement, 9> {
245+ pub fn render_output(
246+ &self,
247+ output: &Output,
248+ target: RenderTarget,
249+ ) -> ArrayVec<ScreenshotUiRenderElement, 9> {
247250 let _span = tracy_client::span!("ScreenshotUi::render_output");
248251
249252 let Self::Open { output_data, .. } = self else {
@@ -269,10 +272,15 @@ impl ScreenshotUi {
269272 }));
270273
271274 // The screenshot itself goes last.
275+ let index = match target {
276+ RenderTarget::Output => 0,
277+ RenderTarget::Screencast => 1,
278+ RenderTarget::ScreenCapture => 2,
279+ };
272280 elements.push(
273281 PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer(
274282 (0., 0.),
275- &output_data.texture_buffer,
283+ &output_data.texture_buffer[index],
276284 None,
277285 None,
278286 None,
@@ -307,7 +315,7 @@ impl ScreenshotUi {
307315 .to_buffer(1, Transform::Normal, &data.size.to_logical(1));
308316
309317 let mapping = renderer
310- .copy_texture(&data.texture, buf_rect, Fourcc::Abgr8888)
318+ .copy_texture(&data.texture[0], buf_rect, Fourcc::Abgr8888)
311319 .context("error copying texture")?;
312320 let copy = renderer
313321 .map_texture(&mapping)