From 03b0d1cc90fb6859ba0deb4e4582dd97358e2d92 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Tue, 25 Mar 2025 09:36:38 -0400 Subject: [PATCH] Debounce set icon geometry gh-2292 --- src/appIcons.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/appIcons.js b/src/appIcons.js index ab0c3f6..b0710fb 100644 --- a/src/appIcons.js +++ b/src/appIcons.js @@ -447,6 +447,11 @@ export const TaskbarAppIcon = GObject.registerClass( _onDestroy() { super._onDestroy() + if (this._updateIconIdleId) { + GLib.source_remove(this._updateIconIdleId) + this._updateIconIdleId = 0 + } + this._timeoutsHandler.destroy() this._signalsHandler.destroy() @@ -477,18 +482,25 @@ export const TaskbarAppIcon = GObject.registerClass( // and position are random values, which might exceeds the integer range // resulting in an error when assigned to the a rect. This is a more like // a workaround to prevent flooding the system with errors. - if (this.get_stage() == null) return + if (this.get_stage() == null || this._updateIconIdleId) return - let rect = new Mtk.Rectangle() + this._updateIconIdleId = GLib.idle_add(GLib.PRIORITY_LOW, () => { + let rect = new Mtk.Rectangle() - ;[rect.x, rect.y] = this.get_transformed_position() - ;[rect.width, rect.height] = this.get_transformed_size() + ;[rect.x, rect.y] = this.get_transformed_position() + ;[rect.width, rect.height] = this.get_transformed_size() - let windows = this.window - ? [this.window] - : this.getAppIconInterestingWindows(true) - windows.forEach(function (w) { - w.set_icon_geometry(rect) + let windows = this.window + ? [this.window] + : this.getAppIconInterestingWindows(true) + + windows.forEach(function (w) { + w.set_icon_geometry(rect) + }) + + this._updateIconIdleId = 0 + + return GLib.SOURCE_REMOVE }) }