[Testing] Implement is_active() on windows and x11 (#163)

* X11 implement is_active()

* winapi implement is_active()

Co-authored-by: Antonino Siena <a.siena@gmx.de>
This commit is contained in:
Antonino Siena 2020-04-06 08:21:03 +02:00 committed by GitHub
parent ed24e436f0
commit f97d90b7a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View file

@ -273,6 +273,7 @@ pub struct Window {
scroll_y: f32, scroll_y: f32,
buttons: [u8; 3], buttons: [u8; 3],
prev_cursor: CursorStyle, prev_cursor: CursorStyle,
active: bool,
should_close: bool, // received delete window message from X server should_close: bool, // received delete window message from X server
@ -363,7 +364,8 @@ impl Window {
| xlib::KeyPressMask | xlib::KeyPressMask
| xlib::KeyReleaseMask | xlib::KeyReleaseMask
| xlib::ButtonPressMask | xlib::ButtonPressMask
| xlib::ButtonReleaseMask, | xlib::ButtonReleaseMask
| xlib::FocusChangeMask,
); );
if !opts.resize { if !opts.resize {
@ -416,6 +418,7 @@ impl Window {
buttons: [0, 0, 0], buttons: [0, 0, 0],
prev_cursor: CursorStyle::Arrow, prev_cursor: CursorStyle::Arrow,
should_close: false, should_close: false,
active: false,
key_handler: KeyHandler::new(), key_handler: KeyHandler::new(),
update_rate: UpdateRate::new(), update_rate: UpdateRate::new(),
menu_counter: MenuHandle(0), menu_counter: MenuHandle(0),
@ -633,8 +636,7 @@ impl Window {
#[inline] #[inline]
pub fn is_active(&mut self) -> bool { pub fn is_active(&mut self) -> bool {
// TODO: Proper implementation self.active
true
} }
fn get_scale_factor( fn get_scale_factor(
@ -866,6 +868,12 @@ impl Window {
) )
.expect("todo"); .expect("todo");
} }
xlib::FocusOut => {
self.active = false;
}
xlib::FocusIn => {
self.active = true;
}
_ => {} _ => {}
} }

View file

@ -828,8 +828,17 @@ impl Window {
#[inline] #[inline]
pub fn is_active(&mut self) -> bool { pub fn is_active(&mut self) -> bool {
// TODO: Proper implementation match self.window {
Some(hwnd) => {
let active = unsafe { winapi::um::winuser::GetActiveWindow() };
if !active.is_null() && active == hwnd {
true true
} else {
false
}
}
None => false,
}
} }
unsafe fn get_scale_factor(width: usize, height: usize, scale: Scale) -> i32 { unsafe fn get_scale_factor(width: usize, height: usize, scale: Scale) -> i32 {