mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
add write-to-disk argument to screenshot actions
This commit is contained in:
committed by
Ivan Molodetskikh
parent
6ae51f287c
commit
0df7a085de
+20
-7
@@ -1185,16 +1185,21 @@ pub enum Action {
|
|||||||
Spawn(#[knuffel(arguments)] Vec<String>),
|
Spawn(#[knuffel(arguments)] Vec<String>),
|
||||||
DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>),
|
DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>),
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
ConfirmScreenshot,
|
ConfirmScreenshot {
|
||||||
|
write_to_disk: bool,
|
||||||
|
},
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
CancelScreenshot,
|
CancelScreenshot,
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
ScreenshotTogglePointer,
|
ScreenshotTogglePointer,
|
||||||
Screenshot,
|
Screenshot,
|
||||||
ScreenshotScreen,
|
ScreenshotScreen(#[knuffel(property(name = "write-to-disk"), default = true)] bool),
|
||||||
ScreenshotWindow,
|
ScreenshotWindow(#[knuffel(property(name = "write-to-disk"), default = true)] bool),
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
ScreenshotWindowById(u64),
|
ScreenshotWindowById {
|
||||||
|
id: u64,
|
||||||
|
write_to_disk: bool,
|
||||||
|
},
|
||||||
CloseWindow,
|
CloseWindow,
|
||||||
#[knuffel(skip)]
|
#[knuffel(skip)]
|
||||||
CloseWindowById(u64),
|
CloseWindowById(u64),
|
||||||
@@ -1351,9 +1356,17 @@ impl From<niri_ipc::Action> for Action {
|
|||||||
niri_ipc::Action::Spawn { command } => Self::Spawn(command),
|
niri_ipc::Action::Spawn { command } => Self::Spawn(command),
|
||||||
niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),
|
niri_ipc::Action::DoScreenTransition { delay_ms } => Self::DoScreenTransition(delay_ms),
|
||||||
niri_ipc::Action::Screenshot {} => Self::Screenshot,
|
niri_ipc::Action::Screenshot {} => Self::Screenshot,
|
||||||
niri_ipc::Action::ScreenshotScreen {} => Self::ScreenshotScreen,
|
niri_ipc::Action::ScreenshotScreen { write_to_disk } => {
|
||||||
niri_ipc::Action::ScreenshotWindow { id: None } => Self::ScreenshotWindow,
|
Self::ScreenshotScreen(write_to_disk)
|
||||||
niri_ipc::Action::ScreenshotWindow { id: Some(id) } => Self::ScreenshotWindowById(id),
|
}
|
||||||
|
niri_ipc::Action::ScreenshotWindow {
|
||||||
|
id: None,
|
||||||
|
write_to_disk,
|
||||||
|
} => Self::ScreenshotWindow(write_to_disk),
|
||||||
|
niri_ipc::Action::ScreenshotWindow {
|
||||||
|
id: Some(id),
|
||||||
|
write_to_disk,
|
||||||
|
} => Self::ScreenshotWindowById { id, write_to_disk },
|
||||||
niri_ipc::Action::CloseWindow { id: None } => Self::CloseWindow,
|
niri_ipc::Action::CloseWindow { id: None } => Self::CloseWindow,
|
||||||
niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id),
|
niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id),
|
||||||
niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow,
|
niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow,
|
||||||
|
|||||||
+12
-1
@@ -167,7 +167,13 @@ pub enum Action {
|
|||||||
/// Open the screenshot UI.
|
/// Open the screenshot UI.
|
||||||
Screenshot {},
|
Screenshot {},
|
||||||
/// Screenshot the focused screen.
|
/// Screenshot the focused screen.
|
||||||
ScreenshotScreen {},
|
ScreenshotScreen {
|
||||||
|
/// Write the screenshot to disk in addition to putting it in your clipboard.
|
||||||
|
///
|
||||||
|
/// The screenshot is saved according to the `screenshot-path` config setting.
|
||||||
|
#[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]
|
||||||
|
write_to_disk: bool,
|
||||||
|
},
|
||||||
/// Screenshot a window.
|
/// Screenshot a window.
|
||||||
#[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))]
|
#[cfg_attr(feature = "clap", clap(about = "Screenshot the focused window"))]
|
||||||
ScreenshotWindow {
|
ScreenshotWindow {
|
||||||
@@ -176,6 +182,11 @@ pub enum Action {
|
|||||||
/// If `None`, uses the focused window.
|
/// If `None`, uses the focused window.
|
||||||
#[cfg_attr(feature = "clap", arg(long))]
|
#[cfg_attr(feature = "clap", arg(long))]
|
||||||
id: Option<u64>,
|
id: Option<u64>,
|
||||||
|
/// Write the screenshot to disk in addition to putting it in your clipboard.
|
||||||
|
///
|
||||||
|
/// The screenshot is saved according to the `screenshot-path` config setting.
|
||||||
|
#[cfg_attr(feature = "clap", arg(short = 'd', long, action = clap::ArgAction::Set, default_value_t = true))]
|
||||||
|
write_to_disk: bool,
|
||||||
},
|
},
|
||||||
/// Close a window.
|
/// Close a window.
|
||||||
#[cfg_attr(feature = "clap", clap(about = "Close the focused window"))]
|
#[cfg_attr(feature = "clap", clap(about = "Close the focused window"))]
|
||||||
|
|||||||
+15
-8
@@ -529,17 +529,17 @@ impl State {
|
|||||||
self.niri.do_screen_transition(renderer, delay_ms);
|
self.niri.do_screen_transition(renderer, delay_ms);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Action::ScreenshotScreen => {
|
Action::ScreenshotScreen(write_to_disk) => {
|
||||||
let active = self.niri.layout.active_output().cloned();
|
let active = self.niri.layout.active_output().cloned();
|
||||||
if let Some(active) = active {
|
if let Some(active) = active {
|
||||||
self.backend.with_primary_renderer(|renderer| {
|
self.backend.with_primary_renderer(|renderer| {
|
||||||
if let Err(err) = self.niri.screenshot(renderer, &active) {
|
if let Err(err) = self.niri.screenshot(renderer, &active, write_to_disk) {
|
||||||
warn!("error taking screenshot: {err:?}");
|
warn!("error taking screenshot: {err:?}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::ConfirmScreenshot => {
|
Action::ConfirmScreenshot { write_to_disk } => {
|
||||||
if !self.niri.screenshot_ui.is_open() {
|
if !self.niri.screenshot_ui.is_open() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,8 @@ impl State {
|
|||||||
self.backend.with_primary_renderer(|renderer| {
|
self.backend.with_primary_renderer(|renderer| {
|
||||||
match self.niri.screenshot_ui.capture(renderer) {
|
match self.niri.screenshot_ui.capture(renderer) {
|
||||||
Ok((size, pixels)) => {
|
Ok((size, pixels)) => {
|
||||||
if let Err(err) = self.niri.save_screenshot(size, pixels) {
|
if let Err(err) = self.niri.save_screenshot(size, pixels, write_to_disk)
|
||||||
|
{
|
||||||
warn!("error saving screenshot: {err:?}");
|
warn!("error saving screenshot: {err:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,23 +582,29 @@ impl State {
|
|||||||
Action::Screenshot => {
|
Action::Screenshot => {
|
||||||
self.open_screenshot_ui();
|
self.open_screenshot_ui();
|
||||||
}
|
}
|
||||||
Action::ScreenshotWindow => {
|
Action::ScreenshotWindow(write_to_disk) => {
|
||||||
let focus = self.niri.layout.focus_with_output();
|
let focus = self.niri.layout.focus_with_output();
|
||||||
if let Some((mapped, output)) = focus {
|
if let Some((mapped, output)) = focus {
|
||||||
self.backend.with_primary_renderer(|renderer| {
|
self.backend.with_primary_renderer(|renderer| {
|
||||||
if let Err(err) = self.niri.screenshot_window(renderer, output, mapped) {
|
if let Err(err) =
|
||||||
|
self.niri
|
||||||
|
.screenshot_window(renderer, output, mapped, write_to_disk)
|
||||||
|
{
|
||||||
warn!("error taking screenshot: {err:?}");
|
warn!("error taking screenshot: {err:?}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action::ScreenshotWindowById(id) => {
|
Action::ScreenshotWindowById { id, write_to_disk } => {
|
||||||
let mut windows = self.niri.layout.windows();
|
let mut windows = self.niri.layout.windows();
|
||||||
let window = windows.find(|(_, m)| m.id().get() == id);
|
let window = windows.find(|(_, m)| m.id().get() == id);
|
||||||
if let Some((Some(monitor), mapped)) = window {
|
if let Some((Some(monitor), mapped)) = window {
|
||||||
let output = monitor.output();
|
let output = monitor.output();
|
||||||
self.backend.with_primary_renderer(|renderer| {
|
self.backend.with_primary_renderer(|renderer| {
|
||||||
if let Err(err) = self.niri.screenshot_window(renderer, output, mapped) {
|
if let Err(err) =
|
||||||
|
self.niri
|
||||||
|
.screenshot_window(renderer, output, mapped, write_to_disk)
|
||||||
|
{
|
||||||
warn!("error taking screenshot: {err:?}");
|
warn!("error taking screenshot: {err:?}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+14
-9
@@ -4519,6 +4519,7 @@ impl Niri {
|
|||||||
&mut self,
|
&mut self,
|
||||||
renderer: &mut GlesRenderer,
|
renderer: &mut GlesRenderer,
|
||||||
output: &Output,
|
output: &Output,
|
||||||
|
write_to_disk: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let _span = tracy_client::span!("Niri::screenshot");
|
let _span = tracy_client::span!("Niri::screenshot");
|
||||||
|
|
||||||
@@ -4541,7 +4542,7 @@ impl Niri {
|
|||||||
elements,
|
elements,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.save_screenshot(size, pixels)
|
self.save_screenshot(size, pixels, write_to_disk)
|
||||||
.context("error saving screenshot")
|
.context("error saving screenshot")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4550,6 +4551,7 @@ impl Niri {
|
|||||||
renderer: &mut GlesRenderer,
|
renderer: &mut GlesRenderer,
|
||||||
output: &Output,
|
output: &Output,
|
||||||
mapped: &Mapped,
|
mapped: &Mapped,
|
||||||
|
write_to_disk: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let _span = tracy_client::span!("Niri::screenshot_window");
|
let _span = tracy_client::span!("Niri::screenshot_window");
|
||||||
|
|
||||||
@@ -4585,7 +4587,7 @@ impl Niri {
|
|||||||
elements,
|
elements,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.save_screenshot(geo.size, pixels)
|
self.save_screenshot(geo.size, pixels, write_to_disk)
|
||||||
.context("error saving screenshot")
|
.context("error saving screenshot")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4593,14 +4595,17 @@ impl Niri {
|
|||||||
&self,
|
&self,
|
||||||
size: Size<i32, Physical>,
|
size: Size<i32, Physical>,
|
||||||
pixels: Vec<u8>,
|
pixels: Vec<u8>,
|
||||||
|
write_to_disk: bool,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let path = match make_screenshot_path(&self.config.borrow()) {
|
let path = write_to_disk
|
||||||
Ok(path) => path,
|
.then(|| match make_screenshot_path(&self.config.borrow()) {
|
||||||
Err(err) => {
|
Ok(path) => path,
|
||||||
warn!("error making screenshot path: {err:?}");
|
Err(err) => {
|
||||||
None
|
warn!("error making screenshot path: {err:?}");
|
||||||
}
|
None
|
||||||
};
|
}
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
|
||||||
// Prepare to set the encoded image as our clipboard selection. This must be done from the
|
// Prepare to set the encoded image as our clipboard selection. This must be done from the
|
||||||
// main thread.
|
// main thread.
|
||||||
|
|||||||
@@ -629,10 +629,15 @@ fn action(raw: Keysym, mods: ModifiersState) -> Option<Action> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mods.ctrl && raw == Keysym::c)
|
if !mods.ctrl && (raw == Keysym::space || raw == Keysym::Return) {
|
||||||
|| (!mods.ctrl && (raw == Keysym::space || raw == Keysym::Return))
|
return Some(Action::ConfirmScreenshot {
|
||||||
{
|
write_to_disk: true,
|
||||||
return Some(Action::ConfirmScreenshot);
|
});
|
||||||
|
}
|
||||||
|
if mods.ctrl && raw == Keysym::c {
|
||||||
|
return Some(Action::ConfirmScreenshot {
|
||||||
|
write_to_disk: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if !mods.ctrl && raw == Keysym::p {
|
if !mods.ctrl && raw == Keysym::p {
|
||||||
|
|||||||
Reference in New Issue
Block a user