Adopt bread_utils::screenshot_cli for --screenshot flags
All checks were successful
dev release / build (push) Successful in 1m22s
All checks were successful
dev release / build (push) Successful in 1m22s
Replace the local settle delay, canvas defaults, and pair-validation error path with bread-utils v0.7.2. Clap parsing stays in-tree.
This commit is contained in:
parent
110f0cd3df
commit
62c6dd5ea3
1 changed files with 15 additions and 15 deletions
|
|
@ -14,16 +14,12 @@
|
||||||
//! windows (`notifications::spawn`/`osd::spawn`, built and primed with
|
//! windows (`notifications::spawn`/`osd::spawn`, built and primed with
|
||||||
//! sample data by `main.rs` before `dispatch` runs — see [`Handles`]).
|
//! sample data by `main.rs` before `dispatch` runs — see [`Handles`]).
|
||||||
|
|
||||||
|
use bread_utils::screenshot_cli::{validate_pair, DEFAULT_HEIGHT, DEFAULT_WIDTH, SETTLE_DELAY};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
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);
|
|
||||||
|
|
||||||
/// Settle time for views whose content depends on `bar::stats::spawn_poller`'s
|
/// Settle time for views whose content depends on `bar::stats::spawn_poller`'s
|
||||||
/// 2-second background loop (control-panel's CPU/RAM/PWR/GPU/network labels,
|
/// 2-second background loop (control-panel's CPU/RAM/PWR/GPU/network labels,
|
||||||
/// gated on popover visibility) or a similar live-data popover load
|
/// gated on popover visibility) or a similar live-data popover load
|
||||||
|
|
@ -38,7 +34,7 @@ const LIVE_DATA_SETTLE_DELAY: Duration = Duration::from_millis(2_200);
|
||||||
/// popover at all) — presumably the parent widget's own allocation isn't
|
/// popover at all) — presumably the parent widget's own allocation isn't
|
||||||
/// settled yet at that exact point. Giving the initial layout pass a beat to
|
/// settled yet at that exact point. Giving the initial layout pass a beat to
|
||||||
/// finish first is what makes it actually render.
|
/// finish first is what makes it actually render.
|
||||||
const PRE_POPUP_DELAY: Duration = Duration::from_millis(300);
|
const PRE_POPUP_DELAY: Duration = SETTLE_DELAY;
|
||||||
|
|
||||||
const KNOWN_VIEWS: &[&str] = &[
|
const KNOWN_VIEWS: &[&str] = &[
|
||||||
"bar",
|
"bar",
|
||||||
|
|
@ -68,11 +64,11 @@ pub struct Cli {
|
||||||
/// Capture canvas width — matches the isolated compositor's output width
|
/// Capture canvas width — matches the isolated compositor's output width
|
||||||
/// (`bread-capture --isolate-width`) so the geometry passed to `grim`
|
/// (`bread-capture --isolate-width`) so the geometry passed to `grim`
|
||||||
/// doesn't depend on querying anything at capture time.
|
/// doesn't depend on querying anything at capture time.
|
||||||
#[arg(long, default_value_t = 1920)]
|
#[arg(long, default_value_t = DEFAULT_WIDTH)]
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
|
|
||||||
/// Capture canvas height — see `width`.
|
/// Capture canvas height — see `width`.
|
||||||
#[arg(long, default_value_t = 1080)]
|
#[arg(long, default_value_t = DEFAULT_HEIGHT)]
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
|
|
||||||
/// Toggle the in-memory notification history on a running breadbar, then
|
/// Toggle the in-memory notification history on a running breadbar, then
|
||||||
|
|
@ -89,16 +85,20 @@ pub struct ScreenshotRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
/// `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/relm4
|
/// `--screenshot` / `--output` pair is incomplete, before any GTK/relm4
|
||||||
/// setup happens.
|
/// setup happens.
|
||||||
pub fn screenshot_request(&self) -> Option<ScreenshotRequest> {
|
pub fn screenshot_request(&self) -> Option<ScreenshotRequest> {
|
||||||
let view = self.screenshot.clone()?;
|
if let Err(e) = validate_pair(self.screenshot.as_deref(), self.output.as_deref()) {
|
||||||
let Some(output) = self.output.clone() else {
|
eprintln!("breadbar: {e}");
|
||||||
eprintln!("breadbar: --screenshot requires --output");
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
};
|
}
|
||||||
Some(ScreenshotRequest { view, output, width: self.width, height: self.height })
|
Some(ScreenshotRequest {
|
||||||
|
view: self.screenshot.clone()?,
|
||||||
|
output: self.output.clone()?,
|
||||||
|
width: self.width,
|
||||||
|
height: self.height,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue