Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions winit-android/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,16 @@ impl CoreWindow for Window {
PhysicalInsets::new(0, 0, 0, 0)
}

fn min_surface_size(&self) -> Option<PhysicalSize<u32>> {
None
}

fn set_min_surface_size(&self, _: Option<Size>) {}

fn max_surface_size(&self) -> Option<PhysicalSize<u32>> {
None
}

fn set_max_surface_size(&self, _: Option<Size>) {}

fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
Expand All @@ -888,8 +896,16 @@ impl CoreWindow for Window {

fn set_title(&self, _title: &str) {}

fn is_transparent(&self) -> bool {
false
}

fn set_transparent(&self, _transparent: bool) {}

fn is_blurred(&self) -> bool {
false
}

fn set_blur(&self, _blur: bool) {}

fn set_visible(&self, _visibility: bool) {}
Expand Down Expand Up @@ -936,8 +952,16 @@ impl CoreWindow for Window {
true
}

fn window_level(&self) -> WindowLevel {
WindowLevel::default()
}

fn set_window_level(&self, _level: WindowLevel) {}

fn window_icon(&self) -> Option<winit_core::icon::Icon> {
None
}

fn set_window_icon(&self, _window_icon: Option<winit_core::icon::Icon>) {}

fn set_ime_cursor_area(&self, _position: Position, _size: Size) {}
Expand Down Expand Up @@ -977,6 +1001,10 @@ impl CoreWindow for Window {

fn request_user_attention(&self, _request_type: Option<window::UserAttentionType>) {}

fn cursor(&self) -> Cursor {
Cursor::default()
}

fn set_cursor(&self, _: Cursor) {}

fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> {
Expand Down Expand Up @@ -1010,6 +1038,10 @@ impl CoreWindow for Window {
None
}

fn content_protected(&self) -> bool {
false
}

fn set_content_protected(&self, _protected: bool) {}

fn has_focus(&self) -> bool {
Expand Down
34 changes: 33 additions & 1 deletion winit-appkit/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::sync::Arc;

use dispatch2::MainThreadBound;
use dpi::{Position, Size};
use dpi::{PhysicalSize, Position, Size};
use objc2::rc::{autoreleasepool, Retained};
use objc2::{define_class, MainThreadMarker, Message};
use objc2_app_kit::{NSPanel, NSResponder, NSWindow};
Expand Down Expand Up @@ -141,10 +141,18 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.safe_area())
}

fn min_surface_size(&self) -> Option<PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.min_surface_size())
}

fn set_min_surface_size(&self, min_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_min_surface_size(min_size))
}

fn max_surface_size(&self) -> Option<PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.max_surface_size())
}

fn set_max_surface_size(&self, max_size: Option<Size>) {
self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
}
Expand All @@ -161,10 +169,18 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_title(title));
}

fn is_transparent(&self) -> bool {
self.maybe_wait_on_main(|delegate| delegate.is_transparent())
}

fn set_transparent(&self, transparent: bool) {
self.maybe_wait_on_main(|delegate| delegate.set_transparent(transparent));
}

fn is_blurred(&self) -> bool {
self.maybe_wait_on_main(|delegate| delegate.is_blurred())
}

fn set_blur(&self, blur: bool) {
self.maybe_wait_on_main(|delegate| delegate.set_blur(blur));
}
Expand Down Expand Up @@ -225,10 +241,18 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.is_decorated())
}

fn window_level(&self) -> WindowLevel {
self.maybe_wait_on_main(|delegate| delegate.window_level())
}

fn set_window_level(&self, level: WindowLevel) {
self.maybe_wait_on_main(|delegate| delegate.set_window_level(level));
}

fn window_icon(&self) -> Option<Icon> {
self.maybe_wait_on_main(|delegate| delegate.window_icon())
}

fn set_window_icon(&self, window_icon: Option<Icon>) {
self.maybe_wait_on_main(|delegate| delegate.set_window_icon(window_icon));
}
Expand Down Expand Up @@ -261,6 +285,10 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.theme())
}

fn content_protected(&self) -> bool {
self.maybe_wait_on_main(|delegate| delegate.content_protected())
}

fn set_content_protected(&self, protected: bool) {
self.maybe_wait_on_main(|delegate| delegate.set_content_protected(protected));
}
Expand All @@ -269,6 +297,10 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.title())
}

fn cursor(&self) -> Cursor {
self.maybe_wait_on_main(|delegate| delegate.cursor())
}

