npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tauri-plugin-snap-layout

v1.0.4

Published

Windows 11 snap layout helper plugin for Tauri v2

Readme

tauri-plugin-snap-layout

Platform Support

| Platform | Snap Layout | Multi-Window | Toggle (Attach/Detach) | Notes | | ------------- | ----------- | ------------ | ---------------------- | ---------------------------- | | Windows 11 | ✅ | ✅ Full | ✅ Native & Frontend | Full support (build ≥ 22000) | | Windows 10 | ❌ | ❌ No-op | ❌ Safe Fallback | Plugin loads cleanly; all APIs callable, no effect | | macOS / Linux | ❌ | ❌ No-op | ❌ Safe Fallback | No-op, compiles cleanly |

Installation

Add the Rust crate to your Tauri app:

# src-tauri/Cargo.toml
[dependencies]
tauri-plugin-snap-layout = "1"

Add the JS/TS bindings to your frontend:

npm install tauri-plugin-snap-layout
# or
pnpm add tauri-plugin-snap-layout
# or your preferred package manager

Usage

1. Rust — Register the plugin and prepare required options.

Register the plugin in your src-tauri/src/lib.rs file:

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(
            tauri_plugin_snap_layout::init()
                .button_id("snap-btn")
                .build()
        )
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Set decorations to false in your src-tauri/tauri.conf.json file. This is done in the "windows" section.

"app": {
    "windows": [
      {
        "decorations": false
      }
    ],
  },

Add this permission to your src-tauri/capabilities/default.json.

{
  "permissions": ["snap-layout:default"]
}

2. Frontend — Add the button

Give your maximize/snap button the ID you configured in the rust setup stage:

<button id="snap-btn">Max</button>

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, changeTarget, attach, detach, isAttached } from "tauri-plugin-snap-layout";

// Swap targetted button dynamically
changeTarget("new-button-id");

// Temporarily remove the Snap Zone by destroying the overlay area.
await detach();

// Re-enable the snap area, you can set a new target here as well.
attach("optional-new-target");

// Change padding
changePadding( {} );

// Get attached state
isAttached();

changeTarget 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.

Padding fields are set, not accumulated — each call overwrites the previous passed fields. all acts as a baseline that can combine with per-side values at render time. The example below results in 5 on the left and 3 on all other sides.

changePadding( {left: 2, right: 0, top: 0, bottom: 0, all:3} );

The options available are left, right, top, bottom, all.

If you need to call it from outside a module context (vanilla JS, inline scripts):

window.changeTarget("new-button-id");
window.changePadding( {} );
window.detach();
window.attach();
window.isAttached();

Note: attach, detach, and isAttached are common names that could conflict with other libraries. In complex apps, prefer the namespaced window.__SNAP_LAYOUT_ATTACH__ variants instead.

The same fields apply to changePadding as above.

Optional Configuration

You can customize the bounding area, cursor, and debug mode via the Rust builder:

tauri_plugin_snap_layout::init()
    .button_id("snap-btn")
    .padding_left(0)
    .padding_right(0)
    .padding_top(0)
    .padding_bottom(0)
    .padding_all(0)
    // defaults to SnapCursor::Arrow if undefined
    .cursor(tauri_plugin_snap_layout::SnapCursor::Hand)
    // set true to show a debug overlay
    .display(false)
    .debug_color("rgba(255, 0, 0, 0.2)")
    .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:

#snap-btn:hover,
#snap-btn.is-hovered {
  background: rgba(255, 255, 255, 0.1);
}

Programmatic Window Management & Multi-Window Support

Multi-window applications are supported. Initialization scripts run globally across all webviews and the Rust backend uses explicit WebviewWindow instances, every open window isolates its own tracking loops and native Win32 child bounds. If you need to alter or toggle the snap zones in Rust, you can use the SnapExt extension trait on any window handle:

use tauri_plugin_snap_layout::SnapExt;

#[tauri::command]
fn manage_window_overlays(window: tauri::WebviewWindow) -> Result<(), tauri_plugin_snap_layout::Error> {
    // Remove the native Win32 child overlay on this window and stop tracking.
    window.snap().detach(&window)?;

    // Recreate overlay and resume tracking.
    window.snap().attach(&window)?;
    
    Ok(())
}

Troubleshooting

If you see something along these lines __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"],
  },
});

How it works

The plugin creates an invisible native Win32 child HWND positioned over your button. This child window returns HTMAXBUTTON from WM_NCHITTEST, which is the correct native path for triggering Windows 11's Snap Layout popup on frameless and borderless windows — no keyboard simulation or input injection.

Credits

Inspired by and originally derived from:

License

MIT — see LICENSE