what the helly

This commit is contained in:
2026-05-04 18:57:20 +02:00
parent 0e6fdb9719
commit 200e76b899
7 changed files with 82 additions and 46 deletions
+26 -14
View File
@@ -25,12 +25,14 @@ use overlay::{SelectionOverlay, SelectionResult};
use review::ReviewWindow;
fn main() -> Result<()> {
// ── 1. Load config ────────────────────────────────────────────────────────
// ── 1. Load config & arguments ────────────────────────────────────────────
let config = config::Config::load().context("Failed to load config")?;
let is_live_mode = config.live_mode || std::env::args().any(|a| a == "--live" || a == "-l");
// ── 2. Query Hyprland metadata (no window open yet) ───────────────────────
// Scale is only needed for window-rect conversion in the overlay.
let scale = hyprland::active_monitor_scale();
let (lw, lh) = hyprland::active_monitor_logical_size().unwrap_or((1920, 1080));
// ── 3. Pre-capture delay ──────────────────────────────────────────────────
// Give the compositor time to unmap the terminal/launcher that started us
@@ -39,11 +41,13 @@ fn main() -> Result<()> {
std::thread::sleep(std::time::Duration::from_millis(config.capture_delay_ms));
// ── 4. Capture full desktop BEFORE opening any window ────────────────────
// This must happen before eframe::run_native is called. eframe maps its
// window immediately on entry — before our first update() frame — causing
// a white rectangle to appear in the snapshot if we capture any later.
let background_snapshot =
capture::capture_all_outputs().context("Failed to capture desktop snapshot")?;
// In freeze mode (default), we snapshot before the overlay.
// In live mode, we skip this and capture later.
let background_snapshot = if is_live_mode {
None
} else {
Some(capture::capture_all_outputs().context("Failed to capture desktop snapshot")?)
};
// ── 5. Run the selection overlay ─────────────────────────────────────────
let selection_result = {
@@ -53,11 +57,14 @@ fn main() -> Result<()> {
let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("rs-pictures-overlay")
.with_inner_size([lw as f32, lh as f32])
.with_position([0.0, 0.0])
.with_fullscreen(true)
.with_maximized(true)
.with_decorations(false)
.with_transparent(true)
.with_always_on_top()
.with_active(false)
.with_resizable(false),
..Default::default()
};
@@ -91,13 +98,18 @@ fn main() -> Result<()> {
}
};
// ── 7. Crop the selected region from the original snapshot ────────────────
let raw_image = {
let px = (region.x.max(0) as u32).min(background_snapshot.width().saturating_sub(1));
let py = (region.y.max(0) as u32).min(background_snapshot.height().saturating_sub(1));
let pw = region.width.min(background_snapshot.width() - px);
let ph = region.height.min(background_snapshot.height() - py);
image::imageops::crop_imm(&background_snapshot, px, py, pw, ph).to_image()
// ── 7. Get the raw region image ───────────────────────────────────────────
let raw_image = if let Some(bg) = background_snapshot {
// Freeze mode: Crop directly from the pre-captured snapshot.
let px = (region.x.max(0) as u32).min(bg.width().saturating_sub(1));
let py = (region.y.max(0) as u32).min(bg.height().saturating_sub(1));
let pw = region.width.min(bg.width() - px);
let ph = region.height.min(bg.height() - py);
image::imageops::crop_imm(&bg, px, py, pw, ph).to_image()
} else {
// Live mode: Wait for the compositor to clear the overlay, then capture just the region.
std::thread::sleep(std::time::Duration::from_millis(config.capture_delay_ms.max(200)));
capture::capture_region(region).context("Failed to capture region")?
};
// ── 8a. Auto-mode — no review window ─────────────────────────────────────