Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Siddharth <siddharth99c@gmail.com>"]
description = "Opnionated window decoration controls for Tauri apps."
edition = "2021"
rust-version = "1.70"
exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"]
exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
links = "tauri-plugin-decorum"
license = "MIT"
homepage = "https://github.com/clearlysid/tauri-plugin-decorum"
Expand All @@ -15,10 +15,12 @@ repository = "https://github.com/clearlysid/tauri-plugin-decorum"
tauri = { version = "2.0.0-rc" }
serde = "1.0"
anyhow = "1.0"
parking_lot = "0.12.3"
serde_json = "1.0.127"

[target.'cfg(target_os = "macos")'.dependencies]
rand = "^0.8"
cocoa = "0.25"
cocoa = "0.26"
objc = "0.2"

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ You'll need to set these for your window in `src-tauri/capabilities/default.json
"core:window:allow-start-dragging",
"core:window:allow-toggle-maximize",
"decorum:allow-show-snap-overlay",
"decorum:allow-set-window-buttons-inset",
```

And ensure the `withGlobalTauri` in your `tauri.conf.json` is set to `true`.
Expand All @@ -44,7 +45,7 @@ And ensure the `withGlobalTauri` in your `tauri.conf.json` is set to `true`.
```rust
use tauri::Manager;

use tauri_plugin_decorum::WebviewWindowExt; // adds helper methods to WebviewWindow
use tauri_plugin_decorum::{WebviewWindowExt, NSWindowLevel};

