Implemented focus_window (#1944)

This commit is contained in:
Max de Danschutter 2021-05-19 18:39:53 +02:00 committed by GitHub
parent 91591c4e94
commit b371b406d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 107 additions and 0 deletions

View file

@ -685,6 +685,20 @@ impl Window {
pub fn theme(&self) -> Theme {
self.window_state.lock().current_theme
}
#[inline]
pub fn focus_window(&self) {
let window = self.window.clone();
let window_flags = self.window_state.lock().window_flags();
let is_visible = window_flags.contains(WindowFlags::VISIBLE);
let is_minimized = window_flags.contains(WindowFlags::MINIMIZED);
let is_foreground = window.0 == unsafe { winuser::GetForegroundWindow() };
if is_visible && !is_minimized && !is_foreground {
unsafe { force_window_active(window.0) };
}
}
}
impl Drop for Window {