visual window picker with marching ants overlay
This commit is contained in:
@@ -5,6 +5,7 @@ mod clicks;
|
||||
mod config;
|
||||
mod encode;
|
||||
mod updates;
|
||||
mod window_picker;
|
||||
mod windows_list;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -36,6 +37,7 @@ pub struct AppState {
|
||||
pub click_recorder: Mutex<Option<clicks::ClickRecorder>>,
|
||||
pub last_clip: Mutex<Option<RecordedClip>>,
|
||||
pub session: Mutex<Option<SessionState>>,
|
||||
pub picker: Mutex<Option<window_picker::PickerSession>>,
|
||||
}
|
||||
|
||||
pub struct SessionState {
|
||||
@@ -780,6 +782,61 @@ fn list_windows() -> Vec<windows_list::WindowInfo> {
|
||||
windows_list::list_visible_windows()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_window_picker(
|
||||
app: AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
let (mw, mh) =
|
||||
capture::primary_monitor_dims().map_err(|e| format!("{e:#}"))?;
|
||||
|
||||
let mut exclude: Vec<isize> = Vec::new();
|
||||
for label in &["main", "overlay", "picker"] {
|
||||
if let Some(w) = app.get_webview_window(label) {
|
||||
if let Ok(h) = w.hwnd() {
|
||||
exclude.push(h.0 as isize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let picker = app
|
||||
.get_webview_window("picker")
|
||||
.ok_or_else(|| "picker window not found".to_string())?;
|
||||
use tauri::{PhysicalPosition, PhysicalSize, Position, Size};
|
||||
picker
|
||||
.set_size(Size::Physical(PhysicalSize::new(mw, mh)))
|
||||
.map_err(|e| e.to_string())?;
|
||||
picker
|
||||
.set_position(Position::Physical(PhysicalPosition::new(0, 0)))
|
||||
.map_err(|e| e.to_string())?;
|
||||
let _ = picker.set_ignore_cursor_events(true);
|
||||
let _ = picker.set_always_on_top(true);
|
||||
picker.show().map_err(|e| e.to_string())?;
|
||||
|
||||
{
|
||||
let mut slot = state.picker.lock().expect("picker mutex");
|
||||
if let Some(existing) = slot.take() {
|
||||
existing.stop();
|
||||
}
|
||||
*slot = Some(window_picker::start(app.clone(), exclude));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn close_window_picker(
|
||||
app: AppHandle,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<(), String> {
|
||||
if let Some(session) = state.picker.lock().expect("picker mutex").take() {
|
||||
session.stop();
|
||||
}
|
||||
if let Some(picker) = app.get_webview_window("picker") {
|
||||
let _ = picker.hide();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn set_overlay_to_window(
|
||||
app: AppHandle,
|
||||
@@ -1005,6 +1062,7 @@ pub fn run() {
|
||||
click_recorder: Mutex::new(None),
|
||||
last_clip: Mutex::new(None),
|
||||
session: Mutex::new(None),
|
||||
picker: Mutex::new(None),
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
@@ -1102,6 +1160,8 @@ pub fn run() {
|
||||
set_overlay_size,
|
||||
set_overlay_to_window,
|
||||
list_windows,
|
||||
open_window_picker,
|
||||
close_window_picker,
|
||||
get_overlay_rect,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
Reference in New Issue
Block a user