Skip to content

Commit 992d17b

Browse files
authored
Add bevy_window::Window options for MacOS (#15820)
# 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.
1 parent 81b3946 commit 992d17b

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

crates/bevy_window/src/window.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,80 @@ pub struct Window {
314314
///
315315
/// - Only used on iOS.
316316
pub recognize_pan_gesture: Option<(u8, u8)>,
317+
/// Enables click-and-drag behavior for the entire window, not just the titlebar.
318+
///
319+
/// Corresponds to [`WindowAttributesExtMacOS::with_movable_by_window_background`].
320+
///
321+
/// # Platform-specific
322+
///
323+
/// - Only used on macOS.
324+
///
325+
/// [`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
326+
pub movable_by_window_background: bool,
327+
/// Makes the window content appear behind the titlebar.
328+
///
329+
/// Corresponds to [`WindowAttributesExtMacOS::with_fullsize_content_view`].
330+
///
331+
/// For apps which want to render the window buttons on top of the apps
332+
/// itself, this should be enabled along with [`titlebar_transparent`].
333+
///
334+
/// # Platform-specific
335+
///
336+
/// - Only used on macOS.
337+
///
338+
/// [`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
339+
/// [`titlebar_transparent`]: Self::titlebar_transparent
340+
pub fullsize_content_view: bool,
341+
/// Toggles drawing the drop shadow behind the window.
342+
///
343+
/// Corresponds to [`WindowAttributesExtMacOS::with_has_shadow`].
344+
///
345+
/// # Platform-specific
346+
///
347+
/// - Only used on macOS.
348+
///
349+
/// [`WindowAttributesExtMacOS::with_has_shadow`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_has_shadow
350+
pub has_shadow: bool,
351+
/// Toggles drawing the titlebar.
352+
///
353+
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_hidden`].
354+
///
355+
/// # Platform-specific
356+
///
357+
/// - Only used on macOS.
358+
///
359+
/// [`WindowAttributesExtMacOS::with_titlebar_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_hidden
360+
pub titlebar_shown: bool,
361+
/// Makes the titlebar transparent, allowing the app content to appear behind it.
362+
///
363+
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_transparent`].
364+
///
365+
/// # Platform-specific
366+
///
367+
/// - Only used on macOS.
368+
///
369+
/// [`WindowAttributesExtMacOS::with_titlebar_transparent`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_transparent
370+
pub titlebar_transparent: bool,
371+
/// Toggles showing the window title.
372+
///
373+
/// Corresponds to [`WindowAttributesExtMacOS::with_title_hidden`].
374+
///
375+
/// # Platform-specific
376+
///
377+
/// - Only used on macOS.
378+
///
379+
/// [`WindowAttributesExtMacOS::with_title_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_title_hidden
380+
pub titlebar_show_title: bool,
381+
/// Toggles showing the traffic light window buttons.
382+
///
383+
/// Corresponds to [`WindowAttributesExtMacOS::with_titlebar_buttons_hidden`].
384+
///
385+
/// # Platform-specific
386+
///
387+
/// - Only used on macOS.
388+
///
389+
/// [`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
390+
pub titlebar_show_buttons: bool,
317391
}
318392

319393
impl Default for Window {
@@ -348,6 +422,13 @@ impl Default for Window {
348422
recognize_rotation_gesture: false,
349423
recognize_doubletap_gesture: false,
350424
recognize_pan_gesture: None,
425+
movable_by_window_background: false,
426+
fullsize_content_view: false,
427+
has_shadow: true,
428+
titlebar_shown: true,
429+
titlebar_transparent: false,
430+
titlebar_show_title: true,
431+
titlebar_show_buttons: true,
351432
}
352433
}
353434
}

crates/bevy_winit/src/winit_windows.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ impl WinitWindows {
127127
winit_window_attributes.with_skip_taskbar(window.skip_taskbar);
128128
}
129129

130+
#[cfg(target_os = "macos")]
131+
{
132+
use winit::platform::macos::WindowAttributesExtMacOS;
133+
winit_window_attributes = winit_window_attributes
134+
.with_movable_by_window_background(window.movable_by_window_background)
135+
.with_fullsize_content_view(window.fullsize_content_view)
136+
.with_has_shadow(window.has_shadow)
137+
.with_titlebar_hidden(!window.titlebar_shown)
138+
.with_titlebar_transparent(window.titlebar_transparent)
139+
.with_title_hidden(!window.titlebar_show_title)
140+
.with_titlebar_buttons_hidden(!window.titlebar_show_buttons);
141+
}
142+
130143
let display_info = DisplayInfo {
131144
window_physical_resolution: (
132145
window.resolution.physical_width(),

0 commit comments

Comments
 (0)