diff --git a/src/os/unix/x11.rs b/src/os/unix/x11.rs index d20f693..f6d59f7 100644 --- a/src/os/unix/x11.rs +++ b/src/os/unix/x11.rs @@ -273,6 +273,7 @@ pub struct Window { scroll_y: f32, buttons: [u8; 3], prev_cursor: CursorStyle, + active: bool, should_close: bool, // received delete window message from X server @@ -363,7 +364,8 @@ impl Window { | xlib::KeyPressMask | xlib::KeyReleaseMask | xlib::ButtonPressMask - | xlib::ButtonReleaseMask, + | xlib::ButtonReleaseMask + | xlib::FocusChangeMask, ); if !opts.resize { @@ -416,6 +418,7 @@ impl Window { buttons: [0, 0, 0], prev_cursor: CursorStyle::Arrow, should_close: false, + active: false, key_handler: KeyHandler::new(), update_rate: UpdateRate::new(), menu_counter: MenuHandle(0), @@ -633,8 +636,7 @@ impl Window { #[inline] pub fn is_active(&mut self) -> bool { - // TODO: Proper implementation - true + self.active } fn get_scale_factor( @@ -866,6 +868,12 @@ impl Window { ) .expect("todo"); } + xlib::FocusOut => { + self.active = false; + } + xlib::FocusIn => { + self.active = true; + } _ => {} } diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index 0c3ebc6..7dc260b 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -828,8 +828,17 @@ impl Window { #[inline] pub fn is_active(&mut self) -> bool { - // TODO: Proper implementation - true + match self.window { + Some(hwnd) => { + let active = unsafe { winapi::um::winuser::GetActiveWindow() }; + if !active.is_null() && active == hwnd { + true + } else { + false + } + } + None => false, + } } unsafe fn get_scale_factor(width: usize, height: usize, scale: Scale) -> i32 {