Skip to content

Commit f8292cc

Browse files
authored
Simple Implementation to address #1327 by adding a focused field to the window and related system (#1386)
* Simple Implementation to address #1327 by adding a focused field to the window and related system * Changing Window update function from bevy_window to bevy_winit. * Removing unused imports.
1 parent b39df9a commit f8292cc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/bevy_window/src/window.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct Window {
6464
cursor_visible: bool,
6565
cursor_locked: bool,
6666
cursor_position: Option<Vec2>,
67+
focused: bool,
6768
mode: WindowMode,
6869
#[cfg(target_arch = "wasm32")]
6970
pub canvas: Option<String>,
@@ -152,6 +153,7 @@ impl Window {
152153
cursor_visible: window_descriptor.cursor_visible,
153154
cursor_locked: window_descriptor.cursor_locked,
154155
cursor_position: None,
156+
focused: true,
155157
mode: window_descriptor.mode,
156158
#[cfg(target_arch = "wasm32")]
157159
canvas: window_descriptor.canvas.clone(),
@@ -395,6 +397,12 @@ impl Window {
395397
.push(WindowCommand::SetCursorPosition { position });
396398
}
397399

400+
#[allow(missing_docs)]
401+
#[inline]
402+
pub fn update_focused_status_from_backend(&mut self, focused: bool) {
403+
self.focused = focused;
404+
}
405+
398406
#[allow(missing_docs)]
399407
#[inline]
400408
pub fn update_cursor_position_from_backend(&mut self, cursor_position: Option<Vec2>) {
@@ -418,6 +426,11 @@ impl Window {
418426
pub fn drain_commands(&mut self) -> impl Iterator<Item = WindowCommand> + '_ {
419427
self.command_queue.drain(..)
420428
}
429+
430+
#[inline]
431+
pub fn is_focused(&self) -> bool {
432+
self.focused
433+
}
421434
}
422435

423436
#[derive(Debug, Clone)]

crates/bevy_winit/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
407407
);
408408
}
409409
WindowEvent::Focused(focused) => {
410+
window.update_focused_status_from_backend(focused);
410411
let mut focused_events =
411412
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
412413
focused_events.send(WindowFocused {

0 commit comments

Comments
 (0)