diff --git a/extension.js b/extension.js index a7a0b44..86c340e 100644 --- a/extension.js +++ b/extension.js @@ -15,9 +15,16 @@ const {Clutter, Gio, Meta} = imports.gi; -const Workspace = imports.ui.workspace.Workspace; -const WindowManager = imports.ui.windowManager.WindowManager; -const WINDOW_REPOSITIONING_DELAY = imports.ui.workspace.WINDOW_REPOSITIONING_DELAY; +const Workspace = imports.ui.workspace.Workspace; +const WindowManager = imports.ui.windowManager.WindowManager; + +// The WindowPreview class is only available on GNOME Shell 3.38+; +let WindowPreview = null; +try { + WindowPreview = imports.ui.windowPreview.WindowPreview; +} catch (error) { + // Nothing to be done, we are on GNOME Shell 3.36. +} const ExtensionUtils = imports.misc.extensionUtils; const Me = imports.misc.extensionUtils.getCurrentExtension(); @@ -69,6 +76,18 @@ class Extension { // the WorkspacesView. const extensionThis = this; + // Do not attempt to close windows twice. Due to the animation in the overview, the + // close button can be clicked twice which normally would lead to a crash. + if (WindowPreview) { + this._origDeleteAll = WindowPreview.prototype._deleteAll; + + WindowPreview.prototype._deleteAll = function() { + if (!this._closeRequested) { + extensionThis._origDeleteAll.apply(this); + } + }; + } + // On GNOME 3.36, the window clone's 'destroy' handler only calls _removeWindowClone // but not _doRemoveWindow. The latter is required to trigger the repositioning of the // overview window layout. Therefore we call this method in addition. @@ -187,6 +206,10 @@ class Extension { Workspace.prototype._addWindowClone = this._origAddWindowClone; WindowManager.prototype._shouldAnimateActor = this._origShouldAnimateActor; + if (WindowPreview) { + WindowPreview.prototype._deleteAll = this._origDeleteAll; + } + this._settings = null; }