Skip to content

Commit 1a51006

Browse files
fix(core): data-tauri-drag-region didn't respect resizable, closes #2314 (#2316)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 807b862 commit 1a51006

File tree

10 files changed

+55
-11
lines changed

10 files changed

+55
-11
lines changed

.changes/api-toggle-maximize.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Add `toggleMaximize()` function to the `WebviewWindow` class.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fix `data-tauri-drag-region` double-click, will now respect `resizable: false` and won't maximize.

core/tauri/scripts/bundle.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.

core/tauri/scripts/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ if (!String.prototype.startsWith) {
205205
cmd: 'manage',
206206
data: {
207207
cmd: {
208-
type: e.detail === 2 ? 'toggleMaximize' : 'startDragging'
208+
type: e.detail === 2 ? '__toggleMaximize' : 'startDragging'
209209
}
210210
}
211211
}

core/tauri/src/endpoints/window.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ pub enum WindowManagerCmd {
8080
SetSkipTaskbar(bool),
8181
StartDragging,
8282
Print,
83+
// internals
84+
#[serde(rename = "__toggleMaximize")]
85+
InternalToggleMaximize,
8386
}
8487

8588
/// The API descriptor.
@@ -179,6 +182,15 @@ impl Cmd {
179182
WindowManagerCmd::SetSkipTaskbar(skip) => window.set_skip_taskbar(skip)?,
180183
WindowManagerCmd::StartDragging => window.start_dragging()?,
181184
WindowManagerCmd::Print => window.print()?,
185+
// internals
186+
WindowManagerCmd::InternalToggleMaximize => {
187+
if window.is_resizable()? {
188+
match window.is_maximized()? {
189+
true => window.unmaximize()?,
190+
false => window.maximize()?,
191+
}
192+
}
193+
}
182194
}
183195
}
184196
}

docs/usage/guides/visual/window-customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ document
8282
.addEventListener('click', () => appWindow.minimize())
8383
document
8484
.getElementById('titlebar-maximize')
85-
.addEventListener('click', async () => await appWindow.isMaximized() ? appWindow.unmaximize() : appWindow.maximize())
85+
.addEventListener('click', () => appWindow.toggleMaximize())
8686
document
8787
.getElementById('titlebar-close')
8888
.addEventListener('click', () => appWindow.close())

tooling/api/src/helpers/event.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
/** @ignore */ /** */
5+
/** @ignore */
66

7+
import { WindowLabel } from '../window'
78
import { invokeTauriCommand } from './tauri'
89

910
/**
@@ -16,7 +17,7 @@ import { invokeTauriCommand } from './tauri'
1617
*/
1718
async function emit(
1819
event: string,
19-
windowLabel?: string,
20+
windowLabel: WindowLabel,
2021
payload?: string
2122
): Promise<void> {
2223
await invokeTauriCommand({

tooling/api/src/helpers/os-check.ts

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

5-
/** @ignore */
5+
/** @ignore */
66

77
function isLinux(): boolean {
88
return navigator.appVersion.includes('Linux')

tooling/api/src/helpers/tauri.ts

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

5-
/** @ignore */ /** */
5+
/** @ignore */
66

77
import { invoke } from '../tauri'
88

tooling/api/src/window.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,18 @@ function getAll(): WebviewWindow[] {
219219
/** @ignore */
220220
// events that are emitted right here instead of by the created webview
221221
const localTauriEvents = ['tauri://created', 'tauri://error']
222-
222+
/** @ignore */
223+
export type WindowLabel = string | null | undefined
223224
/**
224225
* A webview window handle allows emitting and listening to events from the backend that are tied to the window.
225226
*/
226227
class WebviewWindowHandle {
227228
/** Window label. */
228-
label: string | null
229+
label: WindowLabel
229230
/** Local event listeners. */
230231
listeners: { [key: string]: Array<EventCallback<any>> }
231232

232-
constructor(label: string | null) {
233+
constructor(label: WindowLabel) {
233234
this.label = label
234235
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
235236
this.listeners = Object.create(null)
@@ -625,6 +626,26 @@ class WindowManager extends WebviewWindowHandle {
625626
})
626627
}
627628

629+
/**
630+
* Toggles the window maximized state.
631+
*
632+
* @returns A promise indicating the success or failure of the operation.
633+
*/
634+
async toggleMaximize(): Promise<void> {
635+
return invokeTauriCommand({
636+
__tauriModule: 'Window',
637+
message: {
638+
cmd: 'manage',
639+
data: {
640+
label: this.label,
641+
cmd: {
642+
type: 'toggleMaximize'
643+
}
644+
}
645+
}
646+
})
647+
}
648+
628649
/**
629650
* Minimizes the window.
630651
*
@@ -1071,7 +1092,7 @@ class WindowManager extends WebviewWindowHandle {
10711092
* ```
10721093
*/
10731094
class WebviewWindow extends WindowManager {
1074-
constructor(label: string | null, options: WindowOptions = {}) {
1095+
constructor(label: WindowLabel, options: WindowOptions = {}) {
10751096
super(label)
10761097
// @ts-expect-error
10771098
if (!options?.skip) {

0 commit comments

Comments
 (0)