Fix eframe window not being focused on mac on startup (#7593)
* Workaround for https://github.com/rust-windowing/winit/issues/4371 * Closes https://github.com/emilk/egui/issues/7588 Tested manually
This commit is contained in:
parent
78fffc7707
commit
ab461f4115
|
|
@ -775,8 +775,21 @@ impl GlowWinitRunning<'_> {
|
|||
let mut repaint_asap = false;
|
||||
|
||||
match event {
|
||||
winit::event::WindowEvent::Focused(new_focused) => {
|
||||
glutin.focused_viewport = new_focused.then(|| viewport_id).flatten();
|
||||
winit::event::WindowEvent::Focused(focused) => {
|
||||
let focused = if cfg!(target_os = "macos")
|
||||
&& let Some(viewport_id) = viewport_id
|
||||
&& let Some(viewport) = glutin.viewports.get(&viewport_id)
|
||||
&& let Some(window) = &viewport.window
|
||||
{
|
||||
// TODO(emilk): remove this work-around once we update winit
|
||||
// https://github.com/rust-windowing/winit/issues/4371
|
||||
// https://github.com/emilk/egui/issues/7588
|
||||
window.has_focus()
|
||||
} else {
|
||||
*focused
|
||||
};
|
||||
|
||||
glutin.focused_viewport = focused.then_some(viewport_id).flatten();
|
||||
}
|
||||
|
||||
winit::event::WindowEvent::Resized(physical_size) => {
|
||||
|
|
|
|||
|
|
@ -775,8 +775,21 @@ impl WgpuWinitRunning<'_> {
|
|||
let mut repaint_asap = false;
|
||||
|
||||
match event {
|
||||
winit::event::WindowEvent::Focused(new_focused) => {
|
||||
shared.focused_viewport = new_focused.then(|| viewport_id).flatten();
|
||||
winit::event::WindowEvent::Focused(focused) => {
|
||||
let focused = if cfg!(target_os = "macos")
|
||||
&& let Some(viewport_id) = viewport_id
|
||||
&& let Some(viewport) = shared.viewports.get(&viewport_id)
|
||||
&& let Some(window) = &viewport.window
|
||||
{
|
||||
// TODO(emilk): remove this work-around once we update winit
|
||||
// https://github.com/rust-windowing/winit/issues/4371
|
||||
// https://github.com/emilk/egui/issues/7588
|
||||
window.has_focus()
|
||||
} else {
|
||||
*focused
|
||||
};
|
||||
|
||||
shared.focused_viewport = focused.then_some(viewport_id).flatten();
|
||||
}
|
||||
|
||||
winit::event::WindowEvent::Resized(physical_size) => {
|
||||
|
|
|
|||
|
|
@ -423,10 +423,19 @@ impl State {
|
|||
}
|
||||
}
|
||||
WindowEvent::Focused(focused) => {
|
||||
self.egui_input.focused = *focused;
|
||||
let focused = if cfg!(target_os = "macos") {
|
||||
// TODO(emilk): remove this work-around once we update winit
|
||||
// https://github.com/rust-windowing/winit/issues/4371
|
||||
// https://github.com/emilk/egui/issues/7588
|
||||
window.has_focus()
|
||||
} else {
|
||||
*focused
|
||||
};
|
||||
|
||||
self.egui_input.focused = focused;
|
||||
self.egui_input
|
||||
.events
|
||||
.push(egui::Event::WindowFocused(*focused));
|
||||
.push(egui::Event::WindowFocused(focused));
|
||||
EventResponse {
|
||||
repaint: true,
|
||||
consumed: false,
|
||||
|
|
|
|||
Loading…
Reference in New Issue