fn main() {
tauri::Builder::default()
Expand All @@ -58,15 +59,20 @@ fn main() {

// Some macOS-specific helpers
#[cfg(target_os = "macos")] {
// Set a custom inset to the traffic lights
main_window.set_traffic_lights_inset(12.0, 16.0).unwrap();

// Make window transparent without privateApi
main_window.make_transparent().unwrap()

use tauri_plugin_decorum::NSWindowLevel;

// Set window level
// NSWindowLevel: https://developer.apple.com/documentation/appkit/nswindowlevel
main_window.set_window_level(25).unwrap()
let _ = main_window.set_window_level(NSWindowLevel::NSStatusWindowLevel);

// Set a custom inset to the traffic lights
let _ = main_window.set_window_buttons_inset(Some(LogicalPosition::new(12.0, 16.0)));

// Applies transparency to the webview.
// Note that this still uses internal/private APIs.
// This differs from Tauri's implementation as it doesn't make the window itself transparent
// Allowing for shadows to be enabled without artifacts or large performance hits.
let _ = main_window.apply_transparency();
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const COMMANDS: &[&str] = &["show_snap_overlay"];
const COMMANDS: &[&str] = &["show_snap_overlay", "set_window_buttons_inset"];

fn main() {
tauri_plugin::Builder::new(COMMANDS).build();
Expand Down
9 changes: 4 additions & 5 deletions examples/tauri-app/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": [
"main"
],
"windows": ["main"],
"permissions": [
"core:app:default",
"core:path:default",
Expand All @@ -23,6 +21,7 @@
"core:window:allow-is-maximized",
"core:window:allow-start-dragging",
"core:window:allow-toggle-maximize",
"decorum:allow-show-snap-overlay"
"decorum:allow-show-snap-overlay",
"decorum:allow-set-window-buttons-inset"
]
}
}

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/tauri-app/src-tauri/gen/schemas/capabilities.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:app:default","core:path:default","core:menu:default","core:tray:default","core:image:default","core:event:default","core:window:default","core:resources:default","core:window:allow-close","core:window:allow-center","core:window:allow-minimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-start-dragging","core:window:allow-toggle-maximize","decorum:allow-show-snap-overlay"]}}
{"default":{"identifier":"default","description":"Capability for the main window","local":true,"windows":["main"],"permissions":["core:app:default","core:path:default","core:menu:default","core:tray:default","core:image:default","core:event:default","core:window:default","core:resources:default","core:window:allow-close","core:window:allow-center","core:window:allow-minimize","core:window:allow-maximize","core:window:allow-set-size","core:window:allow-set-focus","core:window:allow-is-maximized","core:window:allow-start-dragging","core:window:allow-toggle-maximize","decorum:allow-show-snap-overlay","decorum:allow-set-window-buttons-inset"]}}
42 changes: 14 additions & 28 deletions examples/tauri-app/src-tauri/gen/schemas/desktop-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1039,13 +1039,6 @@
"core:webview:allow-create-webview-window"
]
},
{
"description": "core:webview:allow-get-all-webviews -> Enables the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": [
"core:webview:allow-get-all-webviews"
]
},
{
"description": "core:webview:allow-internal-toggle-devtools -> Enables the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -1130,13 +1123,6 @@
"core:webview:deny-create-webview-window"
]
},
{
"description": "core:webview:deny-get-all-webviews -> Denies the get_all_webviews command without any pre-configured scope.",
"type": "string",
"enum": [
"core:webview:deny-get-all-webviews"
]
},
{
"description": "core:webview:deny-internal-toggle-devtools -> Denies the internal_toggle_devtools command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -1263,13 +1249,6 @@
"core:window:allow-destroy"
]
},
{
"description": "core:window:allow-get-all-windows -> Enables the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": [
"core:window:allow-get-all-windows"
]
},
{
"description": "core:window:allow-hide -> Enables the hide command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -1725,13 +1704,6 @@
"core:window:deny-destroy"
]
},
{
"description": "core:window:deny-get-all-windows -> Denies the get_all_windows command without any pre-configured scope.",
"type": "string",
"enum": [
"core:window:deny-get-all-windows"
]
},
{
"description": "core:window:deny-hide -> Denies the hide command without any pre-configured scope.",
"type": "string",
Expand Down Expand Up @@ -2144,13 +2116,27 @@
"decorum:default"
]
},
{
"description": "decorum:allow-set-window-buttons-inset -> Enables the set_window_buttons_inset command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:allow-set-window-buttons-inset"
]
},
{
"description": "decorum:allow-show-snap-overlay -> Enables the show_snap_overlay command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:allow-show-snap-overlay"
]
},
{
"description": "decorum:deny-set-window-buttons-inset -> Denies the set_window_buttons_inset command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:deny-set-window-buttons-inset"
]
},
{
"description": "decorum:deny-show-snap-overlay -> Denies the show_snap_overlay command without any pre-configured scope.",
"type": "string",
Expand Down
14 changes: 14 additions & 0 deletions examples/tauri-app/src-tauri/gen/schemas/macOS-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2116,13 +2116,27 @@
"decorum:default"
]
},
{
"description": "decorum:allow-set-window-buttons-inset -> Enables the set_window_buttons_inset command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:allow-set-window-buttons-inset"
]
},
{
"description": "decorum:allow-show-snap-overlay -> Enables the show_snap_overlay command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:allow-show-snap-overlay"
]
},
{
"description": "decorum:deny-set-window-buttons-inset -> Denies the set_window_buttons_inset command without any pre-configured scope.",
"type": "string",
"enum": [
"decorum:deny-set-window-buttons-inset"
]
},
{
"description": "decorum:deny-show-snap-overlay -> Denies the show_snap_overlay command without any pre-configured scope.",
"type": "string",
Expand Down
14 changes: 12 additions & 2 deletions examples/tauri-app/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ fn main() {
// On Windows this will hide decoration and render custom window controls
// On macOS it expects a hiddenTitle: true and titleBarStyle: overlay
let main_window = app.get_webview_window("main").unwrap();
main_window.create_overlay_titlebar().unwrap();
// main_window.create_overlay_titlebar().unwrap();

#[cfg(target_os = "macos")]
main_window.set_traffic_lights_inset(16.0, 20.0).unwrap();
{
use tauri_plugin_decorum::NSWindowLevel;

let _ = main_window.make_transparent();
let _ = main_window.create_overlay_titlebar();
// let _ =
// main_window.set_window_buttons_inset(Some(LogicalPosition::new(15.0, 20.0)));

let _ = main_window.set_window_level(NSWindowLevel::NSNormalWindowLevel);
}

Ok(())
})
.run(tauri::generate_context!())
Expand Down
61 changes: 43 additions & 18 deletions examples/tauri-app/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,58 @@
{
"productName": "tauri-app",
"version": "0.0.0",
"identifier": "com.tauritempplugin.dev",
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"productName": "Plugin Decorum Example",
"identifier": "com.github/clearlysid/tauri-plugin-decorum",
"build": {
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn build",
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"frontendDist": "../dist"
"beforeBuildCommand": "pnpm build",
"frontendDist": "../.output/public"
},
"plugins": {
"decorum": {
"all": {
"createOverlayTitlebar": true,
"windowButtons": {
"insetX": 12.0
}
},
"windows": [
{
"label": "main",
"windowButtons": {
"insetY": 15.0
}
}
]
}
},
"app": {
"withGlobalTauri": true,
"security": {
"csp": null
},
"windows": [
{
"fullscreen": false,
"resizable": true,
"title": "tauri-app",
"width": 600,
"title": "Decorum",
"minHeight": 500,
"minWidth": 300,
"width": 580,
"height": 400,
"hiddenTitle": false,
"zoomHotkeysEnabled": true,
"titleBarStyle": "Overlay",
"hiddenTitle": true
"windowEffects": {
"effects": ["underWindowBackground", "mica"]
}
}
]
],
"security": {
"csp": null
},
"withGlobalTauri": false
},
"bundle": {
"macOS": {
"signingIdentity": "-"
},
"active": true,
"targets": "all",
"targets": ["app", "nsis"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand All @@ -36,4 +61,4 @@
"icons/icon.ico"
]
}
}
}
24 changes: 12 additions & 12 deletions examples/tauri-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function App() {
return (
<div className="container">
<h1>Welcome to Tauri!</h1>
return (
<div className="container">
<h1>Welcome to Tauri!</h1>

<div className="row">
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" className="logo tauri" alt="Tauri logo" />
</a>
</div>
<p>Click on the Tauri logo to learn more.</p>
</div>
);
<div className="row">
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" className="logo tauri" alt="Tauri logo" />
</a>
</div>
<p>Click on the Tauri logo to learn more.</p>
</div>
);
}

export default App;
export default App;
Loading