use std::sync::OnceLock;
use gpui::Window;
pub fn never_focus() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("SK_WINDOW_FOCUS").is_ok_and(|v| v == "never"))
}
pub fn send_to_back(window: &mut Window) {
if !never_focus() {
return;
}
window.set_assume_active(true);
if let Some(h) = crate::window::capture_hwnd(window) {
send_hwnd_to_back(h);
}
}
pub(crate) fn send_hwnd_to_back(raw: isize) {
if never_focus() {
to_bottom(raw);
}
}
#[cfg(target_os = "windows")]
fn to_bottom(raw: isize) {
use windows::Win32::Foundation::HWND;
use windows::Win32::UI::WindowsAndMessaging::{
SetWindowPos, HWND_BOTTOM, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE,
};
let _ = unsafe {
SetWindowPos(
HWND(raw as *mut _),
Some(HWND_BOTTOM),
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE,
)
};
}
#[cfg(not(target_os = "windows"))]
fn to_bottom(_raw: isize) {}