Skip to content

Commit 4db6263

Browse files
feat(positioner): add moveWindowConstrained for tray-icon positions (#2076)
1 parent 383e636 commit 4db6263

File tree

11 files changed

+339
-150
lines changed

11 files changed

+339
-150
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"positioner-js": minor
3+
---
4+
5+
Add `moveWindowConstrained` function that is similar to `moveWindow` but constrains the window to the screen dimensions in case of tray icon positions.
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"positioner": minor
3+
---
4+
5+
Add `WindowExt::move_window_constrained` method that is similar to `WindowExt::move_window` but constrains the window to the screen dimensions in case of tray icon positions.
6+

plugins/positioner/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/positioner/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
const COMMANDS: &[&str] = &["move_window", "set_tray_icon_state"];
5+
const COMMANDS: &[&str] = &[
6+
"move_window",
7+
"move_window_constrained",
8+
"set_tray_icon_state",
9+
];
610

711
fn main() {
812
tauri_plugin::Builder::new(COMMANDS)

plugins/positioner/guest-js/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ export async function moveWindow(to: Position): Promise<void> {
3939
})
4040
}
4141

42+
/**
43+
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window_constrained()`
44+
*
45+
* This move operation constrains the window to the screen dimensions in case of
46+
* tray-icon positions.
47+
* @param to The (tray) {@link Position} to move to.
48+
*/
49+
export async function moveWindowConstrained(to: Position): Promise<void> {
50+
await invoke('plugin:positioner|move_window_constrained', {
51+
position: to
52+
})
53+
}
54+
4255
export async function handleIconState(event: TrayIconEvent): Promise<void> {
4356
await invoke('plugin:positioner|set_tray_icon_state', {
4457
position: event.rect.position,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Automatically generated - DO NOT EDIT!
2+
3+
"$schema" = "../../schemas/schema.json"
4+
5+
[[permission]]
6+
identifier = "allow-move-window-constrained"
7+
description = "Enables the move_window_constrained command without any pre-configured scope."
8+
commands.allow = ["move_window_constrained"]
9+
10+
[[permission]]
11+
identifier = "deny-move-window-constrained"
12+
description = "Denies the move_window_constrained command without any pre-configured scope."
13+
commands.deny = ["move_window_constrained"]

plugins/positioner/permissions/autogenerated/reference.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Allows the moveWindow and handleIconState APIs
44

55
- `allow-move-window`
6-
- `set-tray-icon-state`
6+
- `allow-move-window-constrained`
7+
- `allow-set-tray-icon-state`
78

89
## Permission Table
910

@@ -43,6 +44,32 @@ Denies the move_window command without any pre-configured scope.
4344
<tr>
4445
<td>
4546

47+
`positioner:allow-move-window-constrained`
48+
49+
</td>
50+
<td>
51+
52+
Enables the move_window_constrained command without any pre-configured scope.
53+
54+
</td>
55+
</tr>
56+
57+
<tr>
58+
<td>
59+
60+
`positioner:deny-move-window-constrained`
61+
62+
</td>
63+
<td>
64+
65+
Denies the move_window_constrained command without any pre-configured scope.
66+
67+
</td>
68+
</tr>
69+
70+
<tr>
71+
<td>
72+
4673
`positioner:allow-set-tray-icon-state`
4774

4875
</td>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"$schema" = "schemas/schema.json"
22
[default]
33
description = "Allows the moveWindow and handleIconState APIs"
4-
permissions = ["allow-move-window", "set-tray-icon-state"]
4+
permissions = [
5+
"allow-move-window",
6+
"allow-move-window-constrained",
7+
"allow-set-tray-icon-state",
8+
]

plugins/positioner/permissions/schemas/schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@
304304
"type": "string",
305305
"const": "deny-move-window"
306306
},
307+
{
308+
"description": "Enables the move_window_constrained command without any pre-configured scope.",
309+
"type": "string",
310+
"const": "allow-move-window-constrained"
311+
},
312+
{
313+
"description": "Denies the move_window_constrained command without any pre-configured scope.",
314+
"type": "string",
315+
"const": "deny-move-window-constrained"
316+
},
307317
{
308318
"description": "Enables the set_tray_icon_state command without any pre-configured scope.",
309319
"type": "string",

0 commit comments

Comments
 (0)