From a2358b077b300f50faa45e05578b01cef2d8fb26 Mon Sep 17 00:00:00 2001 From: Leleat Date: Mon, 3 Feb 2025 15:57:21 +0100 Subject: [PATCH] fix: fix issues uncovered by adding .jsconfig I've temporarily enabled `checkJs` and this uncovered some issues. They were mostly wrong JSDoc comments. But there were also some actual issues although I don't think they had observable bugs: - GLib.PRIORITY_IDLE -> GLib.PRIORITY_DEFAULT_IDLE ... PRIORITY_IDLE doen't exists - removed unused variables in calls to focusHint.js::getAbsPos - added a missing argument to addGaps call in tileEditingMode.js - fix import for debugging shortcut in utility.js (Also remove brackets in extension.js to satisfy the linter) --- tiling-assistant@leleat-on-github/prefs.js | 2 +- .../src/common.js | 4 +- .../src/extension/focusHint.js | 16 ++--- .../src/extension/moveHandler.js | 4 +- .../src/extension/tileEditingMode.js | 2 +- .../src/extension/tilingPopup.js | 2 +- .../src/extension/tilingWindowManager.js | 67 ++++++++++--------- .../src/extension/utility.js | 20 +++--- .../src/prefs/layoutRowEntry.js | 3 - .../src/prefs/layoutsPrefs.js | 6 +- .../src/prefs/shortcutListener.js | 2 +- 11 files changed, 65 insertions(+), 63 deletions(-) diff --git a/tiling-assistant@leleat-on-github/prefs.js b/tiling-assistant@leleat-on-github/prefs.js index 04b059ea..2769cccc 100644 --- a/tiling-assistant@leleat-on-github/prefs.js +++ b/tiling-assistant@leleat-on-github/prefs.js @@ -144,7 +144,7 @@ export default class Prefs extends ExtensionPreferences { settings.set_string(key, widget.get_rgba().to_string()); }); - // initilaize color + // initialize color const rgba = new Gdk.RGBA(); rgba.parse(settings.get_string(key)); widget.set_rgba(rgba); diff --git a/tiling-assistant@leleat-on-github/src/common.js b/tiling-assistant@leleat-on-github/src/common.js index 1543d1c3..b98da755 100644 --- a/tiling-assistant@leleat-on-github/src/common.js +++ b/tiling-assistant@leleat-on-github/src/common.js @@ -18,7 +18,7 @@ export class Settings { } /** - * @returns {Gio.Settings} the Gio.Settings object. + * @returns {import("./dependencies/gi.js").Gio.Settings} the Gio.Settings object. */ static getGioObject() { return this._settings; @@ -279,7 +279,7 @@ export class Layout { } /** - * @returns {[boolean, string]} whether the layout has valid rects and + * @returns {[boolean, string, number]} whether the layout has valid rects and * a potential error message. */ validate() { diff --git a/tiling-assistant@leleat-on-github/src/extension/focusHint.js b/tiling-assistant@leleat-on-github/src/extension/focusHint.js index af21d5ea..6ac3bf63 100644 --- a/tiling-assistant@leleat-on-github/src/extension/focusHint.js +++ b/tiling-assistant@leleat-on-github/src/extension/focusHint.js @@ -36,8 +36,7 @@ export default class FocusHintManager { this._settingsChangedId = Settings.changed( 'focus-hint', - () => this._setHint(), - this + () => this._setHint() ); this._setHint(); @@ -97,7 +96,9 @@ class Hint { this._removeIdleWatcher(); } - indicate() { + /** @param {Meta.Window} focus */ + // eslint-disable-next-line no-unused-vars + indicate(focus) { throw new Error('`indicate` not implemented by Hint subclass!'); } @@ -597,7 +598,7 @@ class StaticOutlineHint extends AnimatedOutlineHint { /** * This is really only used for the indication when changing workspaces... * - * @param {Window} window - + * @param {Meta.Window} window - * @param {number} workspaceSwitchAnimationDuration - */ indicate(window, workspaceSwitchAnimationDuration = 250) { @@ -764,8 +765,8 @@ function createContainers( let startingPos; if (workspaceAnimationWindowClone) { - const actorAbsPos = getAbsPos(window.get_compositor_private(), monitorNr); - const cloneAbsPos = getAbsPos(workspaceAnimationWindowClone, monitorNr); + const actorAbsPos = getAbsPos(window.get_compositor_private()); + const cloneAbsPos = getAbsPos(workspaceAnimationWindowClone); startingPos = { x: monitorRect.x + cloneAbsPos.x - actorAbsPos.x, @@ -827,8 +828,7 @@ function createContainers( * @returns {Clutter.Clone} */ function createWindowClone(windowActor, container) { - const monitor = windowActor.get_meta_window().get_monitor(); - const { x, y } = getAbsPos(windowActor, monitor); + const { x, y } = getAbsPos(windowActor); const windowClone = new Clutter.Clone({ source: windowActor, diff --git a/tiling-assistant@leleat-on-github/src/extension/moveHandler.js b/tiling-assistant@leleat-on-github/src/extension/moveHandler.js index 9f00a2b5..32971c8f 100644 --- a/tiling-assistant@leleat-on-github/src/extension/moveHandler.js +++ b/tiling-assistant@leleat-on-github/src/extension/moveHandler.js @@ -175,7 +175,7 @@ export default class TilingMoveHandler { // as often when compared to the position-changed signal. if (Settings.getBoolean('low-performance-move-mode')) { this._movingTimerId = GLib.timeout_add( - GLib.PRIORITY_IDLE, + GLib.PRIORITY_DEFAULT_IDLE, this._movingTimerDuration, this._onMoving.bind( this, @@ -343,7 +343,7 @@ export default class TilingMoveHandler { const useIgnoreTa = defaultMode !== MoveModes.IGNORE_TA && pressed[ignoreTAMod] || noMod && defaultMode === MoveModes.IGNORE_TA; - let newMode = ''; + let newMode; if (useAdaptiveTiling) newMode = MoveModes.ADAPTIVE_TILING; diff --git a/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js b/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js index 8d454ce5..91bc0d10 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js +++ b/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js @@ -217,7 +217,7 @@ const Indicator = GObject.registerClass(class TileEditingModeIndicator extends S const workArea = new Rect(activeWs.get_work_area_for_monitor(this._monitor)); // Adjusted for window / screen gaps - const { x, y, width, height } = rect.addGaps(workArea); + const { x, y, width, height } = rect.addGaps(workArea, this._monitor); this.ease({ x: x - display.x, diff --git a/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js b/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js index 7e4ce160..02ad8420 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js +++ b/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js @@ -21,7 +21,7 @@ export const TilingSwitcherPopup = GObject.registerClass({ } }, class TilingSwitcherPopup extends AltTab.TilingAppSwitcherPopup { /** - * @param {Meta.Windows[]} openWindows an array of Meta.Windows, which this + * @param {Meta.Window[]} openWindows an array of Meta.Windows, which this * popup offers to tile. * @param {Rect} freeScreenRect the Rect, which the popup will tile a window * to. The popup will be centered in this rect. diff --git a/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js b/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js index 9dd7c818..208be14c 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js +++ b/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js @@ -1,4 +1,4 @@ -import { Clutter, GLib, GObject, Meta, Mtk, Shell } from '../dependencies/gi.js'; +import { GLib, Meta, Mtk, Shell } from '../dependencies/gi.js'; import { Main } from '../dependencies/shell.js'; import { getWindows } from '../dependencies/unexported/altTab.js'; @@ -13,7 +13,12 @@ export class TilingWindowManager { static initialize() { this._signals = new TilingSignals(); - // { windowId1: [windowIdX, windowIdY, ...], windowId2: [...], ... } + /** + * @type {Map} - { + * windowId1: [windowIdX, windowIdY, ...], + * windowId2: [...], + * } + */ this._tileGroups = new Map(); /** @@ -93,7 +98,7 @@ export class TilingWindowManager { * * @param {boolean} [allWorkspaces=false] determines whether we only want * the windows from the current workspace. - * @returns {Meta.Windows[]} an array of of the open Meta.Windows in + * @returns {Meta.Window[]} an array of of the open Meta.Windows in * stacking order. */ static getWindows(allWorkspaces = false) { @@ -118,7 +123,7 @@ export class TilingWindowManager { /** * @param {Meta.Window} window a Meta.Window. - * @param {Meta.WorkArea|Rect|null} workArea useful for the grace period + * @param {Mtk.Rectangle|Rect|null} workArea useful for the grace period * @returns whether the window is maximized. Be it using GNOME's native * maximization or the maximization by this extension when using gaps. */ @@ -133,18 +138,15 @@ export class TilingWindowManager { * * @param {Meta.Window} window a Meta.Window to tile. * @param {Rect} newRect the Rect the `window` will be tiled to. - * @param {boolean} [openTilingPopup=true] decides, if we open a Tiling + * @param {object} [param] the Rect the `window` will be tiled to. + * @param {boolean} [param.openTilingPopup=true] decides, if we open a Tiling * Popup after the window is tiled and there is unambiguous free * screen space. - * @param {number} [number=null] is used to get the workArea in which the - * window tiles on. It's used for gap calculation. We can't always rely on - * window.get_monitor with its monitor or global.display.get_current_monitor - * (the pointer monitor) because of the 'grace period' during a quick dnd - * towards a screen border since the pointer and the window will be on the - * 'wrong' monitor. - * @param {boolean} [skipAnim=false] decides, if we skip the tile animation. - * @param {boolean} [tileGroup=null] forces the creation of this tile group. - * @param {boolean} [fakeTile=false] don't create a new tile group, don't + * @param {boolean} [param.ignoreTA=false] + * @param {number} [param.monitorNr=null] + * @param {boolean} [param.skipAnim=false] decides, if we skip the tile animation. + * @param {boolean} [param.tileGroup=null] forces the creation of this tile group. + * @param {boolean} [param.fakeTile=false] don't create a new tile group, don't * emit 'tiled' signal or open the Tiling Popup */ static async tile(window, newRect, { @@ -273,10 +275,12 @@ export class TilingWindowManager { * Untiles a tiled window and delete all tiling properties. * * @param {Meta.Window} window a Meta.Window to untile. - * @param {boolean} [restoreFullPos=true] decides, if we restore the + * @param {object} [params] + * @param {boolean} [params.restoreFullPos=true] decides, if we restore the * pre-tile position or whether the size while keeping the titlebar * at the relative same position. - * @param {boolean} [skipAnim=false] decides, if we skip the until animation. + * @param {boolean} [params.skipAnim=false] decides, if we skip the until animation. + * @param {boolean} [params.clampToWorkspace=false] */ static untile(window, { restoreFullPos = true, skipAnim = false, clampToWorkspace = false } = {}) { const wasMaximized = window.get_maximized(); @@ -397,16 +401,14 @@ export class TilingWindowManager { } /** - * @returns {Map} - * For ex: { windowId1: [windowIdX, windowIdY, ...], windowId2: ... } + * @returns {Map} */ static getTileGroups() { return this._tileGroups; } /** - * @param {Map} tileGroups - * For ex: { windowId1: [windowIdX, windowIdY, ...], windowId2: ... } + * @param {Map} tileGroups */ static setTileGroups(tileGroups) { this._tileGroups = tileGroups; @@ -421,7 +423,7 @@ export class TilingWindowManager { * (i. e. ctrl-drag or tile editing mode+space). So manually create the * tile group in those cases. * - * @param {Meta.Windows[]} tileGroup an array of Meta.Windows to group + * @param {Meta.Window[]} tileGroup an array of Meta.Windows to group * together. */ static updateTileGroup(tileGroup) { @@ -563,13 +565,15 @@ export class TilingWindowManager { * *tracked* tile groups since floating windows may overlap some tiled * windows *at the moment* when this function is called. * - * @param {boolean} [skipTopWindow=true] whether we ignore the focused window + * @param {object} [params] + * @param {boolean} [params.skipTopWindow=true] whether we ignore the focused window * in the active search for the top tile group. The focused window may * still be part of the returned array if it is part of another high- * stacked window's tile group. This is mainly only useful, if the * focused window isn't tiled (for example when dnd-ing a window). - * @param {number} [monitor=null] get the group for the monitor number. - * @returns {Meta.Windows[]} an array of tiled Meta.Windows. + * @param {number} [params.monitor=null] get the group for the monitor number. + * + * @returns {Meta.Window[]} an array of tiled Meta.Windows. */ static getTopTileGroup({ skipTopWindow = false, monitor = null } = {}) { // 'Raise Tile Group' setting is enabled so we just return the tracked @@ -674,10 +678,11 @@ export class TilingWindowManager { * * @param {Rect[]} rectList an array of Rects, which occupy the screen. * Like usual, they shouldn't overlap each other. - * @param {Rect} [currRect=null] a Rect, which may be expanded. - * @param {Orientation} [orientation=null] The orientation we want to expand + * @param {object} [params] + * @param {Rect} [params.currRect=null] a Rect, which may be expanded. + * @param {Orientation} [params.orientation=null] The orientation we want to expand * `currRect` into. If `null`, expand in both orientations. - * @param {Rect} [monitor=null] defaults to pointer monitor. + * @param {number} [params.monitorNr=null] defaults to pointer monitor. * @returns {Rect} a new Rect. */ static getBestFreeRect(rectList, { currRect = null, orientation = null, monitorNr = null } = {}) { @@ -802,9 +807,9 @@ export class TilingWindowManager { /** * Gets the nearest Meta.Window in the direction of `dir`. * - * @param {Meta.Windows} currWindow the Meta.Window that the search starts + * @param {Meta.Window} currWindow the Meta.Window that the search starts * from. - * @param {Meta.Windows[]} windows an array of the available Meta.Windows. + * @param {Meta.Window[]} windows an array of the available Meta.Windows. * It may contain the current window itself. The windows shouldn't * overlap each other. * @param {Direction} dir the direction that is look into. @@ -1153,7 +1158,9 @@ export class TilingWindowManager { * Gets the top most non-overlapped/ing tiled windows ignoring * the stacking order and tile groups. * - * @param {{boolean, number}} param1 + * @param {object} [param] + * @param {boolean} [param.skipTopWindow=false] + * @param {number} [param.monitor=null] */ static _getTopTiledWindows({ skipTopWindow = false, monitor = null } = {}) { const openWindows = this.getWindows(); diff --git a/tiling-assistant@leleat-on-github/src/extension/utility.js b/tiling-assistant@leleat-on-github/src/extension/utility.js index af41d1c6..ac2f3856 100644 --- a/tiling-assistant@leleat-on-github/src/extension/utility.js +++ b/tiling-assistant@leleat-on-github/src/extension/utility.js @@ -247,7 +247,7 @@ export class Util { */ static async __debugPrintTileGroups() { log('--- Tiling Assistant: Start ---'); - const twm = await import('./tilingWindowManager.js'); + const twm = (await import('./tilingWindowManager.js')).TilingWindowManager; const openWindows = twm.getWindows(); openWindows.forEach(w => { if (!w.isTiled) @@ -300,7 +300,7 @@ export class Rect { * Gets a new rectangle where the screen and window gaps were * added/subbed to/from `this`. * - * @param {Rect} rect a tiled Rect + * @param {Rect} workArea a tiled Rect * @param {number} monitor the number of the monitor to scale the gap to * @returns {Rect} the rectangle after the gaps were taken into account */ @@ -382,7 +382,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ containsRect(rect) { @@ -398,7 +398,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ couldFitRect(rect) { @@ -407,7 +407,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ equal(rect) { @@ -540,7 +540,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ horizOverlap(rect) { @@ -549,7 +549,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {[boolean, Rect]} */ intersect(rect) { @@ -653,7 +653,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ overlap(rect) { @@ -699,7 +699,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {Rect} */ union(rect) { @@ -708,7 +708,7 @@ export class Rect { } /** - * @param {Rect} rect + * @param {Rect|Mtk.Rectangle} rect * @returns {boolean} */ vertOverlap(rect) { diff --git a/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js b/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js index 90adde76..86a63591 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js +++ b/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js @@ -47,9 +47,6 @@ export const LayoutRowEntry = GObject.registerClass({ this._rectAppButton.set_icon_name(iconName); } - /** - * @param {Gtk.Button} appButton src of the event. - */ _onAppButtonClicked() { // Reset app button, if it already has an app attached if (this._item.appId) { diff --git a/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js b/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js index 83e52d5c..109e009f 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js +++ b/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js @@ -169,9 +169,8 @@ export default class { try { parentDir.make_directory_with_parents(null); } catch (e) { - if (e.code !== Gio.IOErrorEnum.EXISTS) { + if (e.code !== Gio.IOErrorEnum.EXISTS) throw e; - } } // Create file, if it doesn't exist. @@ -182,9 +181,8 @@ export default class { try { file.create(Gio.FileCreateFlags.NONE, null); } catch (e) { - if (e.code !== Gio.IOErrorEnum.EXISTS) { + if (e.code !== Gio.IOErrorEnum.EXISTS) throw e; - } } return file; diff --git a/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js b/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js index 4b093c0c..ebd1f72f 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js +++ b/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js @@ -163,7 +163,7 @@ export const ShortcutListener = GObject.registerClass({ * @returns {boolean} `true` if the key combo is a valid binding. */ _isBindingValid({ mask, keycode, keyval }) { - if ((mask === 0 || mask === Gdk.SHIFT_MASK) && keycode !== 0) { + if ((mask === 0 || mask === Gdk.ModifierType.SHIFT_MASK) && keycode !== 0) { if ( (keyval >= Gdk.KEY_a && keyval <= Gdk.KEY_z) || (keyval >= Gdk.KEY_A && keyval <= Gdk.KEY_Z) ||