Skip to content

Commit

Permalink
Expose macOS ActivationPolicy and activate_ignoring_other_apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Jul 26, 2024
1 parent 555ee3e commit a06e0f5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/src/window/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ mod platform;
use crate::window::{Icon, Level, Position};
use crate::Size;

#[cfg(target_os = "macos")]
pub use platform::ActivationPolicy;

pub use platform::PlatformSpecific;

/// The window settings of an application.
#[derive(Debug, Clone)]
pub struct Settings {
Expand Down
33 changes: 32 additions & 1 deletion core/src/window/settings/macos.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
//! Platform specific settings for macOS.

/// The platform specific window settings of an application.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PlatformSpecific {
/// Hides the window title.
pub title_hidden: bool,
/// Makes the titlebar transparent and allows the content to appear behind it.
pub titlebar_transparent: bool,
/// Makes the window content appear behind the titlebar.
pub fullsize_content_view: bool,
/// Activation policy for the application.
pub activation_policy: ActivationPolicy,
/// Used to prevent the application from automatically activating when launched if
/// another application is already active.
///
/// The default behavior is to ignore other applications and activate when launched.
pub activate_ignoring_other_apps: bool,
}

impl Default for PlatformSpecific {
fn default() -> Self {
Self {
title_hidden: false,
titlebar_transparent: false,
fullsize_content_view: false,
activation_policy: Default::default(), // Regular
activate_ignoring_other_apps: true,
}
}
}

/// Corresponds to `NSApplicationActivationPolicy`.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ActivationPolicy {
/// Corresponds to `NSApplicationActivationPolicyRegular`.
#[default]
Regular,
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
Accessory,
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
Prohibited,
}
38 changes: 35 additions & 3 deletions winit/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,41 @@ where
let mut debug = Debug::new();
debug.startup_started();

let event_loop = EventLoop::with_user_event()
.build()
.expect("Create event loop");
let mut event_loop_builder = EventLoop::with_user_event();

#[cfg(target_os = "macos")]
let mut event_loop_builder = {

Check failure on line 193 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / all (macOS-latest, stable)

variable does not need to be mutable

Check failure on line 193 in winit/src/program.rs

View workflow job for this annotation

GitHub Actions / all (macOS-latest, beta)

variable does not need to be mutable
use winit::platform::macos::{
ActivationPolicy, EventLoopBuilderExtMacOS,
};

if let Some(window_settings) = &window_settings {
let activation_policy =
match window_settings.platform_specific.activation_policy {
window::settings::ActivationPolicy::Regular => {
ActivationPolicy::Regular
}
window::settings::ActivationPolicy::Accessory => {
ActivationPolicy::Accessory
}
window::settings::ActivationPolicy::Prohibited => {
ActivationPolicy::Prohibited
}
};

let activate_ignoring_other_apps = window_settings
.platform_specific
.activate_ignoring_other_apps;

event_loop_builder
.with_activation_policy(activation_policy)
.with_activate_ignoring_other_apps(activate_ignoring_other_apps)
} else {
&mut event_loop_builder
}
};

let event_loop = event_loop_builder.build().expect("Create event loop");

let (proxy, worker) = Proxy::new(event_loop.create_proxy());

Expand Down

0 comments on commit a06e0f5

Please sign in to comment.