Skip to content

Commit

Permalink
Notify widgets of window focus change
Browse files Browse the repository at this point in the history
  • Loading branch information
ForLoveOfCats committed Oct 21, 2021
1 parent 0c0851f commit 1434138
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions druid/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ impl<T: Data, W: Widget<T>> WidgetPod<T, W> {
}
true
}
Event::WindowFocus(_) => true,
Event::WindowSize(_) => {
self.state.needs_layout = true;
ctx.is_root
Expand Down
3 changes: 3 additions & 0 deletions druid/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub enum Event {
/// This event means the window *will* go away; it is safe to dispose of resources and
/// do any other cleanup.
WindowDisconnected,
/// Called when window focus changes.
WindowFocus(bool),
/// Called on the root widget when the window size changes.
///
/// Discussion: it's not obvious this should be propagated to user
Expand Down Expand Up @@ -431,6 +433,7 @@ impl Event {
Event::WindowConnected
| Event::WindowCloseRequested
| Event::WindowDisconnected
| Event::WindowFocus(_)
| Event::WindowSize(_)
| Event::Timer(_)
| Event::AnimFrame(_)
Expand Down
8 changes: 8 additions & 0 deletions druid/src/win_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,14 @@ impl<T: Data> WinHandler for DruidHandler<T> {

fn got_focus(&mut self) {
self.app_state.window_got_focus(self.window_id);

let event = Event::WindowFocus(true);
self.app_state.do_window_event(event, self.window_id);
}

fn lost_focus(&mut self) {
let event = Event::WindowFocus(false);
self.app_state.do_window_event(event, self.window_id);
}

fn timer(&mut self, token: TimerToken) {
Expand Down

0 comments on commit 1434138

Please sign in to comment.