On Windows and MacOS, add Window::has_focus

This commit is contained in:
Amr Bashir 2023-01-17 03:30:14 +02:00 committed by GitHub
parent 067535eb38
commit a88d2e079d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 102 additions and 2 deletions

View file

@ -930,6 +930,10 @@ impl<T: 'static> EventProcessor<T> {
let window_id = mkwid(xev.event);
let position = PhysicalPosition::new(xev.event_x, xev.event_y);
if let Some(window) = self.with_window(xev.event, Arc::clone) {
window.shared_state_lock().has_focus = true;
}
callback(Event::WindowEvent {
window_id,
event: Focused(true),
@ -1002,6 +1006,10 @@ impl<T: 'static> EventProcessor<T> {
event: WindowEvent::ModifiersChanged(ModifiersState::empty()),
});
if let Some(window) = self.with_window(xev.event, Arc::clone) {
window.shared_state_lock().has_focus = false;
}
callback(Event::WindowEvent {
window_id,
event: Focused(false),

View file

@ -55,6 +55,7 @@ pub struct SharedState {
pub resize_increments: Option<Size>,
pub base_size: Option<Size>,
pub visibility: Visibility,
pub has_focus: bool,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@ -94,6 +95,7 @@ impl SharedState {
max_inner_size: None,
resize_increments: None,
base_size: None,
has_focus: true,
})
}
}
@ -1602,6 +1604,10 @@ impl UnownedWindow {
}
#[inline]
pub fn has_focus(&self) -> bool {
self.shared_state_lock().has_focus
}
pub fn title(&self) -> String {
String::new()
}