Skip to content

Commit

Permalink
Simple Implementation to address #1327 by adding a focused field to t…
Browse files Browse the repository at this point in the history
…he 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.
  • Loading branch information
huhlig authored Feb 13, 2021
1 parent b39df9a commit f8292cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct Window {
cursor_visible: bool,
cursor_locked: bool,
cursor_position: Option<Vec2>,
focused: bool,
mode: WindowMode,
#[cfg(target_arch = "wasm32")]
pub canvas: Option<String>,
Expand Down Expand Up @@ -152,6 +153,7 @@ impl Window {
cursor_visible: window_descriptor.cursor_visible,
cursor_locked: window_descriptor.cursor_locked,
cursor_position: None,
focused: true,
mode: window_descriptor.mode,
#[cfg(target_arch = "wasm32")]
canvas: window_descriptor.canvas.clone(),
Expand Down Expand Up @@ -395,6 +397,12 @@ impl Window {
.push(WindowCommand::SetCursorPosition { position });
}

#[allow(missing_docs)]
#[inline]
pub fn update_focused_status_from_backend(&mut self, focused: bool) {
self.focused = focused;
}

#[allow(missing_docs)]
#[inline]
pub fn update_cursor_position_from_backend(&mut self, cursor_position: Option<Vec2>) {
Expand All @@ -418,6 +426,11 @@ impl Window {
pub fn drain_commands(&mut self) -> impl Iterator<Item = WindowCommand> + '_ {
self.command_queue.drain(..)
}

#[inline]
pub fn is_focused(&self) -> bool {
self.focused
}
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ pub fn winit_runner_with(mut app: App, mut event_loop: EventLoop<()>) {
);
}
WindowEvent::Focused(focused) => {
window.update_focused_status_from_backend(focused);
let mut focused_events =
app.resources.get_mut::<Events<WindowFocused>>().unwrap();
focused_events.send(WindowFocused {
Expand Down

0 comments on commit f8292cc

Please sign in to comment.