mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Merge pull request #769 from frewsxcv/activation-policy
Allow OSX WindowBuilder to specify 'activation behavior'.
This commit is contained in:
commit
2e2febaa42
|
@ -39,7 +39,7 @@ objc = "0.2"
|
||||||
[target.x86_64-apple-darwin.dependencies]
|
[target.x86_64-apple-darwin.dependencies]
|
||||||
objc = "0.2"
|
objc = "0.2"
|
||||||
cgl = "0.1"
|
cgl = "0.1"
|
||||||
cocoa = "0.3"
|
cocoa = "0.3.2"
|
||||||
core-foundation = "0"
|
core-foundation = "0"
|
||||||
core-graphics = "0.3"
|
core-graphics = "0.3"
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ use ReleaseBehavior;
|
||||||
use Robustness;
|
use Robustness;
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
use native_monitor::NativeMonitorId;
|
use native_monitor::NativeMonitorId;
|
||||||
|
use os::macos::ActivationPolicy;
|
||||||
|
|
||||||
use objc::runtime::{Class, Object, Sel, BOOL, YES, NO};
|
use objc::runtime::{Class, Object, Sel, BOOL, YES, NO};
|
||||||
use objc::declare::ClassDecl;
|
use objc::declare::ClassDecl;
|
||||||
|
@ -181,7 +182,9 @@ impl Drop for WindowDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PlatformSpecificWindowBuilderAttributes;
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||||
|
pub activation_policy: ActivationPolicy,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
view: IdRef,
|
view: IdRef,
|
||||||
|
@ -276,7 +279,8 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
pub fn new(win_attribs: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
|
||||||
opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
|
opengl: &GlAttributes<&Window>,
|
||||||
|
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
|
||||||
-> Result<Window, CreationError>
|
-> Result<Window, CreationError>
|
||||||
{
|
{
|
||||||
if opengl.sharing.is_some() {
|
if opengl.sharing.is_some() {
|
||||||
|
@ -294,7 +298,7 @@ impl Window {
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
let app = match Window::create_app() {
|
let app = match Window::create_app(pl_attribs.activation_policy) {
|
||||||
Some(app) => app,
|
Some(app) => app,
|
||||||
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
||||||
};
|
};
|
||||||
|
@ -359,13 +363,13 @@ impl Window {
|
||||||
Ok(window)
|
Ok(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_app() -> Option<id> {
|
fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let app = NSApp();
|
let app = NSApp();
|
||||||
if app == nil {
|
if app == nil {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
|
app.setActivationPolicy_(activation_policy.into());
|
||||||
app.finishLaunching();
|
app.finishLaunching();
|
||||||
Some(app)
|
Some(app)
|
||||||
}
|
}
|
||||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -62,7 +62,7 @@ extern crate wayland_client;
|
||||||
|
|
||||||
pub use events::*;
|
pub use events::*;
|
||||||
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
|
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
|
||||||
pub use window::{WindowBuilder, WindowProxy, PollEventsIterator, WaitEventsIterator};
|
pub use window::{WindowProxy, PollEventsIterator, WaitEventsIterator};
|
||||||
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
pub use window::{AvailableMonitorsIter, MonitorId, get_available_monitors, get_primary_monitor};
|
||||||
pub use native_monitor::NativeMonitorId;
|
pub use native_monitor::NativeMonitorId;
|
||||||
|
|
||||||
|
@ -105,6 +105,21 @@ pub struct Window {
|
||||||
window: platform::Window,
|
window: platform::Window,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Object that allows you to build windows.
|
||||||
|
pub struct WindowBuilder<'a> {
|
||||||
|
/// The attributes to use to create the window.
|
||||||
|
pub window: WindowAttributes,
|
||||||
|
|
||||||
|
/// The attributes to use to create the context.
|
||||||
|
pub opengl: GlAttributes<&'a platform::Window>,
|
||||||
|
|
||||||
|
// Should be made public once it's stabilized.
|
||||||
|
pf_reqs: PixelFormatRequirements,
|
||||||
|
|
||||||
|
/// Platform-specific configuration.
|
||||||
|
platform_specific: platform::PlatformSpecificWindowBuilderAttributes,
|
||||||
|
}
|
||||||
|
|
||||||
/// Trait that describes objects that have access to an OpenGL context.
|
/// Trait that describes objects that have access to an OpenGL context.
|
||||||
pub trait GlContext {
|
pub trait GlContext {
|
||||||
/// Sets the context as the current context.
|
/// Sets the context as the current context.
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#![cfg(target_os = "macos")]
|
#![cfg(target_os = "macos")]
|
||||||
|
|
||||||
|
use std::convert::From;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use Window;
|
use cocoa::appkit::NSApplicationActivationPolicy;
|
||||||
|
use {Window, WindowBuilder};
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to MacOS.
|
/// Additional methods on `Window` that are specific to MacOS.
|
||||||
pub trait WindowExt {
|
pub trait WindowExt {
|
||||||
|
@ -17,3 +19,47 @@ impl WindowExt for Window {
|
||||||
self.window.platform_window() as *mut c_void
|
self.window.platform_window() as *mut c_void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Corresponds to `NSApplicationActivationPolicy`.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub enum ActivationPolicy {
|
||||||
|
/// Corresponds to `NSApplicationActivationPolicyRegular`.
|
||||||
|
Regular,
|
||||||
|
/// Corresponds to `NSApplicationActivationPolicyAccessory`.
|
||||||
|
Accessory,
|
||||||
|
/// Corresponds to `NSApplicationActivationPolicyProhibited`.
|
||||||
|
Prohibited,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ActivationPolicy {
|
||||||
|
fn default() -> Self {
|
||||||
|
ActivationPolicy::Regular
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ActivationPolicy> for NSApplicationActivationPolicy {
|
||||||
|
fn from(activation_policy: ActivationPolicy) -> Self {
|
||||||
|
match activation_policy {
|
||||||
|
ActivationPolicy::Regular =>
|
||||||
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyRegular,
|
||||||
|
ActivationPolicy::Accessory =>
|
||||||
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyAccessory,
|
||||||
|
ActivationPolicy::Prohibited =>
|
||||||
|
NSApplicationActivationPolicy::NSApplicationActivationPolicyProhibited,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Additional methods on `WindowBuilder` that are specific to MacOS.
|
||||||
|
pub trait WindowBuilderExt<'a> {
|
||||||
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder<'a>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> WindowBuilderExt<'a> for WindowBuilder<'a> {
|
||||||
|
/// Sets the activation policy for the window being built
|
||||||
|
#[inline]
|
||||||
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder<'a> {
|
||||||
|
self.platform_specific.activation_policy = activation_policy;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,26 +16,12 @@ use PixelFormatRequirements;
|
||||||
use Robustness;
|
use Robustness;
|
||||||
use Window;
|
use Window;
|
||||||
use WindowAttributes;
|
use WindowAttributes;
|
||||||
|
use WindowBuilder;
|
||||||
use native_monitor::NativeMonitorId;
|
use native_monitor::NativeMonitorId;
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
use platform;
|
use platform;
|
||||||
|
|
||||||
/// Object that allows you to build windows.
|
|
||||||
pub struct WindowBuilder<'a> {
|
|
||||||
/// The attributes to use to create the window.
|
|
||||||
pub window: WindowAttributes,
|
|
||||||
|
|
||||||
/// The attributes to use to create the context.
|
|
||||||
pub opengl: GlAttributes<&'a platform::Window>,
|
|
||||||
|
|
||||||
// Should be made public once it's stabilized.
|
|
||||||
pf_reqs: PixelFormatRequirements,
|
|
||||||
|
|
||||||
/// Platform-specific configuration.
|
|
||||||
platform_specific: platform::PlatformSpecificWindowBuilderAttributes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> WindowBuilder<'a> {
|
impl<'a> WindowBuilder<'a> {
|
||||||
/// Initializes a new `WindowBuilder` with default values.
|
/// Initializes a new `WindowBuilder` with default values.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue