Remove windows crate dependency - simplify window click-through

This commit is contained in:
Aether 2026-02-23 21:33:03 +00:00
parent 5ec15e12f3
commit aa9af2a735
No known key found for this signature in database
GPG Key ID: 95AFEE837E39AFD2
1 changed files with 2 additions and 33 deletions

View File

@ -1,4 +1,4 @@
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl, Position, PhysicalPosition};
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl};
use tracing::info;
pub fn create_main_window(app: &AppHandle) -> Window {
@ -30,7 +30,7 @@ pub fn create_overlay_window(app: &AppHandle) {
let x = (monitor_size.width as f64 - window_width) / 2.0;
let y = monitor_size.height as f64 - window_height - 20.0; // 20px from bottom
let window = WindowBuilder::new(
let _window = WindowBuilder::new(
app,
"overlay",
WindowUrl::App("/#/overlay".into())
@ -43,8 +43,6 @@ pub fn create_overlay_window(app: &AppHandle) {
.always_on_top(true)
.skip_taskbar(true)
.visible(false)
// Enable click-through when not focused
.focus()
.build()
.expect("Failed to create overlay window");
@ -57,42 +55,15 @@ pub fn toggle_overlay_window(app: &AppHandle) {
if is_visible {
window.hide().ok();
// Re-enable click-through
enable_click_through(&window, true);
} else {
window.show().ok();
window.set_always_on_top(true).ok();
window.set_focus().ok();
// Disable click-through when active
enable_click_through(&window, false);
}
} else {
create_overlay_window(app);
if let Some(window) = app.get_window("overlay") {
window.show().ok();
enable_click_through(&window, false);
}
}
}
fn enable_click_through(window: &Window, enable: bool) {
#[cfg(target_os = "windows")]
unsafe {
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging::{SetWindowLongW, GetWindowLongW, GWL_EXSTYLE};
use windows::Win32::UI::WindowsAndMessaging::{WS_EX_LAYERED, WS_EX_TRANSPARENT, WS_EX_NOACTIVATE};
let hwnd = HWND(window.hwnd().unwrap().0 as *mut _);
let ex_style = GetWindowLongW(hwnd, GWL_EXSTYLE);
if enable {
// Enable click-through
SetWindowLongW(hwnd, GWL_EXSTYLE,
ex_style | WS_EX_LAYERED.0 as i32 | WS_EX_TRANSPARENT.0 as i32);
} else {
// Disable click-through
SetWindowLongW(hwnd, GWL_EXSTYLE,
ex_style & !(WS_EX_TRANSPARENT.0 as i32));
}
}
}
@ -102,13 +73,11 @@ pub fn show_overlay_window(app: &AppHandle) {
window.show().ok();
window.set_always_on_top(true).ok();
window.set_focus().ok();
enable_click_through(&window, false);
}
}
pub fn hide_overlay_window(app: &AppHandle) {
if let Some(window) = app.get_window("overlay") {
window.hide().ok();
enable_click_through(&window, true);
}
}