fn set_cursor(&self, cursor: Cursor) {
self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor));
}
Expand Down
62 changes: 62 additions & 0 deletions winit-appkit/src/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,10 @@ impl WindowDelegate {
self.window().setTitle(&NSString::from_str(title))
}

pub fn is_transparent(&self) -> bool {
unsafe { !self.window().isOpaque() }
}

pub fn set_transparent(&self, transparent: bool) {
// This is just a hint for Quartz, it doesn't actually speculate with window alpha.
// Providing a wrong value here could result in visual artifacts, when the window is
Expand All @@ -954,6 +958,12 @@ impl WindowDelegate {
self.window().setBackgroundColor(Some(&color));
}

pub fn is_blurred(&self) -> bool {
// What API would we use to get this? `CGSGetWindowBackgroundBlurRadius` doesn't exist.
warn!("getting the background blur of the window is not supported on macOS");
false
}

pub fn set_blur(&self, blur: bool) {
// NOTE: in general we want to specify the blur radius, but the choice of 80
// should be a reasonable default.
Expand Down Expand Up @@ -1073,6 +1083,14 @@ impl WindowDelegate {
None
}

pub fn min_surface_size(&self) -> Option<PhysicalSize<u32>> {
let size = unsafe { self.window().contentMinSize() };
if size == NSSize::ZERO {
return None;
}
Some(LogicalSize::new(size.width, size.height).to_physical(self.scale_factor()))
}

pub fn set_min_surface_size(&self, dimensions: Option<Size>) {
let dimensions =
dimensions.unwrap_or(Size::Logical(LogicalSize { width: 0.0, height: 0.0 }));
Expand All @@ -1092,6 +1110,15 @@ impl WindowDelegate {
self.window().setContentSize(current_size);
}

pub fn max_surface_size(&self) -> Option<PhysicalSize<u32>> {
let size = unsafe { self.window().contentMaxSize() };
// AppKit sets the max size to f32::MAX by default.
if size == NSSize::new(f32::MAX as _, f32::MAX as _) {
return None;
}
Some(LogicalSize::new(size.width, size.height).to_physical(self.scale_factor()))
}

pub fn set_max_surface_size(&self, dimensions: Option<Size>) {
let dimensions = dimensions.unwrap_or(Size::Logical(LogicalSize {
width: f32::MAX as f64,
Expand Down Expand Up @@ -1213,6 +1240,11 @@ impl WindowDelegate {
buttons
}

pub fn cursor(&self) -> Cursor {
warn!("getting the cursor is unimplemented on macOS");
Cursor::default()
}

pub fn set_cursor(&self, cursor: Cursor) {
let view = self.view();

Expand Down Expand Up @@ -1643,6 +1675,20 @@ impl WindowDelegate {
self.ivars().decorations.get()
}

pub fn window_level(&self) -> WindowLevel {
let level = unsafe { self.window().level() };
if level == kCGFloatingWindowLevel as NSWindowLevel {
WindowLevel::AlwaysOnTop
} else if level == (kCGNormalWindowLevel - 1) as NSWindowLevel {
WindowLevel::AlwaysOnBottom
} else if level == kCGNormalWindowLevel as NSWindowLevel {
WindowLevel::Normal
} else {
warn!(?level, "cannot determine window level, it must've been set outside of Winit");
WindowLevel::default()
}
}

#[inline]
pub fn set_window_level(&self, level: WindowLevel) {
// Note: There are two different things at play here:
Expand All @@ -1662,6 +1708,11 @@ impl WindowDelegate {
self.window().setLevel(level);
}

#[inline]
pub fn window_icon(&self) -> Option<Icon> {
None
}

#[inline]
pub fn set_window_icon(&self, _icon: Option<Icon>) {
// macOS doesn't have window icons. Though, there is
Expand Down Expand Up @@ -1815,6 +1866,17 @@ impl WindowDelegate {
unsafe { self.window().setAppearance(theme_to_appearance(theme).as_deref()) };
}

pub fn content_protected(&self) -> bool {
match unsafe { self.window().sharingType() } {
NSWindowSharingType::None => true,
NSWindowSharingType::ReadOnly => false,
sharing_type => {
warn!(?sharing_type, "unknown sharing type");
false
},
}
}

#[inline]
pub fn set_content_protected(&self, protected: bool) {
self.window().setSharingType(if protected {
Expand Down
Loading
Loading