Skip to content
Tauri

Positioner

Position your windows at well-known locations.

This plugin is a port of electron-positioner for Tauri.

Supported Platforms

  • Windows
  • Linux
  • macOS

Setup

This plugin requires a Rust version of at least 1.75

Install the positioner plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add positioner

Additional setup is required to get tray-relative positions to work.

  1. Add tray-icon feature to your Cargo.toml file:

    src-tauri/Cargo.toml
    [dependencies]
    tauri-plugin-positioner = { version = "2.0.0-beta", features = ["tray-icon"] }
  2. Setup on_tray_event for positioner plugin:

    src-tauri/src/lib.rs
    fn run() {
    tauri::Builder::default()
    .plugin(tauri_plugin_positioner::init())
    // This is required to get tray-relative positions to work
    .setup(|app| {
    TrayIconBuilder::new()
    .on_tray_icon_event(|app, event| {
    tauri_plugin_positioner::on_tray_event(app.app_handle(), &event);
    })
    .build(app)?;
    Ok(())
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
    }

Usage

The plugin’s APIs are available through the JavaScript guest bindings:

import { moveWindow, Position } from '@tauri-apps/plugin-positioner';
moveWindow(Position.TopRight);

You can import and use the Window trait extension directly through Rust:

use tauri_plugin_positioner::{WindowExt, Position};
let mut win = app.get_webview_window("main").unwrap();
let _ = win.as_ref().window().move_window(Position::TopRight);

Permissions

By default all plugin commands are blocked and cannot be accessed. You must define a list of permissions in your capabilities configuration.

See Permissions Overview for more information.

src-tauri/capabilities/main.json
{
"permissions": [
...,
"positioner:default",
]
}
PermissionDescription
positioner:allow-move-windowEnables the move_window command without any pre-configured scope.
positioner:deny-move-windowDenies the move_window command without any pre-configured scope.
positioner:defaultAllows the move_window command.

© 2024 Tauri Contributors. CC-BY / MIT