mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 13:31:29 +11:00
[macos] add NSWindow.hasShadow support (#1637)
* [macos] add NSWindow.hasShadow * change log * cargo fmt * Update CHANGELOG.md * Update src/platform_impl/macos/window.rs * Update src/platform/macos.rs * set_has_shadow() with cuter format * adjust code * cargo fmt * changelog
This commit is contained in:
parent
68100102be
commit
514ab043f2
|
@ -15,6 +15,7 @@
|
|||
- On Android, `set_fullscreen` is now a no-op instead of a runtime crash.
|
||||
- On iOS and Android, `set_inner_size` is now a no-op instead of a runtime crash.
|
||||
- On Android, fix `ControlFlow::Poll` not polling the Android event queue.
|
||||
- On macOS, add `NSWindow.hasShadow` support.
|
||||
- **Breaking:** On Web, `set_cursor_position` and `set_cursor_grab` will now always return an error.
|
||||
- **Breaking:** `PixelDelta` scroll events now return a `PhysicalPosition`.
|
||||
|
||||
|
|
|
@ -56,6 +56,12 @@ pub trait WindowExtMacOS {
|
|||
/// And allows the user to have a fullscreen window without using another
|
||||
/// space or taking control over the entire monitor.
|
||||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool;
|
||||
|
||||
/// Returns whether or not the window has shadow.
|
||||
fn has_shadow(&self) -> bool;
|
||||
|
||||
/// Sets whether or not the window has shadow.
|
||||
fn set_has_shadow(&self, has_shadow: bool);
|
||||
}
|
||||
|
||||
impl WindowExtMacOS for Window {
|
||||
|
@ -83,6 +89,16 @@ impl WindowExtMacOS for Window {
|
|||
fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
|
||||
self.window.set_simple_fullscreen(fullscreen)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn has_shadow(&self) -> bool {
|
||||
self.window.has_shadow()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_has_shadow(&self, has_shadow: bool) {
|
||||
self.window.set_has_shadow(has_shadow)
|
||||
}
|
||||
}
|
||||
|
||||
/// Corresponds to `NSApplicationActivationPolicy`.
|
||||
|
@ -131,6 +147,7 @@ pub trait WindowBuilderExtMacOS {
|
|||
/// Build window with `resizeIncrements` property. Values must not be 0.
|
||||
fn with_resize_increments(self, increments: LogicalSize<f64>) -> WindowBuilder;
|
||||
fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
|
||||
fn with_has_shadow(self, has_shadow: bool) -> WindowBuilder;
|
||||
}
|
||||
|
||||
impl WindowBuilderExtMacOS for WindowBuilder {
|
||||
|
@ -190,6 +207,12 @@ impl WindowBuilderExtMacOS for WindowBuilder {
|
|||
self.platform_specific.disallow_hidpi = disallow_hidpi;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn with_has_shadow(mut self, has_shadow: bool) -> WindowBuilder {
|
||||
self.platform_specific.has_shadow = has_shadow;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Additional methods on `MonitorHandle` that are specific to MacOS.
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn get_window_id(window_cocoa_id: id) -> Id {
|
|||
Id(window_cocoa_id as *const Object as _)
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone)]
|
||||
pub struct PlatformSpecificWindowBuilderAttributes {
|
||||
pub activation_policy: ActivationPolicy,
|
||||
pub movable_by_window_background: bool,
|
||||
|
@ -71,6 +71,25 @@ pub struct PlatformSpecificWindowBuilderAttributes {
|
|||
pub fullsize_content_view: bool,
|
||||
pub resize_increments: Option<LogicalSize<f64>>,
|
||||
pub disallow_hidpi: bool,
|
||||
pub has_shadow: bool,
|
||||
}
|
||||
|
||||
impl Default for PlatformSpecificWindowBuilderAttributes {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
activation_policy: Default::default(),
|
||||
movable_by_window_background: false,
|
||||
titlebar_transparent: false,
|
||||
title_hidden: false,
|
||||
titlebar_hidden: false,
|
||||
titlebar_buttons_hidden: false,
|
||||
fullsize_content_view: false,
|
||||
resize_increments: None,
|
||||
disallow_hidpi: false,
|
||||
has_shadow: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_app(activation_policy: ActivationPolicy) -> Option<id> {
|
||||
|
@ -224,6 +243,10 @@ fn create_window(
|
|||
}
|
||||
}
|
||||
|
||||
if !pl_attrs.has_shadow {
|
||||
ns_window.setHasShadow_(NO);
|
||||
}
|
||||
|
||||
ns_window.center();
|
||||
ns_window
|
||||
});
|
||||
|
@ -1094,6 +1117,19 @@ impl WindowExtMacOS for UnownedWindow {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn has_shadow(&self) -> bool {
|
||||
unsafe { self.ns_window.hasShadow() == YES }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_has_shadow(&self, has_shadow: bool) {
|
||||
unsafe {
|
||||
self.ns_window
|
||||
.setHasShadow_(if has_shadow { YES } else { NO })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for UnownedWindow {
|
||||
|
|
Loading…
Reference in a new issue