Skip to content

Commit e1a8af4

Browse files
committed
Platform: add bring-all-to-front() function
Adds `Platform.bring-all-to-front()` to the Slint language, lowered to a new `BuiltinFunction::BringAllToFront` via the platform-lowering pass. On macOS the function calls `[NSApp arrangeInFront:]` via a free function in `i-slint-core`, using the `objc2-app-kit` dependency that was already present for the system tray. On all other platforms it is a no-op. Public-language API only — no `slint::Window::bring_all_to_front()`, no `WindowAdapter` trait method, and no language-binding wrappers. The C FFI entry point (`slint_bring_all_to_front`) is private_api, used only by generated C++ code. Addresses the review feedback from PR #11692: - ogoffart: remove from WindowAdapter trait, implement as free function in i-slint-core using objc2-app-kit directly - ogoffart: no public Rust/C++/JS Window::bring_all_to_front() API - Both reviewers: split into its own PR (orthogonal to minimize/maximize/close)
1 parent 7bd380d commit e1a8af4

12 files changed

Lines changed: 81 additions & 0 deletions

File tree

api/cpp/include/slint.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ inline bool open_url(const SharedString &url, const WindowAdapterRc &window_adap
349349
return cbindgen_private::slint_open_url(&url, &window_adapter.handle());
350350
}
351351

352+
inline void bring_all_to_front()
353+
{
354+
cbindgen_private::slint_bring_all_to_front();
355+
}
356+
352357
inline SharedString translate_from_bundle(std::span<const char8_t *const> strs,
353358
cbindgen_private::Slice<SharedString> arguments)
354359
{

api/cpp/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ pub unsafe extern "C" fn slint_open_url(
276276
i_slint_core::open_url(url, window_adapter.window()).is_ok()
277277
}
278278

279+
#[unsafe(no_mangle)]
280+
pub extern "C" fn slint_bring_all_to_front() {
281+
i_slint_core::bring_all_to_front()
282+
}
283+
279284
#[unsafe(no_mangle)]
280285
pub extern "C" fn slint_string_to_styled_text(text: &SharedString, out: &mut StyledText) {
281286
*out = i_slint_core::styled_text::string_to_styled_text(text.to_string());

api/rs/slint/private_unstable_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub mod re_exports {
198198
};
199199
pub use i_slint_core::menus::{Menu, MenuFromItemTree, MenuVTable};
200200
pub use i_slint_core::model::*;
201+
pub use i_slint_core::bring_all_to_front;
201202
pub use i_slint_core::open_url;
202203
pub use i_slint_core::properties::{
203204
ChangeTracker, Property, PropertyTracker, StateInfo, set_state_binding,

internal/compiler/builtins.slint

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,13 @@ export global Platform {
25622562
/// }
25632563
/// ```
25642564
function open-url(url: string) -> bool { return false; }
2565+
/// Brings all application windows to the front of the screen.
2566+
///
2567+
/// On macOS this invokes `[NSApp arrangeInFront:]`, which raises every application window
2568+
/// to the top of the window stack. On other platforms this function is a no-op.
2569+
///
2570+
/// This corresponds to the standard macOS **Window › Bring All to Front** menu item.
2571+
function bring-all-to-front() { }
25652572
}
25662573

25672574
export component NativeButton {

internal/compiler/expression_tree.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pub enum BuiltinFunction {
123123
StopTimer,
124124
RestartTimer,
125125
OpenUrl,
126+
BringAllToFront,
126127
ParseMarkdown,
127128
StringToStyledText,
128129
}
@@ -303,6 +304,7 @@ declare_builtin_function_types!(
303304
ParseMarkdown: (Type::String, Type::Array(Type::StyledText.into())) -> Type::StyledText,
304305
StringToStyledText: (Type::String) -> Type::StyledText
305306
OpenUrl: (Type::String) -> Type::Bool,
307+
BringAllToFront: () -> Type::Void,
306308
);
307309

308310
impl Default for BuiltinFunctionTypes {
@@ -412,6 +414,7 @@ impl BuiltinFunction {
412414
BuiltinFunction::ParseMarkdown => false,
413415
BuiltinFunction::StringToStyledText => true,
414416
BuiltinFunction::OpenUrl => false,
417+
BuiltinFunction::BringAllToFront => false,
415418
}
416419
}
417420

@@ -497,6 +500,7 @@ impl BuiltinFunction {
497500
BuiltinFunction::ParseMarkdown => true,
498501
BuiltinFunction::StringToStyledText => true,
499502
BuiltinFunction::OpenUrl => false,
503+
BuiltinFunction::BringAllToFront => false,
500504
}
501505
}
502506
}

internal/compiler/generator/cpp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,6 +4926,9 @@ fn compile_builtin_function_call(
49264926
let window = access_window_field(ctx);
49274927
format!("slint::private_api::open_url({url}, {window})")
49284928
}
4929+
BuiltinFunction::BringAllToFront => {
4930+
"slint::private_api::bring_all_to_front()".to_owned()
4931+
}
49294932
BuiltinFunction::ParseMarkdown => {
49304933
let format_string = a.next().unwrap();
49314934
let args = a.next().unwrap();

internal/compiler/generator/rust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,6 +4142,9 @@ fn compile_builtin_function_call(
41424142
let window_adapter_tokens = access_window_adapter_field(ctx);
41434143
quote!(sp::open_url(&#url, #window_adapter_tokens.window()).is_ok())
41444144
}
4145+
BuiltinFunction::BringAllToFront => {
4146+
quote!(sp::bring_all_to_front())
4147+
}
41454148
BuiltinFunction::ParseMarkdown => {
41464149
let format_string = a.next().unwrap();
41474150
let args = a.next().unwrap();

internal/compiler/llr/optim_passes/inline_expressions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
167167
BuiltinFunction::ParseMarkdown => isize::MAX,
168168
BuiltinFunction::StringToStyledText => ALLOC_COST,
169169
BuiltinFunction::OpenUrl => isize::MAX,
170+
BuiltinFunction::BringAllToFront => isize::MAX,
170171
}
171172
}
172173

internal/compiler/passes/lower_platform.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ pub fn lower_platform(component: &Rc<Component>, type_loader: &mut crate::typelo
3434
{
3535
*function = BuiltinFunction::OpenUrl.into();
3636
}
37+
Expression::FunctionCall { function, .. }
38+
if matches!(&*function, Callable::Function(nr)
39+
if is_platform(nr) && nr.name() == "bring-all-to-front") =>
40+
{
41+
*function = BuiltinFunction::BringAllToFront.into();
42+
}
3743
_ => {}
3844
})
3945
})

internal/core/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,14 @@ pub fn is_apple_platform() -> bool {
175175
pub fn open_url(url: &str, window: &crate::api::Window) -> Result<(), crate::api::PlatformError> {
176176
crate::window::WindowInner::from_pub(window).context().platform().open_url(url)
177177
}
178+
179+
#[cfg(target_os = "macos")]
180+
pub fn bring_all_to_front() {
181+
use objc2::MainThreadMarker;
182+
use objc2_app_kit::NSApplication;
183+
let Some(mtm) = MainThreadMarker::new() else { return };
184+
NSApplication::sharedApplication(mtm).arrangeInFront(None);
185+
}
186+
187+
#[cfg(not(target_os = "macos"))]
188+
pub fn bring_all_to_front() {}

0 commit comments

Comments
 (0)