mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 13:31:29 +11:00
On macOS, add documentEdited APIs (#2550)
* On macOS, add documentEdited APIs
Port of 33fdeab629
* Update src/platform/macos.rs
Co-authored-by: Mads Marquart <mads@marquart.dk>
* typo
Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
6d0cf6a275
commit
f77f858e9b
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On macOS, add `WindowExtMacOS::is_document_edited` and `WindowExtMacOS::set_document_edited` APIs.
|
||||||
- **Breaking:** Removed `WindowBuilderExtIOS::with_root_view_class`; instead, you should use `[[view layer] addSublayer: ...]` to add an instance of the desired layer class (e.g. `CAEAGLLayer` or `CAMetalLayer`). See `vulkano-win` or `wgpu` for examples of this.
|
- **Breaking:** Removed `WindowBuilderExtIOS::with_root_view_class`; instead, you should use `[[view layer] addSublayer: ...]` to add an instance of the desired layer class (e.g. `CAEAGLLayer` or `CAMetalLayer`). See `vulkano-win` or `wgpu` for examples of this.
|
||||||
- On MacOS and Windows, add `Window::set_content_protected`.
|
- On MacOS and Windows, add `Window::set_content_protected`.
|
||||||
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
|
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
|
||||||
|
|
|
@ -36,6 +36,25 @@ pub trait WindowExtMacOS {
|
||||||
|
|
||||||
/// Sets whether or not the window has shadow.
|
/// Sets whether or not the window has shadow.
|
||||||
fn set_has_shadow(&self, has_shadow: bool);
|
fn set_has_shadow(&self, has_shadow: bool);
|
||||||
|
|
||||||
|
/// Get the window's edit state.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// WindowEvent::CloseRequested => {
|
||||||
|
/// if window.is_document_edited() {
|
||||||
|
/// // Show the user a save pop-up or similar
|
||||||
|
/// } else {
|
||||||
|
/// // Close the window
|
||||||
|
/// drop(window);
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
fn is_document_edited(&self) -> bool;
|
||||||
|
|
||||||
|
/// Put the window in a state which indicates a file save is required.
|
||||||
|
fn set_document_edited(&self, edited: bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowExtMacOS for Window {
|
impl WindowExtMacOS for Window {
|
||||||
|
@ -68,6 +87,16 @@ impl WindowExtMacOS for Window {
|
||||||
fn set_has_shadow(&self, has_shadow: bool) {
|
fn set_has_shadow(&self, has_shadow: bool) {
|
||||||
self.window.set_has_shadow(has_shadow)
|
self.window.set_has_shadow(has_shadow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn is_document_edited(&self) -> bool {
|
||||||
|
self.window.is_document_edited()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn set_document_edited(&self, edited: bool) {
|
||||||
|
self.window.set_document_edited(edited)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Corresponds to `NSApplicationActivationPolicy`.
|
/// Corresponds to `NSApplicationActivationPolicy`.
|
||||||
|
|
|
@ -168,6 +168,9 @@ extern_methods!(
|
||||||
#[sel(setLevel:)]
|
#[sel(setLevel:)]
|
||||||
pub fn setLevel(&self, level: NSWindowLevel);
|
pub fn setLevel(&self, level: NSWindowLevel);
|
||||||
|
|
||||||
|
#[sel(setDocumentEdited:)]
|
||||||
|
pub fn setDocumentEdited(&self, val: bool);
|
||||||
|
|
||||||
#[sel(occlusionState)]
|
#[sel(occlusionState)]
|
||||||
pub fn occlusionState(&self) -> NSWindowOcclusionState;
|
pub fn occlusionState(&self) -> NSWindowOcclusionState;
|
||||||
|
|
||||||
|
@ -186,6 +189,9 @@ extern_methods!(
|
||||||
#[sel(isZoomed)]
|
#[sel(isZoomed)]
|
||||||
pub fn isZoomed(&self) -> bool;
|
pub fn isZoomed(&self) -> bool;
|
||||||
|
|
||||||
|
#[sel(isDocumentEdited)]
|
||||||
|
pub fn isDocumentEdited(&self) -> bool;
|
||||||
|
|
||||||
#[sel(close)]
|
#[sel(close)]
|
||||||
pub fn close(&self);
|
pub fn close(&self);
|
||||||
|
|
||||||
|
|
|
@ -1229,6 +1229,14 @@ impl WindowExtMacOS for WinitWindow {
|
||||||
fn set_has_shadow(&self, has_shadow: bool) {
|
fn set_has_shadow(&self, has_shadow: bool) {
|
||||||
self.setHasShadow(has_shadow)
|
self.setHasShadow(has_shadow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_document_edited(&self) -> bool {
|
||||||
|
self.isDocumentEdited()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_document_edited(&self, edited: bool) {
|
||||||
|
self.setDocumentEdited(edited)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn get_ns_theme() -> Theme {
|
pub(super) fn get_ns_theme() -> Theme {
|
||||||
|
|
Loading…
Reference in a new issue