Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ impl WindowState {
)
};
}
WindowTask::Focus => unsafe {
SetFocus(self.hwnd);
},
}
}
}
Expand All @@ -597,6 +600,8 @@ pub(super) enum WindowTask {
/// Resize the window to the given size. The size is in logical pixels. DPI scaling is applied
/// automatically.
Resize(Size),
/// Request keyboard focus for the window.
Focus,
}

pub struct Window<'a> {
Expand Down Expand Up @@ -828,9 +833,9 @@ impl Window<'_> {
}

pub fn focus(&mut self) {
unsafe {
SetFocus(self.state.hwnd);
}
// To avoid reentrant event handler calls we'll defer the actual focus request until after
// the event has been handled
self.state.deferred_tasks.borrow_mut().push_back(WindowTask::Focus);
}

pub fn resize(&mut self, size: Size) {
Expand Down
Loading