async_winit/platform/
macos.rs1#[doc(inline)]
25pub use winit::platform::macos::{ActivationPolicy, OptionAsAlt};
26
27use winit::platform::macos::{EventLoopBuilderExtMacOS as _, WindowExtMacOS as _};
28
29use std::os::raw::c_void;
30
31use super::__private as sealed;
32use crate::event_loop::EventLoopBuilder;
33use crate::window::{Window, WindowBuilder};
34use crate::ThreadSafety;
35
36pub trait WindowExtMacOS: sealed::WindowPrivate {
40 fn ns_window(&self) -> *mut c_void;
44
45 fn ns_view(&self) -> *mut c_void;
49
50 fn simple_fullscreen(&self) -> bool;
52
53 fn set_simple_fullscreen(&self, fullscreen: bool) -> bool;
61
62 fn has_shadow(&self) -> bool;
64
65 fn set_has_shadow(&self, has_shadow: bool);
67
68 fn is_document_edited(&self) -> bool;
83
84 fn set_document_edited(&self, edited: bool);
86
87 fn set_option_as_alt(&self, option_as_alt: OptionAsAlt);
94
95 fn option_as_alt(&self) -> OptionAsAlt;
97}
98
99impl<TS: ThreadSafety> WindowExtMacOS for Window<TS> {
100 fn ns_view(&self) -> *mut c_void {
101 self.window().ns_view()
102 }
103
104 fn ns_window(&self) -> *mut c_void {
105 self.window().ns_window()
106 }
107
108 fn simple_fullscreen(&self) -> bool {
109 self.window().simple_fullscreen()
110 }
111
112 fn set_simple_fullscreen(&self, fullscreen: bool) -> bool {
113 self.window().set_simple_fullscreen(fullscreen)
114 }
115
116 fn has_shadow(&self) -> bool {
117 self.window().has_shadow()
118 }
119
120 fn set_has_shadow(&self, has_shadow: bool) {
121 self.window().set_has_shadow(has_shadow)
122 }
123
124 fn is_document_edited(&self) -> bool {
125 self.window().is_document_edited()
126 }
127
128 fn set_document_edited(&self, edited: bool) {
129 self.window().set_document_edited(edited)
130 }
131
132 fn set_option_as_alt(&self, option_as_alt: OptionAsAlt) {
133 self.window().set_option_as_alt(option_as_alt)
134 }
135
136 fn option_as_alt(&self) -> OptionAsAlt {
137 self.window().option_as_alt()
138 }
139}
140
141pub trait WindowBuilderExtMacOS: sealed::WindowBuilderPrivate {
152 fn with_movable_by_window_background(self, movable_by_window_background: bool)
154 -> WindowBuilder;
155 fn with_titlebar_transparent(self, titlebar_transparent: bool) -> WindowBuilder;
157 fn with_title_hidden(self, title_hidden: bool) -> WindowBuilder;
159 fn with_titlebar_hidden(self, titlebar_hidden: bool) -> WindowBuilder;
161 fn with_titlebar_buttons_hidden(self, titlebar_buttons_hidden: bool) -> WindowBuilder;
163 fn with_fullsize_content_view(self, fullsize_content_view: bool) -> WindowBuilder;
165 fn with_disallow_hidpi(self, disallow_hidpi: bool) -> WindowBuilder;
166 fn with_has_shadow(self, has_shadow: bool) -> WindowBuilder;
167 fn with_accepts_first_mouse(self, accepts_first_mouse: bool) -> WindowBuilder;
169
170 fn with_option_as_alt(self, option_as_alt: OptionAsAlt) -> WindowBuilder;
174}
175
176impl WindowBuilderExtMacOS for WindowBuilder {
177 fn with_accepts_first_mouse(mut self, accepts_first_mouse: bool) -> WindowBuilder {
178 self.platform.accepts_first_mouse = Some(accepts_first_mouse);
179 self
180 }
181
182 fn with_movable_by_window_background(
183 mut self,
184 movable_by_window_background: bool,
185 ) -> WindowBuilder {
186 self.platform.movable_by_window_background = Some(movable_by_window_background);
187 self
188 }
189
190 fn with_disallow_hidpi(mut self, disallow_hidpi: bool) -> WindowBuilder {
191 self.platform.disallow_hidpi = Some(disallow_hidpi);
192 self
193 }
194
195 fn with_has_shadow(mut self, has_shadow: bool) -> WindowBuilder {
196 self.platform.has_shadow = Some(has_shadow);
197 self
198 }
199
200 fn with_fullsize_content_view(mut self, fullsize_content_view: bool) -> WindowBuilder {
201 self.platform.fullsize_content_view = Some(fullsize_content_view);
202 self
203 }
204
205 fn with_titlebar_buttons_hidden(mut self, titlebar_buttons_hidden: bool) -> WindowBuilder {
206 self.platform.titlebar_buttons_hidden = Some(titlebar_buttons_hidden);
207 self
208 }
209
210 fn with_titlebar_hidden(mut self, titlebar_hidden: bool) -> WindowBuilder {
211 self.platform.titlebar_hidden = Some(titlebar_hidden);
212 self
213 }
214
215 fn with_option_as_alt(mut self, option_as_alt: OptionAsAlt) -> WindowBuilder {
216 self.platform.option_as_alt = Some(option_as_alt);
217 self
218 }
219
220 fn with_title_hidden(mut self, title_hidden: bool) -> WindowBuilder {
221 self.platform.title_hidden = Some(title_hidden);
222 self
223 }
224
225 fn with_titlebar_transparent(mut self, titlebar_transparent: bool) -> WindowBuilder {
226 self.platform.titlebar_transparent = Some(titlebar_transparent);
227 self
228 }
229}
230
231pub trait EventLoopBuilderExtMacOS: sealed::EventLoopBuilderPrivate {
235 fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self;
256
257 fn with_default_menu(&mut self, enable: bool) -> &mut Self;
278
279 fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self;
284}
285
286impl EventLoopBuilderExtMacOS for EventLoopBuilder {
287 fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self {
288 self.inner.with_activate_ignoring_other_apps(ignore);
289 self
290 }
291
292 fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self {
293 self.inner.with_activation_policy(activation_policy);
294 self
295 }
296
297 fn with_default_menu(&mut self, enable: bool) -> &mut Self {
298 self.inner.with_default_menu(enable);
299 self
300 }
301}
302
303#[derive(Default)]
304pub(crate) struct PlatformSpecific {
305 movable_by_window_background: Option<bool>,
306 titlebar_transparent: Option<bool>,
307 title_hidden: Option<bool>,
308 titlebar_hidden: Option<bool>,
309 titlebar_buttons_hidden: Option<bool>,
310 fullsize_content_view: Option<bool>,
311 disallow_hidpi: Option<bool>,
312 has_shadow: Option<bool>,
313 accepts_first_mouse: Option<bool>,
314 option_as_alt: Option<OptionAsAlt>,
315}
316
317impl PlatformSpecific {
318 pub(crate) fn apply_to(
319 self,
320 mut wb: winit::window::WindowBuilder,
321 ) -> winit::window::WindowBuilder {
322 use winit::platform::macos::WindowBuilderExtMacOS as _;
323
324 if let Some(movable_by_window_background) = self.movable_by_window_background {
325 wb = wb.with_movable_by_window_background(movable_by_window_background);
326 }
327
328 if let Some(titlebar_transparent) = self.titlebar_transparent {
329 wb = wb.with_titlebar_transparent(titlebar_transparent);
330 }
331
332 if let Some(title_hidden) = self.title_hidden {
333 wb = wb.with_title_hidden(title_hidden);
334 }
335
336 if let Some(titlebar_hidden) = self.titlebar_hidden {
337 wb = wb.with_titlebar_hidden(titlebar_hidden);
338 }
339
340 if let Some(titlebar_buttons_hidden) = self.titlebar_buttons_hidden {
341 wb = wb.with_titlebar_buttons_hidden(titlebar_buttons_hidden);
342 }
343
344 if let Some(fullsize_content_view) = self.fullsize_content_view {
345 wb = wb.with_fullsize_content_view(fullsize_content_view);
346 }
347
348 if let Some(disallow_hidpi) = self.disallow_hidpi {
349 wb = wb.with_disallow_hidpi(disallow_hidpi);
350 }
351
352 if let Some(has_shadow) = self.has_shadow {
353 wb = wb.with_has_shadow(has_shadow);
354 }
355
356 if let Some(accepts_first_mouse) = self.accepts_first_mouse {
357 wb = wb.with_accepts_first_mouse(accepts_first_mouse);
358 }
359
360 if let Some(option_as_alt) = self.option_as_alt {
361 wb = wb.with_option_as_alt(option_as_alt);
362 }
363
364 wb
365 }
366}