From 8a2cfbd13192a662f3227bf16339204028ba334e Mon Sep 17 00:00:00 2001 From: Dixeran Date: Tue, 18 Apr 2023 22:13:25 +0800 Subject: [PATCH] Apply 'with_active' option to winit (#2813) * feat: apply 'with_active' option to winit * fix: remove platform specification - winit accept this option for all platforms * build fix --------- Co-authored-by: Emil Ernerfeldt --- crates/eframe/src/epi.rs | 6 ++++++ crates/eframe/src/native/epi_integration.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 76e7636fd17..0cc5e8ed76a 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -284,6 +284,9 @@ pub struct NativeOptions { /// Generally you would use this in conjunction with always_on_top pub mouse_passthrough: bool, + /// Whether grant focus when window initially opened. True by default. + pub active: bool, + /// Turn on vertical syncing, limiting the FPS to the display refresh rate. /// /// The default is `true`. @@ -421,6 +424,9 @@ impl Default for NativeOptions { resizable: true, transparent: false, mouse_passthrough: false, + + active: true, + vsync: true, multisampling: 0, depth_buffer: 0, diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index fb21e7031a6..d3f40c7468e 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -91,6 +91,7 @@ pub fn window_builder( resizable, transparent, centered, + active, .. } = native_options; @@ -104,6 +105,7 @@ pub fn window_builder( .with_resizable(*resizable) .with_transparent(*transparent) .with_window_icon(window_icon) + .with_active(*active) // Keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279 // We must also keep the window hidden until AccessKit is initialized. .with_visible(false);