tauri-plugin-snap-layout
Platform Support
| Platform | Snap Layout | Mouse Events | Maximize Toggle | Notes |
|---|---|---|---|---|
| Windows 11 | ✅ | Intercepted | ✅ | Full support (build ≥ 22000) |
| Windows 10 | ❌ | Normal | ❌ | Plugin loads, no-op |
| macOS / Linux | ❌ | Normal | ❌ | No-op, compiles cleanly |
Installation
Add the Rust crate to your Tauri app:
# src-tauri/Cargo.toml
[]
= "1.0.0"
Add the JS/TS bindings to your frontend:
# or
Usage
1. Rust — Register the plugin
Register the plugin in your src-tauri/src/lib.rs file:
2. Frontend — Add the button
Give your maximize/snap button the ID you configured in Rust:
Max
No initialisation required. The plugin self-initialises via the injected script when the page loads.
If you're using a bundler and have the package installed:
import { changePadding, changeSnapTarget } from "tauri-plugin-snap-layout";
changeSnapTarget("new-button-id");
changePadding( {left: 0} )
changeSnapTarget needs an existing ID to transfer to and will automatically update bounds based on the target.
changePadding will add or remove the area of the hover zone. If using negative padding it will have a minimum width/height of 1px. If this negative padding extends past the bounds of the button it will continue to move the hover area rather than stop at the bounds of the button. The padding applied is additive, so the below will result in 5 padding on the left, and 3 on all other sides.
changePadding( {left: 2, right: 0, top: 0, bottom: 0, all:3} )
If you need to call it from outside a module context (vanilla JS, inline scripts):
window.changeSnapTarget("new-button-id");
window.changePadding( {left: 0} )
Optional Configuration
You can customize the bounding area, cursor, and debug mode via the Rust builder:
init
.button_id
.padding_left
.padding_right
.padding_top
.padding_bottom
.padding_all
// defaults to SnapCursor::Arrow if undefined
.cursor
// set true to show a debug overlay
.display
.debug_color
.build
CSS Hover State
Because the native overlay intercepts pointer events, :hover CSS will not fire on your button naturally. The plugin automatically mirrors any :hover rules it finds for your button into an .is-hovered class, which it applies when the native window detects cursor entry. You can also write .is-hovered styles directly:
}
Permissions (Tauri v2)
If your app uses Tauri v2's strict permission system, ensure your app's capabilities allow the plugin to update bounds:
Programmatic Detach (Rust only)
If you need to programmatically destroy the native Win32 child window while the parent window remains open, you can use the SnapExt trait:
use SnapExt;
// Detaches the native snap zone from the specified window
window.snap.detach_snap_zone?;
Troubleshooting
If you see __SNAP_BUTTON_ID__ is not defined in the console, add the
following to your vite.config.ts to prevent Vite from caching the plugin:
export default defineConfig({
optimizeDeps: {
exclude: ["tauri-plugin-snap-layout"],
},
});
Credits
Inspired by and originally derived from:
- tauri-plugin-frame by clarifei
- tauri-plugin-decorum by Siddharth
License
MIT — see LICENSE