Tauri Plugin polygon
A plugin for tauri@v2 to achieve click-through of the tauri main window by allowing developers to define polygons, thus customizing the mouse response area.
Note that this plugin is only available for
full-screen(normallytransparent background) applications.
Platform Supported
| Platform | Supported |
|---|---|
| Windows | ✅ |
| Linux | ✅ |
| macOS | ✅ |
| Android | ❌ |
| iOS | ❌ |
Install
Before using the library, you may need to learn more information about tauri.
# You need to create a tauri project first
# and then
# You may need to `cd src-tauri` first
Usage
Go with examples.
Configuration
Before using this plugin, we need to make some changes to tauri.conf.json, html and src-tauri\capabilities\default.json, so that we can build a full-screen and transparent background application, and invoke commands from the JS context.
// tauri.conf.json
"app": {
"windows": [
{
// ...
"alwaysOnTop": true,
"transparent": true,
"fullscreen": true
// ...
}
]
},
<!-- index.html -->
// src-tauri\capabilities\default.json
{
// ...
"windows": ["main"],
"permissions": [
// ...
// Depends on your needs
"polygon:allow-register",
"polygon:allow-register-all",
"polygon:allow-show",
"polygon:allow-hide",
"polygon:allow-remove",
"polygon:allow-update",
"polygon:allow-clear"
]
// ...
}
Initialization
use AppHandle;
Call from Rust
Learn more api about tauri-plugin-polygon.
Example
use AppHandle;
use PolygonExt;
Call from Javascript
Example
import from 'tauri-plugin-polygon-api';
const SOME_ID = "my-polygon";
polygon.;
polygon.
Notice:
- Events would be emmitd to
webviewand theclosure(provided in init function)mouse eventtriggered in unregistered areas. As for registered areas, handle it by frendend itself.- Position from 0 to 1, 0.1 means 10% of the
screen(which is fullscreen as we set before)width.- Order of points matters.
- We can get the actual(logical) position by
window.screen.width * position.xandwindow.screen.width * position.y.