From e854169fdd516c21449bd58aa81144bc41aef203 Mon Sep 17 00:00:00 2001 From: Deciare <1689220+deciare@users.noreply.github.com> Date: Sat, 3 Aug 2024 04:27:18 -0400 Subject: [PATCH 1/2] Listen for wheel event instead of mousewheel event. In order to manipulate event listeners, we need to be able to run code after application setup is complete. To facilitate that, the code has been reworked as an extension instead of a custom node. Fixes subtleGradient/TinkerBot-tech-for-ComfyUI-Touchpad/#7. --- README.md | 2 +- web/fix touchpad pan and zoom.js | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f5178de..53f8f24 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ fixes https://github.com/comfyanonymous/ComfyUI/issues/2059 ### Installation -1. Put this folder into ComfyUI/custom_nodes/TinkerBot-tech-for-ComfyUI-Touchpad +1. Put this folder into ComfyUI/web/extensions/TinkerBot-tech-for-ComfyUI-Touchpad 2. Restart ComfyUI 3. Reload the UI 4. Enjoy! diff --git a/web/fix touchpad pan and zoom.js b/web/fix touchpad pan and zoom.js index 5c423a4..e796c76 100644 --- a/web/fix touchpad pan and zoom.js +++ b/web/fix touchpad pan and zoom.js @@ -1,21 +1,17 @@ -// @ts-check -/** @type {any} */ -const { self } = window +import { app } from "../../../scripts/app.js"; -/** @type {import("../../../web/types/litegraph")} */ -const { LGraphCanvas } = self - -// @ts-ignore -import * as ComfyUI_module from "../../../scripts/app.js" -/** @type { import("../../../web/scripts/app.js") } */ -const { app } = ComfyUI_module - -////////////////////////////// +app.registerExtension({ + name: "ComfyUI-Mac-Trackpad", + async setup(app) { + app.canvas.canvas.removeEventListener("mousewheel"); + app.canvas.canvas.addEventListener("wheel", processWheel.bind(app.canvas), false); + } +}); /** * Smooth scrolling for touchpad */ -LGraphCanvas.prototype.processMouseWheel = function (/** @type {WheelEvent}*/ event) { +function processWheel(/** @type {WheelEvent}*/ event) { if (!this.graph || !this.allow_dragcanvas) return const { clientX: x, clientY: y } = event @@ -40,4 +36,4 @@ LGraphCanvas.prototype.processMouseWheel = function (/** @type {WheelEvent}*/ ev event.preventDefault() return false // prevent default -} +} \ No newline at end of file From c940ed509618ae52682388c9d3b3a30c883a7d28 Mon Sep 17 00:00:00 2001 From: Deciare <1689220+deciare@users.noreply.github.com> Date: Sun, 4 Aug 2024 10:36:54 -0400 Subject: [PATCH 2/2] Compatibility with Comfy-Org/ComfyUI_frontend --- web/fix touchpad pan and zoom.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/fix touchpad pan and zoom.js b/web/fix touchpad pan and zoom.js index e796c76..d27d576 100644 --- a/web/fix touchpad pan and zoom.js +++ b/web/fix touchpad pan and zoom.js @@ -1,10 +1,12 @@ import { app } from "../../../scripts/app.js"; + app.registerExtension({ name: "ComfyUI-Mac-Trackpad", - async setup(app) { - app.canvas.canvas.removeEventListener("mousewheel"); - app.canvas.canvas.addEventListener("wheel", processWheel.bind(app.canvas), false); + async setup(app2) { + app2.canvas.ds.element.removeEventListener("mousewheel", app2.canvas.ds._binded_mouse_callback); + app2.canvas.ds.element.removeEventListener("wheel", app2.canvas.ds._binded_mouse_callback); + app2.canvas.ds.element.addEventListener("wheel", processWheel.bind(app2.canvas), false); } });