mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-26 07:11:31 +11:00
7e1c70964d
* macOS: Move the window if there is no title bar On macOS by default windows can only be moved by clicking and dragging on the titlebar, if we spawn a window without one we need to set the `movableByWindowBackground` property. Partial fix for #368 * macOS: Make moveByWindowBackground optional Implements setting the property via WindowBuilderExt: WindowBuilder::new() .with_decorations(false) .with_movable_by_window_background(true) * Update CHANGELOG
97 lines
3.1 KiB
Rust
Executable file
97 lines
3.1 KiB
Rust
Executable file
#![cfg(target_os = "macos")]
|
|
|
|
use std::convert::From;
|
|
use std::os::raw::c_void;
|
|
use cocoa::appkit::NSApplicationActivationPolicy;
|
|
use {MonitorId, Window, WindowBuilder};
|
|
|
|
/// Additional methods on `Window` that are specific to MacOS.
|
|
pub trait WindowExt {
|
|
/// Returns a pointer to the cocoa `NSWindow` that is used by this window.
|
|
///
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
|
fn get_nswindow(&self) -> *mut c_void;
|
|
|
|
/// Returns a pointer to the cocoa `NSView` that is used by this window.
|
|
///
|
|
/// The pointer will become invalid when the `Window` is destroyed.
|
|
fn get_nsview(&self) -> *mut c_void;
|
|
}
|
|
|
|
impl WindowExt for Window {
|
|
#[inline]
|
|
fn get_nswindow(&self) -> *mut c_void {
|
|
self.window.get_nswindow()
|
|
}
|
|
|
|
#[inline]
|
|
fn get_nsview(&self) -> *mut c_void {
|
|
self.window.get_nsview()
|
|
}
|
|
}
|
|
|
|
/// 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 {
|
|
fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder;
|
|
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder;
|
|
}
|
|
|
|
impl WindowBuilderExt for WindowBuilder {
|
|
/// Sets the activation policy for the window being built
|
|
#[inline]
|
|
fn with_activation_policy(mut self, activation_policy: ActivationPolicy) -> WindowBuilder {
|
|
self.platform_specific.activation_policy = activation_policy;
|
|
self
|
|
}
|
|
|
|
/// Enables click-and-drag behavior for the entire window, not just the titlebar
|
|
#[inline]
|
|
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> WindowBuilder {
|
|
self.platform_specific.movable_by_window_background = movable_by_window_background;
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Additional methods on `MonitorId` that are specific to MacOS.
|
|
pub trait MonitorIdExt {
|
|
/// Returns the identifier of the monitor for Cocoa.
|
|
fn native_id(&self) -> u32;
|
|
}
|
|
|
|
impl MonitorIdExt for MonitorId {
|
|
#[inline]
|
|
fn native_id(&self) -> u32 {
|
|
self.inner.get_native_identifier()
|
|
}
|
|
}
|