replace crashing snap with window picker icon on overlay

This commit is contained in:
2026-05-12 02:15:07 +03:00
parent 87384f5113
commit 2904a7ad29
5 changed files with 287 additions and 122 deletions
+35 -6
View File
@@ -4,8 +4,8 @@ mod capture;
mod clicks;
mod config;
mod encode;
mod snap;
mod updates;
mod windows_list;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
@@ -775,6 +775,38 @@ fn set_overlay_size(app: AppHandle, width: u32, height: u32) -> Result<(), Strin
.map_err(|e| e.to_string())
}
#[tauri::command]
fn list_windows() -> Vec<windows_list::WindowInfo> {
windows_list::list_visible_windows()
}
#[tauri::command]
fn set_overlay_to_window(
app: AppHandle,
x: i32,
y: i32,
width: u32,
height: u32,
) -> Result<(), String> {
use tauri::{PhysicalPosition, PhysicalSize, Position, Size};
let win = app
.get_webview_window("overlay")
.ok_or_else(|| "overlay window not found".to_string())?;
let scale = win.scale_factor().map_err(|e| e.to_string())?;
let border_phys = (OVERLAY_BORDER_LOGICAL_PX * scale).round() as i32;
let titlebar_phys = (OVERLAY_TITLEBAR_LOGICAL_PX * scale).round() as i32;
let outer_x = x - border_phys;
let outer_y = y - border_phys - titlebar_phys;
let outer_w = (width as i32 + border_phys * 2).max(2) as u32;
let outer_h = (height as i32 + border_phys * 2 + titlebar_phys).max(2) as u32;
win.set_position(Position::Physical(PhysicalPosition::new(outer_x, outer_y)))
.map_err(|e| e.to_string())?;
win.set_size(Size::Physical(PhysicalSize::new(outer_w, outer_h)))
.map_err(|e| e.to_string())
}
#[tauri::command]
fn get_overlay_rect(app: AppHandle) -> Result<CaptureRect, String> {
let win = app
@@ -1032,11 +1064,6 @@ pub fn run() {
(cfg.updates.check_on_launch, cfg)
};
register_hotkeys(app.handle(), &cfg);
if let Some(overlay) = app.get_webview_window("overlay") {
if let Ok(raw) = overlay.hwnd() {
snap::attach(raw.0 as isize);
}
}
if check_on_launch {
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
@@ -1073,6 +1100,8 @@ pub fn run() {
show_overlay,
hide_overlay,
set_overlay_size,
set_overlay_to_window,
list_windows,
get_overlay_rect,
])
.run(tauri::generate_context!())