Skip to content

Commit 31becbd

Browse files
authored
enhance(core): respect data-tauri-drag-region="false" (#13269)
1 parent da2a6ae commit 31becbd

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": "patch:enhance"
3+
---
4+
5+
Respect `data-tauri-drag-region="false"`, it will no longer start dragging. This is useful when binding the attribute to a state using React, or another framework.

crates/tauri/src/window/scripts/drag.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
// moves after the double click, it should be cancelled (see https://github.com/tauri-apps/tauri/issues/8306)
1212
//-----------------------//
1313
const TAURI_DRAG_REGION_ATTR = 'data-tauri-drag-region'
14-
let x = 0,
15-
y = 0
14+
15+
// initial mousedown position for macOS
16+
let initialX = 0
17+
let initialY = 0
18+
1619
document.addEventListener('mousedown', (e) => {
20+
const attr = e.target.getAttribute(TAURI_DRAG_REGION_ATTR)
1721
if (
1822
// element has the magic data attribute
19-
e.target.hasAttribute(TAURI_DRAG_REGION_ATTR)
23+
attr !== null
24+
// and not false
25+
&& attr !== 'false'
2026
// and was left mouse button
2127
&& e.button === 0
2228
// and was normal click to drag or double click to maximize
@@ -25,8 +31,8 @@
2531
// macOS maximization happens on `mouseup`,
2632
// so we save needed state and early return
2733
if (osName === 'macos' && e.detail == 2) {
28-
x = e.clientX
29-
y = e.clientY
34+
initialX = e.clientX
35+
initialY = e.clientY
3036
return
3137
}
3238

@@ -46,16 +52,19 @@
4652
// if the mouse moves outside the data-tauri-drag-region
4753
if (osName === 'macos') {
4854
document.addEventListener('mouseup', (e) => {
55+
const attr = e.target.getAttribute(TAURI_DRAG_REGION_ATTR)
4956
if (
5057
// element has the magic data attribute
51-
e.target.hasAttribute(TAURI_DRAG_REGION_ATTR)
58+
attr !== null
59+
// and not false
60+
&& attr !== 'false'
5261
// and was left mouse button
5362
&& e.button === 0
5463
// and was double click
5564
&& e.detail === 2
5665
// and the cursor hasn't moved from initial mousedown
57-
&& e.clientX === x
58-
&& e.clientY === y
66+
&& e.clientX === initialX
67+
&& e.clientY === initialY
5968
) {
6069
window.__TAURI_INTERNALS__.invoke(
6170
'plugin:window|internal_toggle_maximize'

0 commit comments

Comments
 (0)