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 Aug 3, 2024
1 parent 90f068f commit 99c14c8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 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,
}
25 changes: 24 additions & 1 deletion winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use futures::channel::mpsc;

use std::mem::ManuallyDrop;
use std::sync::Arc;
use winit::event_loop::EventLoop;

Check warning on line 28 in winit/src/application.rs

View workflow job for this annotation

GitHub Actions / wasm

unused import: `winit::event_loop::EventLoop`
use iced_runtime::command::Action;
use winit::monitor::MonitorHandle;

Expand Down Expand Up @@ -116,9 +117,31 @@ where
let mut debug = Debug::new();
debug.startup_started();

let event_loop = EventLoopBuilder::with_user_event()
let mut event_loop_builder = EventLoopBuilder::with_user_event();

#[cfg(target_os = "macos")]
let event_loop_builder = {
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};

let macos_settings = settings.window.platform_specific;

let activation_policy = match macos_settings.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 = macos_settings.activate_ignoring_other_apps;

event_loop_builder
.with_activation_policy(activation_policy)
.with_activate_ignoring_other_apps(activate_ignoring_other_apps)
};

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

let proxy = event_loop.create_proxy();

let runtime = {
Expand Down

0 comments on commit 99c14c8

Please sign in to comment.