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

@ -1,5 +1,7 @@
//! Handling of various keyboard events.
use std::sync::atomic::Ordering;
use sctk::reexports::client::protocol::wl_keyboard::KeyState;
use sctk::seat::keyboard::Event as KeyboardEvent;
@ -22,6 +24,9 @@ pub(super) fn handle_keyboard(
KeyboardEvent::Enter { surface, .. } => {
let window_id = wayland::make_wid(&surface);
let window_handle = winit_state.window_map.get_mut(&window_id).unwrap();
window_handle.has_focus.store(true, Ordering::Relaxed);
// Window gained focus.
event_sink.push_window_event(WindowEvent::Focused(true), window_id);
@ -44,6 +49,9 @@ pub(super) fn handle_keyboard(
);
}
let window_handle = winit_state.window_map.get_mut(&window_id).unwrap();
window_handle.has_focus.store(false, Ordering::Relaxed);
// Window lost focus.
event_sink.push_window_event(WindowEvent::Focused(false), window_id);