use crate::ForegroundApp;
#[cfg(target_os = "linux")]
use crate::linux::pointer as platform;
#[cfg(target_os = "macos")]
use crate::macos::pointer as platform;
#[cfg(target_os = "windows")]
use crate::windows::pointer as platform;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PointerTarget {
Window {
process_id: i32,
window_id: u64,
},
Desktop,
Unavailable,
Unsupported,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PointerContext {
pub app: Option<ForegroundApp>,
pub target: PointerTarget,
}
#[must_use]
pub fn pointer_context() -> PointerContext {
if !pointer_context_supported() {
return PointerContext {
app: None,
target: PointerTarget::Unsupported,
};
}
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
if let Some(context) = platform::pointer_context() {
return context;
}
PointerContext {
app: None,
target: PointerTarget::Unavailable,
}
}
#[must_use]
pub fn pointer_context_supported() -> bool {
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
return platform::pointer_context_supported();
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
false
}
#[must_use]
pub fn pointer_target_is_focused(target: PointerTarget) -> bool {
if !matches!(target, PointerTarget::Window { .. }) || !pointer_context_supported() {
return false;
}
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
return platform::pointer_target_is_focused(target);
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
false
}
#[cfg(any(target_os = "macos", test))]
pub(crate) mod hit_test;