From 98ecd609c55ae4d0e93dc8363d9c4a36a7ccbd2a Mon Sep 17 00:00:00 2001 From: Petar Vasilev Date: Tue, 8 Apr 2025 02:26:08 +0100 Subject: [PATCH] some hacking --- src/events/eventManager.js | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/events/eventManager.js b/src/events/eventManager.js index 9fb2096..9b95b68 100644 --- a/src/events/eventManager.js +++ b/src/events/eventManager.js @@ -5,6 +5,7 @@ class EventManager { this.evenIds = {}; // event name -> {target, eventID} this.monitoredWindows = {}; // windowID -> {eventName -> eventID} this.unlockHandlerId = null; + this.positionCallbacks = new Set(); // Set of callbacks for position changes } attachGlobalEventOnce(eventName, target, callback) { @@ -23,6 +24,7 @@ class EventManager { event.target.disconnect(event.id); }); this.detachUnlockScreenEvent(); + this.positionCallbacks.clear(); this.evenIds = {}; } @@ -61,6 +63,50 @@ class EventManager { this.unlockHandlerId = null; } } + + attachWindowPositionCallback(window, callback) { + const eventName = 'position-changed'; + this.attachWindowEventOnce(eventName, window, callback); + this.positionCallbacks.add(callback); + return callback; + } + + isPositionCallbackAttached(callback) { + return this.positionCallbacks.has(callback); + } + + attachGlobalPositionCallback(target, callback) { + const eventName = 'position-changed'; + this.attachGlobalEventOnce(eventName, target, callback); + this.positionCallbacks.add(callback); + return callback; + } + + detachGlobalPositionCallback(callback) { + if (this.evenIds['position-changed'] && this.positionCallbacks.has(callback)) { + const event = this.evenIds['position-changed']; + event.target.disconnect(event.id); + delete this.evenIds['position-changed']; + this.positionCallbacks.delete(callback); + } + } + + detachWindowPositionCallback(window, callback) { + const windowId = window.get_id(); + const eventName = 'position-changed'; + + if (this.monitoredWindows[windowId] && + this.monitoredWindows[windowId][eventName] !== undefined) { + window.disconnect(this.monitoredWindows[windowId][eventName]); + delete this.monitoredWindows[windowId][eventName]; + + // If no more events for this window, clean up the entry + if (Object.keys(this.monitoredWindows[windowId]).length === 0) + delete this.monitoredWindows[windowId]; + } + + this.positionCallbacks.delete(callback); + } } export default EventManager;