diff --git a/tiling-assistant@leleat-on-github/extension.js b/tiling-assistant@leleat-on-github/extension.js index 690ce8f..d86457a 100644 --- a/tiling-assistant@leleat-on-github/extension.js +++ b/tiling-assistant@leleat-on-github/extension.js @@ -53,7 +53,9 @@ class SettingsOverrider { } _maybeUpdateOverriden(schemaId, key, value) { - if (this._wasOverridden) return undefined; + if (this._wasOverridden) { + return undefined; + } const savedSettings = this._settings .getValue('overridden-settings') @@ -61,9 +63,11 @@ class SettingsOverrider { const prefKey = `${schemaId}.${key}`; const oldValue = savedSettings[prefKey]; - if (value !== undefined) + if (value !== undefined) { savedSettings[prefKey] = value ?? this._maybeNullValue; - else delete savedSettings[prefKey]; + } else { + delete savedSettings[prefKey]; + } this._settings.setValue( 'overridden-settings', @@ -78,7 +82,9 @@ class SettingsOverrider { const userValue = settings.get_user_value(key); const values = this._overrides.get(settings.schemaId) ?? new Map(); - if (!values.size) this._overrides.set(settings.schemaId, values); + if (!values.size) { + this._overrides.set(settings.schemaId, values); + } values.set(key, userValue); settings.set_value(key, value); @@ -92,15 +98,22 @@ class SettingsOverrider { remove(schema, key) { const settings = this._originalSettings.get(schema); - if (!settings) return; + if (!settings) { + return; + } const values = this._overrides.get(settings.schemaId); const value = values?.get(key); - if (value === undefined) return; + if (value === undefined) { + return; + } - if (value) settings.set_value(key, value); - else settings.reset(key); + if (value) { + settings.set_value(key, value); + } else { + settings.reset(key); + } values.delete(key); this._maybeUpdateOverriden(settings.schemaId, key, undefined); @@ -122,14 +135,20 @@ class SettingsOverrider { new Gio.Settings({schema_id: schemaId}); value = value.get_variant(); - if (value.equal(this._maybeNullValue)) settings.reset(key); - else settings.set_value(key, value); + if (value.equal(this._maybeNullValue)) { + settings.reset(key); + } else { + settings.set_value(key, value); + } }); } else { this._originalSettings.forEach((settings) => { this._overrides.get(settings.schemaId).forEach((value, key) => { - if (value) settings.set_value(key, value); - else settings.reset(key); + if (value) { + settings.set_value(key, value); + } else { + settings.reset(key); + } }); }); } @@ -316,7 +335,9 @@ export default class TilingAssistantExtension extends Extension { * properties of windows before locking the screen. */ _saveBeforeSessionLock() { - if (!Main.sessionMode.isLocked) return; + if (!Main.sessionMode.isLocked) { + return; + } this._wasLocked = true; @@ -330,7 +351,9 @@ export default class TilingAssistantExtension extends Extension { try { parent.make_directory_with_parents(null); } catch (e) { - if (e.code !== Gio.IOErrorEnum.EXISTS) throw e; + if (e.code !== Gio.IOErrorEnum.EXISTS) { + throw e; + } } const path = GLib.build_filenamev([ @@ -342,7 +365,9 @@ export default class TilingAssistantExtension extends Extension { try { file.create(Gio.FileCreateFlags.NONE, null); } catch (e) { - if (e.code !== Gio.IOErrorEnum.EXISTS) throw e; + if (e.code !== Gio.IOErrorEnum.EXISTS) { + throw e; + } } file.replace_contents( @@ -362,7 +387,9 @@ export default class TilingAssistantExtension extends Extension { * reload them here. */ _loadAfterSessionLock() { - if (!this._wasLocked) return; + if (!this._wasLocked) { + return; + } this._wasLocked = false; @@ -372,16 +399,22 @@ export default class TilingAssistantExtension extends Extension { '/tiling-assistant/tiledSessionRestore2.json', ]); const file = Gio.File.new_for_path(path); - if (!file.query_exists(null)) return; + if (!file.query_exists(null)) { + return; + } try { file.create(Gio.FileCreateFlags.NONE, null); } catch (e) { - if (e.code !== Gio.IOErrorEnum.EXISTS) throw e; + if (e.code !== Gio.IOErrorEnum.EXISTS) { + throw e; + } } const [success, contents] = file.load_contents(null); - if (!success || !contents.length) return; + if (!success || !contents.length) { + return; + } const states = JSON.parse(new TextDecoder().decode(contents)); const keysAsNumbers = (entries) => diff --git a/tiling-assistant@leleat-on-github/prefs.js b/tiling-assistant@leleat-on-github/prefs.js index 9ddf40b..a832325 100644 --- a/tiling-assistant@leleat-on-github/prefs.js +++ b/tiling-assistant@leleat-on-github/prefs.js @@ -36,14 +36,21 @@ export default class Prefs extends ExtensionPreferences { settings.connect( 'changed::enable-advanced-experimental-features', () => { - settings.get_boolean('enable-advanced-experimental-features') ? - window.add(layoutsPage) - : window.remove(layoutsPage); + if ( + settings.get_boolean( + 'enable-advanced-experimental-features', + ) + ) { + window.add(layoutsPage); + } else { + window.remove(layoutsPage); + } }, ); - if (settings.get_boolean('enable-advanced-experimental-features')) + if (settings.get_boolean('enable-advanced-experimental-features')) { window.add(layoutsPage); + } // Bind settings to GUI this._bindSwitches(settings, builder); @@ -115,8 +122,11 @@ export default class Prefs extends ExtensionPreferences { }); } - /* + /** * Bind GUI AdwComboRows to settings. + * + * @param {Gio.Settings} settings + * @param {Gtk.Builder} builder */ _bindComboRows(settings, builder) { const comboRows = [ @@ -137,8 +147,11 @@ export default class Prefs extends ExtensionPreferences { }); } - /* + /** * Bind GUI color buttons to settings. + * + * @param {Gio.Settings} settings + * @param {Gtk.Builder} builder */ _bindColorButtons(settings, builder) { const switches = ['focus-hint-color']; @@ -158,8 +171,11 @@ export default class Prefs extends ExtensionPreferences { }); } - /* + /** * Bind radioButtons to settings. + * + * @param {Gio.Settings} settings + * @param {Gtk.Builder} builder */ _bindRadioButtons(settings, builder) { // These 'radioButtons' are basically just used as a 'fake ComboBox' with @@ -207,13 +223,18 @@ export default class Prefs extends ExtensionPreferences { ); // Set initial state - if (idx === currActive) checkButton.activate(); + if (idx === currActive) { + checkButton.activate(); + } }); }); } - /* + /** * Bind keybinding widgets to settings. + * + * @param {Gio.Settings} settings + * @param {Gtk.Builder} builder */ _bindKeybindings(settings, builder) { const shortcuts = Shortcuts.getAllKeys(); @@ -229,6 +250,9 @@ export default class Prefs extends ExtensionPreferences { * discoverable through the GUI and need to first be set with the gsetting. * The normal rows should have the id of: GSETTING_WITH_UNDERSCORES_row. * ShortcutListeners have the format of GSETTING_WITH_UNDERSCORES. + * + * @param {Gio.Settings} settings + * @param {Gtk.Builder} builder */ _setDeprecatedSettings(settings, builder) { // Keybindings @@ -252,6 +276,12 @@ export default class Prefs extends ExtensionPreferences { }); } + /** + * + * @param {Adw.fillPreferencesWindow} window - The preferences window + * @param {Gio.Settings} settings - The settings object + * @param {Gtk.Builder} builder - The builder object + */ _addHeaderBarInfoButton(window, settings, builder) { // Add headerBar button for menu // TODO: is this a 'reliable' method to access the headerbar? @@ -310,6 +340,10 @@ export default class Prefs extends ExtensionPreferences { returnButton.connect('clicked', () => window.close_subpage()); } + /** + * + * @param {Adw.PreferencesWindow} window + */ _openBugReport(window) { Gtk.show_uri( window, @@ -318,6 +352,10 @@ export default class Prefs extends ExtensionPreferences { ); } + /** + * + * @param {Adw.PreferencesWindow} window + */ _openUserGuide(window) { Gtk.show_uri( window, @@ -326,6 +364,10 @@ export default class Prefs extends ExtensionPreferences { ); } + /** + * + * @param {Adw.PreferencesWindow} window + */ _openChangelog(window) { Gtk.show_uri( window, @@ -334,6 +376,10 @@ export default class Prefs extends ExtensionPreferences { ); } + /** + * + * @param {Adw.PreferencesWindow} window + */ _openLicense(window) { Gtk.show_uri( window, @@ -342,6 +388,11 @@ export default class Prefs extends ExtensionPreferences { ); } + /** + * + * @param {Adw.PreferencesWindow} window + * @param {Gtk.Builder} builder + */ _openHiddenSettings(window, builder) { const hiddenSettingsPage = builder.get_object('hidden_settings'); window.present_subpage(hiddenSettingsPage); diff --git a/tiling-assistant@leleat-on-github/src/common.js b/tiling-assistant@leleat-on-github/src/common.js index bd1f6eb..c5ab497 100644 --- a/tiling-assistant@leleat-on-github/src/common.js +++ b/tiling-assistant@leleat-on-github/src/common.js @@ -182,10 +182,18 @@ export class Direction { static opposite(dir) { let opposite = 0; - if (dir & this.N) opposite |= this.S; - if (dir & this.S) opposite |= this.N; - if (dir & this.W) opposite |= this.E; - if (dir & this.E) opposite |= this.W; + if (dir & this.N) { + opposite |= this.S; + } + if (dir & this.S) { + opposite |= this.N; + } + if (dir & this.W) { + opposite |= this.E; + } + if (dir & this.E) { + opposite |= this.W; + } return opposite; } @@ -275,7 +283,9 @@ export class Layout { */ validate() { const rects = this.getItems().map((i) => i.rect); - if (!rects.length) return [false, 'No valid rectangles defined.', -1]; + if (!rects.length) { + return [false, 'No valid rectangles defined.', -1]; + } const getOverlapArea = (r1, r2) => { return ( @@ -295,23 +305,27 @@ export class Layout { for (let i = 0; i < rects.length; i++) { const rect = rects[i]; - if (rect.width <= 0 || rect.width > 1) + if (rect.width <= 0 || rect.width > 1) { return [false, `Rectangle ${i} has an invalid width.`, i]; + } - if (rect.height <= 0 || rect.height > 1) + if (rect.height <= 0 || rect.height > 1) { return [false, `Rectangle ${i} has an invalid height.`, i]; + } if ( rect.x < 0 || rect.y < 0 || rect.x + rect.width > 1 || rect.y + rect.height > 1 - ) + ) { return [false, `Rectangle ${i} extends beyond the screen.`, i]; + } for (let j = i + 1; j < rects.length; j++) { - if (getOverlapArea(rect, rects[j]) !== 0) + if (getOverlapArea(rect, rects[j]) !== 0) { return [false, `Rectangles ${i} and ${j} overlap.`, j]; + } } } diff --git a/tiling-assistant@leleat-on-github/src/dependencies/unexported/altTab.js b/tiling-assistant@leleat-on-github/src/dependencies/unexported/altTab.js index 8cb427f..a0282f9 100644 --- a/tiling-assistant@leleat-on-github/src/dependencies/unexported/altTab.js +++ b/tiling-assistant@leleat-on-github/src/dependencies/unexported/altTab.js @@ -3,6 +3,10 @@ import {Meta} from '../gi.js'; export const baseIconSizes = [96, 64, 48, 32, 22]; export const APP_ICON_HOVER_TIMEOUT = 200; // milliseconds +/** + * + * @param {Meta.Workspace} workspace + */ export function getWindows(workspace) { // We ignore skip-taskbar windows in switchers, but if they are attached // to their parent, their position in the MRU list may be more appropriate diff --git a/tiling-assistant@leleat-on-github/src/extension/altTab.js b/tiling-assistant@leleat-on-github/src/extension/altTab.js index 9848fbd..11c509c 100644 --- a/tiling-assistant@leleat-on-github/src/extension/altTab.js +++ b/tiling-assistant@leleat-on-github/src/extension/altTab.js @@ -22,15 +22,18 @@ import {TilingWindowManager as Twm} from './tilingWindowManager.js'; */ export default class AltTabOverride { constructor() { - if (Settings.getBoolean('tilegroups-in-app-switcher')) + if (Settings.getBoolean('tilegroups-in-app-switcher')) { this._overrideNativeAppSwitcher(); + } this._settingsId = Settings.changed( 'tilegroups-in-app-switcher', () => { - if (Settings.getBoolean('tilegroups-in-app-switcher')) + if (Settings.getBoolean('tilegroups-in-app-switcher')) { this._overrideNativeAppSwitcher(); - else this._restoreNativeAppSwitcher(); + } else { + this._restoreNativeAppSwitcher(); + } }, ); } @@ -64,8 +67,9 @@ export default class AltTabOverride { * @param {*} binding - */ _startSwitcher(display, window, binding) { - if (Main.wm._workspaceSwitcherPopup !== null) + if (Main.wm._workspaceSwitcherPopup !== null) { Main.wm._workspaceSwitcherPopup.destroy(); + } const tabPopup = new TilingAppSwitcherPopup(); @@ -75,8 +79,9 @@ export default class AltTabOverride { binding.get_name(), binding.get_mask(), ) - ) + ) { tabPopup.destroy(); + } } } @@ -104,7 +109,9 @@ export const TilingAppSwitcherPopup = GObject.registerClass( // Called when closing an entire app / tileGroup _quitApplication(index) { const item = this._items[index]; - if (!item) return; + if (!item) { + return; + } item.cachedWindows.forEach((w) => w.delete(global.get_current_time()), @@ -117,7 +124,9 @@ export const TilingAppSwitcherPopup = GObject.registerClass( // meaning that .cachedWindow of an item was updated via signals _windowRemoved(thumbnailSwitcher, n) { const item = this._items[this._selectedIndex]; - if (!item) return; + if (!item) { + return; + } if (item.cachedWindows.length) { const newIndex = Math.min(n, item.cachedWindows.length - 1); @@ -205,8 +214,9 @@ export const TilingAppSwitcher = GObject.registerClass( this._apps = [...new Set(allApps)]; this._stateChangedIds = this._apps.map((app) => app.connect('notify::state', () => { - if (app.state !== Shell.AppState.RUNNING) + if (app.state !== Shell.AppState.RUNNING) { this.icons.forEach((item) => item.removeApp(app)); + } }), ); @@ -214,8 +224,9 @@ export const TilingAppSwitcher = GObject.registerClass( } _onDestroy() { - if (this._mouseTimeOutId !== 0) + if (this._mouseTimeOutId !== 0) { GLib.source_remove(this._mouseTimeOutId); + } this._stateChangedIds?.forEach((id, index) => this._apps[index].disconnect(id), @@ -229,8 +240,9 @@ export const TilingAppSwitcher = GObject.registerClass( while ( this._items.length > 1 && this._items[j].style_class !== 'item-box' - ) + ) { j++; + } let themeNode = this._items[j].get_theme_node(); this._list.ensure_style(); @@ -265,21 +277,26 @@ export const TilingAppSwitcher = GObject.registerClass( iconSize = baseIconSizes[i]; let height = iconSizes[i] + iconSpacing; let w = height * this._items.length + totalSpacing; - if (w <= availWidth) break; + if (w <= availWidth) { + break; + } } } this._iconSize = iconSize; for (let i = 0; i < this.icons.length; i++) { - // eslint-disable-next-line eqeqeq - if (this.icons[i].icon != null) break; + if (this.icons[i].icon != null) { + break; + } this.icons[i].set_size(iconSize); } } vfunc_get_preferred_height(forWidth) { - if (!this._iconSize) this._setIconSize(); + if (!this._iconSize) { + this._setIconSize(); + } return super.vfunc_get_preferred_height(forWidth); } @@ -317,8 +334,9 @@ export const TilingAppSwitcher = GObject.registerClass( if ( item === this._items[this._highlighted] || item === this._items[this._delayedHighlighted] - ) + ) { return Clutter.EVENT_PROPAGATE; + } const index = this._items.indexOf(item); @@ -358,8 +376,9 @@ export const TilingAppSwitcher = GObject.registerClass( x, y, ); - if (this._items[index].contains(pickedActor)) + if (this._items[index].contains(pickedActor)) { this._itemEntered(index); + } } // We override SwitcherList's highlight() method to also deal with @@ -371,12 +390,13 @@ export const TilingAppSwitcher = GObject.registerClass( // highlighted. highlight(n, justOutline) { if (this.icons[this._highlighted]) { - if (this.icons[this._highlighted].cachedWindows.length === 1) + if (this.icons[this._highlighted].cachedWindows.length === 1) { this._arrows[this._highlighted].hide(); - else + } else { this._arrows[this._highlighted].remove_style_pseudo_class( 'highlighted', ); + } } super.highlight(n, justOutline); @@ -385,12 +405,13 @@ export const TilingAppSwitcher = GObject.registerClass( if ( justOutline && this.icons[this._highlighted].cachedWindows.length === 1 - ) + ) { this._arrows[this._highlighted].show(); - else + } else { this._arrows[this._highlighted].add_style_pseudo_class( 'highlighted', ); + } } } @@ -401,8 +422,9 @@ export const TilingAppSwitcher = GObject.registerClass( appIcon.app.connectObject( 'notify::state', (app) => { - if (app.state !== Shell.AppState.RUNNING) + if (app.state !== Shell.AppState.RUNNING) { this._removeIcon(app); + } }, this, ); @@ -414,13 +436,18 @@ export const TilingAppSwitcher = GObject.registerClass( this.add_child(arrow); this._arrows.push(arrow); - if (appIcon.cachedWindows.length === 1) arrow.hide(); - else item.add_accessible_state(Atk.StateType.EXPANDABLE); + if (appIcon.cachedWindows.length === 1) { + arrow.hide(); + } else { + item.add_accessible_state(Atk.StateType.EXPANDABLE); + } } _removeIcon(item) { const index = this.icons.findIndex((i) => i === item); - if (index === -1) return; + if (index === -1) { + return; + } this._arrows[index].destroy(); this._arrows.splice(index, 1); @@ -494,7 +521,11 @@ const AppSwitcherItem = GObject.registerClass( // Only unique apps : this.cachedWindows.reduce((allApps, w) => { const a = winTracker.get_window_app(w); - !allApps.includes(a) && allApps.push(a); + + if (!allApps.includes(a)) { + allApps.push(a); + } + return allApps; }, []); @@ -505,7 +536,9 @@ const AppSwitcherItem = GObject.registerClass( this.appIcons.push(appIcon); // Add chain to the right AppIcon except for the last AppIcon - if (idx >= apps.length - 1) return; + if (idx >= apps.length - 1) { + return; + } // Chain const chain = new St.Icon({ @@ -529,7 +562,9 @@ const AppSwitcherItem = GObject.registerClass( removeApp(app) { for (let i = this.appIcons.length - 1; i >= 0; i--) { const appIcon = this.appIcons[i]; - if (appIcon.app !== app) continue; + if (appIcon.app !== app) { + continue; + } this.appIcons.splice(i, 1); appIcon.destroy(); @@ -537,7 +572,9 @@ const AppSwitcherItem = GObject.registerClass( chain?.destroy(); } - if (!this.appIcons.length) this.emit('all-icons-removed'); + if (!this.appIcons.length) { + this.emit('all-icons-removed'); + } } }, ); diff --git a/tiling-assistant@leleat-on-github/src/extension/focusHint.js b/tiling-assistant@leleat-on-github/src/extension/focusHint.js index efae3a2..73df5cd 100644 --- a/tiling-assistant@leleat-on-github/src/extension/focusHint.js +++ b/tiling-assistant@leleat-on-github/src/extension/focusHint.js @@ -37,8 +37,9 @@ export default class FocusHintManager { ); this._setHint(); - if (this._hint?.shouldIndicate(initialWindow)) + if (this._hint?.shouldIndicate(initialWindow)) { this._hint.indicate(initialWindow); + } } destroy() { @@ -106,17 +107,24 @@ class Hint { const idleMonitor = global.backend.get_core_idle_monitor(); const idleTime = 120 * 1000; - this._activeWatchId && idleMonitor.remove_watch(this._activeWatchId); - this._activeWatchId = 0; + if (this._activeWatchId) { + idleMonitor.remove_watch(this._activeWatchId); + this._activeWatchId = 0; + } + + if (this._idleWatchId) { + idleMonitor.remove_watch(this._idleWatchId); + } - this._idleWatchId && idleMonitor.remove_watch(this._idleWatchId); this._idleWatchId = idleMonitor.add_idle_watch(idleTime, () => { this._activeWatchId = idleMonitor.add_user_active_watch(() => { this._activeWatchId = 0; const focus = global.display.focus_window; - if (this.shouldIndicate(focus)) this.indicate(focus); + if (this.shouldIndicate(focus)) { + this.indicate(focus); + } }); }); } @@ -142,7 +150,9 @@ class Hint { } _onWindowCreated(window) { - if (!this._allowedWindowType(window.get_window_type())) return; + if (!this._allowedWindowType(window.get_window_type())) { + return; + } window.connectObject( 'unmanaged', @@ -151,8 +161,11 @@ class Hint { const focus = global.display.focus_window; - if (focus && this.shouldIndicate(focus)) this.indicate(focus); - else this.resetAnimation(); + if (focus && this.shouldIndicate(focus)) { + this.indicate(focus); + } else { + this.resetAnimation(); + } }, this, ); @@ -188,7 +201,9 @@ class Hint { if (global.display.remove_keybinding(key)) { const handler = (_, __, keybinding) => { - if (!Main.sessionMode.hasOverview) return; + if (!Main.sessionMode.hasOverview) { + return; + } const [, , , target] = keybinding.get_name().split('-'); const apps = AppFavorites.getAppFavorites().getFavorites(); @@ -248,7 +263,9 @@ class Hint { // This is set if the focused window moved to the new workspace // along with the workspace switch animation. E. g. when using // Shift + Super + Alt + Arrow_Keys. - if (this.movingWindow) return; + if (this.movingWindow) { + return; + } // There are 2 different 'focus behaviors' during a workspace // animation. 1: When the workspace switch is initiated by an app or @@ -268,23 +285,31 @@ class Hint { global.workspace_manager.get_workspace_by_index(to); const [newFocus] = AltTab.getWindows(newWorkspace); - if (that.shouldIndicate(newFocus)) that.indicate(newFocus); - else that.resetAnimation(); + if (that.shouldIndicate(newFocus)) { + that.indicate(newFocus); + } else { + that.resetAnimation(); + } }, ); }; } shouldIndicate(window) { - if (!window || !window.get_compositor_private()) return false; + if (!window || !window.get_compositor_private()) { + return false; + } - if (!this._allowedWindowType(window.get_window_type())) return false; + if (!this._allowedWindowType(window.get_window_type())) { + return false; + } if ( window.is_fullscreen() || window.get_maximized() === Meta.MaximizeFlags.BOTH - ) + ) { return false; + } return true; } @@ -292,11 +317,15 @@ class Hint { _removeIdleWatcher() { const idleMonitor = global.backend.get_core_idle_monitor(); - this._activeWatchId && idleMonitor.remove_watch(this._activeWatchId); - this._activeWatchId = 0; + if (this._activeWatchId) { + idleMonitor.remove_watch(this._activeWatchId); + this._activeWatchId = 0; + } - this._idleWatchId && idleMonitor.remove_watch(this._idleWatchId); - this._idleWatchId = 0; + if (this._idleWatchId) { + idleMonitor.remove_watch(this._idleWatchId); + this._idleWatchId = 0; + } } _restoreSwitcherPopupFinish() { @@ -385,7 +414,9 @@ class AnimatedOutlineHint extends Hint { indicate(window, workspaceSwitchAnimationDuration = 250) { this.resetAnimation(); - if (!this.shouldIndicate(window)) return; + if (!this.shouldIndicate(window)) { + return; + } const windowActor = window.get_compositor_private(); const workspaceAnimationWindowClone = @@ -467,7 +498,9 @@ class AnimatedUpscaleHint extends Hint { indicate(window, workspaceSwitchAnimationDuration = 250) { this.resetAnimation(); - if (!this.shouldIndicate(window)) return; + if (!this.shouldIndicate(window)) { + return; + } const windowActor = window.get_compositor_private(); const workspaceAnimationWindowClone = @@ -583,14 +616,18 @@ class StaticOutlineHint extends AnimatedOutlineHint { indicate(window, workspaceSwitchAnimationDuration = 250) { this.resetAnimation(); - if (!this.shouldIndicate(window)) return; + if (!this.shouldIndicate(window)) { + return; + } const animatingWorkspaceSwitch = !!Main.wm._workspaceAnimation._switchData; // Only need to use an animation to indicate the focus when switching // workspaces. In the other cases, there is the static `this._outline`. - if (!animatingWorkspaceSwitch) return; + if (!animatingWorkspaceSwitch) { + return; + } const windowActor = window.get_compositor_private(); const workspaceAnimationWindowClone = @@ -647,7 +684,9 @@ class StaticOutlineHint extends AnimatedOutlineHint { _queueGeometryUpdate() { const windowActor = this._window.get_compositor_private(); - if (!windowActor) return; + if (!windowActor) { + return; + } this._laterID = global.compositor .get_laters() @@ -690,9 +729,11 @@ class StaticOutlineHint extends AnimatedOutlineHint { if ( this._window.is_fullscreen() || this._window.get_maximized() === Meta.MaximizeFlags.BOTH - ) + ) { this._outline.hide(); - else this._queueGeometryUpdate(); + } else { + this._queueGeometryUpdate(); + } } _updateGeometry() { @@ -779,9 +820,11 @@ function createContainers( .get_children() .find((child) => child instanceof OsdWindow.OsdWindow); - if (osdWindow) + if (osdWindow) { Main.uiGroup.insert_child_below(monitorContainer, osdWindow); - else Main.uiGroup.add_child(monitorContainer); + } else { + Main.uiGroup.add_child(monitorContainer); + } } else { global.window_group.add_child(monitorContainer); } @@ -842,7 +885,9 @@ function findWindowCloneForWorkspaceAnimation( windowActor, animatingWorkspaceSwitch, ) { - if (!animatingWorkspaceSwitch) return null; + if (!animatingWorkspaceSwitch) { + return null; + } const switchData = Main.wm._workspaceAnimation._switchData; let clone = null; @@ -852,7 +897,9 @@ function findWindowCloneForWorkspaceAnimation( return workspaceGroup._windowRecords.find((record) => { const foundClone = record.windowActor === windowActor; - if (foundClone) ({clone} = record); + if (foundClone) { + ({clone} = record); + } return foundClone; }); diff --git a/tiling-assistant@leleat-on-github/src/extension/keybindingHandler.js b/tiling-assistant@leleat-on-github/src/extension/keybindingHandler.js index 9c81fca..de52019 100644 --- a/tiling-assistant@leleat-on-github/src/extension/keybindingHandler.js +++ b/tiling-assistant@leleat-on-github/src/extension/keybindingHandler.js @@ -70,7 +70,9 @@ export default class TilingKeybindingHandler { } const window = global.display.focus_window; - if (!window) return; + if (!window) { + return; + } // Auto-tile: tile to empty space. If there's none: untile, // if it's already tiled else maximize @@ -96,7 +98,11 @@ export default class TilingKeybindingHandler { // Toggle always-on-top } else if (shortcutName === 'toggle-always-on-top') { - window.is_above() ? window.unmake_above() : window.make_above(); + if (window.is_above()) { + window.unmake_above(); + } else { + window.make_above(); + } // Toggle maximization vertically } else if (shortcutName === 'tile-maximize-vertically') { @@ -202,11 +208,12 @@ export default class TilingKeybindingHandler { // Restore window size } else if (shortcutName === 'restore-window') { - if (window.untiledRect) + if (window.untiledRect) { // Tiled & maximized with gaps Twm.untile(window, {clampToWorkspace: true}); - else if (window.get_maximized()) + } else if (window.get_maximized()) { window.unmaximize(window.get_maximized()); + } // Center window } else if (shortcutName === 'center-window') { @@ -220,26 +227,35 @@ export default class TilingKeybindingHandler { currRect.height, ); - if (tileRect.equal(currRect)) return; + if (tileRect.equal(currRect)) { + return; + } Twm.tile(window, tileRect, {openTilingPopup: false}); } else if (!Twm.isMaximized(window)) { - if (!window.allows_move()) return; + if (!window.allows_move()) { + return; + } const currRect = window.get_frame_rect(); const x = workArea.center.x - Math.floor(currRect.width / 2); const y = workArea.center.y - Math.floor(currRect.height / 2); - if (x === currRect.x && y === currRect.y) return; + if (x === currRect.x && y === currRect.y) { + return; + } const wActor = window.get_compositor_private(); - wActor && + + if (wActor) { Main.wm._prepareAnimationInfo( global.window_manager, wActor, currRect, Meta.SizeChange.UNMAXIMIZE, ); + } + window.move_frame(false, x, y); } // Tile a window but ignore T-A features @@ -594,9 +610,13 @@ export default class TilingKeybindingHandler { workArea, window.get_monitor(), ); - isWindowsStyle ? - window.minimize() - : Twm.toggleTiling(window, rect); + + if (isWindowsStyle) { + window.minimize(); + } else { + Twm.toggleTiling(window, rect); + } + return; } } else if (isTopLeftQuarter) { @@ -662,9 +682,13 @@ export default class TilingKeybindingHandler { workArea, window.get_monitor(), ); - isWindowsStyle ? - window.minimize() - : Twm.toggleTiling(window, rect); + + if (isWindowsStyle) { + window.minimize(); + } else { + Twm.toggleTiling(window, rect); + } + return; } } else if (isBottomRightQuarter) { @@ -692,9 +716,13 @@ export default class TilingKeybindingHandler { workArea, window.get_monitor(), ); - isWindowsStyle ? - window.minimize() - : Twm.toggleTiling(window, rect); + + if (isWindowsStyle) { + window.minimize(); + } else { + Twm.toggleTiling(window, rect); + } + return; } } diff --git a/tiling-assistant@leleat-on-github/src/extension/layoutsManager.js b/tiling-assistant@leleat-on-github/src/extension/layoutsManager.js index 47413f1..beda29b 100644 --- a/tiling-assistant@leleat-on-github/src/extension/layoutsManager.js +++ b/tiling-assistant@leleat-on-github/src/extension/layoutsManager.js @@ -129,7 +129,9 @@ export default class TilingLayoutsManager { */ startLayouting(index) { const layout = Util.getLayouts()?.[index]; - if (!layout) return; + if (!layout) { + return; + } const allWs = Settings.getBoolean('tiling-popup-all-workspace'); this._remainingWindows = Twm.getWindows(allWs); @@ -202,7 +204,12 @@ export default class TilingLayoutsManager { } const appId = this._currItem.appId; - appId ? this._openAppTiled(appId) : this._openTilingPopup(); + + if (appId) { + this._openAppTiled(appId); + } else { + this._openTilingPopup(); + } } _openAppTiled(appId) { @@ -219,7 +226,10 @@ export default class TilingLayoutsManager { (w) => winTracker.get_window_app(w) === app, ); const window = this._remainingWindows[idx]; - idx !== -1 && this._remainingWindows.splice(idx, 1); + + if (idx !== -1) { + this._remainingWindows.splice(idx, 1); + } if (window) { Twm.tile(window, this._currRect, { @@ -336,7 +346,7 @@ const LayoutSearch = GObject.registerClass( // We expect at least a keyboard grab here if ((grab.get_seat_state() & Clutter.GrabState.KEYBOARD) === 0) { Main.popModal(grab); - return false; + return; } this._grab = grab; @@ -433,9 +443,13 @@ const LayoutSearch = GObject.registerClass( _onTextChanged(clutterText) { const filterText = clutterText.get_text(); this._items.forEach((item) => { - item.text.toLowerCase().includes(filterText.toLowerCase()) ? - item.show() - : item.hide(); + if ( + item.text.toLowerCase().includes(filterText.toLowerCase()) + ) { + item.show(); + } else { + item.hide(); + } }); const nextVisibleIdx = this._items.findIndex( (item) => item.visible, @@ -468,7 +482,10 @@ const LayoutSearch = GObject.registerClass( } _activate() { - this._focused !== -1 && this.emit('item-activated', this._focused); + if (this._focused !== -1) { + this.emit('item-activated', this._focused); + } + this.destroy(); } }, diff --git a/tiling-assistant@leleat-on-github/src/extension/moveHandler.js b/tiling-assistant@leleat-on-github/src/extension/moveHandler.js index 864ddf0..f9399b7 100644 --- a/tiling-assistant@leleat-on-github/src/extension/moveHandler.js +++ b/tiling-assistant@leleat-on-github/src/extension/moveHandler.js @@ -23,8 +23,9 @@ export default class TilingMoveHandler { (src, window, grabOp) => { grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED - if (window && moveOps.includes(grabOp)) + if (window && moveOps.includes(grabOp)) { this._onMoveStarted(window, grabOp); + } }, this, ); @@ -60,16 +61,18 @@ export default class TilingMoveHandler { if (currMod === '') { for (const key of modKeys) { const mod = Settings.getInt(key); - if (mod === 2) + if (mod === 2) { // Alt Settings.setInt(key, 0); + } } } else if (currMod === '') { for (const key of modKeys) { const mod = Settings.getInt(key); - if (mod === 4) + if (mod === 4) { // Super Settings.setInt(key, 0); + } } } }; @@ -115,10 +118,11 @@ export default class TilingMoveHandler { } _onMonitorEntered(src, monitorNr, window) { - if (this._isGrabOp) + if (this._isGrabOp) { // Reset preview mode: // Currently only needed to grab the favorite layout for the new monitor. this._preparePreviewModeChange(this._currPreviewMode, window); + } } _onMoveStarted(window, grabOp) { @@ -131,8 +135,10 @@ export default class TilingMoveHandler { // Try to restore the window size if (window.tiledRect || this._wasMaximizedOnStart) { let counter = 0; - this._restoreSizeTimerId && + if (this._restoreSizeTimerId) { GLib.Source.remove(this._restoreSizeTimerId); + } + this._restoreSizeTimerId = GLib.timeout_add( GLib.PRIORITY_HIGH_IDLE, 10, @@ -234,8 +240,9 @@ export default class TilingMoveHandler { isCtrlReplacement = true; ctrlReplacedTileGroup.push(window); topTileGroup.forEach((w) => { - if (!this._tileRect.containsRect(w.tiledRect)) + if (!this._tileRect.containsRect(w.tiledRect)) { ctrlReplacedTileGroup.push(w); + } }); } @@ -254,9 +261,9 @@ export default class TilingMoveHandler { // Create a new tile group, in which some windows are already part // of a different tile group, with ctrl-(super)-drag. The window may // be maximized by ctrl-super-drag. - isCtrlReplacement && - window.isTiled && + if (isCtrlReplacement && window.isTiled) { Twm.updateTileGroup(ctrlReplacedTileGroup); + } } } finally { if (this._posChangedId) { @@ -320,8 +327,9 @@ export default class TilingMoveHandler { const updateInterval = 500; const timeSinceLastUpdate = this._movingTimerDuration * this._movingTimeoutsSinceUpdate; - if (timeSinceLastUpdate < updateInterval && !forceMoveUpdate) + if (timeSinceLastUpdate < updateInterval && !forceMoveUpdate) { return GLib.SOURCE_CONTINUE; + } this._movingTimeoutsSinceUpdate = 0; } @@ -367,13 +375,19 @@ export default class TilingMoveHandler { let newMode = ''; - if (useAdaptiveTiling) newMode = MoveModes.ADAPTIVE_TILING; - else if (usefavLayout) newMode = MoveModes.FAVORITE_LAYOUT; - else if (useIgnoreTa) newMode = MoveModes.IGNORE_TA; - else newMode = MoveModes.EDGE_TILING; + if (useAdaptiveTiling) { + newMode = MoveModes.ADAPTIVE_TILING; + } else if (usefavLayout) { + newMode = MoveModes.FAVORITE_LAYOUT; + } else if (useIgnoreTa) { + newMode = MoveModes.IGNORE_TA; + } else { + newMode = MoveModes.EDGE_TILING; + } - if (this._currPreviewMode !== newMode) + if (this._currPreviewMode !== newMode) { this._preparePreviewModeChange(newMode, window); + } switch (newMode) { case MoveModes.IGNORE_TA: @@ -470,8 +484,11 @@ export default class TilingMoveHandler { if (this._lastMonitorNr !== currMonitorNr) { this._monitorNr = this._lastMonitorNr; let timerId = 0; - this._latestMonitorLockTimerId && + + if (this._latestMonitorLockTimerId) { GLib.Source.remove(this._latestMonitorLockTimerId); + } + this._latestMonitorLockTimerId = GLib.timeout_add( GLib.PRIORITY_DEFAULT, 150, @@ -480,8 +497,9 @@ export default class TilingMoveHandler { if (timerId === this._latestMonitorLockTimerId) { this._monitorNr = global.display.get_current_monitor(); - if (global.display.is_grabbed()) + if (global.display.is_grabbed()) { this._edgeTilingPreview(window, grabOp); + } } this._latestMonitorLockTimerId = null; @@ -599,8 +617,9 @@ export default class TilingMoveHandler { this._tilePreview._rect && (holdTileRect.equal(this._tilePreview._rect) || this._tilePreview._rect.equal(tileRect.meta)) - ) + ) { return; + } this._tileRect = tileRect; this._tilePreview.open( @@ -610,8 +629,11 @@ export default class TilingMoveHandler { ); let timerId = 0; - this._latestPreviewTimerId && + + if (this._latestPreviewTimerId) { GLib.Source.remove(this._latestPreviewTimerId); + } + this._latestPreviewTimerId = GLib.timeout_add( GLib.PRIORITY_DEFAULT, Settings.getInt('toggle-maximize-tophalf-timer'), @@ -735,14 +757,16 @@ export default class TilingMoveHandler { const atRightEdge = this._lastPointerPos.x > hoveredRect.x2 - edgeRadius; - atTopEdge || atBottomEdge || atLeftEdge || atRightEdge ? + if (atTopEdge || atBottomEdge || atLeftEdge || atRightEdge) { this._adaptiveTilingPreviewGroup(window, hoveredRect, { atTopEdge, atBottomEdge, atLeftEdge, atRightEdge, - }) - : this._adaptiveTilingPreviewSingle(window, hoveredRect); + }); + } else { + this._adaptiveTilingPreviewSingle(window, hoveredRect); + } } } @@ -781,7 +805,9 @@ export default class TilingMoveHandler { this._tileRect = hoveredRect.copy(); } - if (!this._tilePreview.needsUpdate(this._tileRect)) return; + if (!this._tilePreview.needsUpdate(this._tileRect)) { + return; + } const monitor = global.display.get_current_monitor(); this._tilePreview.open(window, this._tileRect.meta, monitor); @@ -791,11 +817,15 @@ export default class TilingMoveHandler { return w.tiledRect.containsPoint(this._lastPointerPos); }); - if (!hoveredWindow) return; + if (!hoveredWindow) { + return; + } // Don't halve the window, if we compelety cover it i. e. // the user is hovering the tiled window at the center. - if (hoveredWindow.tiledRect.equal(this._tileRect)) return; + if (hoveredWindow.tiledRect.equal(this._tileRect)) { + return; + } const splitRect = hoveredWindow.tiledRect.minus(this._tileRect)[0]; this._splitRects.set(hoveredWindow, splitRect); @@ -822,34 +852,38 @@ export default class TilingMoveHandler { if ( w.tiledRect.y === hoveredRect.y || w.tiledRect.y2 === hoveredRect.y - ) + ) { return w.tiledRect.height < smallest.tiledRect.height ? w : smallest; + } } else if (hovered.atBottomEdge) { if ( w.tiledRect.y === hoveredRect.y2 || w.tiledRect.y2 === hoveredRect.y2 - ) + ) { return w.tiledRect.height < smallest.tiledRect.height ? w : smallest; + } } else if (hovered.atLeftEdge) { if ( w.tiledRect.x === hoveredRect.x || w.tiledRect.x2 === hoveredRect.x - ) + ) { return w.tiledRect.width < smallest.tiledRect.width ? w : smallest; + } } else if (hovered.atRightEdge) { if ( w.tiledRect.x === hoveredRect.x2 || w.tiledRect.x2 === hoveredRect.x2 - ) + ) { return w.tiledRect.width < smallest.tiledRect.width ? w : smallest; + } } return smallest; @@ -972,7 +1006,9 @@ export default class TilingMoveHandler { this._tileRect.tryAlignWith(workArea); - if (!this._tilePreview.needsUpdate(this._tileRect)) return; + if (!this._tilePreview.needsUpdate(this._tileRect)) { + return; + } this._tilePreview.open(window, this._tileRect.meta, monitor); this._splitRects.clear(); @@ -981,7 +1017,9 @@ export default class TilingMoveHandler { const leftOver = w.tiledRect.minus(this._tileRect); const splitRect = leftOver[0]; // w isn't an affected window. - if (splitRect?.equal(this._tileRect) ?? true) return; + if (splitRect?.equal(this._tileRect) ?? true) { + return; + } this._splitRects.set(w, splitRect); }); @@ -1038,11 +1076,15 @@ const TilePreview = GObject.registerClass( // Added param for animation and removed style for rounded corners open(window, tileRect, monitorIndex, animateTo = undefined) { const windowActor = window.get_compositor_private(); - if (!windowActor) return; + if (!windowActor) { + return; + } global.window_group.set_child_below_sibling(this, windowActor); - if (this._rect && this._rect.equal(tileRect)) return; + if (this._rect && this._rect.equal(tileRect)) { + return; + } const changeMonitor = this._monitorIndex === -1 || @@ -1080,12 +1122,26 @@ const TilePreview = GObject.registerClass( mode: Clutter.AnimationMode.EASE_OUT_QUAD, }; } else { - animateTo.x === undefined && this.set_x(tileRect.x); - animateTo.y === undefined && this.set_y(tileRect.y); - animateTo.width === undefined && this.set_width(tileRect.width); - animateTo.height === undefined && + if (animateTo.x === undefined) { + this.set_x(tileRect.x); + } + + if (animateTo.y === undefined) { + this.set_y(tileRect.y); + } + + if (animateTo.width === undefined) { + this.set_width(tileRect.width); + } + + if (animateTo.height === undefined) { this.set_height(tileRect.height); - animateTo.opacity === undefined && this.set_opacity(255); + } + + if (animateTo.opacity === undefined) { + this.set_opacity(255); + } + animateTo.duration = animateTo.duration ?? WINDOW_ANIMATION_TIME; animateTo.mode = diff --git a/tiling-assistant@leleat-on-github/src/extension/resizeHandler.js b/tiling-assistant@leleat-on-github/src/extension/resizeHandler.js index e5bb5eb..71438c8 100644 --- a/tiling-assistant@leleat-on-github/src/extension/resizeHandler.js +++ b/tiling-assistant@leleat-on-github/src/extension/resizeHandler.js @@ -43,8 +43,9 @@ export default class TilingResizeHandler { (d, window, grabOp) => { grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED - if (window && isResizing(grabOp)) + if (window && isResizing(grabOp)) { this._onResizeStarted(window, grabOp); + } }, this, ); @@ -53,8 +54,9 @@ export default class TilingResizeHandler { (d, window, grabOp) => { grabOp &= ~1024; // META_GRAB_OP_WINDOW_FLAG_UNCONSTRAINED - if (window && isResizing(grabOp)) + if (window && isResizing(grabOp)) { this._onResizeFinished(window, grabOp); + } }, this, ); @@ -72,7 +74,9 @@ export default class TilingResizeHandler { } _onResizeStarted(window, grabOp) { - if (!window.isTiled) return; + if (!window.isTiled) { + return; + } // Use the same margin for the alignment and equality check below. const margin = 5; @@ -80,13 +84,14 @@ export default class TilingResizeHandler { topTileGroup.forEach((w) => { this._preGrabRects.set(w, new Rect(w.get_frame_rect())); - if (w !== window) + if (w !== window) { // There is no snapping for tiled windows, if the user set a window // gap. So the windows may not align properly, if the user tried // to manually resize them to be edge to edge. In that case, assume // that windows that are within a certain margin distance to each // other are meant to align and resize them together. w.tiledRect.tryAlignWith(window.tiledRect, margin); + } }); // Windows can be part of multiple tile groups. We however only resize @@ -96,20 +101,29 @@ export default class TilingResizeHandler { // group's tiles. So remove the shared windows from the lower tile group. const allWindows = Twm.getWindows(); allWindows.forEach((w) => { - if (!w.isTiled) return; + if (!w.isTiled) { + return; + } - if (topTileGroup.includes(w)) return; + if (topTileGroup.includes(w)) { + return; + } // Gets a tile group of windows without the ones // which are about to be resized const group = Twm.getTileGroupFor(w); const newGroup = group.reduce((gr, win) => { - !topTileGroup.includes(win) && gr.push(win); + if (!topTileGroup.includes(win)) { + gr.push(win); + } + return gr; }, []); // Tile groups are the same - if (group.length === newGroup.length) return; + if (group.length === newGroup.length) { + return; + } // Remove old tile group and create new one Twm.clearTilingProps(w.get_id()); @@ -132,12 +146,13 @@ export default class TilingResizeHandler { Meta.GrabOp.RESIZING_W, Meta.GrabOp.RESIZING_E, ]; - if (isCtrlPressed && singleEdgeResizeOp.includes(grabOp)) + if (isCtrlPressed && singleEdgeResizeOp.includes(grabOp)) { topTileGroup = this._getWindowsForIndividualResize( window, topTileGroup, grabOp, ); + } switch (grabOp) { // Resizing cardinal directions @@ -150,7 +165,9 @@ export default class TilingResizeHandler { false, false, ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -169,7 +186,9 @@ export default class TilingResizeHandler { false, false, ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -188,7 +207,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x2, otherRect.x2, margin), Util.equal(grabbedRect.x2, otherRect.x, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -207,7 +228,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x, otherRect.x, margin), Util.equal(grabbedRect.x, otherRect.x2, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -227,7 +250,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x, otherRect.x, margin), Util.equal(grabbedRect.x, otherRect.x2, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -251,7 +276,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x2, otherRect.x2, margin), Util.equal(grabbedRect.x2, otherRect.x, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -275,7 +302,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x, otherRect.x, margin), Util.equal(grabbedRect.x, otherRect.x2, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -299,7 +328,9 @@ export default class TilingResizeHandler { Util.equal(grabbedRect.x2, otherRect.x2, margin), Util.equal(grabbedRect.x2, otherRect.x, margin), ); - resizeOp && this._resizeOps.set(otherWindow, resizeOp); + if (resizeOp) { + this._resizeOps.set(otherWindow, resizeOp); + } } window.connectObject( @@ -319,7 +350,9 @@ export default class TilingResizeHandler { _onResizeFinished(window, grabOp) { window.disconnectObject(this); - if (!window.isTiled) return; + if (!window.isTiled) { + return; + } const monitor = window.get_monitor(); const screenTopGap = @@ -345,17 +378,19 @@ export default class TilingResizeHandler { let newGrabbedTiledRectX = window.tiledRect.x + (grabbedsNewRect.x - grabbedsOldRect.x); // Switch the screenGap for a windowGap - if (isResizingW && window.tiledRect.x === workArea.x) + if (isResizingW && window.tiledRect.x === workArea.x) { newGrabbedTiledRectX = newGrabbedTiledRectX + screenLeftGap - windowGap / 2; + } // Same as W but different orientation const isResizingN = (grabOp & Meta.GrabOp.RESIZING_N) > 1; let newGrabbedTiledRectY = window.tiledRect.y + (grabbedsNewRect.y - grabbedsOldRect.y); - if (isResizingN && window.tiledRect.y === workArea.y) + if (isResizingN && window.tiledRect.y === workArea.y) { newGrabbedTiledRectY = newGrabbedTiledRectY + screenTopGap - windowGap / 2; + } // If resizing on the E side, you can simply rely on get_frame_rect's // new width else x2 should stick to where it was (manual calc due @@ -402,7 +437,9 @@ export default class TilingResizeHandler { window.tiledRect.height - grabbedsOldTiledRect.height; this._resizeOps.forEach((resizeOp, win) => { - if (win === window) return; + if (win === window) { + return; + } if (resizeOp.side & Side.SAME_H) { win.tiledRect.x += tiledRectDiffX; @@ -445,7 +482,7 @@ export default class TilingResizeHandler { resizeOp.side & Side.OPPOSING_H, ); - if (rectV && rectH) + if (rectV && rectH) { window.move_resize_frame( false, rectH[0], @@ -453,8 +490,11 @@ export default class TilingResizeHandler { rectH[2], rectV[3], ); - else if (rectV) window.move_resize_frame(false, ...rectV); - else if (rectH) window.move_resize_frame(false, ...rectH); + } else if (rectV) { + window.move_resize_frame(false, ...rectV); + } else if (rectH) { + window.move_resize_frame(false, ...rectH); + } }); } @@ -468,9 +508,13 @@ export default class TilingResizeHandler { resizeOnSameSide, resizeOnOpposingSide, ) { - if (!grabOp) return null; + if (!grabOp) { + return null; + } - if (!resizeOnSameSide && !resizeOnOpposingSide) return null; + if (!resizeOnSameSide && !resizeOnOpposingSide) { + return null; + } const resizedRect = new Rect(resizedWindow.get_frame_rect()); const wRect = new Rect(window.get_frame_rect()); @@ -538,6 +582,8 @@ export default class TilingResizeHandler { wRect.height, ]; } + + return null; } /** @@ -605,8 +651,9 @@ export default class TilingResizeHandler { checkingWindows.forEach((w) => { uncheckedWindows.forEach((unchecked) => { - if (borders(w, unchecked, sideDeterminant)) + if (borders(w, unchecked, sideDeterminant)) { borderingWindows.push(unchecked); + } }); }); @@ -663,11 +710,17 @@ const ResizeOp = class ResizeOp { let verticalResizeSide = Side.NONE; let horizontalResizeSide = Side.NONE; - if (resizeOnSameSideV) verticalResizeSide = Side.SAME_V; - else if (resizeOnOpposingSideV) verticalResizeSide = Side.OPPOSING_V; + if (resizeOnSameSideV) { + verticalResizeSide = Side.SAME_V; + } else if (resizeOnOpposingSideV) { + verticalResizeSide = Side.OPPOSING_V; + } - if (resizeOnSameSideH) horizontalResizeSide = Side.SAME_H; - else if (resizeOnOpposingSideH) horizontalResizeSide = Side.OPPOSING_H; + if (resizeOnSameSideH) { + horizontalResizeSide = Side.SAME_H; + } else if (resizeOnOpposingSideH) { + horizontalResizeSide = Side.OPPOSING_H; + } const resizeSide = verticalResizeSide | horizontalResizeSide; return resizeSide ? new ResizeOp(resizeSide) : null; diff --git a/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js b/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js index acbff3c..d725b28 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js +++ b/tiling-assistant@leleat-on-github/src/extension/tileEditingMode.js @@ -65,7 +65,7 @@ export const TileEditor = GObject.registerClass( ); Main.notify('Tiling Assistant', msg); this.close(); - return; + return false; } this.monitor = this._windows[0].get_monitor(); @@ -80,11 +80,13 @@ export const TileEditor = GObject.registerClass( // The windows may not be at the foreground. They just weren't // overlapping other windows. So raise the entire tile group. this._windows.forEach((w) => { - if (w.raise_and_make_recent_on_workspace) + if (w.raise_and_make_recent_on_workspace) { w.raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else w.raise_and_make_recent(); + } else { + w.raise_and_make_recent(); + } }); // Create the active selection indicator. @@ -97,6 +99,8 @@ export const TileEditor = GObject.registerClass( ); this._selectIndicator.focus(window.tiledRect, window); this.add_child(this._selectIndicator); + + return true; } close() { @@ -110,17 +114,23 @@ export const TileEditor = GObject.registerClass( // this._selectIndicator may be undefined, if Tile Editing Mode is // left as soon as it's entered (e. g. when there's no tile group). - this._selectIndicator?.window?.activate(global.get_current_time()); - this._selectIndicator?.ease({ - x: this._selectIndicator.x + SCALE_SIZE / 2, - y: this._selectIndicator.y + SCALE_SIZE / 2, - width: this._selectIndicator.width - SCALE_SIZE, - height: this._selectIndicator.height - SCALE_SIZE, - opacity: 0, - duration: 150, - mode: Clutter.AnimationMode.EASE_OUT_QUAD, - onComplete: () => this.destroy(), - }) ?? this.destroy(); + if (this._selectIndicator) { + this._selectIndicator.window?.activate( + global.get_current_time(), + ); + this._selectIndicator.ease({ + x: this._selectIndicator.x + SCALE_SIZE / 2, + y: this._selectIndicator.y + SCALE_SIZE / 2, + width: this._selectIndicator.width - SCALE_SIZE, + height: this._selectIndicator.height - SCALE_SIZE, + opacity: 0, + duration: 150, + mode: Clutter.AnimationMode.EASE_OUT_QUAD, + onComplete: () => this.destroy(), + }); + } else { + this.destroy(); + } } vfunc_button_press_event() { @@ -133,32 +143,46 @@ export const TileEditor = GObject.registerClass( let newMode; // Swap windows - if (mods & Clutter.ModifierType.CONTROL_MASK) newMode = Modes.SWAP; + if (mods & Clutter.ModifierType.CONTROL_MASK) { + newMode = Modes.SWAP; + } // Move group to different workspace / monitor - else if (mods & Clutter.ModifierType.SHIFT_MASK) + else if (mods & Clutter.ModifierType.SHIFT_MASK) { newMode = Modes.MOVE; + } // Resize windows - else if (mods & Clutter.ModifierType.MOD4_MASK) + else if (mods & Clutter.ModifierType.MOD4_MASK) { newMode = Modes.RESIZE; + } // Default keys - else newMode = Modes.DEFAULT; + else { + newMode = Modes.DEFAULT; + } // First switch mode, if a new mod is pressed. - if (newMode !== this._mode) this._switchMode(newMode); + if (newMode !== this._mode) { + this._switchMode(newMode); + } // Handle the key press and get mode depending on that. newMode = await this._keyHandler.handleKeyPress(keyEvent); - if (newMode && newMode !== this._mode) this._switchMode(newMode); + if (newMode && newMode !== this._mode) { + this._switchMode(newMode); + } } vfunc_key_release_event(keyEvent) { const newMode = this._keyHandler.handleKeyRelease(keyEvent); - if (newMode && newMode !== this._mode) this._switchMode(newMode); + if (newMode && newMode !== this._mode) { + this._switchMode(newMode); + } } _switchMode(newMode) { - if (!newMode) return; + if (!newMode) { + return; + } this._mode = newMode; this._keyHandler.prepareLeave(); @@ -189,9 +213,9 @@ export const TileEditor = GObject.registerClass( const Indicator = GObject.registerClass( class TileEditingModeIndicator extends St.Widget { /** - * @param {string} widgetParams * @param {Rect} rect the final rect / pos of the indicator * @param {number} monitor + * @param {object} [widgetParams] */ _init(rect, monitor, widgetParams = {}) { // Start from a scaled down position. @@ -273,28 +297,38 @@ const DefaultKeyHandler = class DefaultKeyHandler { // [E]xpand to fill the available space } else if (keyVal === Clutter.KEY_e || keyVal === Clutter.KEY_E) { const window = this._selectIndicator.window; - if (!window) return Modes.DEFAULT; + if (!window) { + return Modes.DEFAULT; + } const tiledRect = this._windows.map((w) => w.tiledRect); const tileRect = Twm.getBestFreeRect(tiledRect, { currRect: window.tiledRect, }); - if (window.tiledRect.equal(tileRect)) return Modes.DEFAULT; + if (window.tiledRect.equal(tileRect)) { + return Modes.DEFAULT; + } const workArea = window.get_work_area_current_monitor(); const maximize = tileRect.equal(workArea); - if (maximize && this._windows.length > 1) return Modes.DEFAULT; + if (maximize && this._windows.length > 1) { + return Modes.DEFAULT; + } Twm.tile(window, tileRect, {openTilingPopup: false}); - if (maximize) return Modes.CLOSE; + if (maximize) { + return Modes.CLOSE; + } this._selectIndicator.focus(window.tiledRect, window); // [C]ycle through halves of the available space around the window } else if (keyVal === Clutter.KEY_c || keyVal === Clutter.KEY_C) { const window = this._selectIndicator.window; - if (!window) return Modes.DEFAULT; + if (!window) { + return Modes.DEFAULT; + } const tiledRects = this._windows.map((w) => w.tiledRect); const fullRect = Twm.getBestFreeRect(tiledRects, { @@ -330,31 +364,41 @@ const DefaultKeyHandler = class DefaultKeyHandler { // [Q]uit a window } else if (keyVal === Clutter.KEY_q || keyVal === Clutter.KEY_Q) { const window = this._selectIndicator.window; - if (!window) return Modes.DEFAULT; + if (!window) { + return Modes.DEFAULT; + } this._windows.splice(this._windows.indexOf(window), 1); window.delete(global.get_current_time()); const newWindow = this._windows[0]; - if (!newWindow) return Modes.CLOSE; + if (!newWindow) { + return Modes.CLOSE; + } this._selectIndicator.focus(newWindow.tiledRect, newWindow); // [R]estore a window's size } else if (keyVal === Clutter.KEY_r || keyVal === Clutter.KEY_R) { const window = this._selectIndicator.window; - if (!window) return Modes.DEFAULT; + if (!window) { + return Modes.DEFAULT; + } const selectedRect = window.tiledRect.copy(); this._windows.splice(this._windows.indexOf(window), 1); Twm.untile(window); - if (!this._windows.length) return Modes.CLOSE; + if (!this._windows.length) { + return Modes.CLOSE; + } // Re-raise tile group, so it isn't below the just-untiled window - if (this._windows[0].raise_and_make_recent_on_workspace) + if (this._windows[0].raise_and_make_recent_on_workspace) { this._windows[0].raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else this._windows[0].raise_and_make_recent(); + } else { + this._windows[0].raise_and_make_recent(); + } this._selectIndicator.focus(selectedRect, null); // [Enter] / [Esc]ape Tile Editing Mode @@ -383,13 +427,18 @@ const DefaultKeyHandler = class DefaultKeyHandler { } tilingPopup.connect('closed', (popup, canceled) => { - if (canceled) return; + if (canceled) { + return; + } const {tiledWindow} = popup; const replaced = this._windows.findIndex((w) => w.tiledRect.equal(tiledWindow.tiledRect), ); - replaced !== -1 && this._windows.splice(replaced, 1); + + if (replaced !== -1) { + this._windows.splice(replaced, 1); + } // Create the new tile group to allow 1 window to be part of multiple tile groups Twm.updateTileGroup([tiledWindow, ...this._windows]); @@ -406,9 +455,11 @@ const DefaultKeyHandler = class DefaultKeyHandler { * Automatically called on a keyEvent. * * @param {number} keyEvent + * * @returns {Modes|undefined} The mode to enter after the event was handled. */ - handleKeyRelease() { + // eslint-disable-next-line no-unused-vars + handleKeyRelease(keyEvent) { return undefined; } @@ -428,7 +479,9 @@ const DefaultKeyHandler = class DefaultKeyHandler { dir, screenRects, ); - if (!nearestRect) return; + if (!nearestRect) { + return; + } const newWindow = this._windows.find((w) => w.tiledRect.equal(nearestRect), @@ -485,10 +538,13 @@ const SwapKeyHandler = class SwapKeyHandler extends DefaultKeyHandler { const direction = Util.getDirection(keyEvent.get_key_symbol()); // [Directions] to choose a window to swap with WASD, hjkl or arrow keys - if (direction) this._focusInDir(direction); + if (direction) { + this._focusInDir(direction); + } // [Esc]ape Tile Editing Mode - else if (keyEvent.get_key_symbol() === Clutter.KEY_Escape) + else if (keyEvent.get_key_symbol() === Clutter.KEY_Escape) { return Modes.DEFAULT; + } return Modes.SWAP; } @@ -541,33 +597,37 @@ const MoveKeyHandler = class MoveKeyHandler extends DefaultKeyHandler { // To new workspace if (moveWorkspace) { let metaDir = Meta.MotionDirection.UP; - if (direction === Direction.N) + if (direction === Direction.N) { metaDir = Meta.MotionDirection.UP; - else if (direction === Direction.S) + } else if (direction === Direction.S) { metaDir = Meta.MotionDirection.DOWN; - else if (direction === Direction.W) + } else if (direction === Direction.W) { metaDir = Meta.MotionDirection.LEFT; - else if (direction === Direction.E) + } else if (direction === Direction.E) { metaDir = Meta.MotionDirection.RIGHT; + } const activeWs = global.workspace_manager.get_active_workspace(); const newWs = activeWs.get_neighbor(metaDir); - if (activeWs === newWs) return Modes.MOVE; + if (activeWs === newWs) { + return Modes.MOVE; + } Twm.moveGroupToWorkspace(this._tileEditor._windows, newWs); // To new monitor } else { let metaDir = Meta.DisplayDirection.UP; - if (direction === Direction.N) + if (direction === Direction.N) { metaDir = Meta.DisplayDirection.UP; - else if (direction === Direction.S) + } else if (direction === Direction.S) { metaDir = Meta.DisplayDirection.DOWN; - else if (direction === Direction.W) + } else if (direction === Direction.W) { metaDir = Meta.DisplayDirection.LEFT; - else if (direction === Direction.E) + } else if (direction === Direction.E) { metaDir = Meta.DisplayDirection.RIGHT; + } // get_current_monitor isn't accurate for our case const currMonitor = this._tileEditor.monitor; @@ -575,7 +635,9 @@ const MoveKeyHandler = class MoveKeyHandler extends DefaultKeyHandler { currMonitor, metaDir, ); - if (newMonitor === -1) return Modes.MOVE; + if (newMonitor === -1) { + return Modes.MOVE; + } Twm.moveGroupToMonitor( this._tileEditor._windows, @@ -618,7 +680,9 @@ const ResizeKeyHandler = class ResizeKeyHandler extends DefaultKeyHandler { const direction = Util.getDirection(keyEvent.get_key_symbol()); if (direction) { const window = this._selectIndicator.window; - if (!window) return Modes.DEFAULT; + if (!window) { + return Modes.DEFAULT; + } // First call: Go to an edge. if (!this._currEdge) { @@ -673,16 +737,19 @@ const ResizeKeyHandler = class ResizeKeyHandler extends DefaultKeyHandler { let resizeAmount = 50; // Limit resizeAmount to the workArea - if (this._currEdge === Direction.N && keyDir === Direction.N) + if (this._currEdge === Direction.N && keyDir === Direction.N) { resizeAmount = Math.min(resizeAmount, resizedRect.y - workArea.y); - else if (this._currEdge === Direction.S && keyDir === Direction.S) + } else if (this._currEdge === Direction.S && keyDir === Direction.S) { resizeAmount = Math.min(resizeAmount, workArea.y2 - resizedRect.y2); - else if (this._currEdge === Direction.W && keyDir === Direction.W) + } else if (this._currEdge === Direction.W && keyDir === Direction.W) { resizeAmount = Math.min(resizeAmount, resizedRect.x - workArea.x); - else if (this._currEdge === Direction.E && keyDir === Direction.E) + } else if (this._currEdge === Direction.E && keyDir === Direction.E) { resizeAmount = Math.min(resizeAmount, workArea.x2 - resizedRect.x2); + } - if (resizeAmount <= 0) return; + if (resizeAmount <= 0) { + return; + } // Function to update the passed rect by the resizeAmount depending on // the edge that is resized. Some windows will resize on the same edge diff --git a/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js b/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js index ffff8e6..4d40ef5 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js +++ b/tiling-assistant@leleat-on-github/src/extension/tilingPopup.js @@ -58,7 +58,9 @@ export const TilingSwitcherPopup = GObject.registerClass( // Destroy popup when touching outside of popup this.connect('touch-event', () => { - if (Meta.is_wayland_compositor()) this.fadeAndDestroy(); + if (Meta.is_wayland_compositor()) { + this.fadeAndDestroy(); + } return Clutter.EVENT_PROPAGATE; }); @@ -75,7 +77,9 @@ export const TilingSwitcherPopup = GObject.registerClass( tileGroup[0]?.get_monitor() ?? global.display.get_current_monitor(); - if (!this._items.length) return false; + if (!this._items.length) { + return false; + } const grab = Main.pushModal(this); // We expect at least a keyboard grab here @@ -141,7 +145,9 @@ export const TilingSwitcherPopup = GObject.registerClass( mode: Clutter.AnimationMode.EASE_OUT_QUAD, }); - if (!tiledWindow) return; + if (!tiledWindow) { + return; + } // Clones to correctly shade the background for consecutive tiling. for (let i = 1; i < tileGroup.length; i++) { @@ -234,8 +240,9 @@ export const TilingSwitcherPopup = GObject.registerClass( const spacing = this.get_theme_node().get_length('spacing'); cbox.x2 = cbox.x1 + cNatWidth; - if (cbox.x2 > monitor.x + monitor.width - rightPadd) + if (cbox.x2 > monitor.x + monitor.width - rightPadd) { cbox.x2 = monitor.x + monitor.width - rightPadd; + } cbox.y1 = this._switcherList.allocation.y2 + spacing; this._thumbnails.addClones( monitor.y + monitor.height - bottomPadding - cbox.y1, @@ -268,13 +275,15 @@ export const TilingSwitcherPopup = GObject.registerClass( const moveRight = Util.isDirection(keysym, Direction.E); if (this._thumbnailsFocused) { - if (moveLeft) + if (moveLeft) { this._select(this._selectedIndex, this._previousWindow()); - else if (moveRight) + } else if (moveRight) { this._select(this._selectedIndex, this._nextWindow()); - else if (moveUp || moveDown) + } else if (moveUp || moveDown) { this._select(this._selectedIndex, null, true); - else return Clutter.EVENT_PROPAGATE; + } else { + return Clutter.EVENT_PROPAGATE; + } } else if (moveLeft) { this._select(this._previous()); } else if (moveRight) { @@ -303,7 +312,9 @@ export const TilingSwitcherPopup = GObject.registerClass( } fadeAndDestroy() { - if (this._alreadyDestroyed) return; + if (this._alreadyDestroyed) { + return; + } this._alreadyDestroyed = true; @@ -370,8 +381,9 @@ const TSwitcherList = GObject.registerClass( while ( this._items.length > 1 && this._items[j].style_class !== 'item-box' - ) + ) { j++; + } const themeNode = this._items[j].get_theme_node(); this._list.ensure_style(); @@ -406,14 +418,17 @@ const TSwitcherList = GObject.registerClass( iconSize = baseIconSizes[i]; const height = iconSizes[i] + iconSpacing; const w = height * this._items.length + totalSpacing; - if (w <= availWidth) break; + if (w <= availWidth) { + break; + } } } this._iconSize = iconSize; - for (let i = 0; i < this.icons.length; i++) + for (let i = 0; i < this.icons.length; i++) { this.icons[i].set_size(iconSize); + } } }, ); diff --git a/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js b/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js index ad45be6..8209574 100644 --- a/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js +++ b/tiling-assistant@leleat-on-github/src/extension/tilingWindowManager.js @@ -119,7 +119,9 @@ export class TilingWindowManager { // extension can crash GNOME Shell.. so guard against it. A way to // have a window's monitor be -1, for example, is explained here: // https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4713 - if (w.get_monitor() === -1) return false; + if (w.get_monitor() === -1) { + return false; + } // Assumption: a maximized window can also resize (once unmaximized) const canResize = @@ -147,18 +149,19 @@ 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 + * @param {boolean} [param.openTilingPopup] 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 + * @param {boolean} [param.ignoreTA] + * @param {number} [param.monitorNr] 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.skipAnim] decides, if we skip the tile animation. + * @param {boolean} [param.fakeTile] don't create a new tile group, don't * emit 'tiled' signal or open the Tiling Popup */ static async tile( @@ -172,14 +175,20 @@ export class TilingWindowManager { fakeTile = false, } = {}, ) { - if (!window || window.is_skip_taskbar()) return; + if (!window || window.is_skip_taskbar()) { + return; + } const wasMaximized = window.get_maximized(); - if (wasMaximized) window.unmaximize(wasMaximized); + if (wasMaximized) { + window.unmaximize(wasMaximized); + } window.unmake_fullscreen(); - if (!window.allows_resize() || !window.allows_move()) return; + if (!window.allows_resize() || !window.allows_move()) { + return; + } // Remove window from the other windows' tileGroups so it // doesn't falsely get raised with them. @@ -189,11 +198,13 @@ export class TilingWindowManager { window.unminimize(); // Raise window since tiling with the popup means that // the window can be below others. - if (window.raise_and_make_recent_on_workspace) + if (window.raise_and_make_recent_on_workspace) { window.raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else window.raise_and_make_recent(); + } else { + window.raise_and_make_recent(); + } const oldRect = new Rect(window.get_frame_rect()); const monitor = monitorNr ?? window.get_monitor(); @@ -201,7 +212,9 @@ export class TilingWindowManager { const maximize = newRect.equal(workArea); window.isTiled = !maximize; - if (!window.untiledRect) window.untiledRect = oldRect; + if (!window.untiledRect) { + window.untiledRect = oldRect; + } if (maximize && !Settings.getBoolean('maximize-with-gap')) { window.tiledRect = null; @@ -278,7 +291,9 @@ export class TilingWindowManager { this.emit('window-tiled', window); - if (openTilingPopup) await this.tryOpeningTilingPopup(); + if (openTilingPopup) { + await this.tryOpeningTilingPopup(); + } } } @@ -286,13 +301,15 @@ 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} param + * @param {boolean} [param.restoreFullPos] decides, if we restore the * pre-tile position or whether the size while keeping the titlebar * at the relative same position. - * @param {number} [xAnchor=undefined] used when wanting to restore the + * @param {number} [param.xAnchor] used when wanting to restore the * size while keeping titlebar at the relative x position. By default, * we use the pointer position. - * @param {boolean} [skipAnim=false] decides, if we skip the until animation. + * @param {boolean} [param.skipAnim] decides, if we skip the until animation. + * @param {boolean} [param.clampToWorkspace] */ static untile( window, @@ -304,25 +321,30 @@ export class TilingWindowManager { } = {}, ) { const wasMaximized = window.get_maximized(); - if (wasMaximized) window.unmaximize(wasMaximized); + if (wasMaximized) { + window.unmaximize(wasMaximized); + } if ( !window.untiledRect || !window.allows_resize() || !window.allows_move() - ) + ) { return; + } // If you tiled a window and then used the popup to tile more // windows, the consecutive windows will be raised above the first // one. So untiling the initial window after tiling more windows with // the popup (without re-focusing the initial window), means the // untiled window will be below the others. - if (window.raise_and_make_recent_on_workspace) + if (window.raise_and_make_recent_on_workspace) { window.raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else window.raise_and_make_recent(); + } else { + window.raise_and_make_recent(); + } // Animation const untileAnim = Settings.getBoolean('enable-untile-animations'); @@ -358,8 +380,9 @@ export class TilingWindowManager { const newPosX = xAnchor - oldRect.width * relativeMouseX; // Wayland workaround for DND / restore position - Meta.is_wayland_compositor() && + if (Meta.is_wayland_compositor()) { window.move_frame(true, newPosX, currWindowFrame.y); + } window.move_resize_frame( userOp, @@ -431,8 +454,9 @@ export class TilingWindowManager { newTile.height = Math.floor(w.tiledRect.height * (1 / vScale)); // Try to align with all previously scaled tiles and the workspace to prevent gaps - for (let i = 0; i < idx; i++) + for (let i = 0; i < idx; i++) { newTile.tryAlignWith(tileGroup[i].tiledRect); + } newTile.tryAlignWith(newWorkArea, 10); @@ -506,7 +530,9 @@ export class TilingWindowManager { // Reconnect unmanaging signal const unmanagingSignal = signals.get(TilingSignals.UNMANAGING); - unmanagingSignal && window.disconnect(unmanagingSignal); + if (unmanagingSignal) { + window.disconnect(unmanagingSignal); + } const umId = window.connect('unmanaging', () => { this.clearTilingProps(windowId); @@ -515,7 +541,9 @@ export class TilingWindowManager { // Reconnect ws-changed signal const wsChangeSignal = signals.get(TilingSignals.WS_CHANGED); - wsChangeSignal && window.disconnect(wsChangeSignal); + if (wsChangeSignal) { + window.disconnect(wsChangeSignal); + } const wsId = window.connect('workspace-changed', () => this._onWindowWorkspaceChanged(window), @@ -524,7 +552,9 @@ export class TilingWindowManager { // Reconnect raise signal const raiseSignal = signals.get(TilingSignals.RAISE); - raiseSignal && window.disconnect(raiseSignal); + if (raiseSignal) { + window.disconnect(raiseSignal); + } const raiseId = window.connect('raised', (raisedWindow) => { const raisedWindowId = raisedWindow.get_id(); @@ -547,11 +577,13 @@ export class TilingWindowManager { // Prevent an infinite loop of windows raising each other w.block_signal_handler(otherRaiseId); - if (w.raise_and_make_recent_on_workspace) + if (w.raise_and_make_recent_on_workspace) { w.raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else w.raise_and_make_recent(); + } else { + w.raise_and_make_recent(); + } w.unblock_signal_handler(otherRaiseId); }); @@ -562,11 +594,13 @@ export class TilingWindowManager { .getSignalsFor(raisedWindowId) .get(TilingSignals.RAISE); raisedWindow.block_signal_handler(signalId); - if (raisedWindow.raise_and_make_recent_on_workspace) + if (raisedWindow.raise_and_make_recent_on_workspace) { raisedWindow.raise_and_make_recent_on_workspace( global.workspace_manager.get_active_workspace(), ); - else raisedWindow.raise_and_make_recent(); + } else { + raisedWindow.raise_and_make_recent(); + } raisedWindow.unblock_signal_handler(signalId); } @@ -594,39 +628,46 @@ export class TilingWindowManager { const signals = this._signals.getSignalsFor(windowId); if (signals.get(TilingSignals.RAISE)) { - window && window.disconnect(signals.get(TilingSignals.RAISE)); + window?.disconnect(signals.get(TilingSignals.RAISE)); signals.set(TilingSignals.RAISE, 0); } if (signals.get(TilingSignals.WS_CHANGED)) { - window && window.disconnect(signals.get(TilingSignals.WS_CHANGED)); + window?.disconnect(signals.get(TilingSignals.WS_CHANGED)); signals.set(TilingSignals.WS_CHANGED, 0); } if (signals.get(TilingSignals.UNMANAGING)) { - window && window.disconnect(signals.get(TilingSignals.UNMANAGING)); + window?.disconnect(signals.get(TilingSignals.UNMANAGING)); signals.set(TilingSignals.UNMANAGING, 0); } - if (!this._tileGroups.has(windowId)) return; + if (!this._tileGroups.has(windowId)) { + return; + } // Delete window's tileGroup this._tileGroups.delete(windowId); // Delete window from other windows' tileGroup this._tileGroups.forEach((tileGroup) => { const idx = tileGroup.indexOf(windowId); - idx !== -1 && tileGroup.splice(idx, 1); + if (idx !== -1) { + tileGroup.splice(idx, 1); + } }); } /** * @param {Meta.Window} window a Meta.Window. + * * @returns {Meta.Window[]} an array of Meta.Windows, which are in `window`'s * tile group (including the `window` itself). */ static getTileGroupFor(window) { const tileGroup = this._tileGroups.get(window.get_id()); - if (!tileGroup) return []; + if (!tileGroup) { + return []; + } return this._getAllWindows().filter((w) => tileGroup.includes(w.get_id()), @@ -639,12 +680,14 @@ 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} param + * @param {boolean} [param.skipTopWindow] 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. + * @param {number} [param.monitor] get the group for the monitor number. + * * @returns {Meta.Windows[]} an array of tiled Meta.Windows. */ static getTopTileGroup({skipTopWindow = false, monitor = null} = {}) { @@ -657,13 +700,17 @@ export class TilingWindowManager { Settings.getBoolean('disable-tile-groups') ) { const openWindows = this.getWindows(); - if (!openWindows.length) return []; + if (!openWindows.length) { + return []; + } if (skipTopWindow) { // the focused window isn't necessarily the top window due to always // on top windows. const idx = openWindows.indexOf(global.display.focus_window); - idx !== -1 && openWindows.splice(idx, 1); + if (idx !== -1) { + openWindows.splice(idx, 1); + } } const ignoredWindows = []; @@ -673,11 +720,15 @@ export class TilingWindowManager { openWindows[0].get_monitor(); for (const window of openWindows) { - if (window.get_monitor() !== mon) continue; + if (window.get_monitor() !== mon) { + continue; + } // Ignore non-tiled windows, which are always-on-top, for the // calculation since they are probably some utility apps etc. - if (window.is_above() && !window.isTiled) continue; + if (window.is_above() && !window.isTiled) { + continue; + } // Find the first not overlapped tile group, if it exists if (window.isTiled) { @@ -687,8 +738,11 @@ export class TilingWindowManager { return rect.overlap(window.tiledRect); }); - if (overlapsIgnoredWindow) ignoredWindows.push(window); - else return this.getTileGroupFor(window); + if (overlapsIgnoredWindow) { + ignoredWindows.push(window); + } else { + return this.getTileGroupFor(window); + } } else { ignoredWindows.push(window); } @@ -718,7 +772,9 @@ export class TilingWindowManager { const monitor = monitorNr ?? global.display.get_current_monitor(); const workArea = new Rect(activeWs.get_work_area_for_monitor(monitor)); const freeScreenRects = workArea.minus(rectList); - if (!freeScreenRects.length) return null; + if (!freeScreenRects.length) { + return null; + } // Create the union of all freeScreenRects and calculate the sum // of their areas. If the area of the union-rect equals the area @@ -738,10 +794,14 @@ export class TilingWindowManager { {checkSum: 0, combinedRect: startRect}, ); - if (combinedRect.area !== checkSum) return null; + if (combinedRect.area !== checkSum) { + return null; + } // Random min. size requirement - if (combinedRect.width < 250 || combinedRect.height < 250) return null; + if (combinedRect.width < 250 || combinedRect.height < 250) { + return null; + } return combinedRect; } @@ -753,10 +813,12 @@ 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} param + * @param {Rect} [param.currRect] a Rect, which may be expanded. + * @param {Orientation} [param.orientation] The orientation we want to expand * `currRect` into. If `null`, expand in both orientations. - * @param {Rect} [monitor=null] defaults to pointer monitor. + * @param {Rect} [param.monitorNr] defaults to pointer monitor. + * * @returns {Rect} a new Rect. */ static getBestFreeRect( @@ -767,7 +829,9 @@ export class TilingWindowManager { const monitor = monitorNr ?? global.display.get_current_monitor(); const workArea = new Rect(activeWs.get_work_area_for_monitor(monitor)); const freeRects = workArea.minus(rectList); - if (!freeRects.length) return currRect ?? new Rect(workArea); + if (!freeRects.length) { + return currRect ?? new Rect(workArea); + } // Try to expand the currRect to fill the rest of the space // that is available around it. @@ -797,10 +861,11 @@ export class TilingWindowManager { // or after (right / bottom) the current rect. const {before, after} = borderingRects.reduce( (result, r) => { - if (currRect[xpndPos1] === r[xpndPos2]) + if (currRect[xpndPos1] === r[xpndPos2]) { result.before.push(r); - else if (currRect[xpndPos2] === r[xpndPos1]) + } else if (currRect[xpndPos2] === r[xpndPos1]) { result.after.push(r); + } return result; }, @@ -919,7 +984,9 @@ export class TilingWindowManager { const getRect = (w) => w.tiledRect ?? new Rect(w.get_frame_rect()); const rects = windows.map((w) => getRect(w)); const nearestRect = getRect(currWindow).getNeighbor(dir, rects, wrap); - if (!nearestRect) return null; + if (!nearestRect) { + return null; + } return windows.find((w) => getRect(w).equal(nearestRect)); } @@ -942,12 +1009,14 @@ export class TilingWindowManager { * used to implement the 'grace period' to enable quickly tiling a * window using the screen edges even if there is another monitor * at that edge. - * @returns a Rect. + * + * @returns {Rect} a Rect. */ static getTileFor(shortcut, workArea, monitor = null) { // Don't try to adapt a tile rect - if (Settings.getBoolean('disable-tile-groups')) + if (Settings.getBoolean('disable-tile-groups')) { return this.getDefaultTileFor(shortcut, workArea); + } const topTileGroup = this.getTopTileGroup({ skipTopWindow: true, @@ -961,7 +1030,11 @@ export class TilingWindowManager { // part of the returned array if it's part of another high-stackeing // window's tile group. const idx = topTileGroup.indexOf(global.display.focus_window); - idx !== -1 && topTileGroup.splice(idx, 1); + + if (idx !== -1) { + topTileGroup.splice(idx, 1); + } + const favLayout = Util.getFavoriteLayout(monitor); const useFavLayout = favLayout.length && @@ -969,13 +1042,17 @@ export class TilingWindowManager { const twRects = (useFavLayout && favLayout) || topTileGroup.map((w) => w.tiledRect); - if (!twRects.length) return this.getDefaultTileFor(shortcut, workArea); + if (!twRects.length) { + return this.getDefaultTileFor(shortcut, workArea); + } // Return the adapted rect only if it doesn't overlap an existing tile. // Ignore an overlap, if a fav layout is used since we always prefer the // user set layout in that case. const getTile = (rect) => { - if (useFavLayout) return rect; + if (useFavLayout) { + return rect; + } const overlapsTiles = twRects.some((r) => r.overlap(rect)); return overlapsTiles ? @@ -1128,12 +1205,15 @@ export class TilingWindowManager { return getTile(result); } } + + throw new Error('Invalid shortcut'); } /** * @param {string} shortcut determines, which half/quarter to get the tile for * @param {Rect} workArea - * @returns + * + * @returns {Rect} */ static getDefaultTileFor(shortcut, workArea) { switch (shortcut) { @@ -1180,6 +1260,8 @@ export class TilingWindowManager { .getUnitAt(1, workArea.width / 2, Orientation.V) .getUnitAt(1, workArea.height / 2, Orientation.H); } + + throw new Error('Invalid shortcut'); } /** @@ -1187,7 +1269,9 @@ export class TilingWindowManager { * and offer to tile an open window to that spot. */ static async tryOpeningTilingPopup() { - if (!Settings.getBoolean('enable-tiling-popup')) return; + if (!Settings.getBoolean('enable-tiling-popup')) { + return; + } const allWs = Settings.getBoolean('tiling-popup-all-workspace'); const openWindows = this.getWindows(allWs); @@ -1195,19 +1279,25 @@ export class TilingWindowManager { topTileGroup.forEach((w) => openWindows.splice(openWindows.indexOf(w), 1), ); - if (!openWindows.length) return; + if (!openWindows.length) { + return; + } const tRects = topTileGroup.map((w) => w.tiledRect); const monitor = topTileGroup[0]?.get_monitor(); // for the grace period const freeSpace = this.getFreeScreen(tRects, monitor); - if (!freeSpace) return; + if (!freeSpace) { + return; + } const TilingPopup = await import('./tilingPopup.js'); const popup = new TilingPopup.TilingSwitcherPopup( openWindows, freeSpace, ); - if (!popup.show(topTileGroup)) popup.destroy(); + if (!popup.show(topTileGroup)) { + popup.destroy(); + } } /** @@ -1215,6 +1305,7 @@ export class TilingWindowManager { * * @param {Meta.Window} window a Meta.Window. * @param {Rect} rect the Rect the `window` tiles to or untiles from. + * @param {object} params */ static toggleTiling(window, rect, params = {}) { const workArea = window.get_work_area_current_monitor(); @@ -1223,9 +1314,11 @@ export class TilingWindowManager { if ( (window.isTiled && equalsTile) || (this.isMaximized(window) && equalsWA) - ) + ) { this.untile(window, params); - else this.tile(window, rect, params); + } else { + this.tile(window, rect, params); + } } /** @@ -1237,7 +1330,9 @@ export class TilingWindowManager { * appear, if there is free screen space after the `app` was tiled. */ static openAppTiled(app, rect, openTilingPopup = false) { - if (!app?.can_open_new_window()) return; + if (!app?.can_open_new_window()) { + return; + } let createId = global.display.connect( 'window-created', @@ -1273,16 +1368,24 @@ export class TilingWindowManager { // window doesn't match the original app. It may be a loading screen // or the user started an app in between etc... but in case the checks/ // signals above fail disconnect the signals after 1 min at the latest - this._openAppTiledTimerId && + if (this._openAppTiledTimerId) { GLib.Source.remove(this._openAppTiledTimerId); + } + this._openAppTiledTimerId = GLib.timeout_add( GLib.PRIORITY_DEFAULT, 60000, () => { - createId && global.display.disconnect(createId); - createId = 0; - firstFrameId && wActor.disconnect(firstFrameId); - firstFrameId = 0; + if (createId) { + global.display.disconnect(createId); + createId = 0; + } + + if (firstFrameId) { + wActor.disconnect(firstFrameId); + firstFrameId = 0; + } + this._openAppTiledTimerId = null; return GLib.SOURCE_REMOVE; }, @@ -1326,10 +1429,14 @@ export class TilingWindowManager { /** * Gets the top windows, which are supposed to be in a tile group. That * means windows, which are tiled, and don't overlap each other. + * + * @param {number} [monitor] */ static _getWindowsForBuildingTileGroup(monitor = null) { const openWindows = this.getWindows(); - if (!openWindows.length) return []; + if (!openWindows.length) { + return []; + } const ignoredWindows = []; const result = []; @@ -1339,14 +1446,22 @@ export class TilingWindowManager { openWindows[0].get_monitor(); for (const window of openWindows) { - if (window.get_monitor() !== mon) continue; + if (window.get_monitor() !== mon) { + continue; + } - if (window.is_above() && !window.isTiled) continue; + if (window.is_above() && !window.isTiled) { + continue; + } if (window.isTiled) { // Window was already checked as part of another's tileGroup. - if (ignoredWindows.includes(window) || result.includes(window)) + if ( + ignoredWindows.includes(window) || + result.includes(window) + ) { continue; + } // Check for the other windows in the tile group as well regardless // of the 'raise tile group' setting so that once the setting is @@ -1371,13 +1486,17 @@ export class TilingWindowManager { ), ); - tileGroupOverlaps ? - tileGroup.forEach((w) => ignoredWindows.push(w)) - : tileGroup.forEach((w) => result.push(w)); + if (tileGroupOverlaps) { + tileGroup.forEach((w) => ignoredWindows.push(w)); + } else { + tileGroup.forEach((w) => result.push(w)); + } } else { // The window is maximized, so all windows below it can't belong // to this group anymore. - if (this.isMaximized(window)) break; + if (this.isMaximized(window)) { + break; + } ignoredWindows.push(window); } @@ -1394,13 +1513,17 @@ export class TilingWindowManager { */ static _getTopTiledWindows({skipTopWindow = false, monitor = null} = {}) { const openWindows = this.getWindows(); - if (!openWindows.length) return []; + if (!openWindows.length) { + return []; + } if (skipTopWindow) { // the focused window isn't necessarily the top window due to always // on top windows. const idx = openWindows.indexOf(global.display.focus_window); - idx !== -1 && openWindows.splice(idx, 1); + if (idx !== -1) { + openWindows.splice(idx, 1); + } } const topTiledWindows = []; @@ -1411,9 +1534,13 @@ export class TilingWindowManager { openWindows[0].get_monitor(); for (const window of openWindows) { - if (window.get_monitor() !== mon) continue; + if (window.get_monitor() !== mon) { + continue; + } - if (window.is_above() && !window.isTiled) continue; + if (window.is_above() && !window.isTiled) { + continue; + } if (window.isTiled) { const wRect = window.tiledRect; @@ -1430,13 +1557,17 @@ export class TilingWindowManager { w.tiledRect.overlap(wRect), ); - overlapsIgnoredWindow || overlapsTopTiledWindows ? - ignoredWindows.push(window) - : topTiledWindows.push(window); + if (overlapsIgnoredWindow || overlapsTopTiledWindows) { + ignoredWindows.push(window); + } else { + topTiledWindows.push(window); + } } else { // The window is maximized, so all windows below it can't belong // to this group anymore. - if (this.isMaximized(window)) break; + if (this.isMaximized(window)) { + break; + } ignoredWindows.push(window); } @@ -1459,7 +1590,9 @@ export class TilingWindowManager { ]; blockedSignals.forEach((s) => { const id = signals.get(s); - id && window.block_signal_handler(id); + if (id) { + window.block_signal_handler(id); + } }); } @@ -1478,7 +1611,9 @@ export class TilingWindowManager { ]; blockedSignals.forEach((s) => { const id = signals.get(s); - id && window.unblock_signal_handler(id); + if (id) { + window.unblock_signal_handler(id); + } }); } @@ -1493,7 +1628,9 @@ export class TilingWindowManager { // Refresh 'unmanaging' signal const unmanagingSignal = signals.get(TilingSignals.UNMANAGING); - unmanagingSignal && window.disconnect(unmanagingSignal); + if (unmanagingSignal) { + window.disconnect(unmanagingSignal); + } const umId = window.connect('unmanaging', () => { this.clearTilingProps(window.get_id()); @@ -1519,7 +1656,7 @@ export class TilingWindowManager { * Gets the window matching a window id * * @param {number} id - * @returns {Meta.Window} + * @returns {Meta.Window|undefined} */ static _getWindow(id) { return this._getAllWindows().find((w) => w.get_id() === id); @@ -1535,7 +1672,11 @@ export class TilingWindowManager { */ static _onWorkspaceAdded() { this._ignoreWsChange = true; - this._wsAddedTimer && GLib.Source.remove(this._wsAddedTimer); + + if (this._wsAddedTimer) { + GLib.Source.remove(this._wsAddedTimer); + } + this._wsAddedTimer = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 50, () => { this._ignoreWsChange = false; this._wsAddedTimer = null; @@ -1553,7 +1694,11 @@ export class TilingWindowManager { */ static _onWorkspaceRemoved() { this._ignoreWsChange = true; - this._wsRemovedTimer && GLib.Source.remove(this._wsRemovedTimer); + + if (this._wsRemovedTimer) { + GLib.Source.remove(this._wsRemovedTimer); + } + this._wsRemovedTimer = GLib.timeout_add( GLib.PRIORITY_DEFAULT, 50, @@ -1591,12 +1736,16 @@ export class TilingWindowManager { return; } - if (this._ignoreWsChange) return; + if (this._ignoreWsChange) { + return; + } if (this.isMaximized(window)) { const wA = window.get_work_area_for_monitor(window.get_monitor()); const workArea = new Rect(wA); - if (workArea.equal(window.tiledRect)) return; + if (workArea.equal(window.tiledRect)) { + return; + } this.tile(window, workArea, { openTilingPopup: false, @@ -1649,7 +1798,10 @@ const TilingSignals = GObject.registerClass( ); this._ids.forEach((signals, windowId) => { const window = allWindows.find((w) => w.get_id() === windowId); - window && signals.forEach((s) => s && window.disconnect(s)); + + if (window) { + signals.forEach((s) => s && window.disconnect(s)); + } }); super.destroy(); diff --git a/tiling-assistant@leleat-on-github/src/extension/utility.js b/tiling-assistant@leleat-on-github/src/extension/utility.js index 4ab2cfc..4cf85d2 100644 --- a/tiling-assistant@leleat-on-github/src/extension/utility.js +++ b/tiling-assistant@leleat-on-github/src/extension/utility.js @@ -91,17 +91,23 @@ export class Util { * @returns {Direction} */ static getDirection(keyVal) { - if (this.isDirection(keyVal, Direction.N)) return Direction.N; - else if (this.isDirection(keyVal, Direction.S)) return Direction.S; - else if (this.isDirection(keyVal, Direction.W)) return Direction.W; - else if (this.isDirection(keyVal, Direction.E)) return Direction.E; - else return null; + if (this.isDirection(keyVal, Direction.N)) { + return Direction.N; + } else if (this.isDirection(keyVal, Direction.S)) { + return Direction.S; + } else if (this.isDirection(keyVal, Direction.W)) { + return Direction.W; + } else if (this.isDirection(keyVal, Direction.E)) { + return Direction.E; + } else { + return null; + } } /** * Get the window or screen gaps scaled to the monitor scale. * - * @param {String} settingsKey the key for the gap + * @param {string} settingsKey the key for the gap * @param {number} monitor the number of the monitor to scale the gap to * @returns {number} the scaled gap as a even number since the window gap * will be divided by 2. @@ -139,10 +145,14 @@ export class Util { const pathArr = [userDir, '/tiling-assistant/layouts.json']; const path = GLib.build_filenamev(pathArr); const file = Gio.File.new_for_path(path); - if (!file.query_exists(null)) return []; + if (!file.query_exists(null)) { + return []; + } const [success, contents] = file.load_contents(null); - if (!success || !contents.length) return []; + if (!success || !contents.length) { + return []; + } return JSON.parse(new TextDecoder().decode(contents)); } @@ -161,7 +171,9 @@ export class Util { const layouts = this.getLayouts(); const layout = layouts?.[Settings.getStrv('favorite-layouts')[monitor]]; - if (!layout) return []; + if (!layout) { + return []; + } const activeWs = global.workspace_manager.get_active_workspace(); const workArea = new Rect(activeWs.get_work_area_for_monitor(monitor)); @@ -178,7 +190,9 @@ export class Util { ); favoriteLayout.push(rect); - for (let i = 0; i < idx; i++) rect.tryAlignWith(favoriteLayout[i]); + for (let i = 0; i < idx; i++) { + rect.tryAlignWith(favoriteLayout[i]); + } }); favoriteLayout.forEach((rect) => rect.tryAlignWith(workArea)); @@ -262,7 +276,9 @@ export class Util { const twm = await import('./tilingWindowManager.js'); const openWindows = twm.getWindows(); openWindows.forEach((w) => { - if (!w.isTiled) return; + if (!w.isTiled) { + return; + } log(`Tile group for: ${w.get_wm_class()}`); const tileGroup = twm.getTileGroupFor(w); @@ -313,7 +329,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 * @param {number} monitor the number of the monitor to scale the gap to * @returns {Rect} the rectangle after the gaps were taken into account */ @@ -340,9 +356,11 @@ export class Rect { r[dim] -= windowGap / 2; } - if (this[pos] + this[dim] === workArea[pos] + workArea[dim]) + if (this[pos] + this[dim] === workArea[pos] + workArea[dim]) { r[dim] -= dimGap; - else r[dim] -= windowGap / 2; + } else { + r[dim] -= windowGap / 2; + } }); // Use the single screen gap } else { @@ -358,9 +376,11 @@ export class Rect { r[dim] -= windowGap / 2; } - if (this[pos] + this[dim] === workArea[pos] + workArea[dim]) + if (this[pos] + this[dim] === workArea[pos] + workArea[dim]) { r[dim] -= singleScreenGap; - else r[dim] -= windowGap / 2; + } else { + r[dim] -= windowGap / 2; + } }); } @@ -459,22 +479,27 @@ export class Rect { // nearest on the non-compared axis ('nonCmprProp'). The x property // in the this example. let startProp, cmprProp, nonCmprProp; - if (dir === Direction.N) + if (dir === Direction.N) { [startProp, cmprProp, nonCmprProp] = ['y', 'y2', 'x']; - else if (dir === Direction.S) + } else if (dir === Direction.S) { [startProp, cmprProp, nonCmprProp] = ['y2', 'y', 'x']; - else if (dir === Direction.W) + } else if (dir === Direction.W) { [startProp, cmprProp, nonCmprProp] = ['x', 'x2', 'y']; - else if (dir === Direction.E) + } else if (dir === Direction.E) { [startProp, cmprProp, nonCmprProp] = ['x2', 'x', 'y']; + } // Put rects into a Map with their relevenat pos'es as the keys and // filter out `this`. const posMap = rects.reduce((map, rect) => { - if (rect.equal(this)) return map; + if (rect.equal(this)) { + return map; + } const pos = rect[cmprProp]; - if (!map.has(pos)) map.set(pos, []); + if (!map.has(pos)) { + map.set(pos, []); + } map.get(pos).push(rect); return map; @@ -491,7 +516,9 @@ export class Rect { sortedPoses.find((pos) => pos >= this[startProp]) : sortedPoses.find((pos) => pos <= this[startProp]); - if (!neighborPos && !wrap) return null; + if (!neighborPos && !wrap) { + return null; + } // Since the sortedPoses array is in descending order when 'going // backwards', we always wrap by getting the 0-th item, if there @@ -554,8 +581,11 @@ export class Rect { } }; - if (index === lastIndex) return getLastRect(); - else return getNonLastRect(this, index); + if (index === lastIndex) { + return getLastRect(); + } else { + return getNonLastRect(this, index); + } } /** @@ -605,26 +635,32 @@ export class Rect { */ _minusRect(rect) { rect = rect instanceof Mtk.Rectangle ? new Rect(rect) : rect; - if (rect.containsRect(this)) return []; + if (rect.containsRect(this)) { + return []; + } const [intersect] = this.intersect(rect); - if (!intersect) return [this.copy()]; + if (!intersect) { + return [this.copy()]; + } const resultRects = []; // Left rect const leftRectWidth = rect.x - this.x; - if (leftRectWidth > 0 && this.height > 0) + if (leftRectWidth > 0 && this.height > 0) { resultRects.push( new Rect(this.x, this.y, leftRectWidth, this.height), ); + } // Right rect const rightRectWidth = this.x2 - rect.x2; - if (rightRectWidth > 0 && this.height > 0) + if (rightRectWidth > 0 && this.height > 0) { resultRects.push( new Rect(rect.x2, this.y, rightRectWidth, this.height), ); + } const vertRectsX1 = rect.x > this.x ? rect.x : this.x; const vertRectsX2 = rect.x2 < this.x2 ? rect.x2 : this.x2; @@ -632,14 +668,15 @@ export class Rect { // Top rect const topRectHeight = rect.y - this.y; - if (topRectHeight > 0 && vertRectsWidth > 0) + if (topRectHeight > 0 && vertRectsWidth > 0) { resultRects.push( new Rect(vertRectsX1, this.y, vertRectsWidth, topRectHeight), ); + } // Bottom rect const bottomRectHeight = this.y2 - rect.y2; - if (bottomRectHeight > 0 && vertRectsWidth > 0) + if (bottomRectHeight > 0 && vertRectsWidth > 0) { resultRects.push( new Rect( vertRectsX1, @@ -648,6 +685,7 @@ export class Rect { bottomRectHeight, ), ); + } return resultRects; } @@ -660,7 +698,9 @@ export class Rect { * @returns {Rect[]} an array of the remaining Rects. */ _minusRectArray(rects) { - if (!rects.length) return [this.copy()]; + if (!rects.length) { + return [this.copy()]; + } // First cut off all rects individually from `this`. The result is an // array of leftover rects (which are arrays themselves) from `this`. @@ -673,7 +713,10 @@ export class Rect { for (const leftOver of currLeftOvers) { for (const currFreeRect of result) { const [ok, inters] = currFreeRect.intersect(leftOver); - ok && intersections.push(new Rect(inters)); + + if (ok) { + intersections.push(new Rect(inters)); + } } } @@ -705,17 +748,29 @@ export class Rect { const equalApprox = (value1, value2) => Math.abs(value1 - value2) <= margin; - if (equalApprox(rect.x, this.x)) this.x = rect.x; - else if (equalApprox(rect.x2, this.x)) this.x = rect.x2; + if (equalApprox(rect.x, this.x)) { + this.x = rect.x; + } else if (equalApprox(rect.x2, this.x)) { + this.x = rect.x2; + } - if (equalApprox(rect.y, this.y)) this.y = rect.y; - else if (equalApprox(rect.y2, this.y)) this.y = rect.y2; + if (equalApprox(rect.y, this.y)) { + this.y = rect.y; + } else if (equalApprox(rect.y2, this.y)) { + this.y = rect.y2; + } - if (equalApprox(rect.x, this.x2)) this.width = rect.x - this.x; - else if (equalApprox(rect.x2, this.x2)) this.width = rect.x2 - this.x; + if (equalApprox(rect.x, this.x2)) { + this.width = rect.x - this.x; + } else if (equalApprox(rect.x2, this.x2)) { + this.width = rect.x2 - this.x; + } - if (equalApprox(rect.y, this.y2)) this.height = rect.y - this.y; - else if (equalApprox(rect.y2, this.y2)) this.height = rect.y2 - this.y; + if (equalApprox(rect.y, this.y2)) { + this.height = rect.y - this.y; + } else if (equalApprox(rect.y2, this.y2)) { + this.height = rect.y2 - this.y; + } return this; } diff --git a/tiling-assistant@leleat-on-github/src/prefs/layoutRow.js b/tiling-assistant@leleat-on-github/src/prefs/layoutRow.js index 2bb2043..4f21eba 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/layoutRow.js +++ b/tiling-assistant@leleat-on-github/src/prefs/layoutRow.js @@ -52,6 +52,7 @@ export const LayoutRow = GObject.registerClass( * @param {{_name: string, _items: {rect: object, appId: ?string, loopType: ?string}[] * }|null} layout a parsed JS object representing a layout from the * layouts.json file. + * @param {Gio.Settings} settings */ _init(layout, settings) { super._init(); diff --git a/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js b/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js index e16ec77..bf339ba 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js +++ b/tiling-assistant@leleat-on-github/src/prefs/layoutRowEntry.js @@ -51,9 +51,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) { @@ -119,8 +116,9 @@ export const LayoutRowEntry = GObject.registerClass( _validateFormat(text) { const values = text.split('--'); // 4 -> x, y, width, height; 5 -> additionally, a loopType - if (values.length < 4 || values.length > 5) + if (values.length < 4 || values.length > 5) { return [false, 'Wrong format: invalid count.']; + } const notJustNrs = ['x', 'y', 'width', 'height'].some((p, idx) => { return Number.isNaN(parseFloat(values[idx].trim())); diff --git a/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js b/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js index 65c87ca..6ed0d30 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js +++ b/tiling-assistant@leleat-on-github/src/prefs/layoutsPrefs.js @@ -80,7 +80,9 @@ export default class { // Try to load layouts file. const saveFile = this._makeFile(); const [success, contents] = saveFile.load_contents(null); - if (!success) return; + if (!success) { + return; + } let layouts = []; @@ -89,17 +91,21 @@ export default class { layouts = JSON.parse(new TextDecoder().decode(contents)); // Ensure at least 1 empty row otherwise the listbox won't have // a height but a weird looking shadow only. - layouts.length ? + if (layouts.length) { layouts.forEach((layout, idx) => this._createLayoutRow(idx, layout), - ) - : this._createLayoutRow(0); + ); + } else { + this._createLayoutRow(0); + } // Otherwise import the examples... but only do it once! // Use a setting as a flag. } else { const importExamples = 'import-layout-examples'; - if (!this._settings.get_boolean(importExamples)) return; + if (!this._settings.get_boolean(importExamples)) { + return; + } this._settings.set_boolean(importExamples, false); const exampleFile = this._makeFile( @@ -107,7 +113,9 @@ export default class { 'layouts_example.json', ); const [succ, c] = exampleFile.load_contents(null); - if (!succ) return; + if (!succ) { + return; + } layouts = c.length ? JSON.parse(new TextDecoder().decode(c)) : []; layouts.forEach((layout, idx) => @@ -129,7 +137,9 @@ export default class { // Check, if all layoutRows were valid so far. Use getIdx() // instead of forEach's idx because a layoutRow may have been // deleted by the user. - if (layoutRow.getIdx() === layouts.length - 1) return; + if (layoutRow.getIdx() === layouts.length - 1) { + return; + } // Invalid or empty layouts are ignored. For example, the user // defined a valid layout with a keybinding on row idx 3 but left @@ -223,11 +233,15 @@ export default class { /** * @param {number} index the index of the new layouts row. * @param {Layout} layout the parsed JS Object from the layouts file. + * + * @returns {LayoutRow|undefined} the new LayoutRow. */ _createLayoutRow(index, layout = null) { // Layouts are limited to 20 since there are only // that many keybindings in the schemas.xml file - if (index >= 20) return; + if (index >= 20) { + return null; + } const layoutRow = new LayoutRow(layout, this._settings); layoutRow.connect('changed', (row, ok) => { @@ -243,7 +257,7 @@ export default class { _forEachLayoutRow(callback) { for ( let i = 0, child = this._layoutsListBox.get_first_child(); - !!child; + child; i++ ) { // Get a ref to the next widget in case the curr widget diff --git a/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js b/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js index dda4578..6027fe4 100644 --- a/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js +++ b/tiling-assistant@leleat-on-github/src/prefs/shortcutListener.js @@ -46,7 +46,9 @@ export const ShortcutListener = GObject.registerClass( * @param {ShortcutListener} shortcutListener the new active ShortcutListener */ static listen(shortcutListener) { - if (shortcutListener === ShortcutListener.listener) return; + if (shortcutListener === ShortcutListener.listener) { + return; + } ShortcutListener.stopListening(); @@ -60,7 +62,9 @@ export const ShortcutListener = GObject.registerClass( * Stops listening for a keyboard shortcut. */ static stopListening() { - if (!ShortcutListener.isListening) return; + if (!ShortcutListener.isListening) { + return; + } ShortcutListener.isListening = false; ShortcutListener.isAppendingShortcut = false; @@ -101,7 +105,9 @@ export const ShortcutListener = GObject.registerClass( const kbLabel = this.keybinding.reduce((label, kb) => { const [, keyval, mask] = Gtk.accelerator_parse(kb); const l = Gtk.accelerator_get_label(keyval, mask); - if (!label) return l; + if (!label) { + return l; + } return l ? `${label} / ${l}` : label; }, ''); @@ -110,9 +116,11 @@ export const ShortcutListener = GObject.registerClass( } _onActivated() { - this.isActive ? - ShortcutListener.stopListening() - : ShortcutListener.listen(this); + if (this.isActive) { + ShortcutListener.stopListening(); + } else { + ShortcutListener.listen(this); + } } _onKeybindingChanged() { @@ -127,7 +135,9 @@ export const ShortcutListener = GObject.registerClass( } _onKeyPressed(eventControllerKey, keyval, keycode, state) { - if (this !== ShortcutListener.listener) return Gdk.EVENT_PROPAGATE; + if (this !== ShortcutListener.listener) { + return Gdk.EVENT_PROPAGATE; + } let mask = state & Gtk.accelerator_get_default_mod_mask(); mask &= ~Gdk.ModifierType.LOCK_MASK; @@ -157,8 +167,9 @@ export const ShortcutListener = GObject.registerClass( if ( !this._isBindingValid({mask, keycode, keyval}) || !Gtk.accelerator_valid(keyval, mask) - ) + ) { return Gdk.EVENT_STOP; + } const sc = Gtk.accelerator_name_with_keycode( null, @@ -204,8 +215,9 @@ export const ShortcutListener = GObject.registerClass( keyval <= Gdk.KEY_Hangul_J_YeorinHieuh) || (keyval === Gdk.KEY_space && mask === 0) || this._isKeyvalForbidden(keyval) - ) + ) { return false; + } } return true; }