🎉 add `show-pointer` for `Screenshot` and `ScreenshotScreen`
Browse files at this commit47dd338340e2c8c17ce210579bcdcf8f320d755eParent: 87b6c12- feat
- 🎉 add `show-pointer` for `Screenshot` and `ScreenshotScreen`
7 changed files +72 -29
- niri-config/src/lib.rs +10 -6
- niri-ipc/src/lib.rs +9 -1
- src/input/mod.rs +7 -4
- src/niri.rs +9 -4
- src/ui/hotkey_overlay.rs +14 -11
- src/ui/screenshot_ui.rs +2 -1
- wiki/Configuration:-Key-Bindings.md +21 -2
niri-config/src/lib.rsmodified+10 -6
| @@ -1454,8 +1454,11 @@ pub enum Action { | |||
| 1454 | CancelScreenshot, | 1454 | CancelScreenshot, |
| 1455 | #[knuffel(skip)] | 1455 | #[knuffel(skip)] |
| 1456 | ScreenshotTogglePointer, | 1456 | ScreenshotTogglePointer, |
| 1457 | - Screenshot, | 1457 | + Screenshot(#[knuffel(property(name = "show-pointer"), default = true)] bool), |
| 1458 | - ScreenshotScreen(#[knuffel(property(name = "write-to-disk"), default = true)] bool), | 1458 | + ScreenshotScreen( |
| 1459 | + #[knuffel(property(name = "write-to-disk"), default = true)] bool, | ||
| 1460 | + #[knuffel(property(name = "show-pointer"), default = true)] bool, | ||
| 1461 | + ), | ||
| 1459 | ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool), | 1462 | ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool), |
| 1460 | #[knuffel(skip)] | 1463 | #[knuffel(skip)] |
| 1461 | ScreenshotWindowById { | 1464 | ScreenshotWindowById { |
| @@ -1641,10 +1644,11 @@ impl From<niri_ipc::Action> for Action { | |||
| 1641 | niri_ipc::Action::PowerOnMonitors {} => Self::PowerOnMonitors, | 1644 | niri_ipc::Action::PowerOnMonitors {} => Self::PowerOnMonitors, |
| 1642 | niri_ipc::Action::Spawn { command } => Self::Spawn(command), | 1645 | niri_ipc::Action::Spawn { command } => Self::Spawn(command), |
| 1643 | niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms), | 1646 | niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms), |
| 1644 | - niri_ipc::Action::Screenshot {} => Self::Screenshot, | 1647 | + niri_ipc::Action::Screenshot { show_pointer } => Self::Screenshot(show_pointer), |
| 1645 | - niri_ipc::Action::ScreenshotScreen { write_to_disk } => { | 1648 | + niri_ipc::Action::ScreenshotScreen { |
| 1646 | - Self::ScreenshotScreen(write_to_disk) | 1649 | + write_to_disk, |
| 1647 | - } | 1650 | + show_pointer, |
| 1651 | + } => Self::ScreenshotScreen(write_to_disk, show_pointer), | ||
| 1648 | niri_ipc::Action::ScreenshotWindow { | 1652 | niri_ipc::Action::ScreenshotWindow { |
| 1649 | id: None, | 1653 | id: None, |
| 1650 | write_to_disk, | 1654 | write_to_disk, |
niri-ipc/src/lib.rsmodified+9 -1
| @@ -169,7 +169,11 @@ pub enum Action { | |||
| 169 | delay_ms: Option<u16>, | 169 | delay_ms: Option<u16>, |
| 170 | }, | 170 | }, |
| 171 | /// Open the screenshot UI. | 171 | /// Open the screenshot UI. |
| 172 | - Screenshot {}, | 172 | + Screenshot { |
| 173 | + /// Whether to show the mouse pointer by default in the screenshot UI. | ||
| 174 | + #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] | ||
| 175 | + show_pointer: bool, | ||
| 176 | + }, | ||
| 173 | /// Screenshot the focused screen. | 177 | /// Screenshot the focused screen. |
| 174 | ScreenshotScreen { | 178 | ScreenshotScreen { |
| 175 | /// Write the screenshot to disk in addition to putting it in your clipboard. | 179 | /// Write the screenshot to disk in addition to putting it in your clipboard. |
| @@ -177,6 +181,10 @@ pub enum Action { | |||
| 177 | /// The screenshot is saved according to the `screenshot-path` config setting. | 181 | /// The screenshot is saved according to the `screenshot-path` config setting. |
| 178 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] | 182 | #[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))] |
| 179 | write_to_disk: bool, | 183 | write_to_disk: bool, |
| 184 | + | ||
| 185 | + /// Whether to include the mouse pointer in the screenshot. | ||
| 186 | + #[cfg_attr(feature = "clap", arg(short = 'p', long, action = clap::ArgAction::Set, default_value_t = true))] | ||
| 187 | + show_pointer: bool, | ||
| 180 | }, | 188 | }, |
| 181 | /// Screenshot a window. | 189 | /// Screenshot a window. |
| 182 | #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))] | 190 | #[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))] |
src/input/mod.rsmodified+7 -4
| @@ -565,11 +565,14 @@ impl State { | |||
| 565 | self.niri.do_screen_transition(renderer, delay_ms); | 565 | self.niri.do_screen_transition(renderer, delay_ms); |
| 566 | }); | 566 | }); |
| 567 | } | 567 | } |
| 568 | - Action::ScreenshotScreen(write_to_disk) => { | 568 | + Action::ScreenshotScreen(write_to_disk, show_pointer) => { |
| 569 | let active = self.niri.layout.active_output().cloned(); | 569 | let active = self.niri.layout.active_output().cloned(); |
| 570 | if let Some(active) = active { | 570 | if let Some(active) = active { |
| 571 | self.backend.with_primary_renderer(|renderer| { | 571 | self.backend.with_primary_renderer(|renderer| { |
| 572 | - if let Err(err) = self.niri.screenshot(renderer, &active, write_to_disk) { | 572 | + if let Err(err) = |
| 573 | + self.niri | ||
| 574 | + .screenshot(renderer, &active, write_to_disk, show_pointer) | ||
| 575 | + { | ||
| 573 | warn!("error taking screenshot: {err:?}"); | 576 | warn!("error taking screenshot: {err:?}"); |
| 574 | } | 577 | } |
| 575 | }); | 578 | }); |
| @@ -615,8 +618,8 @@ impl State { | |||
| 615 | self.niri.screenshot_ui.toggle_pointer(); | 618 | self.niri.screenshot_ui.toggle_pointer(); |
| 616 | self.niri.queue_redraw_all(); | 619 | self.niri.queue_redraw_all(); |
| 617 | } | 620 | } |
| 618 | - Action::Screenshot => { | 621 | + Action::Screenshot(show_cursor) => { |
| 619 | - self.open_screenshot_ui(); | 622 | + self.open_screenshot_ui(show_cursor); |
| 620 | } | 623 | } |
| 621 | Action::ScreenshotWindow(write_to_disk) => { | 624 | Action::ScreenshotWindow(write_to_disk) => { |
| 622 | let focus = self.niri.layout.focus_with_output(); | 625 | let focus = self.niri.layout.focus_with_output(); |
src/niri.rsmodified+9 -4
| @@ -1538,7 +1538,7 @@ impl State { | |||
| 1538 | self.niri.output_management_state.notify_changes(new_config); | 1538 | self.niri.output_management_state.notify_changes(new_config); |
| 1539 | } | 1539 | } |
| 1540 | 1540 | ||
| 1541 | - pub fn open_screenshot_ui(&mut self) { | 1541 | + pub fn open_screenshot_ui(&mut self, show_pointer: bool) { |
| 1542 | if self.niri.is_locked() || self.niri.screenshot_ui.is_open() { | 1542 | if self.niri.is_locked() || self.niri.screenshot_ui.is_open() { |
| 1543 | return; | 1543 | return; |
| 1544 | } | 1544 | } |
| @@ -1570,7 +1570,7 @@ impl State { | |||
| 1570 | self.backend.with_primary_renderer(|renderer| { | 1570 | self.backend.with_primary_renderer(|renderer| { |
| 1571 | self.niri | 1571 | self.niri |
| 1572 | .screenshot_ui | 1572 | .screenshot_ui |
| 1573 | - .open(renderer, screenshots, default_output) | 1573 | + .open(renderer, screenshots, default_output, show_pointer) |
| 1574 | }); | 1574 | }); |
| 1575 | 1575 | ||
| 1576 | self.niri | 1576 | self.niri |
| @@ -4701,6 +4701,7 @@ impl Niri { | |||
| 4701 | renderer: &mut GlesRenderer, | 4701 | renderer: &mut GlesRenderer, |
| 4702 | output: &Output, | 4702 | output: &Output, |
| 4703 | write_to_disk: bool, | 4703 | write_to_disk: bool, |
| 4704 | + include_pointer: bool, | ||
| 4704 | ) -> anyhow::Result<()> { | 4705 | ) -> anyhow::Result<()> { |
| 4705 | let _span = tracy_client::span!("Niri::screenshot"); | 4706 | let _span = tracy_client::span!("Niri::screenshot"); |
| 4706 | 4707 | ||
| @@ -4711,8 +4712,12 @@ impl Niri { | |||
| 4711 | let size = transform.transform_size(size); | 4712 | let size = transform.transform_size(size); |
| 4712 | 4713 | ||
| 4713 | let scale = Scale::from(output.current_scale().fractional_scale()); | 4714 | let scale = Scale::from(output.current_scale().fractional_scale()); |
| 4714 | - let elements = | 4715 | + let elements = self.render::<GlesRenderer>( |
| 4715 | - self.render::<GlesRenderer>(renderer, output, true, RenderTarget::ScreenCapture); | 4716 | + renderer, |
| 4717 | + output, | ||
| 4718 | + include_pointer, | ||
| 4719 | + RenderTarget::ScreenCapture, | ||
| 4720 | + ); | ||
| 4716 | let elements = elements.iter().rev(); | 4721 | let elements = elements.iter().rev(); |
| 4717 | let pixels = render_to_vec( | 4722 | let pixels = render_to_vec( |
| 4718 | renderer, | 4723 | renderer, |
src/ui/hotkey_overlay.rsmodified+14 -11
| @@ -254,8 +254,11 @@ fn render( | |||
| 254 | ]); | 254 | ]); |
| 255 | 255 | ||
| 256 | // Screenshot is not as important, can omit if not bound. | 256 | // Screenshot is not as important, can omit if not bound. |
| 257 | - if binds.iter().any(|bind| bind.action == Action::Screenshot) { | 257 | + if let Some(bind) = binds |
| 258 | - actions.push(&Action::Screenshot); | 258 | + .iter() |
| 259 | + .find(|bind| matches!(bind.action, Action::Screenshot(_))) | ||
| 260 | + { | ||
| 261 | + actions.push(&bind.action); | ||
| 259 | } | 262 | } |
| 260 | 263 | ||
| 261 | // Add actions with a custom hotkey-overlay-title. | 264 | // Add actions with a custom hotkey-overlay-title. |
| @@ -436,7 +439,7 @@ fn action_name(action: &Action) -> String { | |||
| 436 | Action::SwitchFocusBetweenFloatingAndTiling => { | 439 | Action::SwitchFocusBetweenFloatingAndTiling => { |
| 437 | String::from("Switch Focus Between Floating and Tiling") | 440 | String::from("Switch Focus Between Floating and Tiling") |
| 438 | } | 441 | } |
| 439 | - Action::Screenshot => String::from("Take a Screenshot"), | 442 | + Action::Screenshot(_) => String::from("Take a Screenshot"), |
| 440 | Action::Spawn(args) => format!( | 443 | Action::Spawn(args) => format!( |
| 441 | "Spawn <span face='monospace' bgcolor='#000000'>{}</span>", | 444 | "Spawn <span face='monospace' bgcolor='#000000'>{}</span>", |
| 442 | args.first().unwrap_or(&String::new()) | 445 | args.first().unwrap_or(&String::new()) |
| @@ -545,7 +548,7 @@ mod tests { | |||
| 545 | #[test] | 548 | #[test] |
| 546 | fn test_format_bind() { | 549 | fn test_format_bind() { |
| 547 | // Not bound. | 550 | // Not bound. |
| 548 | - assert_snapshot!(check("", Action::Screenshot), @" (not bound) : Take a Screenshot"); | 551 | + assert_snapshot!(check("", Action::Screenshot(true)), @" (not bound) : Take a Screenshot"); |
| 549 | 552 | ||
| 550 | // Bound with a default title. | 553 | // Bound with a default title. |
| 551 | assert_snapshot!( | 554 | assert_snapshot!( |
| @@ -553,7 +556,7 @@ mod tests { | |||
| 553 | r#"binds { | 556 | r#"binds { |
| 554 | Mod+P { screenshot; } | 557 | Mod+P { screenshot; } |
| 555 | }"#, | 558 | }"#, |
| 556 | - Action::Screenshot, | 559 | + Action::Screenshot(true), |
| 557 | ), | 560 | ), |
| 558 | @" Super + P : Take a Screenshot" | 561 | @" Super + P : Take a Screenshot" |
| 559 | ); | 562 | ); |
| @@ -564,7 +567,7 @@ mod tests { | |||
| 564 | r#"binds { | 567 | r#"binds { |
| 565 | Mod+P hotkey-overlay-title="Hello" { screenshot; } | 568 | Mod+P hotkey-overlay-title="Hello" { screenshot; } |
| 566 | }"#, | 569 | }"#, |
| 567 | - Action::Screenshot, | 570 | + Action::Screenshot(true), |
| 568 | ), | 571 | ), |
| 569 | @" Super + P : Hello" | 572 | @" Super + P : Hello" |
| 570 | ); | 573 | ); |
| @@ -576,7 +579,7 @@ mod tests { | |||
| 576 | Mod+P { screenshot; } | 579 | Mod+P { screenshot; } |
| 577 | Print { screenshot; } | 580 | Print { screenshot; } |
| 578 | }"#, | 581 | }"#, |
| 579 | - Action::Screenshot, | 582 | + Action::Screenshot(true), |
| 580 | ), | 583 | ), |
| 581 | @" Super + P : Take a Screenshot" | 584 | @" Super + P : Take a Screenshot" |
| 582 | ); | 585 | ); |
| @@ -588,7 +591,7 @@ mod tests { | |||
| 588 | Mod+P { screenshot; } | 591 | Mod+P { screenshot; } |
| 589 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } | 592 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } |
| 590 | }"#, | 593 | }"#, |
| 591 | - Action::Screenshot, | 594 | + Action::Screenshot(true), |
| 592 | ), | 595 | ), |
| 593 | @" PrtSc : My Cool Bind" | 596 | @" PrtSc : My Cool Bind" |
| 594 | ); | 597 | ); |
| @@ -600,7 +603,7 @@ mod tests { | |||
| 600 | Mod+P hotkey-overlay-title="First" { screenshot; } | 603 | Mod+P hotkey-overlay-title="First" { screenshot; } |
| 601 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } | 604 | Print hotkey-overlay-title="My Cool Bind" { screenshot; } |
| 602 | }"#, | 605 | }"#, |
| 603 | - Action::Screenshot, | 606 | + Action::Screenshot(true), |
| 604 | ), | 607 | ), |
| 605 | @" Super + P : First" | 608 | @" Super + P : First" |
| 606 | ); | 609 | ); |
| @@ -612,7 +615,7 @@ mod tests { | |||
| 612 | Mod+P { screenshot; } | 615 | Mod+P { screenshot; } |
| 613 | Print hotkey-overlay-title=null { screenshot; } | 616 | Print hotkey-overlay-title=null { screenshot; } |
| 614 | }"#, | 617 | }"#, |
| 615 | - Action::Screenshot, | 618 | + Action::Screenshot(true), |
| 616 | ), | 619 | ), |
| 617 | @"None" | 620 | @"None" |
| 618 | ); | 621 | ); |
| @@ -624,7 +627,7 @@ mod tests { | |||
| 624 | Mod+P hotkey-overlay-title="Hello" { screenshot; } | 627 | Mod+P hotkey-overlay-title="Hello" { screenshot; } |
| 625 | Print hotkey-overlay-title=null { screenshot; } | 628 | Print hotkey-overlay-title=null { screenshot; } |
| 626 | }"#, | 629 | }"#, |
| 627 | - Action::Screenshot, | 630 | + Action::Screenshot(true), |
| 628 | ), | 631 | ), |
| 629 | @" Super + P : Hello" | 632 | @" Super + P : Hello" |
| 630 | ); | 633 | ); |
src/ui/screenshot_ui.rsmodified+2 -1
| @@ -101,6 +101,7 @@ impl ScreenshotUi { | |||
| 101 | // Output, screencast, screen capture. | 101 | // Output, screencast, screen capture. |
| 102 | screenshots: HashMap<Output, [OutputScreenshot; 3]>, | 102 | screenshots: HashMap<Output, [OutputScreenshot; 3]>, |
| 103 | default_output: Output, | 103 | default_output: Output, |
| 104 | + show_pointer: bool, | ||
| 104 | ) -> bool { | 105 | ) -> bool { |
| 105 | if screenshots.is_empty() { | 106 | if screenshots.is_empty() { |
| 106 | return false; | 107 | return false; |
| @@ -191,7 +192,7 @@ impl ScreenshotUi { | |||
| 191 | selection, | 192 | selection, |
| 192 | output_data, | 193 | output_data, |
| 193 | mouse_down: false, | 194 | mouse_down: false, |
| 194 | - show_pointer: true, | 195 | + show_pointer, |
| 195 | open_anim, | 196 | open_anim, |
| 196 | clock: clock.clone(), | 197 | clock: clock.clone(), |
| 197 | config: config.clone(), | 198 | config: config.clone(), |
wiki/Configuration:-Key-Bindings.mdmodified+21 -2
| @@ -306,9 +306,13 @@ binds { | |||
| 306 | } | 306 | } |
| 307 | ``` | 307 | ``` |
| 308 | 308 | ||
| 309 | -#### `screenshot-screen`, `screenshot-window` | 309 | +#### `screenshot`, `screenshot-screen`, `screenshot-window` |
| 310 | + | ||
| 311 | +Actions for taking screenshots. | ||
| 312 | + | ||
| 313 | +- `screenshot`: opens the built-in interactive screenshot UI. | ||
| 314 | +- `screenshot-screen`, `screenshow-window`: takes a screenshot of the focused screen or window respectively. | ||
| 310 | 315 | ||
| 311 | -Take a screenshot of the focused screen or window respectively. | ||
| 312 | The screenshot is both stored to the clipboard and saved to disk, according to the [`screenshot-path` option](./Configuration:-Miscellaneous.md). | 316 | The screenshot is both stored to the clipboard and saved to disk, according to the [`screenshot-path` option](./Configuration:-Miscellaneous.md). |
| 313 | 317 | ||
| 314 | <sup>Since: 25.02</sup> You can disable saving to disk for a specific bind with the `write-to-disk=false` property: | 318 | <sup>Since: 25.02</sup> You can disable saving to disk for a specific bind with the `write-to-disk=false` property: |
| @@ -320,6 +324,21 @@ binds { | |||
| 320 | } | 324 | } |
| 321 | ``` | 325 | ``` |
| 322 | 326 | ||
| 327 | +In the interactive screenshot UI, pressing <kbd>Ctrl</kbd><kbd>C</kbd> will copy the screenshot to the clipboard without writing it to disk. | ||
| 328 | + | ||
| 329 | +<sup>Since: next release</sup> You can hide the mouse pointer in screenshots with the `show-pointer=false` property: | ||
| 330 | + | ||
| 331 | +```kdl | ||
| 332 | +binds { | ||
| 333 | + // The pointer will be hidden by default | ||
| 334 | + // (you can still show it by pressing P). | ||
| 335 | + Print { screenshot show-pointer=false; } | ||
| 336 | + | ||
| 337 | + // The pointer will be hidden on the screenshot. | ||
| 338 | + Ctrl+Print { screenshot-screen show-pointer=false; } | ||
| 339 | +} | ||
| 340 | +``` | ||
| 341 | + | ||
| 323 | #### `toggle-keyboard-shortcuts-inhibit` | 342 | #### `toggle-keyboard-shortcuts-inhibit` |
| 324 | 343 | ||
| 325 | <sup>Since: 25.02</sup> | 344 | <sup>Since: 25.02</sup> |