Add allow_automatic_tabbing task to runtime::window

Co-authored-by: Karolis Ramanauskas <karolisr@gmail.com>
This commit is contained in:
Héctor Ramón Jiménez 2025-11-25 23:13:36 +01:00
parent c1acd8cdda
commit aef64e56b8
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 35 additions and 5 deletions

View file

@ -178,6 +178,11 @@ pub enum Action {
/// Get the logical dimensions of the monitor containing the window with the given [`Id`]. /// Get the logical dimensions of the monitor containing the window with the given [`Id`].
GetMonitorSize(Id, oneshot::Sender<Option<Size>>), GetMonitorSize(Id, oneshot::Sender<Option<Size>>),
/// Set whether the system can automatically organize windows into tabs.
///
/// See https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing
SetAllowAutomaticTabbing(bool),
/// Redraw all the windows. /// Redraw all the windows.
RedrawAll, RedrawAll,
@ -329,7 +334,7 @@ pub fn set_resize_increments<T>(id: Id, increments: Option<Size>) -> Task<T> {
))) )))
} }
/// Get the window's size in logical dimensions. /// Gets the window size in logical dimensions.
pub fn size(id: Id) -> Task<Size> { pub fn size(id: Id) -> Task<Size> {
task::oneshot(move |channel| { task::oneshot(move |channel| {
crate::Action::Window(Action::GetSize(id, channel)) crate::Action::Window(Action::GetSize(id, channel))
@ -401,7 +406,7 @@ pub fn toggle_decorations<T>(id: Id) -> Task<T> {
task::effect(crate::Action::Window(Action::ToggleDecorations(id))) task::effect(crate::Action::Window(Action::ToggleDecorations(id)))
} }
/// Request user attention to the window. This has no effect if the application /// Requests user attention to the window. This has no effect if the application
/// is already focused. How requesting for user attention manifests is platform dependent, /// is already focused. How requesting for user attention manifests is platform dependent,
/// see [`UserAttention`] for details. /// see [`UserAttention`] for details.
/// ///
@ -432,7 +437,7 @@ pub fn set_level<T>(id: Id, level: Level) -> Task<T> {
task::effect(crate::Action::Window(Action::SetLevel(id, level))) task::effect(crate::Action::Window(Action::SetLevel(id, level)))
} }
/// Show the [system menu] at cursor position. /// Shows the [system menu] at cursor position.
/// ///
/// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu /// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu
pub fn show_system_menu<T>(id: Id) -> Task<T> { pub fn show_system_menu<T>(id: Id) -> Task<T> {
@ -487,7 +492,7 @@ pub fn enable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::EnableMousePassthrough(id))) task::effect(crate::Action::Window(Action::EnableMousePassthrough(id)))
} }
/// Disable mouse passthrough for the given window. /// Disables mouse passthrough for the given window.
/// ///
/// This enables mouse events for the window and stops mouse events /// This enables mouse events for the window and stops mouse events
/// from being passed to whatever is underneath. /// from being passed to whatever is underneath.
@ -495,9 +500,18 @@ pub fn disable_mouse_passthrough<Message>(id: Id) -> Task<Message> {
task::effect(crate::Action::Window(Action::DisableMousePassthrough(id))) task::effect(crate::Action::Window(Action::DisableMousePassthrough(id)))
} }
/// Get the logical dimensions of the monitor containing the window with the given [`Id`]. /// Gets the logical dimensions of the monitor containing the window with the given [`Id`].
pub fn monitor_size(id: Id) -> Task<Option<Size>> { pub fn monitor_size(id: Id) -> Task<Option<Size>> {
task::oneshot(move |channel| { task::oneshot(move |channel| {
crate::Action::Window(Action::GetMonitorSize(id, channel)) crate::Action::Window(Action::GetMonitorSize(id, channel))
}) })
} }
/// Sets whether the system can automatically organize windows into tabs.
///
/// See https://developer.apple.com/documentation/appkit/nswindow/1646657-allowsautomaticwindowtabbing
pub fn allow_automatic_tabbing<T>(enabled: bool) -> Task<T> {
task::effect(crate::Action::Window(Action::SetAllowAutomaticTabbing(
enabled,
)))
}

View file

@ -435,6 +435,16 @@ where
self.error = Some(error); self.error = Some(error);
event_loop.exit(); event_loop.exit();
} }
Control::SetAutomaticWindowTabbing(_enabled) => {
#[cfg(target_os = "macos")]
{
use winit::platform::macos::ActiveEventLoopExtMacOS;
event_loop
.set_allows_automatic_window_tabbing(
_enabled,
);
}
}
}, },
_ => { _ => {
break; break;
@ -492,6 +502,7 @@ enum Control {
on_open: oneshot::Sender<window::Id>, on_open: oneshot::Sender<window::Id>,
scale_factor: f32, scale_factor: f32,
}, },
SetAutomaticWindowTabbing(bool),
} }
async fn run_instance<P>( async fn run_instance<P>(
@ -1657,6 +1668,11 @@ fn run_action<'a, P, C>(
let _ = channel.send(size); let _ = channel.send(size);
} }
} }
window::Action::SetAllowAutomaticTabbing(enabled) => {
control_sender
.start_send(Control::SetAutomaticWindowTabbing(enabled))
.expect("Send control action");
}
window::Action::RedrawAll => { window::Action::RedrawAll => {
for (_id, window) in window_manager.iter_mut() { for (_id, window) in window_manager.iter_mut() {
window.raw.request_redraw(); window.raw.request_redraw();