Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions crates/tauri/src/window/scripts/drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@
let initialX = 0
let initialY = 0

let dragTimer = null
let resizeTimer = null

function onDragStart(callbackStopped) {
function stop() {
window.removeEventListener("mousemove", watch);
window.removeEventListener("mouseup", stop);
window.removeEventListener("mouseleave", stop);
callbackStopped();
}

function watch() {
// dragging is happening
}

window.addEventListener("mousemove", watch);
window.addEventListener("mouseup", stop);
window.addEventListener("mouseleave", stop);
}

document.addEventListener('mousedown', (e) => {
const attr = e.target.getAttribute(TAURI_DRAG_REGION_ATTR)
if (
Expand Down Expand Up @@ -43,9 +63,14 @@
// https://github.com/tauri-apps/tauri/issues/2549#issuecomment-1250036908
e.stopImmediatePropagation()

// start dragging if the element has a `tauri-drag-region` data attribute and maximize on double-clicking it
const cmd = e.detail === 2 ? 'internal_toggle_maximize' : 'start_dragging'
window.__TAURI_INTERNALS__.invoke('plugin:window|' + cmd)
// maximize on double-clicking it, or start dragging on single click
if (e.detail === 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I believe this only works for the dragging from our custom draggable region (data-tauri-drag-region)?

Copy link
Author

@Khyati-Kapil Khyati-Kapil Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, I will try to provide the complete solution using another approach.

window.__TAURI_INTERNALS__.invoke('plugin:window|internal_toggle_maximize')
} else {
onDragStart(() => {
window.dispatchEvent(new CustomEvent('drag-stopped'))
})
}
}
})
// on macOS we maximize on mouseup instead, to match the system behavior where maximization can be canceled
Expand All @@ -72,4 +97,11 @@
}
})
}

window.addEventListener('tauri://resize', () => {
Copy link
Contributor

@Legend-Master Legend-Master Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not reliable to be honest

clearTimeout(resizeTimer)
resizeTimer = setTimeout(() => {
window.dispatchEvent(new CustomEvent('resize-stopped'))
}, 120)
})
})()