Skip to content

Commit

Permalink
feat(positioner): add moveWindowConstrained for tray-icon positions (
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobwesthoff authored Nov 20, 2024
1 parent 383e636 commit 4db6263
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 150 deletions.
6 changes: 6 additions & 0 deletions .changes/positioner-move-window-constrained-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"positioner-js": minor
---

Add `moveWindowConstrained` function that is similar to `moveWindow` but constrains the window to the screen dimensions in case of tray icon positions.

6 changes: 6 additions & 0 deletions .changes/positioner-move-window-constrained.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"positioner": minor
---

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.

2 changes: 1 addition & 1 deletion plugins/positioner/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion plugins/positioner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

const COMMANDS: &[&str] = &["move_window", "set_tray_icon_state"];
const COMMANDS: &[&str] = &[
"move_window",
"move_window_constrained",
"set_tray_icon_state",
];

fn main() {
tauri_plugin::Builder::new(COMMANDS)
Expand Down
13 changes: 13 additions & 0 deletions plugins/positioner/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ export async function moveWindow(to: Position): Promise<void> {
})
}

/**
* Moves the `Window` to the given {@link Position} using `WindowExt.move_window_constrained()`
*
* This move operation constrains the window to the screen dimensions in case of
* tray-icon positions.
* @param to The (tray) {@link Position} to move to.
*/
export async function moveWindowConstrained(to: Position): Promise<void> {
await invoke('plugin:positioner|move_window_constrained', {
position: to
})
}

export async function handleIconState(event: TrayIconEvent): Promise<void> {
await invoke('plugin:positioner|set_tray_icon_state', {
position: event.rect.position,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatically generated - DO NOT EDIT!

"$schema" = "../../schemas/schema.json"

[[permission]]
identifier = "allow-move-window-constrained"
description = "Enables the move_window_constrained command without any pre-configured scope."
commands.allow = ["move_window_constrained"]

[[permission]]
identifier = "deny-move-window-constrained"
description = "Denies the move_window_constrained command without any pre-configured scope."
commands.deny = ["move_window_constrained"]
29 changes: 28 additions & 1 deletion plugins/positioner/permissions/autogenerated/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Allows the moveWindow and handleIconState APIs

- `allow-move-window`
- `set-tray-icon-state`
- `allow-move-window-constrained`
- `allow-set-tray-icon-state`

## Permission Table

Expand Down Expand Up @@ -43,6 +44,32 @@ Denies the move_window command without any pre-configured scope.
<tr>
<td>

`positioner:allow-move-window-constrained`

</td>
<td>

Enables the move_window_constrained command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`positioner:deny-move-window-constrained`

</td>
<td>

Denies the move_window_constrained command without any pre-configured scope.

</td>
</tr>

<tr>
<td>

`positioner:allow-set-tray-icon-state`

</td>
Expand Down
6 changes: 5 additions & 1 deletion plugins/positioner/permissions/default.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"$schema" = "schemas/schema.json"
[default]
description = "Allows the moveWindow and handleIconState APIs"
permissions = ["allow-move-window", "set-tray-icon-state"]
permissions = [
"allow-move-window",
"allow-move-window-constrained",
"allow-set-tray-icon-state",
]
10 changes: 10 additions & 0 deletions plugins/positioner/permissions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@
"type": "string",
"const": "deny-move-window"
},
{
"description": "Enables the move_window_constrained command without any pre-configured scope.",
"type": "string",
"const": "allow-move-window-constrained"
},
{
"description": "Denies the move_window_constrained command without any pre-configured scope.",
"type": "string",
"const": "deny-move-window-constrained"
},
{
"description": "Enables the set_tray_icon_state command without any pre-configured scope.",
"type": "string",
Expand Down
Loading

0 comments on commit 4db6263

Please sign in to comment.