[FEATURE]: Desktop v2 — custom titlebar with native window controls on Linux

未关闭
#65,342 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
electron, linux, typescript
领域
desktop-dev

调研方向

Start in the desktop main process where the window factory branches only on darwin/win32: add the Linux branch and check the overlay factory's max(44, 44 * zoom) height against the 36 px header. Relax the win32 guard on the setTitleBarOverlay updater so theme switches reach Linux, then align the five renderer conditions (hideVerticalTitlebar, actionInSidebarHeader, the titlebar toggle, the vertical-tabs header, useCollapsedSlot) with the Windows path. PR #52338 already holds this change, so rebasing it is the fastest route; done means WCO visible at 36 px, legible buttons in both themes, and no duplicate collapsed toggle.

由索引模型根据 Issue 内容生成。

描述

area/desktop platform/linux type/feature version/v2
  • I have checked that this feature has not been requested before (see "Related" below — the only prior request, #36225, was closed as not planned for v1 with a note to open a v2 request)
Description

On Linux the desktop app still gets a native GTK titlebar, stacked on top of its own top bar: two headers, and the app menu / sidebar toggle sit in the second one. Windows and macOS have a single custom top bar with the window controls drawn at its right edge (macOS keeps its traffic lights at the left). Linux should look the same.

Environment: OpenCode desktop v2 2.3.2 (Fedora RPM opencode-2.3.2-1.x86_64), Electron 44.9.1 / Chromium 152, Fedora 44, GNOME on Wayland, org.gnome.desktop.interface color-scheme = prefer-dark.

Electron supports this on Linux: titleBarStyle: "hidden" together with titleBarOverlay enables the Window Controls Overlay (WCO), and Chromium draws real minimize / maximize / close buttons itself — no custom button component needed. That is the same mechanism the Windows build already uses.

Related
  • #36225 — Desktop: use custom titlebar instead of native GNOME/GTK titlebar on Linux. Closed as not planned for v1; the closing note said v2 still uses the native frame and a separate v2 request should be opened, hence this issue.
  • #52338 — PR doing essentially the change below for v2 (Linux WCO, frame.ts refactor, tests, screenshots for left/right/split controls and vertical tabs). Auto-closed by the stale/cleanup bot; the author asked for it to be reopened.
  • #37620 — earlier attempt, closed unmerged.

If #52338 can be reopened, it is probably the better vehicle; this issue is meant to record the v2 request and the exact behaviour expected.

What the 2.3.2 build actually does

Putting the shipped app.asar next to Electron's docs:

  1. Window options (main process): the factory only branches on darwin (titleBarStyle: "hidden", trafficLightPosition) and win32 (frame: false, titleBarStyle: "hidden", titleBarOverlay). Linux matches neither, so it gets Electron's default frame: true.

  2. Overlay colours on theme change: the renderer calls WindowSetTitlebar({ mode, scheme }) whenever a theme is applied; the desktop chunk stores it and calls a helper that is guarded by process.platform === "win32". On Linux the overlay keeps its window-creation colours, so as soon as the app theme differs from the system theme the buttons are dark-on-dark or light-on-light.

  3. Renderer, non-Windows branches that exist because Linux had a native titlebar:

    • hideVerticalTitlebar — with vertical tabs the app top bar is hidden on every non-Windows platform.
    • actionInSidebarHeader — on non-Windows the first action ("home" / "new session") moves into the sidebar header.
    • the titlebar sidebar toggle — shown only on Windows.
    • the vertical-tabs sidebar header — shown on non-Windows.
    • useCollapsedSlot — the floating collapsed-sidebar toggle is excluded only on Windows, because elsewhere the header had no toggle of its own.

    Remove the native frame without touching these and the result is worse than today: no native titlebar and no app menu (the top bar is hidden under vertical tabs).

Proposed change
  1. Main, window options: add a Linux branch — frame: false, titleBarStyle: "hidden", titleBarOverlay: { ... }. Keep macOS and Windows as they are.
  2. Overlay height: the overlay factory returns max(44, round(44 * zoom)), sized for the Windows header (which includes a content inset). The Linux header row is 36 px, so the height should follow the platform (or the header height constant) rather than reuse 44.
  3. Overlay colours: relax the win32 guard on the setTitleBarOverlay updater to "every platform with an overlay" (i.e. not macOS), so theme switches update symbolColor / color on Linux too.
  4. Renderer: treat Linux like Windows, not like macOS, in the five places above — keep the app top bar under vertical tabs, put the sidebar toggle in the top bar next to the menu button, drop the duplicate sidebar header and the floating collapsed toggle. This is what the Windows layout already is.
  5. GTK button layout: if feasible, respect org.gnome.desktop.wm.preferences button-layout (buttons on the left is a common setting). Not a blocker — WCO drawn on the right matches the current Windows layout and is what my local test does.
  6. Escape hatch: Wayland resize-by-edge behaviour with frame: false differs slightly from a native frame. An env/setting gate (e.g. keep native decorations if set) would let users opt out while this settles.
Verified locally

I applied the change above as equal-length byte patches to the 2.3.2 app.asar (no source build) and measured it through the main-process inspector and renderer CDP:

  • BrowserWindow.getBounds() and getContentBounds() are identical, before and after maximize/restore → no native frame remains.
  • navigator.windowControlsOverlay.visible === true; getTitlebarAreaRect() is 1167×36 in a 1280 px window — 113 px at the top right reserved for the system buttons, matching the 36 px header row.
  • Top bar [data-slot=titlebar-v2] is visible at 36 px, menu button at (12, 8), sidebar toggle at (50, 8), app menu opens normally.
  • Collapsing the sidebar sets [data-slot=vertical-tabs-sidebar] width to 0 and leaves zero [data-slot=collapsed-sidebar-toggle] elements; flipping the condition back to the original makes the floating toggle reappear at (18, 54), which confirms the duplicate.
  • Theme switch: setTitleBarOverlay is called with symbolColor: "black" for the light theme and "white" for the dark one, height 36 in both. Visually the buttons stay legible in both themes.
  • maximize() / unmaximize() / minimize() / restore() / close() all work; the WCO buttons call the same BrowserWindow methods.

Caveats: screenshots were not possible on this machine (no screencopy under this GNOME/Wayland session), so "the buttons are drawn" is confirmed only through the WCO API and the reserved rect — #52338's screenshots cover the visual side. Only one configuration was tested (Fedora 44 / GNOME / Wayland / Electron 44.9.1, vertical tabs), and the WCO reserve means a horizontal-tabs layout with third-party titlebar plugin items can have its rightmost item covered.

I am happy to help turn this into a source-level PR (or to review / rebase #52338) if that is useful.

主要语言
TypeScript
星标
227k
派生
30.7k
平均合并
3 小时 57 分钟
30 天内合并 PR
484

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anomalyco/opencode 的其他 Issue

查看 anomalyco/opencode 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。