Skip to content

Commit

Permalink
Enhance ZenUIManager for improved toolbar handling and compact mode l…
Browse files Browse the repository at this point in the history
…ayout
  • Loading branch information
mauro-balades committed Nov 24, 2024
1 parent 0658345 commit 3f58521
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/browser/base/content/ZenUIManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ var gZenVerticalTabsManager = {
Services.prefs.addObserver('zen.view.sidebar-expanded.max-width', updateEvent);
Services.prefs.addObserver('zen.view.use-single-toolbar', updateEvent);

this._toolbarOriginalParent = document.getElementById('nav-bar').parentElement;

gZenCompactModeManager.addEventListener(updateEvent);
this._updateEvent();
this.initRightSideOrderContextMenu();
Expand Down Expand Up @@ -192,6 +194,10 @@ var gZenVerticalTabsManager = {
},

_updateEvent() {
if (this._isUpdating) {
return;
}
this._isUpdating = true;
this._updateMaxWidth();
const topButtons = document.getElementById('zen-sidebar-top-buttons');
const isCompactMode = Services.prefs.getBoolPref('zen.view.compact');
Expand Down Expand Up @@ -228,9 +234,9 @@ var gZenVerticalTabsManager = {

let windowButtons = this.actualWindowButtons;
let doNotChangeWindowButtons = !isCompactMode && isRightSide && this.isWindowsStyledButtons;
const navBar = document.getElementById('nav-bar');

if (isSingleToolbar) {
const navBar = document.getElementById('nav-bar');
this._navbarParent = navBar.parentElement;
let elements = document.querySelectorAll('#nav-bar-customization-target > *:is(toolbarbutton, #stop-reload-button)');
elements = Array.from(elements);
Expand All @@ -247,12 +253,18 @@ var gZenVerticalTabsManager = {
if (this.isWindowsStyledButtons && !doNotChangeWindowButtons) {
document.getElementById('zen-appcontent-navbar-container').append(windowButtons);
}
if (isCompactMode) {
titlebar.prepend(navBar);
titlebar.prepend(topButtons);
} else {
titlebar.before(topButtons);
titlebar.before(navBar);
}
document.documentElement.setAttribute("zen-single-toolbar", true);
this._hasSetSingleToolbar = true;
} else if (this._hasSetSingleToolbar) {
this._hasSetSingleToolbar = false;
// Do the opposite
const navBar = document.getElementById('nav-bar');
this._navbarParent.prepend(navBar);
const elements = document.querySelectorAll('#zen-sidebar-top-buttons-customization-target > *:is(toolbarbutton, #stop-reload-button)');
for (const button of elements) {
Expand All @@ -270,15 +282,14 @@ var gZenVerticalTabsManager = {
navBar.prepend(windowButtons);
}
}
this._toolbarOriginalParent.prepend(navBar);
CustomizableUI.zenInternalCU._rebuildRegisteredAreas();
}

if (isCompactMode) {
titlebar.prepend(navBar);
titlebar.prepend(topButtons);
} else {
titlebar.before(topButtons);
titlebar.before(navBar);
}

if (doNotChangeWindowButtons) {
Expand All @@ -287,6 +298,7 @@ var gZenVerticalTabsManager = {

// Always move the splitter next to the sidebar
this.navigatorToolbox.after(document.getElementById('zen-sidebar-splitter'));
this._isUpdating = false;
},

_updateMaxWidth() {
Expand Down
4 changes: 4 additions & 0 deletions src/browser/base/content/zen-styles/zen-compact-mode.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

:root[zen-single-toolbar='true'] & {
top: var(--zen-element-separation);

& #nav-bar {
margin-left: calc(var(--zen-toolbox-padding) / 2) !important;
}
}
}

Expand Down

0 comments on commit 3f58521

Please sign in to comment.