From c87cd9fd04fed6251478332a6cf2f783e9c04341 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Tue, 29 Apr 2025 22:59:43 +0200 Subject: [PATCH 1/6] feat: Added full on workspace syncing, b=(bug #7079), c=workspaces --- .../sessionstore/SessionStore-sys-mjs.patch | 16 +- .../sessionstore/TabState-sys-mjs.patch | 5 +- .../tabbrowser/content/tabbrowser-js.patch | 72 +++--- src/zen/workspaces/ZenWorkspaces.mjs | 220 ++++++++++++++++++ 4 files changed, 272 insertions(+), 41 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index 2afcff59..2487dd23 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083e79f383a 100644 +index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc303de496d9 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -3202,7 +3202,7 @@ var SessionStoreInternal = { @@ -11,17 +11,18 @@ index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083 return; } -@@ -3911,6 +3911,9 @@ var SessionStoreInternal = { +@@ -3911,6 +3911,10 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; + tabState.zenEssential = false; + tabState.zenPinnedId = null; + tabState.zenHasStaticLabel = false; ++ tabState.zenTabId = null; if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -5416,14 +5419,15 @@ var SessionStoreInternal = { +@@ -5416,14 +5420,15 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -39,7 +40,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083 continue; } let tabData = lazy.TabState.collect(tab, TAB_CUSTOM_VALUES.get(tab)); -@@ -5442,7 +5446,7 @@ var SessionStoreInternal = { +@@ -5442,7 +5447,7 @@ var SessionStoreInternal = { // We don't store the Firefox View tab in Session Store, so if it was the last selected "tab" when // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). @@ -48,7 +49,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083 selectedIndex = 1; winData.title = tabbrowser.tabs[0].label; } -@@ -5599,6 +5603,7 @@ var SessionStoreInternal = { +@@ -5599,6 +5604,7 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -56,7 +57,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083 this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6148,8 +6153,23 @@ var SessionStoreInternal = { +@@ -6148,8 +6154,26 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -69,6 +70,9 @@ index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } diff --git a/src/browser/components/sessionstore/TabState-sys-mjs.patch b/src/browser/components/sessionstore/TabState-sys-mjs.patch index c3c77e19..59186ad9 100644 --- a/src/browser/components/sessionstore/TabState-sys-mjs.patch +++ b/src/browser/components/sessionstore/TabState-sys-mjs.patch @@ -1,8 +1,8 @@ diff --git a/browser/components/sessionstore/TabState.sys.mjs b/browser/components/sessionstore/TabState.sys.mjs -index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..254849e13f7566029dc780c45e376e0f0d427cb5 100644 +index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..f73cd2d5b43d22a4ff14eb59cb9b168707a437f3 100644 --- a/browser/components/sessionstore/TabState.sys.mjs +++ b/browser/components/sessionstore/TabState.sys.mjs -@@ -84,6 +84,16 @@ class _TabState { +@@ -84,6 +84,17 @@ class _TabState { tabData.groupId = tab.group.id; } @@ -15,6 +15,7 @@ index 8f7ed557e6aa61e7e16ed4a8d785ad5fe651b3d8..254849e13f7566029dc780c45e376e0f + tabData.zenPinnedIcon = tab.getAttribute("zen-pinned-icon"); + tabData.zenIsEmpty = tab.hasAttribute("zen-empty-tab"); + tabData.zenHasStaticLabel = tab.hasAttribute("zen-has-static-label"); ++ tabData.zenTabId = tab.getAttribute("zen-tab-id"); + tabData.searchMode = tab.ownerGlobal.gURLBar.getSearchMode(browser, true); diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index 1c8fc221..c6215f1a 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66f0137ad2 100644 +index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b15b3451aa 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -415,11 +415,58 @@ @@ -310,7 +310,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 }); } -@@ -3589,6 +3684,27 @@ +@@ -3589,6 +3684,30 @@ ) { tabWasReused = true; tab = this.selectedTab; @@ -323,6 +323,9 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } @@ -338,7 +341,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (!tabData.pinned) { this.unpinTab(tab); } else { -@@ -3637,7 +3753,27 @@ +@@ -3637,7 +3756,30 @@ skipLoad: true, preferredRemoteType, }); @@ -355,6 +358,9 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -367,7 +373,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (select) { tabToSelect = tab; } -@@ -3661,7 +3797,8 @@ +@@ -3661,7 +3803,8 @@ // needs calling: shouldUpdateForPinnedTabs = true; } @@ -377,7 +383,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 let { groupId } = tabData; const tabGroup = tabGroupWorkingData.get(groupId); // if a tab refers to a tab group we don't know, skip any group -@@ -3675,7 +3812,10 @@ +@@ -3675,7 +3818,10 @@ tabGroup.stateData.id, tabGroup.stateData.color, tabGroup.stateData.collapsed, @@ -389,7 +395,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 ); tabsFragment.appendChild(tabGroup.node); } -@@ -3726,6 +3866,9 @@ +@@ -3726,6 +3872,9 @@ this.selectedTab = tabToSelect; this.removeTab(leftoverTab); } @@ -399,7 +405,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (tabs.length > 1 || !tabs[0].selected) { this._updateTabsAfterInsert(); -@@ -3912,7 +4055,7 @@ +@@ -3912,7 +4061,7 @@ // Ensure we have an index if one was not provided. if (typeof index != "number") { // Move the new tab after another tab if needed, to the end otherwise. @@ -408,7 +414,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if ( !bulkOrderedOpen && ((openerTab && -@@ -3958,18 +4101,18 @@ +@@ -3958,18 +4107,18 @@ // Ensure index is within bounds. if (tab.pinned) { @@ -431,7 +437,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4290,6 +4433,9 @@ +@@ -4290,6 +4439,9 @@ return; } @@ -441,7 +447,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 this.removeTabs(selectedTabs, { telemetrySource }); } -@@ -4542,6 +4688,7 @@ +@@ -4542,6 +4694,7 @@ telemetrySource, } = {} ) { @@ -449,7 +455,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4626,6 +4773,7 @@ +@@ -4626,6 +4779,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -457,7 +463,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 } catch (e) { console.error(e); } -@@ -4650,6 +4798,7 @@ +@@ -4650,6 +4804,7 @@ telemetrySource, } = {} ) { @@ -465,7 +471,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.finish("browser.tabs.opening", window); } -@@ -4663,6 +4812,12 @@ +@@ -4663,6 +4818,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -478,7 +484,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -4677,7 +4832,9 @@ +@@ -4677,7 +4838,9 @@ // frame created for it (for example, by updating the visually selected // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; @@ -489,7 +495,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -4840,7 +4997,7 @@ +@@ -4840,7 +5003,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -498,7 +504,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -4864,6 +5021,7 @@ +@@ -4864,6 +5027,7 @@ newTab = true; } @@ -506,7 +512,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -4903,9 +5061,7 @@ +@@ -4903,9 +5067,7 @@ aTab._mouseleave(); if (newTab) { @@ -517,7 +523,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 } else { TabBarVisibility.update(); } -@@ -5034,6 +5190,8 @@ +@@ -5034,6 +5196,8 @@ this.tabs[i]._tPos = i; } @@ -526,7 +532,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (!this._windowIsClosing) { if (wasPinned) { this.tabContainer._positionPinnedTabs(); -@@ -5159,8 +5317,8 @@ +@@ -5159,8 +5323,8 @@ return closedCount; } @@ -537,7 +543,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (unloadBlocked) { return; } -@@ -5260,13 +5418,13 @@ +@@ -5260,13 +5424,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -553,7 +559,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5282,7 +5440,7 @@ +@@ -5282,7 +5446,7 @@ } if (tab) { @@ -562,7 +568,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5303,7 +5461,7 @@ +@@ -5303,7 +5467,7 @@ }); } @@ -571,7 +577,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 } _blurTab(aTab) { -@@ -5704,10 +5862,10 @@ +@@ -5704,10 +5868,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -584,7 +590,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6001,7 +6159,7 @@ +@@ -6001,7 +6165,7 @@ // Don't allow mixing pinned and unpinned tabs. if (this.isTab(element) && element.pinned) { @@ -593,7 +599,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6028,9 +6186,16 @@ +@@ -6028,9 +6192,16 @@ element, () => { let neighbor = this.tabs[tabIndex]; @@ -611,7 +617,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6099,7 +6264,9 @@ +@@ -6099,7 +6270,9 @@ targetElement = targetElement.group; } } @@ -622,7 +628,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 // Don't allow mixing pinned and unpinned tabs. if (element.pinned && !targetElement?.pinned) { targetElement = this.tabs[this.pinnedTabCount - 1]; -@@ -6109,7 +6276,13 @@ +@@ -6109,7 +6282,13 @@ moveBefore = true; } @@ -636,7 +642,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 if (element.pinned && this.tabContainer.verticalMode) { return this.tabContainer.verticalPinnedTabsContainer; } -@@ -6169,7 +6342,7 @@ +@@ -6169,7 +6348,7 @@ if (!this.isTab(aTab)) { throw new Error("Can only move a tab into a tab group"); } @@ -645,7 +651,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6263,6 +6436,10 @@ +@@ -6263,6 +6442,10 @@ moveActionCallback(); @@ -656,7 +662,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7080,7 +7257,7 @@ +@@ -7080,7 +7263,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -665,7 +671,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 window.focus(); aEvent.preventDefault(); break; -@@ -7981,6 +8158,7 @@ +@@ -7981,6 +8164,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -673,7 +679,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -8954,7 +9132,7 @@ var TabContextMenu = { +@@ -8954,7 +9138,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -682,7 +688,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66 // Move Tab items let contextMoveTabOptions = document.getElementById( "context_moveTabOptions" -@@ -9223,6 +9401,7 @@ var TabContextMenu = { +@@ -9223,6 +9407,7 @@ var TabContextMenu = { telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP, }); } else { diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index d90a8cae..ea1a43b0 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -2910,3 +2910,223 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { }); } })(); + +{ + class gZenWorkspaceWindowSync extends ZenMultiWindowFeature { + #ignoreNextEvents = false; + #waitForPromise = null; + + constructor() { + super(); + if (!window.closed) { + this.init(); + } + } + + async init() { + await ZenWorkspaces.promiseInitialized; + this.#makeSureAllTabsHaveIds(); + this.#setUpEventListeners(); + } + + #makeSureAllTabsHaveIds() { + const allTabs = ZenWorkspaces.allStoredTabs; + for (const tab of allTabs) { + if (!tab.hasAttribute('zen-tab-id')) { + const tabId = gZenUIManager.generateUuidv4(); + tab.setAttribute('zen-tab-id', tabId); + } + } + } + + #setUpEventListeners() { + const kEvents = [ + 'TabClose', + 'TabOpen', + 'TabPinned', + 'TabUnpinned', + 'TabAddedToEssentials', + 'TabRemovedFromEssentials', + 'TabHide', + 'TabShow', + 'TabMove', + ]; + const eventListener = this.#handleEvent.bind(this); + for (const event of kEvents) { + window.addEventListener(event, eventListener); + } + } + + #handleEvent(event) { + this.#propagateToOtherWindows(event); + } + + async #propagateToOtherWindows(event) { + if (this.#ignoreNextEvents) { + return; + } + if (this.#waitForPromise) { + await this.#waitForPromise; + } + this.#waitForPromise = new Promise(async (resolve) => { + await this.foreachWindowAsActive(async (browser) => { + if (browser.gZenWorkspaceWindowSync && !this.windowIsActive(browser)) { + await browser.gZenWorkspaceWindowSync.onExternalTabEvent(event); + } + }); + resolve(); + }); + } + + async onExternalTabEvent(event) { + this.#ignoreNextEvents = true; + switch (event.type) { + case 'TabClose': + this.#onTabClose(event); + break; + case 'TabOpen': + await this.#onTabOpen(event); + break; + case 'TabPinned': + this.#onTabPinned(event); + break; + case 'TabUnpinned': + this.#onTabUnpinned(event); + break; + case 'TabAddedToEssentials': + this.#onTabAddedToEssentials(event); + break; + case 'TabRemovedFromEssentials': + this.#onTabRemovedFromEssentials(event); + break; + case 'TabHide': + this.#onTabHide(event); + break; + case 'TabShow': + this.#onTabShow(event); + break; + case 'TabMove': + this.#onTabMove(event); + break; + default: + console.warn(`Unhandled event type: ${event.type}`); + break; + } + this.#ignoreNextEvents = false; + } + + #getTabId(tab) { + return tab.getAttribute('zen-tab-id'); + } + + #getTabWithId(tabId) { + for (const tab of ZenWorkspaces.allStoredTabs) { + if (this.#getTabId(tab) === tabId) { + return tab; + } + } + return null; + } + + #onTabClose(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToClose = this.#getTabWithId(tabId); + if (tabToClose) { + gBrowser.removeTab(tabToClose); + } + } + + #onTabPinned(event) { + const targetTab = event.target; + if (targetTab.hasAttribute('zen-essential')) { + return this.#onTabAddedToEssentials(event); + } + const tabId = this.#getTabId(targetTab); + const tabIndex = targetTab._tPos; + const tabToPin = this.#getTabWithId(tabId); + if (tabToPin) { + gBrowser.pinTab(tabToPin); + gBrowser.moveTabTo(tabToPin, { tabIndex, forceUngrouped: !!targetTab.group }); + } + } + + #onTabUnpinned(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToUnpin = this.#getTabWithId(tabId); + if (tabToUnpin) { + gBrowser.unpinTab(tabToUnpin); + } + } + + #onTabAddedToEssentials(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToAdd = this.#getTabWithId(tabId); + if (tabToAdd) { + gZenPinnedTabManager.addToEssentials(tabToAdd); + } + } + + #onTabRemovedFromEssentials(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToRemove = this.#getTabWithId(tabId); + if (tabToRemove) { + gZenPinnedTabManager.removeFromEssentials(tabToRemove); + } + } + + #onTabHide(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToHide = this.#getTabWithId(tabId); + if (tabToHide) { + gBrowser.hideTab(tabToHide); + } + } + + #onTabShow(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToShow = this.#getTabWithId(tabId); + if (tabToShow) { + gBrowser.showTab(tabToShow); + } + } + + #onTabMove(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabIndex = targetTab._tPos; + const tabToMove = this.#getTabWithId(tabId); + if (tabToMove) { + gBrowser.moveTabTo(tabToMove, { tabIndex, forceUngrouped: !!targetTab.group }); + } + } + + async #onTabOpen(event) { + await new Promise((resolve) => { + setTimeout(() => { + const targetTab = event.target; + const isPinned = targetTab.pinned; + const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); + const tabIndex = targetTab._tPos; + + const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0, true); + if (isEssential) { + gZenPinnedTabManager.addToEssentials(duplicatedTab); + } else if (isPinned) { + gBrowser.pinTab(duplicatedTab); + } + + gBrowser.moveTabTo(duplicatedTab, { tabIndex, forceUngrouped: !!targetTab.group }); + resolve(); + }, 0); + }); + } + } + + window.gZenWorkspaceWindowSync = new gZenWorkspaceWindowSync(); +} From e7c3631a717e12436973a623f3d89dae18adecaa Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Wed, 30 Apr 2025 18:28:44 +0200 Subject: [PATCH 2/6] chore: Update tab icons and labels in sync, b=(no-bug), c=tabs, workspaces --- .../tabbrowser/content/tabbrowser-js.patch | 84 +++++++++++-------- src/zen/tabs/ZenPinnedTabManager.mjs | 2 + src/zen/workspaces/ZenWorkspaces.mjs | 26 ++++++ 3 files changed, 77 insertions(+), 35 deletions(-) diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index c6215f1a..cd1bc036 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b15b3451aa 100644 +index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069b17d16d7 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -415,11 +415,58 @@ @@ -323,12 +323,12 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenTabId) { -+ tab.setAttribute("zen-tab-id", tabData.zenTabId); -+ } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -395,17 +395,23 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 ); tabsFragment.appendChild(tabGroup.node); } -@@ -3726,6 +3872,9 @@ +@@ -3723,8 +3869,15 @@ + // to remove the old selected tab. + if (tabToSelect) { + let leftoverTab = this.selectedTab; ++ if (tabToSelect.pinned) { ++ ZenWorkspaces._tabToRemoveForEmpty = leftoverTab; ++ } else { this.selectedTab = tabToSelect; this.removeTab(leftoverTab); - } ++ } ++ } + else { + this.selectedTab._possiblyEmpty = this.selectedTab.isEmpty; // Not needed, but just in case. -+ } + } if (tabs.length > 1 || !tabs[0].selected) { - this._updateTabsAfterInsert(); -@@ -3912,7 +4061,7 @@ +@@ -3912,7 +4065,7 @@ // Ensure we have an index if one was not provided. if (typeof index != "number") { // Move the new tab after another tab if needed, to the end otherwise. @@ -414,7 +420,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if ( !bulkOrderedOpen && ((openerTab && -@@ -3958,18 +4107,18 @@ +@@ -3958,18 +4111,18 @@ // Ensure index is within bounds. if (tab.pinned) { @@ -437,7 +443,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4290,6 +4439,9 @@ +@@ -4290,6 +4443,9 @@ return; } @@ -447,7 +453,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 this.removeTabs(selectedTabs, { telemetrySource }); } -@@ -4542,6 +4694,7 @@ +@@ -4542,6 +4698,7 @@ telemetrySource, } = {} ) { @@ -455,7 +461,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4626,6 +4779,7 @@ +@@ -4626,6 +4783,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -463,7 +469,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 } catch (e) { console.error(e); } -@@ -4650,6 +4804,7 @@ +@@ -4650,6 +4808,7 @@ telemetrySource, } = {} ) { @@ -471,7 +477,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.finish("browser.tabs.opening", window); } -@@ -4663,6 +4818,12 @@ +@@ -4663,6 +4822,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -484,7 +490,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -4677,7 +4838,9 @@ +@@ -4677,7 +4842,9 @@ // frame created for it (for example, by updating the visually selected // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; @@ -495,7 +501,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -4840,7 +5003,7 @@ +@@ -4840,7 +5007,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -504,7 +510,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -4864,6 +5027,7 @@ +@@ -4864,6 +5031,7 @@ newTab = true; } @@ -512,7 +518,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -4903,9 +5067,7 @@ +@@ -4903,9 +5071,7 @@ aTab._mouseleave(); if (newTab) { @@ -523,7 +529,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 } else { TabBarVisibility.update(); } -@@ -5034,6 +5196,8 @@ +@@ -5034,6 +5200,8 @@ this.tabs[i]._tPos = i; } @@ -532,7 +538,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (!this._windowIsClosing) { if (wasPinned) { this.tabContainer._positionPinnedTabs(); -@@ -5159,8 +5323,8 @@ +@@ -5159,8 +5327,8 @@ return closedCount; } @@ -543,7 +549,15 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (unloadBlocked) { return; } -@@ -5260,13 +5424,13 @@ +@@ -5247,6 +5415,7 @@ + aExcludeTabs.push(FirefoxViewHandler.tab); + } + ++ aExcludeTabs.push(...ZenWorkspaces.getTabsToExclude(aTab)); + let excludeTabs = new Set(aExcludeTabs); + + // If this tab has a successor, it should be selectable, since +@@ -5260,13 +5429,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -559,7 +573,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5282,7 +5446,7 @@ +@@ -5282,7 +5451,7 @@ } if (tab) { @@ -568,7 +582,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5303,7 +5467,7 @@ +@@ -5303,7 +5472,7 @@ }); } @@ -577,7 +591,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 } _blurTab(aTab) { -@@ -5704,10 +5868,10 @@ +@@ -5704,10 +5873,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -590,7 +604,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6001,7 +6165,7 @@ +@@ -6001,7 +6170,7 @@ // Don't allow mixing pinned and unpinned tabs. if (this.isTab(element) && element.pinned) { @@ -599,7 +613,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6028,9 +6192,16 @@ +@@ -6028,9 +6197,16 @@ element, () => { let neighbor = this.tabs[tabIndex]; @@ -617,7 +631,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6099,7 +6270,9 @@ +@@ -6099,7 +6275,9 @@ targetElement = targetElement.group; } } @@ -628,7 +642,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 // Don't allow mixing pinned and unpinned tabs. if (element.pinned && !targetElement?.pinned) { targetElement = this.tabs[this.pinnedTabCount - 1]; -@@ -6109,7 +6282,13 @@ +@@ -6109,7 +6287,13 @@ moveBefore = true; } @@ -642,7 +656,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 if (element.pinned && this.tabContainer.verticalMode) { return this.tabContainer.verticalPinnedTabsContainer; } -@@ -6169,7 +6348,7 @@ +@@ -6169,7 +6353,7 @@ if (!this.isTab(aTab)) { throw new Error("Can only move a tab into a tab group"); } @@ -651,7 +665,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6263,6 +6442,10 @@ +@@ -6263,6 +6447,10 @@ moveActionCallback(); @@ -662,7 +676,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7080,7 +7263,7 @@ +@@ -7080,7 +7268,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -671,7 +685,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 window.focus(); aEvent.preventDefault(); break; -@@ -7981,6 +8164,7 @@ +@@ -7981,6 +8169,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -679,7 +693,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -8954,7 +9138,7 @@ var TabContextMenu = { +@@ -8954,7 +9143,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -688,7 +702,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..ccf33e469c3e4b8d0fb55a50561023b1 // Move Tab items let contextMoveTabOptions = document.getElementById( "context_moveTabOptions" -@@ -9223,6 +9407,7 @@ var TabContextMenu = { +@@ -9223,6 +9412,7 @@ var TabContextMenu = { telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP, }); } else { diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index 11483592..ce158587 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -82,6 +82,7 @@ } onTabIconChanged(tab, url = null) { + tab.dispatchEvent(new CustomEvent('Zen:TabIconChanged', { bubbles: true, detail: { tab } })); const iconUrl = url ?? tab.iconImage.src; if (!iconUrl) { try { @@ -1015,6 +1016,7 @@ } async onTabLabelChanged(tab) { + tab.dispatchEvent(new CustomEvent('Zen:TabLabelChanged', { detail: { tab } })); if (!this._pinsCache) { return; } diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index ea1a43b0..4967a2b8 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -2950,6 +2950,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { 'TabHide', 'TabShow', 'TabMove', + 'Zen:TabIconChanged', + 'Zen:TabLabelChanged', ]; const eventListener = this.#handleEvent.bind(this); for (const event of kEvents) { @@ -3008,6 +3010,12 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { case 'TabMove': this.#onTabMove(event); break; + case 'Zen:TabIconChanged': + this.#onTabIconChanged(event); + break; + case 'Zen:TabLabelChanged': + this.#onTabLabelChanged(event); + break; default: console.warn(`Unhandled event type: ${event.type}`); break; @@ -3028,6 +3036,24 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { return null; } + #onTabIconChanged(event) { + this.#updateTabIconAndLabel(event); + } + + #onTabLabelChanged(event) { + this.#updateTabIconAndLabel(event); + } + + #updateTabIconAndLabel(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToChange = this.#getTabWithId(tabId); + if (tabToChange) { + gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab)); + gBrowser._setTabLabel(tabToChange, targetTab.label); + } + } + #onTabClose(event) { const targetTab = event.target; const tabId = this.#getTabId(targetTab); From 494c8fe5999ebc1da2197b6b9aaaeebdb9bbadb3 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mauro-balades@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:31:08 +0200 Subject: [PATCH 3/6] Discard changes to src/browser/components/sessionstore/SessionStore-sys-mjs.patch --- .../sessionstore/SessionStore-sys-mjs.patch | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index 2487dd23..2afcff59 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc303de496d9 100644 +index 5633e5032f5d50c70512187d27e045b579978927..dd7aa4827eaa809dadc7e1fe6cdd1083e79f383a 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -3202,7 +3202,7 @@ var SessionStoreInternal = { @@ -11,18 +11,17 @@ index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc30 return; } -@@ -3911,6 +3911,10 @@ var SessionStoreInternal = { +@@ -3911,6 +3911,9 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; + tabState.zenEssential = false; + tabState.zenPinnedId = null; + tabState.zenHasStaticLabel = false; -+ tabState.zenTabId = null; if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -5416,14 +5420,15 @@ var SessionStoreInternal = { +@@ -5416,14 +5419,15 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -40,7 +39,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc30 continue; } let tabData = lazy.TabState.collect(tab, TAB_CUSTOM_VALUES.get(tab)); -@@ -5442,7 +5447,7 @@ var SessionStoreInternal = { +@@ -5442,7 +5446,7 @@ var SessionStoreInternal = { // We don't store the Firefox View tab in Session Store, so if it was the last selected "tab" when // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). @@ -49,7 +48,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc30 selectedIndex = 1; winData.title = tabbrowser.tabs[0].label; } -@@ -5599,6 +5604,7 @@ var SessionStoreInternal = { +@@ -5599,6 +5603,7 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -57,7 +56,7 @@ index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc30 this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6148,8 +6154,26 @@ var SessionStoreInternal = { +@@ -6148,8 +6153,23 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -70,9 +69,6 @@ index 5633e5032f5d50c70512187d27e045b579978927..95a903916f89003486567c37f6a7cc30 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenTabId) { -+ tab.setAttribute("zen-tab-id", tabData.zenTabId); -+ } + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } From 40d24ffa6159afe591415f84e5cd8ccd3877e5d5 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mauro-balades@users.noreply.github.com> Date: Wed, 30 Apr 2025 18:32:56 +0200 Subject: [PATCH 4/6] Discard changes to src/browser/components/tabbrowser/content/tabbrowser-js.patch --- .../tabbrowser/content/tabbrowser-js.patch | 92 ++++++++----------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index cd1bc036..1c8fc221 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069b17d16d7 100644 +index 6dece2b9d0462d90a28e75350ce983d87816ef73..e80730ed2db404c0d47f2e29c3235c66f0137ad2 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -415,11 +415,58 @@ @@ -310,7 +310,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 }); } -@@ -3589,6 +3684,30 @@ +@@ -3589,6 +3684,27 @@ ) { tabWasReused = true; tab = this.selectedTab; @@ -326,9 +326,6 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } -+ if (tabData.zenTabId) { -+ tab.setAttribute("zen-tab-id", tabData.zenTabId); -+ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -341,7 +338,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (!tabData.pinned) { this.unpinTab(tab); } else { -@@ -3637,7 +3756,30 @@ +@@ -3637,7 +3753,27 @@ skipLoad: true, preferredRemoteType, }); @@ -358,9 +355,6 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenTabId) { -+ tab.setAttribute("zen-tab-id", tabData.zenTabId); -+ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -373,7 +367,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (select) { tabToSelect = tab; } -@@ -3661,7 +3803,8 @@ +@@ -3661,7 +3797,8 @@ // needs calling: shouldUpdateForPinnedTabs = true; } @@ -383,7 +377,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 let { groupId } = tabData; const tabGroup = tabGroupWorkingData.get(groupId); // if a tab refers to a tab group we don't know, skip any group -@@ -3675,7 +3818,10 @@ +@@ -3675,7 +3812,10 @@ tabGroup.stateData.id, tabGroup.stateData.color, tabGroup.stateData.collapsed, @@ -395,23 +389,17 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 ); tabsFragment.appendChild(tabGroup.node); } -@@ -3723,8 +3869,15 @@ - // to remove the old selected tab. - if (tabToSelect) { - let leftoverTab = this.selectedTab; -+ if (tabToSelect.pinned) { -+ ZenWorkspaces._tabToRemoveForEmpty = leftoverTab; -+ } else { +@@ -3726,6 +3866,9 @@ this.selectedTab = tabToSelect; this.removeTab(leftoverTab); -+ } -+ } + } + else { + this.selectedTab._possiblyEmpty = this.selectedTab.isEmpty; // Not needed, but just in case. - } ++ } if (tabs.length > 1 || !tabs[0].selected) { -@@ -3912,7 +4065,7 @@ + this._updateTabsAfterInsert(); +@@ -3912,7 +4055,7 @@ // Ensure we have an index if one was not provided. if (typeof index != "number") { // Move the new tab after another tab if needed, to the end otherwise. @@ -420,7 +408,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if ( !bulkOrderedOpen && ((openerTab && -@@ -3958,18 +4111,18 @@ +@@ -3958,18 +4101,18 @@ // Ensure index is within bounds. if (tab.pinned) { @@ -443,7 +431,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4290,6 +4443,9 @@ +@@ -4290,6 +4433,9 @@ return; } @@ -453,7 +441,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 this.removeTabs(selectedTabs, { telemetrySource }); } -@@ -4542,6 +4698,7 @@ +@@ -4542,6 +4688,7 @@ telemetrySource, } = {} ) { @@ -461,7 +449,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4626,6 +4783,7 @@ +@@ -4626,6 +4773,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -469,7 +457,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 } catch (e) { console.error(e); } -@@ -4650,6 +4808,7 @@ +@@ -4650,6 +4798,7 @@ telemetrySource, } = {} ) { @@ -477,7 +465,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.finish("browser.tabs.opening", window); } -@@ -4663,6 +4822,12 @@ +@@ -4663,6 +4812,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -490,7 +478,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -4677,7 +4842,9 @@ +@@ -4677,7 +4832,9 @@ // frame created for it (for example, by updating the visually selected // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; @@ -501,7 +489,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -4840,7 +5007,7 @@ +@@ -4840,7 +4997,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -510,7 +498,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -4864,6 +5031,7 @@ +@@ -4864,6 +5021,7 @@ newTab = true; } @@ -518,7 +506,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -4903,9 +5071,7 @@ +@@ -4903,9 +5061,7 @@ aTab._mouseleave(); if (newTab) { @@ -529,7 +517,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 } else { TabBarVisibility.update(); } -@@ -5034,6 +5200,8 @@ +@@ -5034,6 +5190,8 @@ this.tabs[i]._tPos = i; } @@ -538,7 +526,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (!this._windowIsClosing) { if (wasPinned) { this.tabContainer._positionPinnedTabs(); -@@ -5159,8 +5327,8 @@ +@@ -5159,8 +5317,8 @@ return closedCount; } @@ -549,15 +537,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (unloadBlocked) { return; } -@@ -5247,6 +5415,7 @@ - aExcludeTabs.push(FirefoxViewHandler.tab); - } - -+ aExcludeTabs.push(...ZenWorkspaces.getTabsToExclude(aTab)); - let excludeTabs = new Set(aExcludeTabs); - - // If this tab has a successor, it should be selectable, since -@@ -5260,13 +5429,13 @@ +@@ -5260,13 +5418,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -573,7 +553,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5282,7 +5451,7 @@ +@@ -5282,7 +5440,7 @@ } if (tab) { @@ -582,7 +562,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5303,7 +5472,7 @@ +@@ -5303,7 +5461,7 @@ }); } @@ -591,7 +571,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 } _blurTab(aTab) { -@@ -5704,10 +5873,10 @@ +@@ -5704,10 +5862,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -604,7 +584,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6001,7 +6170,7 @@ +@@ -6001,7 +6159,7 @@ // Don't allow mixing pinned and unpinned tabs. if (this.isTab(element) && element.pinned) { @@ -613,7 +593,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6028,9 +6197,16 @@ +@@ -6028,9 +6186,16 @@ element, () => { let neighbor = this.tabs[tabIndex]; @@ -631,7 +611,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6099,7 +6275,9 @@ +@@ -6099,7 +6264,9 @@ targetElement = targetElement.group; } } @@ -642,7 +622,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 // Don't allow mixing pinned and unpinned tabs. if (element.pinned && !targetElement?.pinned) { targetElement = this.tabs[this.pinnedTabCount - 1]; -@@ -6109,7 +6287,13 @@ +@@ -6109,7 +6276,13 @@ moveBefore = true; } @@ -656,7 +636,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 if (element.pinned && this.tabContainer.verticalMode) { return this.tabContainer.verticalPinnedTabsContainer; } -@@ -6169,7 +6353,7 @@ +@@ -6169,7 +6342,7 @@ if (!this.isTab(aTab)) { throw new Error("Can only move a tab into a tab group"); } @@ -665,7 +645,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6263,6 +6447,10 @@ +@@ -6263,6 +6436,10 @@ moveActionCallback(); @@ -676,7 +656,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7080,7 +7268,7 @@ +@@ -7080,7 +7257,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -685,7 +665,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 window.focus(); aEvent.preventDefault(); break; -@@ -7981,6 +8169,7 @@ +@@ -7981,6 +8158,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -693,7 +673,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -8954,7 +9143,7 @@ var TabContextMenu = { +@@ -8954,7 +9132,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -702,7 +682,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069 // Move Tab items let contextMoveTabOptions = document.getElementById( "context_moveTabOptions" -@@ -9223,6 +9412,7 @@ var TabContextMenu = { +@@ -9223,6 +9401,7 @@ var TabContextMenu = { telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP, }); } else { From 7fe7e898af3366c7a1f3de5b7cf9bbbdc12c6547 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Wed, 30 Apr 2025 18:33:41 +0200 Subject: [PATCH 5/6] chore: Export tab browser patch, b=(no-bug), c=no-component --- .../tabbrowser/content/tabbrowser-js.patch | 74 ++++++++++--------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index a91f4a78..cd1bc036 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c0275645f8a5cd3 100644 +index 6dece2b9d0462d90a28e75350ce983d87816ef73..fc09d86f76ce3de8ecc2731450681069b17d16d7 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -415,11 +415,58 @@ @@ -310,7 +310,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 }); } -@@ -3589,6 +3684,27 @@ +@@ -3589,6 +3684,30 @@ ) { tabWasReused = true; tab = this.selectedTab; @@ -326,6 +326,9 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 + if (tabData.zenPinnedId) { + tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -338,7 +341,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (!tabData.pinned) { this.unpinTab(tab); } else { -@@ -3637,7 +3753,27 @@ +@@ -3637,7 +3756,30 @@ skipLoad: true, preferredRemoteType, }); @@ -355,6 +358,9 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } ++ if (tabData.zenTabId) { ++ tab.setAttribute("zen-tab-id", tabData.zenTabId); ++ } + if (tabData.zenEssential) { + tab.setAttribute("zen-essential", "true"); + } @@ -367,7 +373,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (select) { tabToSelect = tab; } -@@ -3661,7 +3797,8 @@ +@@ -3661,7 +3803,8 @@ // needs calling: shouldUpdateForPinnedTabs = true; } @@ -377,7 +383,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 let { groupId } = tabData; const tabGroup = tabGroupWorkingData.get(groupId); // if a tab refers to a tab group we don't know, skip any group -@@ -3675,7 +3812,10 @@ +@@ -3675,7 +3818,10 @@ tabGroup.stateData.id, tabGroup.stateData.color, tabGroup.stateData.collapsed, @@ -389,7 +395,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 ); tabsFragment.appendChild(tabGroup.node); } -@@ -3723,8 +3863,15 @@ +@@ -3723,8 +3869,15 @@ // to remove the old selected tab. if (tabToSelect) { let leftoverTab = this.selectedTab; @@ -405,7 +411,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } if (tabs.length > 1 || !tabs[0].selected) { -@@ -3912,7 +4059,7 @@ +@@ -3912,7 +4065,7 @@ // Ensure we have an index if one was not provided. if (typeof index != "number") { // Move the new tab after another tab if needed, to the end otherwise. @@ -414,7 +420,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if ( !bulkOrderedOpen && ((openerTab && -@@ -3958,18 +4105,18 @@ +@@ -3958,18 +4111,18 @@ // Ensure index is within bounds. if (tab.pinned) { @@ -437,7 +443,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4290,6 +4437,9 @@ +@@ -4290,6 +4443,9 @@ return; } @@ -447,7 +453,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 this.removeTabs(selectedTabs, { telemetrySource }); } -@@ -4542,6 +4692,7 @@ +@@ -4542,6 +4698,7 @@ telemetrySource, } = {} ) { @@ -455,7 +461,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4626,6 +4777,7 @@ +@@ -4626,6 +4783,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -463,7 +469,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } catch (e) { console.error(e); } -@@ -4650,6 +4802,7 @@ +@@ -4650,6 +4808,7 @@ telemetrySource, } = {} ) { @@ -471,7 +477,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.finish("browser.tabs.opening", window); } -@@ -4663,6 +4816,12 @@ +@@ -4663,6 +4822,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -484,7 +490,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -4677,7 +4836,9 @@ +@@ -4677,7 +4842,9 @@ // frame created for it (for example, by updating the visually selected // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; @@ -495,7 +501,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -4840,7 +5001,7 @@ +@@ -4840,7 +5007,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -504,7 +510,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -4864,6 +5025,7 @@ +@@ -4864,6 +5031,7 @@ newTab = true; } @@ -512,7 +518,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -4903,9 +5065,7 @@ +@@ -4903,9 +5071,7 @@ aTab._mouseleave(); if (newTab) { @@ -523,7 +529,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } else { TabBarVisibility.update(); } -@@ -5034,6 +5194,8 @@ +@@ -5034,6 +5200,8 @@ this.tabs[i]._tPos = i; } @@ -532,7 +538,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (!this._windowIsClosing) { if (wasPinned) { this.tabContainer._positionPinnedTabs(); -@@ -5159,8 +5321,8 @@ +@@ -5159,8 +5327,8 @@ return closedCount; } @@ -543,7 +549,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (unloadBlocked) { return; } -@@ -5247,6 +5409,7 @@ +@@ -5247,6 +5415,7 @@ aExcludeTabs.push(FirefoxViewHandler.tab); } @@ -551,7 +557,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 let excludeTabs = new Set(aExcludeTabs); // If this tab has a successor, it should be selectable, since -@@ -5260,13 +5423,13 @@ +@@ -5260,13 +5429,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -567,7 +573,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5282,7 +5445,7 @@ +@@ -5282,7 +5451,7 @@ } if (tab) { @@ -576,7 +582,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5303,7 +5466,7 @@ +@@ -5303,7 +5472,7 @@ }); } @@ -585,7 +591,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } _blurTab(aTab) { -@@ -5704,10 +5867,10 @@ +@@ -5704,10 +5873,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -598,7 +604,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6001,7 +6164,7 @@ +@@ -6001,7 +6170,7 @@ // Don't allow mixing pinned and unpinned tabs. if (this.isTab(element) && element.pinned) { @@ -607,7 +613,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6028,9 +6191,16 @@ +@@ -6028,9 +6197,16 @@ element, () => { let neighbor = this.tabs[tabIndex]; @@ -625,7 +631,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6099,7 +6269,9 @@ +@@ -6099,7 +6275,9 @@ targetElement = targetElement.group; } } @@ -636,7 +642,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 // Don't allow mixing pinned and unpinned tabs. if (element.pinned && !targetElement?.pinned) { targetElement = this.tabs[this.pinnedTabCount - 1]; -@@ -6109,7 +6281,13 @@ +@@ -6109,7 +6287,13 @@ moveBefore = true; } @@ -650,7 +656,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 if (element.pinned && this.tabContainer.verticalMode) { return this.tabContainer.verticalPinnedTabsContainer; } -@@ -6169,7 +6347,7 @@ +@@ -6169,7 +6353,7 @@ if (!this.isTab(aTab)) { throw new Error("Can only move a tab into a tab group"); } @@ -659,7 +665,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6263,6 +6441,10 @@ +@@ -6263,6 +6447,10 @@ moveActionCallback(); @@ -670,7 +676,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7080,7 +7262,7 @@ +@@ -7080,7 +7268,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -679,7 +685,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 window.focus(); aEvent.preventDefault(); break; -@@ -7981,6 +8163,7 @@ +@@ -7981,6 +8169,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -687,7 +693,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -8954,7 +9137,7 @@ var TabContextMenu = { +@@ -8954,7 +9143,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -696,7 +702,7 @@ index 6dece2b9d0462d90a28e75350ce983d87816ef73..a285c5cbc23eaeebc8248b950c027564 // Move Tab items let contextMoveTabOptions = document.getElementById( "context_moveTabOptions" -@@ -9223,6 +9406,7 @@ var TabContextMenu = { +@@ -9223,6 +9412,7 @@ var TabContextMenu = { telemetrySource: gBrowser.TabMetrics.METRIC_SOURCE.TAB_STRIP, }); } else { From 0d0967c823713d45bd42e30132a5a963275454f9 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Wed, 30 Apr 2025 19:06:12 +0200 Subject: [PATCH 6/6] chore: Started working on browser swaping, b=(no-bug), c=workspaces --- src/zen/workspaces/ZenWorkspaces.mjs | 82 ++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index 135e22c8..6bbf3f37 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -2930,6 +2930,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { #ignoreNextEvents = false; #waitForPromise = null; + lastSelectedWindow = false; + constructor() { super(); if (!window.closed) { @@ -2941,6 +2943,8 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { await ZenWorkspaces.promiseInitialized; this.#makeSureAllTabsHaveIds(); this.#setUpEventListeners(); + + this.lastSelectedWindow = ZenMultiWindowFeature.isActiveWindow; } #makeSureAllTabsHaveIds() { @@ -2971,12 +2975,60 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { for (const event of kEvents) { window.addEventListener(event, eventListener); } + + window.addEventListener('unload', () => { + for (const event of kEvents) { + window.removeEventListener(event, eventListener); + } + }); + + window.addEventListener('focus', this.#onWindowFocus.bind(this)); } #handleEvent(event) { this.#propagateToOtherWindows(event); } + #getLastSelectedWindow() { + return new Promise(async (resolve) => { + await this.foreachWindowAsActive(async (browser) => { + if (browser.gZenWorkspaceWindowSync && browser.gZenWorkspaceWindowSync.lastSelectedWindow) { + resolve(browser); + } + }); + resolve(null); + }); + } + + async #onWindowFocus(event) { + const lastSelectedWindow = await this.#getLastSelectedWindow(); + if (lastSelectedWindow && lastSelectedWindow !== window) { + lastSelectedWindow.gZenWorkspaceWindowSync.lastSelectedWindow = false; + this.lastSelectedWindow = true; + this.#replaceBrowsersWithLastSelectedWindow(lastSelectedWindow); + } else { + this.lastSelectedWindow = false; + } + } + + #replaceBrowsersWithLastSelectedWindow(lastSelectedWindow) { + // Replace all `linkedBrowser` elements with the last selected window's browsers + // from all the tabs in the current window + const allTabs = lastSelectedWindow.ZenWorkspaces.allStoredTabs; + for (const oldTab of allTabs) { + const tabId = this.#getTabId(oldTab); + const targetTab = this.#getTabWithId(tabId); + if (targetTab) { + const browserToReplace = oldTab.linkedBrowser; + const browserReplaced = targetTab.linkedBrowser; + const parentNode = browserReplaced.parentNode; + if (browserToReplace && parentNode) { + gBrowser.swapBrowsers(browserToReplace, browserReplaced); + } + } + } + } + async #propagateToOtherWindows(event) { if (this.#ignoreNextEvents) { return; @@ -3148,22 +3200,20 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { async #onTabOpen(event) { await new Promise((resolve) => { - setTimeout(() => { - const targetTab = event.target; - const isPinned = targetTab.pinned; - const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); - const tabIndex = targetTab._tPos; - - const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0, true); - if (isEssential) { - gZenPinnedTabManager.addToEssentials(duplicatedTab); - } else if (isPinned) { - gBrowser.pinTab(duplicatedTab); - } - - gBrowser.moveTabTo(duplicatedTab, { tabIndex, forceUngrouped: !!targetTab.group }); - resolve(); - }, 0); + const targetTab = event.target; + const isPinned = targetTab.pinned; + const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); + const tabIndex = targetTab._tPos; + + const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0, true); + if (isEssential) { + gZenPinnedTabManager.addToEssentials(duplicatedTab); + } else if (isPinned) { + gBrowser.pinTab(duplicatedTab); + } + + gBrowser.moveTabTo(duplicatedTab, { tabIndex, forceUngrouped: !!targetTab.group }); + resolve(); }); } }