|
142 | 142 | ) |
143 | 143 | } |
144 | 144 |
|
145 | | - // drag region |
| 145 | + //-----------------------// |
| 146 | + // data-tauri-drag-region |
| 147 | + // |
| 148 | + // drag on mousedown and maximize on double click on Windows and Linux |
| 149 | + // while macOS macos maximization should be on mouseup and if the mouse |
| 150 | + // moves after the double click, it should be cancelled (see https://github.com/tauri-apps/tauri/issues/8306) |
| 151 | + //-----------------------// |
| 152 | + const TAURI_DRAG_REGION_ATTR = 'data-tauri-drag-region'; |
| 153 | + let x = 0, y = 0; |
146 | 154 | document.addEventListener('mousedown', (e) => { |
147 | | - if (e.target.hasAttribute('data-tauri-drag-region') && e.button === 0) { |
| 155 | + if ( |
| 156 | + // element has the magic data attribute |
| 157 | + e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) && |
| 158 | + // and was left mouse button |
| 159 | + e.button === 0 && |
| 160 | + // and was normal click to drag or double click to maximize |
| 161 | + (e.detail === 1 || e.detail === 2) |
| 162 | + ) { |
| 163 | + |
| 164 | + // macOS maximization happens on `mouseup`, |
| 165 | + // so we save needed state and early return |
| 166 | + if (osName === 'macos' && e.detail == 2) { |
| 167 | + x = e.clientX |
| 168 | + y = e.clientY |
| 169 | + return |
| 170 | + } |
| 171 | + |
148 | 172 | // prevents text cursor |
149 | 173 | e.preventDefault() |
| 174 | + |
150 | 175 | // fix #2549: double click on drag region edge causes content to maximize without window sizing change |
151 | 176 | // https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908 |
152 | 177 | e.stopImmediatePropagation() |
153 | 178 |
|
154 | | - // start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it |
155 | 179 | window.__TAURI_INVOKE__('tauri', { |
156 | 180 | __tauriModule: 'Window', |
157 | 181 | message: { |
|
165 | 189 | }) |
166 | 190 | } |
167 | 191 | }) |
| 192 | + // on macOS we maximze on mouseup instead, to match the system behavior where maximization can be canceled |
| 193 | + // if the mouse moves outside the data-tauri-drag-region |
| 194 | + if (osName === "macos") { |
| 195 | + document.addEventListener('mouseup', (e) => { |
| 196 | + if ( |
| 197 | + // element has the magic data attribute |
| 198 | + e.target.hasAttribute(TAURI_DRAG_REGION_ATTR) && |
| 199 | + // and was left mouse button |
| 200 | + e.button === 0 && |
| 201 | + // and was double click |
| 202 | + e.detail === 2 && |
| 203 | + // and the cursor hasn't moved from initial mousedown |
| 204 | + e.clientX === x && e.clientY === y |
| 205 | + ) { |
| 206 | + window.__TAURI_INVOKE__('tauri', { |
| 207 | + __tauriModule: 'Window', |
| 208 | + message: { |
| 209 | + cmd: 'manage', |
| 210 | + data: { |
| 211 | + cmd: { |
| 212 | + type: '__toggleMaximize' |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + }) |
| 217 | + } |
| 218 | + }) |
| 219 | + } |
168 | 220 |
|
169 | 221 | let permissionSettable = false |
170 | 222 | let permissionValue = 'default' |
|
0 commit comments