Remove windows crate dependency - simplify window click-through
This commit is contained in:
parent
5ec15e12f3
commit
aa9af2a735
|
|
@ -1,4 +1,4 @@
|
||||||
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl, Position, PhysicalPosition};
|
use tauri::{AppHandle, Manager, Window, WindowBuilder, WindowUrl};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
pub fn create_main_window(app: &AppHandle) -> Window {
|
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 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 y = monitor_size.height as f64 - window_height - 20.0; // 20px from bottom
|
||||||
|
|
||||||
let window = WindowBuilder::new(
|
let _window = WindowBuilder::new(
|
||||||
app,
|
app,
|
||||||
"overlay",
|
"overlay",
|
||||||
WindowUrl::App("/#/overlay".into())
|
WindowUrl::App("/#/overlay".into())
|
||||||
|
|
@ -43,8 +43,6 @@ pub fn create_overlay_window(app: &AppHandle) {
|
||||||
.always_on_top(true)
|
.always_on_top(true)
|
||||||
.skip_taskbar(true)
|
.skip_taskbar(true)
|
||||||
.visible(false)
|
.visible(false)
|
||||||
// Enable click-through when not focused
|
|
||||||
.focus()
|
|
||||||
.build()
|
.build()
|
||||||
.expect("Failed to create overlay window");
|
.expect("Failed to create overlay window");
|
||||||
|
|
||||||
|
|
@ -57,42 +55,15 @@ pub fn toggle_overlay_window(app: &AppHandle) {
|
||||||
|
|
||||||
if is_visible {
|
if is_visible {
|
||||||
window.hide().ok();
|
window.hide().ok();
|
||||||
// Re-enable click-through
|
|
||||||
enable_click_through(&window, true);
|
|
||||||
} else {
|
} else {
|
||||||
window.show().ok();
|
window.show().ok();
|
||||||
window.set_always_on_top(true).ok();
|
window.set_always_on_top(true).ok();
|
||||||
window.set_focus().ok();
|
window.set_focus().ok();
|
||||||
// Disable click-through when active
|
|
||||||
enable_click_through(&window, false);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
create_overlay_window(app);
|
create_overlay_window(app);
|
||||||
if let Some(window) = app.get_window("overlay") {
|
if let Some(window) = app.get_window("overlay") {
|
||||||
window.show().ok();
|
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.show().ok();
|
||||||
window.set_always_on_top(true).ok();
|
window.set_always_on_top(true).ok();
|
||||||
window.set_focus().ok();
|
window.set_focus().ok();
|
||||||
enable_click_through(&window, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hide_overlay_window(app: &AppHandle) {
|
pub fn hide_overlay_window(app: &AppHandle) {
|
||||||
if let Some(window) = app.get_window("overlay") {
|
if let Some(window) = app.get_window("overlay") {
|
||||||
window.hide().ok();
|
window.hide().ok();
|
||||||
enable_click_through(&window, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue