diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-10 14:37:46 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-12-10 14:38:00 +0000 |
commit | 63dcc06bf83a178012909a708babedb71eeebd9a (patch) | |
tree | 7e1015b1f8ca941869e163d8d13fceb1036e202f /extensions/44/vertical-workspaces/lib/layout.js | |
parent | Releasing debian version 20230618-3. (diff) | |
download | gnome-shell-extensions-extra-63dcc06bf83a178012909a708babedb71eeebd9a.tar.xz gnome-shell-extensions-extra-63dcc06bf83a178012909a708babedb71eeebd9a.zip |
Merging upstream version 20231210.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | extensions/44/vertical-workspaces/lib/layout.js (renamed from extensions/vertical-workspaces/lib/layout.js) | 211 |
1 files changed, 142 insertions, 69 deletions
diff --git a/extensions/vertical-workspaces/lib/layout.js b/extensions/44/vertical-workspaces/lib/layout.js index f6562fd..6e72645 100644 --- a/extensions/vertical-workspaces/lib/layout.js +++ b/extensions/44/vertical-workspaces/lib/layout.js @@ -10,67 +10,107 @@ 'use strict'; -const { Meta, GLib, Shell, Clutter, GObject } = imports.gi; +const GLib = imports.gi.GLib; +const Meta = imports.gi.Meta; +const Gio = imports.gi.Gio; -const Main = imports.ui.main; const Layout = imports.ui.layout; -const Ripples = imports.ui.ripples; -const DND = imports.ui.dnd; +const Main = imports.ui.main; -const Me = imports.misc.extensionUtils.getCurrentExtension(); -const _Util = Me.imports.lib.util; +let Me; +let opt; -let _overrides; let _timeouts; -let opt; -let _firstRun = true; -let _originalUpdateHotCorners; -function update(reset = false) { - opt = Me.imports.lib.settings.opt; - const moduleEnabled = opt.get('layoutModule', true); - const conflict = _Util.getEnabledExtensions('custom-hot-corners').length || - _Util.getEnabledExtensions('dash-to-panel').length; - reset = reset || !moduleEnabled; +var LayoutModule = class { + constructor(me) { + Me = me; + opt = Me.opt; + _timeouts = {}; - // don't even touch this module if disabled or in conflict - if (_firstRun && (reset || conflict)) - return; + this._firstActivation = true; + this.moduleEnabled = false; + this._overrides = null; + this._originalUpdateHotCorners = null; + } - _firstRun = false; + cleanGlobals() { + Me = null; + opt = null; + } + + update(reset) { + this._removeTimeouts(); + + this.moduleEnabled = opt.get('layoutModule'); + const conflict = Me.Util.getEnabledExtensions('custom-hot-corners').length || + Me.Util.getEnabledExtensions('dash-to-panel').length; - if (!_originalUpdateHotCorners) - _originalUpdateHotCorners = Layout.LayoutManager.prototype._updateHotCorners; + if (conflict && !reset) + console.warn(`[${Me.metadata.name}] Warning: "Layout" module disabled due to potential conflict with another extension`); - if (_overrides) - _overrides.removeAll(); + reset = reset || !this.moduleEnabled || conflict; - if (_timeouts) { - Object.values(_timeouts).forEach(t => { - if (t) - GLib.source_remove(t); - }); + // don't touch the original code if module disabled + if (reset && !this._firstActivation) { + this._disableModule(); + } else if (!reset) { + this._firstActivation = false; + this._activateModule(); + } + if (reset && this._firstActivation) + console.debug(' LayoutModule - Keeping untouched'); } - if (reset) { - _overrides = null; - opt = null; - _timeouts = null; - Main.layoutManager._updateHotCorners = _originalUpdateHotCorners; + _activateModule() { + if (!this._overrides) + this._overrides = new Me.Util.Overrides(); + + _timeouts = {}; + + this._overrides.addOverride('LayoutManager', Main.layoutManager, LayoutManagerCommon); + this._overrides.addOverride('HotCorner', Layout.HotCorner.prototype, HotCornerCommon); + + Main.layoutManager._updatePanelBarrier(); Main.layoutManager._updateHotCorners(); - return; + + if (!this._hotCornersEnabledConId) { + this._interfaceSettings = new Gio.Settings({ + schema_id: 'org.gnome.desktop.interface', + }); + this._hotCornersEnabledConId = this._interfaceSettings.connect('changed::enable-hot-corners', + () => Main.layoutManager._updateHotCorners()); + } + + console.debug(' LayoutModule - Activated'); } - _timeouts = {}; + _disableModule() { + if (this._overrides) + this._overrides.removeAll(); + this._overrides = null; - _overrides = new _Util.Overrides(); - _overrides.addOverride('LayoutManager', Layout.LayoutManager.prototype, LayoutManagerCommon); + Main.layoutManager._updateHotCorners(); - Main.layoutManager._updateHotCorners = LayoutManagerCommon._updateHotCorners.bind(Main.layoutManager); + if (this._hotCornersEnabledConId) { + this._interfaceSettings.disconnect(this._hotCornersEnabledConId); + this._hotCornersEnabledConId = 0; + this._interfaceSettings = null; + } - Main.layoutManager._updatePanelBarrier(); - Main.layoutManager._updateHotCorners(); -} + console.debug(' LayoutModule - Disabled'); + } + + _removeTimeouts() { + if (_timeouts) { + Object.values(_timeouts).forEach(t => { + if (t) + GLib.source_remove(t); + }); + _timeouts = null; + } + } +}; const LayoutManagerCommon = { _updatePanelBarrier() { @@ -84,7 +124,7 @@ const LayoutManagerCommon = { this._leftPanelBarrier = null; } - if (!this.primaryMonitor || !opt) + if (!this.primaryMonitor || !opt || Me.Util.getEnabledExtensions('hidetopbar')) return; if (this.panelBox.height) { @@ -113,6 +153,7 @@ const LayoutManagerCommon = { // avoid errors if called from foreign override if (!opt) return; + // destroy old hot corners this.hotCorners.forEach(corner => corner?.destroy()); this.hotCorners = []; @@ -122,7 +163,7 @@ const LayoutManagerCommon = { return; } - let size = this.panelBox.height; + let size = this.panelBox.height ? this.panelBox.height : 27; // position 0 - default, 1-TL, 2-TR, 3-BL, 4-BR const position = opt.HOT_CORNER_POSITION; @@ -181,8 +222,8 @@ const LayoutManagerCommon = { } if (haveCorner) { - let corner = new HotCorner(this, monitor, cornerX, cornerY); - corner.setBarrierSize(size); + let corner = new Layout.HotCorner(this, monitor, cornerX, cornerY); + corner.setBarrierSize(size, false); this.hotCorners.push(corner); } else { this.hotCorners.push(null); @@ -193,11 +234,8 @@ const LayoutManagerCommon = { }, }; -var HotCorner = GObject.registerClass( -class HotCorner extends Layout.HotCorner { - _init(layoutManager, monitor, x, y) { - super._init(layoutManager, monitor, x, y); - +const HotCornerCommon = { + after__init() { let angle = 0; switch (opt.HOT_CORNER_POSITION) { case 2: @@ -214,9 +252,14 @@ class HotCorner extends Layout.HotCorner { this._ripples._ripple1.rotation_angle_z = angle; this._ripples._ripple2.rotation_angle_z = angle; this._ripples._ripple3.rotation_angle_z = angle; - } + }, + + setBarrierSize(size, notMyCall = true) { + // ignore calls from the original _updateHotCorners() callback to avoid building barriers outside screen + if (notMyCall && size > 0) { + return; + } - setBarrierSize(size) { if (this._verticalBarrier) { this._pressureBarrier.removeBarrier(this._verticalBarrier); this._verticalBarrier.destroy(); @@ -232,8 +275,8 @@ class HotCorner extends Layout.HotCorner { if (size > 0) { const primaryMonitor = global.display.get_primary_monitor(); const monitor = this._monitor; - const extendV = opt && opt.HOT_CORNER_EDGE && opt.DASH_VERTICAL && monitor.index === primaryMonitor; - const extendH = opt && opt.HOT_CORNER_EDGE && !opt.DASH_VERTICAL && monitor.index === primaryMonitor; + const extendV = opt && opt.HOT_CORNER_ACTION && opt.HOT_CORNER_EDGE && opt.DASH_VERTICAL && monitor.index === primaryMonitor; + const extendH = opt && opt.HOT_CORNER_ACTION && opt.HOT_CORNER_EDGE && !opt.DASH_VERTICAL && monitor.index === primaryMonitor; if (opt.HOT_CORNER_POSITION <= 1) { this._verticalBarrier = new Meta.Barrier({ @@ -284,25 +327,52 @@ class HotCorner extends Layout.HotCorner { this._pressureBarrier.addBarrier(this._verticalBarrier); this._pressureBarrier.addBarrier(this._horizontalBarrier); } - } + }, _toggleOverview() { if (!opt.HOT_CORNER_ACTION || (!opt.HOT_CORNER_FULLSCREEN && this._monitor.inFullscreen && !Main.overview.visible)) return; if (Main.overview.shouldToggleByCornerOrButton()) { - if ((opt.HOT_CORNER_ACTION === 1 && !_Util.isCtrlPressed()) || (opt.HOT_CORNER_ACTION === 2 && _Util.isCtrlPressed())) + if (Main.overview._shown) { this._toggleWindowPicker(true); - else if ((opt.HOT_CORNER_ACTION === 2 && !_Util.isCtrlPressed()) || (opt.HOT_CORNER_ACTION === 1 && _Util.isCtrlPressed()) || (opt.HOT_CORNER_ACTION === 3 && _Util.isCtrlPressed())) + } else if ((opt.HOT_CORNER_ACTION === 2 && !Me.Util.isCtrlPressed()) || ([3, 4, 5, 6].includes(opt.HOT_CORNER_ACTION) && Me.Util.isCtrlPressed())) { + // Default overview + opt.OVERVIEW_MODE = 0; + opt.OVERVIEW_MODE2 = false; + opt.WORKSPACE_MODE = 1; + this._toggleWindowPicker(true, true); + } else if (opt.HOT_CORNER_ACTION === 1) { + Main.overview.resetOverviewMode(); + this._toggleWindowPicker(true, true); + } else if ((opt.HOT_CORNER_ACTION === 3 && !Me.Util.isCtrlPressed()) || (opt.HOT_CORNER_ACTION === 2 && Me.Util.isCtrlPressed()) || (opt.HOT_CORNER_ACTION === 6 && Me.Util.isCtrlPressed())) { + // Applications this._toggleApplications(true); - else if (opt.HOT_CORNER_ACTION === 3 && !_Util.isCtrlPressed()) + } else if (opt.HOT_CORNER_ACTION === 4 && !Me.Util.isCtrlPressed()) { + // Overview - static ws preview + opt.OVERVIEW_MODE = 1; + opt.OVERVIEW_MODE2 = false; + opt.WORKSPACE_MODE = 0; + this._toggleWindowPicker(true, true); + } else if (opt.HOT_CORNER_ACTION === 5 && !Me.Util.isCtrlPressed()) { + // Overview - static ws + opt.OVERVIEW_MODE = 2; + opt.OVERVIEW_MODE2 = true; + opt.WORKSPACE_MODE = 0; + this._toggleWindowPicker(true, true); + } else if (opt.HOT_CORNER_ACTION === 6 && !Me.Util.isCtrlPressed()) { + // Window search provider + opt.OVERVIEW_MODE = 2; + opt.OVERVIEW_MODE2 = true; + opt.WORKSPACE_MODE = 0; this._toggleWindowSearchProvider(); + } if (opt.HOT_CORNER_RIPPLES && Main.overview.animationInProgress) this._ripples.playAnimation(this._x, this._y); } - } + }, - _toggleWindowPicker(leaveOverview = false) { + _toggleWindowPicker(leaveOverview = false, customOverviewMode = false) { if (Main.overview._shown && (leaveOverview || !Main.overview.dash.showAppsButton.checked)) { Main.overview.hide(); } else if (Main.overview.dash.showAppsButton.checked) { @@ -320,17 +390,17 @@ class HotCorner extends Layout.HotCorner { // delay cannot be too short 200, () => { - Main.overview.show(); + Main.overview.show(1, customOverviewMode); _timeouts.releaseKeyboardTimeoutId = 0; return GLib.SOURCE_REMOVE; } ); } else { - Main.overview.show(); + Main.overview.show(1, customOverviewMode); } } - } + }, _toggleApplications(leaveOverview = false) { if ((leaveOverview && Main.overview._shown) || Main.overview.dash.showAppsButton.checked) { @@ -360,12 +430,15 @@ class HotCorner extends Layout.HotCorner { Main.overview.show(2); // 2 for App Grid } } - } + }, _toggleWindowSearchProvider() { if (!Main.overview._overview._controls._searchController._searchActive) { - this._toggleWindowPicker(); - const prefix = 'wq// '; + opt.OVERVIEW_MODE = 2; + opt.OVERVIEW_MODE2 = true; + opt.WORKSPACE_MODE = 0; + this._toggleWindowPicker(false, true); + const prefix = Me.WSP_PREFIX; const position = prefix.length; const searchEntry = Main.overview.searchEntry; searchEntry.set_text(prefix); @@ -376,5 +449,5 @@ class HotCorner extends Layout.HotCorner { // Main.overview.searchEntry.text = ''; Main.overview.hide(); } - } -}); + }, +}; |