Add WindowBuilder::with_active

Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
Amr Bashir 2023-01-27 07:08:29 +02:00 committed by GitHub
parent 930df0ec45
commit b457329003
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 60 additions and 5 deletions

View file

@ -114,6 +114,9 @@ extern_methods!(
#[sel(makeKeyAndOrderFront:)]
pub fn makeKeyAndOrderFront(&self, sender: Option<&Object>);
#[sel(orderFront:)]
pub fn orderFront(&self, sender: Option<&Object>);
#[sel(miniaturize:)]
pub fn miniaturize(&self, sender: Option<&Object>);

View file

@ -19,6 +19,7 @@ use crate::{
LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size, Size::Logical,
},
error::{ExternalError, NotSupportedError, OsError as RootOsError},
event::WindowEvent,
icon::Icon,
platform::macos::WindowExtMacOS,
platform_impl::platform::{
@ -464,14 +465,20 @@ impl WinitWindow {
// state, since otherwise we'll briefly see the window at normal size
// before it transitions.
if attrs.visible {
// Tightly linked with `app_state::window_activation_hack`
this.makeKeyAndOrderFront(None);
if attrs.active {
// Tightly linked with `app_state::window_activation_hack`
this.makeKeyAndOrderFront(None);
} else {
this.orderFront(None);
}
}
if attrs.maximized {
this.set_maximized(attrs.maximized);
}
delegate.queue_event(WindowEvent::Focused(false));
Ok((this, delegate))
}

View file

@ -406,7 +406,7 @@ impl WinitWindowDelegate {
}
}
fn queue_event(&self, event: WindowEvent<'static>) {
pub(crate) fn queue_event(&self, event: WindowEvent<'static>) {
let event = Event::WindowEvent {
window_id: WindowId(self.window.id()),
event,