Porting a Slint UI Rust desktop application from Windows to macOS

After releasing my first Rust desktop application PitchGrid Continuum Bridge for Windows, I worked out that, If I wanted a Mac version, I would have to buy my first Mac and implement it myself. So I bought a Mac Mini, which is great if you are primarily a Windows user. I naively expected that the app would immediately run on macOS with no problems. Actually, of the five full days of heavily LLM-assisted effort that ended with the production of the macOS installer, most consisted in getting the app to work properly on the Mac, with the rest to do with the development of the installer.

The problems were entirely to do with the Slint-based GUI. Everything else worked flawlessly. My experience may be of use to others. The following are the specific GUI problems I had to fix on the Mac.

Stop the application title bar from being transparent.

This took two LLMs about 6 attempts, with one LLM giving up and claiming that transparent title bars were normal in macOS!

15 lines of code, excluding comments: see main.install_solid_title_bar_platform.

Stop Cmd+Q, the standard close app keyboard shortcut, from functioning as an abort / forced shutdown, skipping required main window close processing.

That behaviour is not standard for macOS apps; it's just how Slint has chosen to implement it.

39+ lines of code, including 14 in Object C: see main.init_ui_handlers.

Setting window position

For Windows, physical co-ordinates must be specified to set a window's location on the screen(s). For macOS, it's logical co-ordinates.

27 lines of code: see main.perform_close, ui_methods.set_main_window_position.

Application Icon

This was apparently inevitable. In macOS, it seems application icons are really associations in the operating system with the app rather than part of the app. At least with my app, they are configured in the app bundle, which you need to run in order to see the icon in the dock and application switch list.

1 line of code: see Cargo.toml. Also scripting a way for the bundle to be run from the IDE.

Comparison

By way of comparison, after I ported the Rust app to macOS, I ported a .NET application with Avalonia UI. Physical window coordinates worked for both Windows and macOS. The following were the only UI changes required.

  • The inevitable special processing for the application icon, 88 lines of code but not requiring a bundle to be run.
  • The Windows app uses hotkey shortcuts, those underlined letters on controls that you press with the Alt key down. In macOS, the letters are underlined, but there is no keyboard shortcut, such as Option+underlined letter. Hotkeys are not idiomatic in macOS, which is perhaps why it was not implemented. I developed a compromise approach, Cmd+underlined letter for macOS, Alt+underlined letter for Windows.

Possible points for discussion

Are there better fixes than those the LLMs made for me? I suspect I could have got the application icon working without having to run the bundle but, as in the .Net fix, it surely would have been much more complicated.

Why do physical coordinates for window positions not work for macOS in Slint/Rust, when it's not an issue in Avalonia/.Net? Is there way to make that work? I wonder whether this is a limitation of winit, the Rust library used by Slint and other UI libraries, rather than of Slint itself.

Now that I've fixed the Slint interoperability problems in one app, I'll probably stick with Slint for future cross-platform desktop Rust applications. However, you may wish to recommend or warn against other Rust UI libraries from the perspective of cross-platform desktop development.