Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): give left-hand window controls room in the vertical layout
Elian Doran800b5ec45773
diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsxindex 2dac62926b..5554baafa5 100644--- a/apps/client/src/layouts/desktop_layout.tsx+++ b/apps/client/src/layouts/desktop_layout.tsx@@ -66,14 +66,15 @@ export default class DesktopLayout {const launcherPaneIsHorizontal = options.get("layoutOrientation") === "horizontal";const launcherPane = this.#buildLauncherPane(launcherPaneIsHorizontal);const isElectron = utils.isElectron();- const isMac = window.glob.platform === "darwin";const hasNativeTitleBar = window.glob.hasNativeTitleBar;/*** If true, the tab bar is displayed above the launcher pane with full width; if false (default), the tab bar is displayed in the rest pane.- * On macOS we need to force the full-width tab bar on Electron in order to allow the semaphore (window controls) enough space.+ * We force the full-width tab bar on Electron whenever the window controls sit on the left (always on macOS, and on Linux+ * depending on the desktop's decoration layout): the rest pane starts past the launcher pane, so a tab bar confined to it+ * cannot give those controls room, and they end up drawn over the launcher pane instead.*/- const fullWidthTabBar = launcherPaneIsHorizontal || (isElectron && !hasNativeTitleBar && isMac);+ const fullWidthTabBar = launcherPaneIsHorizontal || (isElectron && !hasNativeTitleBar && utils.areWindowControlsOnLeft());const isNewLayout = isExperimentalFeatureEnabled("new-layout");const rootContainer = new RootContainer(true)diff --git a/apps/client/src/services/utils.spec.ts b/apps/client/src/services/utils.spec.tsindex e89d5bcefd..d56457d83e 100644--- a/apps/client/src/services/utils.spec.ts+++ b/apps/client/src/services/utils.spec.ts@@ -1,6 +1,7 @@import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import utils, {+ areWindowControlsOnLeft,arrayEqual,clearBrowserCache,createImageSrcUrl,@@ -242,6 +243,32 @@ describe("platform / device detection", () => {expect(isMac()).toBe(false);});+ it("areWindowControlsOnLeft follows the platform and the overlay geometry", () => {+ const platformSpy = vi.spyOn(navigator, "platform", "get");+ const overlay = (visible: boolean, x: number) => {+ navigator.windowControlsOverlay = {+ visible,+ getTitlebarAreaRect: () => ({ x }) as DOMRect+ } as WindowControlsOverlay;+ };++ // macOS keeps the traffic lights on the left regardless of the overlay.+ platformSpy.mockReturnValue("MacIntel");+ expect(areWindowControlsOnLeft()).toBe(true);++ platformSpy.mockReturnValue("Linux x86_64");+ expect(areWindowControlsOnLeft()).toBe(false); // no overlay at all++ overlay(false, 92); // native title bar: geometry is stale, ignore it+ expect(areWindowControlsOnLeft()).toBe(false);++ overlay(true, 0); // controls on the right (Windows, and Linux by default)+ expect(areWindowControlsOnLeft()).toBe(false);++ overlay(true, 92); // controls on the left+ expect(areWindowControlsOnLeft()).toBe(true);+ });+it("isCtrlKey uses ctrlKey on non-Mac and metaKey on Mac", () => {const platformSpy = vi.spyOn(navigator, "platform", "get");platformSpy.mockReturnValue("Win32");diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.tsindex 093bf86fa8..725b46c2da 100644--- a/apps/client/src/services/utils.ts+++ b/apps/client/src/services/utils.ts@@ -163,7 +163,7 @@ export function isPWA() {window.matchMedia('(display-mode: standalone)').matches|| window.matchMedia('(display-mode: window-controls-overlay)').matches|| window.navigator.standalone- || window.navigator.windowControlsOverlay+ || !!window.navigator.windowControlsOverlay);}@@ -187,6 +187,28 @@ export function isLinux() {return window.glob?.platform === "linux";}+/**+ * Returns `true` when the native caption buttons sit on the leading (left) edge of the title bar,+ * where they overlap the top of a vertical launcher pane. Always the case on macOS; on Linux it+ * follows the desktop's decoration layout (e.g. GNOME's `button-layout`), which Chromium mirrors+ * into the Window Controls Overlay geometry. Windows always keeps them on the right.+ *+ * Reflects the layout as of the call; it is not re-evaluated if the desktop setting changes while+ * the app is running.+ */+export function areWindowControlsOnLeft() {+ if (isMac()) {+ return true;+ }++ const overlay = window.navigator.windowControlsOverlay;+ if (!overlay?.visible) {+ return false;+ }++ return overlay.getTitlebarAreaRect().x > 0;+}+/*** Returns `true` when the (server-reported) host platform is Windows.*/@@ -937,6 +959,7 @@ export default {isMac,isLinux,isWindows,+ areWindowControlsOnLeft,isCtrlKey,assertArguments,escapeHtml,diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex 3b7e9a4a71..ee696cdb80 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -2195,10 +2195,18 @@ body.electron.platform-darwin:not(.native-titlebar) .tab-row-container {}#tab-row-left-spacer {- width: env(titlebar-area-x);-webkit-app-region: drag;}+/*+ * Only macOS reserves the traffic lights' room with this spacer; every other platform uses the+ * container padding below, which handles controls on either side. Keeping the spacer at zero+ * elsewhere avoids reserving `titlebar-area-x` twice on a Linux desktop with left-hand controls.+ */+body.electron.platform-darwin #tab-row-left-spacer {+ width: env(titlebar-area-x);+}+body.electron.platform-darwin:not(.native-titlebar):not(.full-screen) #tab-row-left-spacer {width: 80px;}diff --git a/apps/client/src/types-lib.d.ts b/apps/client/src/types-lib.d.tsindex 59e7dbc4d9..029b78c01e 100644--- a/apps/client/src/types-lib.d.ts+++ b/apps/client/src/types-lib.d.ts@@ -60,11 +60,22 @@ declare module "leaflet" {}declare global {+ /** Geometry of the title bar area left free by the native window controls, and changes to it. */+ interface WindowControlsOverlay extends EventTarget {+ /** Whether the window controls overlay is drawn (false when the native title bar is used). */+ readonly visible: boolean;+ /**+ * The part of the title bar not covered by the native caption buttons. A non-zero `x` means+ * the buttons sit on the left; `x + width < window width` means they sit on the right.+ */+ getTitlebarAreaRect(): DOMRect;+ }+interface Navigator {/** Returns a boolean indicating whether the browser is running in standalone mode. Available on Apple's iOS Safari only. */standalone?: boolean;/** Returns the WindowControlsOverlay interface which exposes information about the geometry of the title bar in desktop Progressive Web Apps, and an event to know whenever it changes. */- windowControlsOverlay?: unknown;+ windowControlsOverlay?: WindowControlsOverlay;}}