Skip to content

Commit e803d44

Browse files
committed
screenshot_ui: add ctrl+a command to select entire output
1 parent e863f52 commit e803d44

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

niri-config/src/binds.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ pub enum Action {
118118
#[knuffel(skip)]
119119
CancelScreenshot,
120120
#[knuffel(skip)]
121+
ScreenshotSelectAll,
122+
#[knuffel(skip)]
121123
ScreenshotTogglePointer,
122124
Screenshot(
123125
#[knuffel(property(name = "show-pointer"), default = true)] bool,

src/input/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ impl State {
733733
.set_cursor_image(CursorImageStatus::default_named());
734734
self.niri.queue_redraw_all();
735735
}
736+
Action::ScreenshotSelectAll => {
737+
self.niri.screenshot_ui.select_entire_output();
738+
self.niri.queue_redraw_all();
739+
}
736740
Action::ScreenshotTogglePointer => {
737741
self.niri.screenshot_ui.toggle_pointer();
738742
self.niri.queue_redraw_all();

src/ui/screenshot_ui.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ const FONT: &str = "sans 14px";
3838
const BORDER: i32 = 4;
3939
const TEXT_HIDE_P: &str =
4040
"Press <span face='mono' bgcolor='#2C2C2C'> Space </span> to save the screenshot.\n\
41+
Press <span face='mono' bgcolor='#2C2C2C'> Ctrl+A </span> to select the entire output.\n\
4142
Press <span face='mono' bgcolor='#2C2C2C'> P </span> to hide the pointer.";
4243
const TEXT_SHOW_P: &str =
4344
"Press <span face='mono' bgcolor='#2C2C2C'> Space </span> to save the screenshot.\n\
45+
Press <span face='mono' bgcolor='#2C2C2C'> Ctrl+A </span> to select the entire output.\n\
4446
Press <span face='mono' bgcolor='#2C2C2C'> P </span> to show the pointer.";
4547

4648
// Ideally the screenshot UI should support cross-output selections. However, that poses some
@@ -460,6 +462,23 @@ impl ScreenshotUi {
460462
self.update_buffers();
461463
}
462464

465+
466+
pub fn select_entire_output(&mut self) {
467+
let Self::Open {
468+
selection,
469+
output_data,
470+
..
471+
} = self else { return };
472+
473+
let current_data = &output_data[&selection.0];
474+
let size = current_data.size;
475+
476+
selection.1 = Point::new(0, 0);
477+
selection.2 = Point::new(size.w - 1, size.h - 1);
478+
479+
self.update_buffers();
480+
}
481+
463482
pub fn set_width(&mut self, change: SizeChange) {
464483
let Self::Open {
465484
selection: (output, a, b),
@@ -1067,6 +1086,10 @@ fn action(raw: Keysym, mods: ModifiersState) -> Option<Action> {
10671086
});
10681087
}
10691088

1089+
if mods.ctrl && raw == Keysym::a {
1090+
return Some(Action::ScreenshotSelectAll);
1091+
}
1092+
10701093
if !mods.ctrl && raw == Keysym::p {
10711094
return Some(Action::ScreenshotTogglePointer);
10721095
}

0 commit comments

Comments
 (0)