|
11 | 11 | // moves after the double click, it should be cancelled (see https://github.com/tauri-apps/tauri/issues/8306) |
12 | 12 | //-----------------------// |
13 | 13 | 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 | + |
16 | 19 | document.addEventListener('mousedown', (e) => { |
| 20 | + const attr = e.target.getAttribute(TAURI_DRAG_REGION_ATTR) |
17 | 21 | if ( |
18 | 22 | // element has the magic data attribute |
19 | | - e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) |
| 23 | + attr !== null |
| 24 | + // and not false |
| 25 | + && attr !== 'false' |
20 | 26 | // and was left mouse button |
21 | 27 | && e.button === 0 |
22 | 28 | // and was normal click to drag or double click to maximize |
|
25 | 31 | // macOS maximization happens on `mouseup`, |
26 | 32 | // so we save needed state and early return |
27 | 33 | if (osName === 'macos' && e.detail == 2) { |
28 | | - x = e.clientX |
29 | | - y = e.clientY |
| 34 | + initialX = e.clientX |
| 35 | + initialY = e.clientY |
30 | 36 | return |
31 | 37 | } |
32 | 38 |
|
|
46 | 52 | // if the mouse moves outside the data-tauri-drag-region |
47 | 53 | if (osName === 'macos') { |
48 | 54 | document.addEventListener('mouseup', (e) => { |
| 55 | + const attr = e.target.getAttribute(TAURI_DRAG_REGION_ATTR) |
49 | 56 | if ( |
50 | 57 | // element has the magic data attribute |
51 | | - e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) |
| 58 | + attr !== null |
| 59 | + // and not false |
| 60 | + && attr !== 'false' |
52 | 61 | // and was left mouse button |
53 | 62 | && e.button === 0 |
54 | 63 | // and was double click |
55 | 64 | && e.detail === 2 |
56 | 65 | // 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 |
59 | 68 | ) { |
60 | 69 | window.__TAURI_INTERNALS__.invoke( |
61 | 70 | 'plugin:window|internal_toggle_maximize' |
|
0 commit comments