Back to Home
Tauri v2 Plugin Restores Windows 11 Snap Layouts for Borderless Apps

Tauri v2 Plugin Restores Windows 11 Snap Layouts for Borderless Apps

B
Blizine Admin
·2 min read·0 views
Quick Brief
  • Enables Windows 11 snap layouts in borderless Tauri v2 apps.
  • Plugin tracks HTML element for native overlay display.
  • Simple setup integrates easily into existing projects.
📌Key Points
1Tauri v2 plugin restores Windows 11 snap layout for borderless applications.
2Plugin named tauri-plugin-snap-layout tracks HTML element dimensions.
3It creates a transparent native overlay to trigger Windows 11 functionality.
4Installation requires adding a crate, npm package, and configuring Tauri.
5The plugin is cross-platform safe, with no operations on non-Windows 11 systems.

Restoring Key Windows Functionality

A new plugin called tauri-plugin-snap-layout now allows Tauri v2 applications running in borderless mode to fully utilize Windows 11's native snap layout overlay. This solution addresses a common issue where custom-designed, decoration-free apps on Windows 11 lose access to this essential window management feature.

Bridging the Gap for Custom Interfaces

The developer created this plugin after finding no existing solution that perfectly integrated the Windows 11 snap layout with a sleek, custom application look. It aims to provide a focused fix for applications that disable native window decorations in Tauri, which typically removes the snap layout functionality.

How the Plugin Operates

The plugin works by tracking a specific HTML element ID on the application's frontend to get its dimensions. It then creates a transparent native overlay, effectively tricking Windows 11 into displaying the native snap layout when a user hovers over a custom maximize button. This clever approach ensures that custom UI designs do not compromise core operating system features.

Beyond displaying the overlay, the plugin also intercepts WM_NCHITTEST messages to precisely position the snap layout over the custom button. It handles clicks, acting as a native maximize/restore toggle, and preserves UI states by forwarding hover events to the frontend, forcing CSS :hover states to trigger correctly.

Simple Integration and Cross-Platform Safety

Despite the complex problem it solves, the plugin is designed for straightforward integration into Tauri v2 projects. It operates safely across different platforms, performing no operations on macOS, Linux, or Windows versions older than Windows 11.

  • Add the tauri-plugin-snap-layout crate to your Cargo.toml file.
  • Run npm install tauri-plugin-snap-layout to include the frontend package.
  • Ensure "snap-layout:default" is added to Tauri permissions in default.json.
  • Set "decorations": false in your tauri.conf.json for borderless mode.
  • Initialize the plugin in lib.rs using .plugin(tauri_plugin_snap_layout::init().button_id("your-custom-id").build()).
  • Assign the specified ID to your HTML's custom maximize button element.

Key Points

  • The tauri-plugin-snap-layout enables Windows 11 snap layouts for borderless Tauri v2 apps.
  • It works by creating a transparent native overlay over a custom maximize button.
  • The plugin intercepts WM_NCHITTEST messages and handles mouse events.
  • Installation involves adding a crate, npm package, and configuring Tauri settings.
  • It is designed to perform no operations on macOS, Linux, or older Windows versions.

The Bottom Line

For developers building custom-looking Tauri v2 applications on Windows 11, this plugin offers a crucial fix. It allows for modern, borderless designs without sacrificing the native window management features users expect. This focused solution simplifies development, letting engineers create polished applications more efficiently.

Frequently Asked Questions

What problem does the tauri-plugin-snap-layout solve?
The plugin solves the problem of borderless Tauri v2 applications on Windows 11 losing access to the native snap layout overlay. It allows developers to maintain custom UI designs while retaining this essential window management feature.
How does the tauri-plugin-snap-layout work?
It tracks a specific HTML element ID on the frontend, gets its dimensions, and creates a transparent native overlay. This overlay tricks Windows 11 into displaying the snap layout when a user hovers over a custom maximize button, while also intercepting mouse events and preserving UI states.
Is the tauri-plugin-snap-layout compatible with other operating systems?
The plugin is designed specifically for Windows 11. It performs no operations on macOS, Linux, or Windows versions older than Windows 11, ensuring safe cross-platform compatibility without causing issues on unsupported systems.

📰Dev.to — dev.to

Comments