bazooka/src/fullscreen.rs
Candifloss 5a125a5993 Full-screen screenshot
- Working `bazooka-full` binary from `fullscreen.rs` module
2025-12-07 16:47:30 +05:30

39 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mod core;
use chrono::Local;
use core::{XContext, capture_root_image, save_png};
use std::fs;
fn main() -> anyhow::Result<()> {
// Establish connection to X11 and gather screen info.
let ctx = XContext::new()?;
// Capture the entire screen as an RGBA8 buffer.
let img = capture_root_image(&ctx)?;
// Build an output path:
// ~/Pictures/Screenshots/screenshot_YYYYMMDDHHMMSS.png
//
// Using timestamps avoids overwriting previous screenshots,
// and matches the behavior of many modern screenshot tools.
let timestamp = Local::now().format("%Y%m%d%H%M%S").to_string();
let mut path = dirs::home_dir().unwrap_or_else(|| ".".into());
path.push("Pictures");
path.push("Screenshots");
// Ensure the directory exists
fs::create_dir_all(&path)?;
path.push(format!("screenshot_{timestamp}.png"));
// Convert PathBuf → &str (safe because its UTF-8 on all Linux systems).
let path_str = path.to_string_lossy();
// Write the PNG file to disk.
save_png(&path_str, ctx.width, ctx.height, &img)?;
println!("Saved {path_str}");
Ok(())
}