Make screenshot UI render target-aware
Browse files at this commit5f23d344d5d20d238eea65cd9e7189a2baf499c8Parent: e43e10f3 changed files +57 -40
- resources/default-config.kdl +9 -6
- src/niri.rs +27 -21
- src/ui/screenshot_ui.rs +21 -13
resources/default-config.kdlmodified+9 -6
| @@ -402,14 +402,17 @@ animations { | |||
| 402 | // To preview and set up this rule, check the preview-render option | 402 | // To preview and set up this rule, check the preview-render option |
| 403 | // in the debug section of the config. | 403 | // in the debug section of the config. |
| 404 | // | 404 | // |
| 405 | - // WARNING: the window is NOT blocked out from the screenshot UI. | 405 | + // WARNING: the window is NOT blocked out from third-party screenshot tools. |
| 406 | - // If you open the screenshot UI while screencasting, blocked out windows | 406 | + // If you open some screenshot tool with preview while screencasting, |
| 407 | - // WILL BE VISIBLE on the screencast. | 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. | ||
| 408 | block-out-from "screencast" | 411 | block-out-from "screencast" |
| 409 | 412 | ||
| 410 | // You can also block out the window out of all screen captures, including | 413 | // 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 | 414 | + // third-party screenshot tools. This way you avoid accidentally showing |
| 412 | - // on a screencast when opening the screenshot UI. | 415 | + // the window on a screencast when opening a third-party screenshot preview. |
| 413 | block-out-from "screen-capture" | 416 | block-out-from "screen-capture" |
| 414 | 417 | ||
| 415 | // You can amend the window's minimum and maximum size in logical pixels. | 418 | // You can amend the window's minimum and maximum size in logical pixels. |
| @@ -459,7 +462,7 @@ window-rule { | |||
| 459 | match app-id=r#"^org\.keepassxc\.KeePassXC$"# | 462 | match app-id=r#"^org\.keepassxc\.KeePassXC$"# |
| 460 | match app-id=r#"^org\.gnome\.World\.Secrets$"# | 463 | match app-id=r#"^org\.gnome\.World\.Secrets$"# |
| 461 | 464 | ||
| 462 | - // Warning: will be visible when opening the screenshot UI. | 465 | + // Warning: will be visible on third-party screenshot tools. |
| 463 | block-out-from "screencast" | 466 | block-out-from "screencast" |
| 464 | 467 | ||
| 465 | // Use this instead to block out from all screen captures. | 468 | // Use this instead to block out from all screen captures. |
src/niri.rsmodified+27 -21
| @@ -2307,7 +2307,7 @@ impl Niri { | |||
| 2307 | if self.screenshot_ui.is_open() { | 2307 | if self.screenshot_ui.is_open() { |
| 2308 | elements.extend( | 2308 | elements.extend( |
| 2309 | self.screenshot_ui | 2309 | self.screenshot_ui |
| 2310 | - .render_output(output) | 2310 | + .render_output(output, target) |
| 2311 | .into_iter() | 2311 | .into_iter() |
| 2312 | .map(OutputRenderElements::from), | 2312 | .map(OutputRenderElements::from), |
| 2313 | ); | 2313 | ); |
| @@ -3104,31 +3104,37 @@ impl Niri { | |||
| 3104 | let size = transform.transform_size(size); | 3104 | let size = transform.transform_size(size); |
| 3105 | 3105 | ||
| 3106 | let scale = Scale::from(output.current_scale().fractional_scale()); | 3106 | let scale = Scale::from(output.current_scale().fractional_scale()); |
| 3107 | - let elements = self.render::<GlesRenderer>( | 3107 | + let targets = [ |
| 3108 | - renderer, | 3108 | + RenderTarget::Output, |
| 3109 | - &output, | 3109 | + RenderTarget::Screencast, |
| 3110 | - true, | ||
| 3111 | RenderTarget::ScreenCapture, | 3110 | RenderTarget::ScreenCapture, |
| 3112 | - ); | 3111 | + ]; |
| 3113 | - let elements = elements.iter().rev(); | 3112 | + let textures = targets.map(|target| { |
| 3113 | + let elements = self.render::<GlesRenderer>(renderer, &output, true, target); | ||
| 3114 | + let elements = elements.iter().rev(); | ||
| 3114 | 3115 | ||
| 3115 | - let res = render_to_texture( | 3116 | + let res = render_to_texture( |
| 3116 | - renderer, | 3117 | + renderer, |
| 3117 | - size, | 3118 | + size, |
| 3118 | - scale, | 3119 | + scale, |
| 3119 | - Transform::Normal, | 3120 | + Transform::Normal, |
| 3120 | - Fourcc::Abgr8888, | 3121 | + Fourcc::Abgr8888, |
| 3121 | - elements, | 3122 | + elements, |
| 3122 | - ); | 3123 | + ); |
| 3123 | - let screenshot = match res { | 3124 | + |
| 3124 | - Ok((texture, _)) => texture, | 3125 | + if let Err(err) = &res { |
| 3125 | - Err(err) => { | ||
| 3126 | warn!("error rendering output {}: {err:?}", output.name()); | 3126 | warn!("error rendering output {}: {err:?}", output.name()); |
| 3127 | - return None; | ||
| 3128 | } | 3127 | } |
| 3129 | - }; | ||
| 3130 | 3128 | ||
| 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)) | ||
| 3132 | }) | 3138 | }) |
| 3133 | .collect(); | 3139 | .collect(); |
| 3134 | 3140 | ||
src/ui/screenshot_ui.rsmodified+21 -13
| @@ -19,6 +19,7 @@ use smithay::utils::{Physical, Point, Rectangle, Size, Transform}; | |||
| 19 | 19 | ||
| 20 | use crate::niri_render_elements; | 20 | use crate::niri_render_elements; |
| 21 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; | 21 | use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement; |
| 22 | +use crate::render_helpers::RenderTarget; | ||
| 22 | 23 | ||
| 23 | const BORDER: i32 = 2; | 24 | const BORDER: i32 = 2; |
| 24 | 25 | ||
| @@ -42,8 +43,9 @@ pub struct OutputData { | |||
| 42 | size: Size<i32, Physical>, | 43 | size: Size<i32, Physical>, |
| 43 | scale: i32, | 44 | scale: i32, |
| 44 | transform: Transform, | 45 | transform: Transform, |
| 45 | - texture: GlesTexture, | 46 | + // Output, screencast, screen capture. |
| 46 | - texture_buffer: TextureBuffer<GlesTexture>, | 47 | + texture: [GlesTexture; 3], |
| 48 | + texture_buffer: [TextureBuffer<GlesTexture>; 3], | ||
| 47 | buffers: [SolidColorBuffer; 8], | 49 | buffers: [SolidColorBuffer; 8], |
| 48 | locations: [Point<i32, Physical>; 8], | 50 | locations: [Point<i32, Physical>; 8], |
| 49 | } | 51 | } |
| @@ -65,7 +67,8 @@ impl ScreenshotUi { | |||
| 65 | pub fn open( | 67 | pub fn open( |
| 66 | &mut self, | 68 | &mut self, |
| 67 | renderer: &GlesRenderer, | 69 | renderer: &GlesRenderer, |
| 68 | - screenshots: HashMap<Output, GlesTexture>, | 70 | + // Output, screencast, screen capture. |
| 71 | + screenshots: HashMap<Output, [GlesTexture; 3]>, | ||
| 69 | default_output: Output, | 72 | default_output: Output, |
| 70 | ) -> bool { | 73 | ) -> bool { |
| 71 | if screenshots.is_empty() { | 74 | if screenshots.is_empty() { |
| @@ -110,13 +113,9 @@ impl ScreenshotUi { | |||
| 110 | let output_mode = output.current_mode().unwrap(); | 113 | let output_mode = output.current_mode().unwrap(); |
| 111 | let size = transform.transform_size(output_mode.size); | 114 | let size = transform.transform_size(output_mode.size); |
| 112 | let scale = output.current_scale().integer_scale(); | 115 | let scale = output.current_scale().integer_scale(); |
| 113 | - let texture_buffer = TextureBuffer::from_texture( | 116 | + let texture_buffer = texture.clone().map(|texture| { |
| 114 | - renderer, | 117 | + TextureBuffer::from_texture(renderer, texture, scale, Transform::Normal, None) |
| 115 | - texture.clone(), | 118 | + }); |
| 116 | - scale, | ||
| 117 | - Transform::Normal, | ||
| 118 | - None, | ||
| 119 | - ); | ||
| 120 | let buffers = [ | 119 | let buffers = [ |
| 121 | SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]), | 120 | SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]), |
| 122 | SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]), | 121 | SolidColorBuffer::new((0, 0), [1., 1., 1., 1.]), |
| @@ -243,7 +242,11 @@ impl ScreenshotUi { | |||
| 243 | } | 242 | } |
| 244 | } | 243 | } |
| 245 | 244 | ||
| 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> { | ||
| 247 | let _span = tracy_client::span!("ScreenshotUi::render_output"); | 250 | let _span = tracy_client::span!("ScreenshotUi::render_output"); |
| 248 | 251 | ||
| 249 | let Self::Open { output_data, .. } = self else { | 252 | let Self::Open { output_data, .. } = self else { |
| @@ -269,10 +272,15 @@ impl ScreenshotUi { | |||
| 269 | })); | 272 | })); |
| 270 | 273 | ||
| 271 | // The screenshot itself goes last. | 274 | // The screenshot itself goes last. |
| 275 | + let index = match target { | ||
| 276 | + RenderTarget::Output => 0, | ||
| 277 | + RenderTarget::Screencast => 1, | ||
| 278 | + RenderTarget::ScreenCapture => 2, | ||
| 279 | + }; | ||
| 272 | elements.push( | 280 | elements.push( |
| 273 | PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer( | 281 | PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer( |
| 274 | (0., 0.), | 282 | (0., 0.), |
| 275 | - &output_data.texture_buffer, | 283 | + &output_data.texture_buffer[index], |
| 276 | None, | 284 | None, |
| 277 | None, | 285 | None, |
| 278 | None, | 286 | None, |
| @@ -307,7 +315,7 @@ impl ScreenshotUi { | |||
| 307 | .to_buffer(1, Transform::Normal, &data.size.to_logical(1)); | 315 | .to_buffer(1, Transform::Normal, &data.size.to_logical(1)); |
| 308 | 316 | ||
| 309 | let mapping = renderer | 317 | let mapping = renderer |
| 310 | - .copy_texture(&data.texture, buf_rect, Fourcc::Abgr8888) | 318 | + .copy_texture(&data.texture[0], buf_rect, Fourcc::Abgr8888) |
| 311 | .context("error copying texture")?; | 319 | .context("error copying texture")?; |
| 312 | let copy = renderer | 320 | let copy = renderer |
| 313 | .map_texture(&mapping) | 321 | .map_texture(&mapping) |