Adopt bread_utils::screenshot_cli for --screenshot flags
Use the crate for pair validation, settle delay, and canvas defaults in breadpad and breadman. breadman now depends on bread-utils v0.7.2 for screenshot_cli; existing hand-rolled argv parsing stays.
This commit is contained in:
parent
54eba3d73a
commit
c929517b49
6 changed files with 37 additions and 32 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -353,6 +353,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bread-screenshots",
|
"bread-screenshots",
|
||||||
"bread-theme",
|
"bread-theme",
|
||||||
|
"bread-utils",
|
||||||
"breadpad-shared",
|
"breadpad-shared",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 5.0.1",
|
"dirs 5.0.1",
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ path = "src/main.rs"
|
||||||
breadpad-shared = { path = "../breadpad-shared" }
|
breadpad-shared = { path = "../breadpad-shared" }
|
||||||
# Capture primitives for `--screenshot` mode — see src/screenshot.rs.
|
# Capture primitives for `--screenshot` mode — see src/screenshot.rs.
|
||||||
bread-screenshots = { git = "https://git.breadway.dev/Breadway/bread-ecosystem", tag = "v0.7.2" }
|
bread-screenshots = { git = "https://git.breadway.dev/Breadway/bread-ecosystem", tag = "v0.7.2" }
|
||||||
|
# Shared `--screenshot` pair validation + settle delay (`screenshot_cli`).
|
||||||
|
bread-utils = { git = "https://git.breadway.dev/Breadway/bread-ecosystem", tag = "v0.7.2" }
|
||||||
# `adw` implies `gtk`. Local chip/init shims remain in src/theme_widgets.rs.
|
# `adw` implies `gtk`. Local chip/init shims remain in src/theme_widgets.rs.
|
||||||
bread-theme = { git = "https://git.breadway.dev/Breadway/bread-ecosystem", tag = "v0.7.2", features = ["adw"] }
|
bread-theme = { git = "https://git.breadway.dev/Breadway/bread-ecosystem", tag = "v0.7.2", features = ["adw"] }
|
||||||
libadwaita = { version = "0.9", features = ["v1_7"] }
|
libadwaita = { version = "0.9", features = ["v1_7"] }
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ mod views;
|
||||||
// ── Args ─────────────────────────────────────────────────────────────────────
|
// ── Args ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
mod args {
|
mod args {
|
||||||
|
use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
pub view: Option<String>,
|
pub view: Option<String>,
|
||||||
|
|
@ -32,18 +35,20 @@ mod args {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
/// `None` for a normal run. Exits the process with an error if
|
/// `None` for a normal run. Exits the process with an error if the
|
||||||
/// `--screenshot` was given without `--output`, before any GTK
|
/// `--screenshot` / `--output` pair is incomplete, before any GTK
|
||||||
/// setup happens.
|
/// setup happens.
|
||||||
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
||||||
let view = self.screenshot.clone()?;
|
if let Err(e) = validate_pair(
|
||||||
let Some(output) = self.output.clone() else {
|
self.screenshot.as_deref(),
|
||||||
eprintln!("breadman: --screenshot requires --output");
|
self.output.as_deref().map(Path::new),
|
||||||
|
) {
|
||||||
|
eprintln!("breadman: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
};
|
}
|
||||||
Some(crate::screenshot::ScreenshotRequest {
|
Some(crate::screenshot::ScreenshotRequest {
|
||||||
view,
|
view: self.screenshot.clone()?,
|
||||||
output: output.into(),
|
output: self.output.clone()?.into(),
|
||||||
width: self.width,
|
width: self.width,
|
||||||
height: self.height,
|
height: self.height,
|
||||||
})
|
})
|
||||||
|
|
@ -57,8 +62,8 @@ mod args {
|
||||||
upcoming_plain: false,
|
upcoming_plain: false,
|
||||||
screenshot: None,
|
screenshot: None,
|
||||||
output: None,
|
output: None,
|
||||||
width: 1920,
|
width: DEFAULT_WIDTH,
|
||||||
height: 1080,
|
height: DEFAULT_HEIGHT,
|
||||||
};
|
};
|
||||||
let raw: Vec<String> = std::env::args().skip(1).collect();
|
let raw: Vec<String> = std::env::args().skip(1).collect();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
//! the button/click-handler entirely), with no-op save/delete/error
|
//! the button/click-handler entirely), with no-op save/delete/error
|
||||||
//! callbacks since nothing here should actually persist a change.
|
//! callbacks since nothing here should actually persist a change.
|
||||||
|
|
||||||
|
use bread_utils::screenshot_cli::SETTLE_DELAY;
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use libadwaita::prelude::*;
|
use libadwaita::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
@ -26,15 +27,10 @@ use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Extra settle time after `map` for the first frame to actually paint
|
|
||||||
/// before grim runs — `map` fires once the surface exists, not once
|
|
||||||
/// anything has been drawn into it.
|
|
||||||
const SETTLE_DELAY: Duration = Duration::from_millis(300);
|
|
||||||
|
|
||||||
/// Delay before popping the editor popover open — same reasoning as every
|
/// Delay before popping the editor popover open — same reasoning as every
|
||||||
/// other app's PRE_POPUP_DELAY: the parent window's own layout needs a beat
|
/// other app's PRE_POPUP_DELAY: the parent window's own layout needs a beat
|
||||||
/// to settle first.
|
/// to settle first.
|
||||||
const PRE_POPUP_DELAY: Duration = Duration::from_millis(300);
|
const PRE_POPUP_DELAY: Duration = SETTLE_DELAY;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ScreenshotRequest {
|
pub struct ScreenshotRequest {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ fn init_ort_once(cfg: &Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod args {
|
mod args {
|
||||||
|
use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
pub note_type: Option<String>,
|
pub note_type: Option<String>,
|
||||||
|
|
@ -69,18 +72,20 @@ mod args {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
/// `None` for a normal run. Exits the process with an error if
|
/// `None` for a normal run. Exits the process with an error if the
|
||||||
/// `--screenshot` was given without `--output`, before any GTK
|
/// `--screenshot` / `--output` pair is incomplete, before any GTK
|
||||||
/// setup happens.
|
/// setup happens.
|
||||||
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
pub fn screenshot_request(&self) -> Option<crate::screenshot::ScreenshotRequest> {
|
||||||
let view = self.screenshot.clone()?;
|
if let Err(e) = validate_pair(
|
||||||
let Some(output) = self.output.clone() else {
|
self.screenshot.as_deref(),
|
||||||
eprintln!("breadpad: --screenshot requires --output");
|
self.output.as_deref().map(Path::new),
|
||||||
|
) {
|
||||||
|
eprintln!("breadpad: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
};
|
}
|
||||||
Some(crate::screenshot::ScreenshotRequest {
|
Some(crate::screenshot::ScreenshotRequest {
|
||||||
view,
|
view: self.screenshot.clone()?,
|
||||||
output: output.into(),
|
output: self.output.clone()?.into(),
|
||||||
width: self.width,
|
width: self.width,
|
||||||
height: self.height,
|
height: self.height,
|
||||||
})
|
})
|
||||||
|
|
@ -99,8 +104,8 @@ mod args {
|
||||||
calendar_list_uid: None,
|
calendar_list_uid: None,
|
||||||
screenshot: None,
|
screenshot: None,
|
||||||
output: None,
|
output: None,
|
||||||
width: 1920,
|
width: DEFAULT_WIDTH,
|
||||||
height: 1080,
|
height: DEFAULT_HEIGHT,
|
||||||
listen: false,
|
listen: false,
|
||||||
};
|
};
|
||||||
let raw: Vec<String> = std::env::args().skip(1).collect();
|
let raw: Vec<String> = std::env::args().skip(1).collect();
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,15 @@
|
||||||
//! entirely), and "reminder-snooze" (the same window with its snooze
|
//! entirely), and "reminder-snooze" (the same window with its snooze
|
||||||
//! popover open).
|
//! popover open).
|
||||||
|
|
||||||
|
use bread_utils::screenshot_cli::SETTLE_DELAY;
|
||||||
use gtk4::prelude::*;
|
use gtk4::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Extra settle time after `map` for the first frame to actually paint
|
|
||||||
/// before grim runs — `map` fires once the surface exists, not once
|
|
||||||
/// anything has been drawn into it.
|
|
||||||
const SETTLE_DELAY: Duration = Duration::from_millis(300);
|
|
||||||
|
|
||||||
/// Delay before popping the snooze popover open — same reasoning as every
|
/// Delay before popping the snooze popover open — same reasoning as every
|
||||||
/// other app's PRE_POPUP_DELAY: the parent window's own layout needs a beat
|
/// other app's PRE_POPUP_DELAY: the parent window's own layout needs a beat
|
||||||
/// to settle first.
|
/// to settle first.
|
||||||
const PRE_POPUP_DELAY: Duration = Duration::from_millis(300);
|
const PRE_POPUP_DELAY: Duration = SETTLE_DELAY;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ScreenshotRequest {
|
pub struct ScreenshotRequest {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue