Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bevy_window::Window options for MacOS #15820

Merged
merged 2 commits into from
Oct 11, 2024
Merged
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
81 changes: 81 additions & 0 deletions crates/bevy_window/src/window.rs
aecsocket marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,80 @@ pub struct Window {
///
/// - Only used on iOS.
pub recognize_pan_gesture: Option<(u8, u8)>,
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_movable_by_window_background`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_movable_by_window_background`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_movable_by_window_background
pub movable_by_window_background: bool,
/// Makes the window content appear behind the titlebar.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_fullsize_content_view`].
///
/// For apps which want to render the window buttons on top of the apps
/// itself, this should be enabled along with [`titlebar_transparent`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_fullsize_content_view`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_fullsize_content_view
/// [`titlebar_transparent`]: Self::titlebar_transparent
pub fullsize_content_view: bool,
/// Toggles drawing the drop shadow behind the window.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_has_shadow`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_has_shadow`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_has_shadow
pub has_shadow: bool,
/// Toggles drawing the titlebar.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_hidden`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_titlebar_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_hidden
pub titlebar_shown: bool,
/// Makes the titlebar transparent, allowing the app content to appear behind it.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_transparent`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_titlebar_transparent`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_transparent
pub titlebar_transparent: bool,
/// Toggles showing the window title.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_title_hidden`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_title_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_title_hidden
pub titlebar_show_title: bool,
/// Toggles showing the traffic light window buttons.
///
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_buttons_hidden`].
///
/// # Platform-specific
///
/// - Only used on macOS.
///
/// [`WindowAttributesExtMacOS::with_titlebar_buttons_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_buttons_hidden
pub titlebar_show_buttons: bool,
}

impl Default for Window {
Expand Down Expand Up @@ -348,6 +422,13 @@ impl Default for Window {
recognize_rotation_gesture: false,
recognize_doubletap_gesture: false,
recognize_pan_gesture: None,
movable_by_window_background: false,
fullsize_content_view: false,
has_shadow: true,
titlebar_shown: true,
titlebar_transparent: false,
titlebar_show_title: true,
titlebar_show_buttons: true,
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ impl WinitWindows {
winit_window_attributes.with_skip_taskbar(window.skip_taskbar);
}

#[cfg(target_os = "macos")]
{
use winit::platform::macos::WindowAttributesExtMacOS;
winit_window_attributes = winit_window_attributes
.with_movable_by_window_background(window.movable_by_window_background)
.with_fullsize_content_view(window.fullsize_content_view)
.with_has_shadow(window.has_shadow)
.with_titlebar_hidden(!window.titlebar_shown)
.with_titlebar_transparent(window.titlebar_transparent)
.with_title_hidden(!window.titlebar_show_title)
.with_titlebar_buttons_hidden(!window.titlebar_show_buttons);
}

let display_info = DisplayInfo {
window_physical_resolution: (
window.resolution.physical_width(),
Expand Down