Skip to content

Commit

Permalink
Add bevy_window::Window options for MacOS (#15820)
Browse files Browse the repository at this point in the history
# Objective

MacOS has some nice options for controlling the window and titlebar to
make the content appear much more "immersively" in the window. This PR
exposes options for controlling this.

## Solution

Adds new fields to `Window` to control these, with doc comments to
explain what they do and that they're MacOS only.

## Testing

Tested on a MacOS machine (not my own, I don't have one). That's where
the below screenshots were taken.

---

## Showcase

On MacOS, you now have more options for configuring the window titlebar.
You can, for example, make the title bar transparent and only show the
window controls. This provides a more "immersive" experience for your
rendered content.

Before, only this was possible:
<img width="1392" alt="image"
src="https://github.com/user-attachments/assets/abf03da2-d247-4202-a7e7-731c45d80d54">

Now, you can create windows like this:
<img width="1392" alt="image2"
src="https://github.com/user-attachments/assets/3239d0e3-4708-4798-8755-188541e14f93">

This uses the following `bevy_window::Window` settings:
```rs
fullsize_content_view: true,
titlebar_transparent: true,
titlebar_show_title: false,
```

## Migration Guide

`bevy_window::Window` now has extra fields for configuring MacOS window
settings:
```rs
    pub movable_by_window_background: bool,
    pub fullsize_content_view: bool,
    pub has_shadow: bool,
    pub titlebar_shown: bool,
    pub titlebar_transparent: bool,
    pub titlebar_show_title: bool,
    pub titlebar_show_buttons: bool,
```

Using `Window::default` keeps the same behaviour as before.
  • Loading branch information
aecsocket authored Oct 11, 2024
1 parent 81b3946 commit 992d17b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
81 changes: 81 additions & 0 deletions crates/bevy_window/src/window.rs
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

0 comments on commit 992d17b

Please sign in to comment.