Skip to content

Commit

Permalink
Avoid patching mouse events - Fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
Aioros committed Jul 2, 2024
1 parent b19d482 commit 8a12400
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"discord": "MrAioros"
}
],
"version": "2.0.1",
"version": "2.0.2",
"compatibility": {
"minimum": "11",
"verified": "12.327"
Expand All @@ -37,7 +37,7 @@
}
],
"url": "https://github.com/Oromis/touch-vtt",
"download": "https://github.com/Oromis/touch-vtt/releases/download/v2.0.1/touch-vtt-v2.0.1.zip",
"download": "https://github.com/Oromis/touch-vtt/releases/download/v2.0.2/touch-vtt-v2.0.2.zip",
"manifest": "https://raw.githubusercontent.com/Oromis/touch-vtt/main/module.json",
"license": "https://www.gnu.org/licenses/gpl-3.0.en.html",
"readme": "README.md",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "touch-vtt",
"version": "2.0.1",
"version": "2.0.2",
"description": "Adds touch support to FoundryVTT",
"main": "src/touch-vtt.js",
"scripts": {
Expand Down
48 changes: 27 additions & 21 deletions src/touch-vtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,38 @@ Hooks.once('init', () => {

// This wrap gives us control over every MouseInteractionManager
wrapMethod('MouseInteractionManager.prototype.callback', async function (originalMethod, event, ...args) {
//console.log("MIM", this.object.constructor.name, event, ...args)

// v12 only: ugly patch to fix annoying issue where a double-click that opens a sheet also sends one of the clicks to an active listener on the sheet.
// For example, you open an actor sheet, if something clickable is under your finger (icon, action, ability, etc.) it will get wrongly clicked.
// What we do here is delay the sheet rendering a little bit, and also dispatch a right click on the canvas to avoid a lingering drag select on the placeable.
if (parseInt(game.version) >= 12) {
if (event == "clickLeft2") {
await new Promise(resolve => setTimeout(resolve, 100))
document.getElementById("board").dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true, view: window, button: 2}))
return originalMethod.call(this, event, ...args)
if (args[0].pointerType == "touch") {

//console.log("MIM", this.object.constructor.name, event, ...args)

// v12 only: ugly patch to fix annoying issue where a double-click that opens a sheet also sends one of the clicks to an active listener on the sheet.
// For example, you open an actor sheet, if something clickable is under your finger (icon, action, ability, etc.) it will get wrongly clicked.
// What we do here is delay the sheet rendering a little bit, and also dispatch a right click on the canvas to avoid a lingering drag select on the placeable.
if (parseInt(game.version) >= 12) {
if (event == "clickLeft2") {
await new Promise(resolve => setTimeout(resolve, 100))
document.getElementById("board").dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true, view: window, button: 2}))
return originalMethod.call(this, event, ...args)
}
}
}

// This is for sending a right click on long press (doesn't happen by default on the canvas)
if (event == "clickLeft") {
clearTimeout(canvasRightClickTimeout)
canvasRightClickTimeout = setTimeout(() => {
dispatchModifiedEvent(args[0], "pointerdown", {button: 2, buttons: 2})
}, 400)
} else {
clearTimeout(canvasRightClickTimeout)
// This is for sending a right click on long press (doesn't happen by default on the canvas)
if (event == "clickLeft") {
clearTimeout(canvasRightClickTimeout)
canvasRightClickTimeout = setTimeout(() => {
dispatchModifiedEvent(args[0], "pointerdown", {button: 2, buttons: 2})
}, 400)
} else {
clearTimeout(canvasRightClickTimeout)
}

callbackForEasyTarget(event, args)
callbackForSnapToGrid(event, args)

}

callbackForEasyTarget(event, args)
callbackForSnapToGrid(event, args)
return originalMethod.call(this, event, ...args)

}, 'MIXED')

// This wrap is used for wall chaining: when the chain button is active, pretend we are holding Ctrl
Expand Down

0 comments on commit 8a12400

Please sign in to comment.