|
|
|
@ -24,14 +24,11 @@ use windows::Win32::{
|
|
|
|
|
|
|
|
|
|
use crate::{Bounds, UnderlayEvent};
|
|
|
|
|
|
|
|
|
|
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> =
|
|
|
|
|
AtomicPtr::new(std::ptr::null_mut());
|
|
|
|
|
static GLOBAL_RUNTIME: AtomicPtr<Arc<Mutex<Runtime>>> = AtomicPtr::new(std::ptr::null_mut());
|
|
|
|
|
|
|
|
|
|
pub fn focus_target() {
|
|
|
|
|
unsafe {
|
|
|
|
|
if let Ok(runtime) =
|
|
|
|
|
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
|
|
|
|
|
{
|
|
|
|
|
if let Ok(runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
|
|
|
|
|
if runtime.target.hwnd.is_valid() {
|
|
|
|
|
SetForegroundWindow(runtime.target.hwnd);
|
|
|
|
|
}
|
|
|
|
@ -181,9 +178,7 @@ unsafe extern "system" fn global_hook(
|
|
|
|
|
_ideventthread: u32,
|
|
|
|
|
_dwmseventtime: u32,
|
|
|
|
|
) {
|
|
|
|
|
if let Ok(mut runtime) =
|
|
|
|
|
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
|
|
|
|
|
{
|
|
|
|
|
if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
|
|
|
|
|
runtime.on_event(Event::from_data(
|
|
|
|
|
event,
|
|
|
|
|
hwnd,
|
|
|
|
@ -199,9 +194,7 @@ unsafe extern "system" fn global_timer_hook(
|
|
|
|
|
_timer_id: usize,
|
|
|
|
|
_dwms_event_time: u32,
|
|
|
|
|
) {
|
|
|
|
|
if let Ok(mut runtime) =
|
|
|
|
|
(*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock()
|
|
|
|
|
{
|
|
|
|
|
if let Ok(mut runtime) = (*GLOBAL_RUNTIME.load(std::sync::atomic::Ordering::Relaxed)).lock() {
|
|
|
|
|
let system_foreground_window = GetForegroundWindow();
|
|
|
|
|
if runtime.foreground_window != system_foreground_window
|
|
|
|
|
&& runtime.msaa_check_window_focused_state(system_foreground_window)
|
|
|
|
@ -251,10 +244,10 @@ impl Runtime {
|
|
|
|
|
log::trace!("ForegroundChange: {hwnd:?}");
|
|
|
|
|
|
|
|
|
|
//Sometimes focus changes doesn't keep up, check manually.
|
|
|
|
|
if unsafe { GetForegroundWindow() } != hwnd {
|
|
|
|
|
if !self.msaa_check_window_focused_state(hwnd) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if unsafe { GetForegroundWindow() } != hwnd
|
|
|
|
|
&& !self.msaa_check_window_focused_state(hwnd)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.on_new_foreground(hwnd)
|
|
|
|
@ -430,7 +423,7 @@ impl Runtime {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return is_focused;
|
|
|
|
|
is_focused
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn handle_movesize(&self) {
|
|
|
|
|