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

Đang mở
#65,342 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
electron, linux, typescript
Lĩnh vực
desktop-dev

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
227k
Fork
30.7k
Merge trung bình
3 giờ 57 phút
Pull request đã merge (30 ngày)
484

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của anomalyco/opencode

Tất cả issue của anomalyco/opencode

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.