Skip to content

Follow the desktop's window button layout on Linux - #349

Open
jiangsy wants to merge 5 commits into
mainfrom
auto-window-buttons
Open

jiangsy wants to merge 5 commits into
mainfrom
auto-window-buttons

Conversation

@jiangsy

@jiangsy jiangsy commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

An alternative to #344. Rather than adding Window buttons and Window button style settings, the desktop app follows the system:

  • Linux: when the app starts, the main process reads the desktop's own button layout and the window shows those buttons, in that order, on that side.

    • GNOME, Unity, Budgie and Pantheon: gsettings get org.gnome.desktop.wm.preferences button-layout
    • Cinnamon: org.cinnamon.desktop.wm.preferences
    • MATE: org.mate.Marco.general
    • KDE Plasma: ButtonsOnLeft / ButtonsOnRight in kwinrc, with the user's file layered over system ones in XDG_CONFIG_DIRS
    • Xfce: xfconf-query -c xfwm4 -p /general/button_layout

    GNOME's default (appmenu:close), for example, shows a single close button on the right. On other desktops (LXQt, COSMIC, tiling window managers), or when the layout can't be read, the window keeps today's close/minimize/maximize on the left. GNOME's schema is read only on the desktops above: other desktops often install it without setting it, and its default would leave a single close button.

  • Windows: unchanged. Wide buttons stay on the right; Windows has no setting to move them.

  • macOS: unchanged. The native traffic lights stay on the left.

Button style follows the platform (compact on Linux, wide on Windows), so there's no setting and no new UI text.

How it works:

  • desktop/window-buttons.ts parses the three layout formats and picks one side. When a layout splits the buttons, they gather on the side that holds close.
  • The lookup starts with the app and runs while the backend starts. Only the first window waits for it, and the lookup times out after 2 seconds.
  • The layout reaches the sandboxed preload as a JSON additionalArguments entry, then the page as papilotDesktop.windowButtons.
  • desktop-chrome.css now keys on data-desktop-controls="left|right" instead of the platform, and sizes the controls from --desktop-window-buttons (the button count).
  • Right-side controls are portaled after the workspace on any platform, so their no-drag regions win hit testing over the toolbars they overlap.

Two existing layout bugs the new browser check found, fixed here:

  • At Windows' 900px minimum window width, the chat heading's view selector ran under the window buttons. The manuscript shortcut label now truncates first.
  • Below 680px, left-side buttons (Linux, macOS) covered the manuscript shortcut. The phone-width bar now reserves the leading space, in addition to its own inset.

Modern Web Guidance

  • single-line-overflow: the manuscript shortcut's label truncates with overflow: hidden and an ellipsis inside a flex item given min-width: 0. This avoids a flex item that refuses to shrink below its text. The full name stays the button's accessible name and is shown in full in the sidebar.
  • form-factor-adaptation: keep text and controls clear of system UI (here, the window buttons) at every width, rather than letting them collide at the minimum window size.

How it was checked

  • npm run typecheck
  • npm test: new tests/window-buttons.test.ts (parsers, per-desktop detection, unknown desktops, kwinrc layering) passes. One failure, tests/desktop-layer.test.ts ("the engine keeps only dependencies…"), also fails on main in my local checkout (mupdf in node_modules) and isn't related to this change.
  • npm run build
  • node --import tsx scripts/check-appearance.mjs: new window-button section covers Linux default, GNOME (close only, right), full right, two-button left, Windows, and macOS's traffic-light space. For each it checks button order, edge placement, and that no toolbar control sits under the buttons with the sidebar open or hidden, at 1440, 900 and 680px. Screenshots inspected.
  • npm run test:desktop (development app, macOS) passes.
  • scripts/check-desktop.mjs now gives the Linux run a known KDE kwinrc and asserts the page receives and renders that layout, so the Linux desktop CI job covers the real main → preload → page path.
  • Confirmed with a minimal Electron 45 app that a sandboxed preload reads process.argv entries from additionalArguments.

Limitations

  • The layout is read once at startup. Changing it in GNOME Tweaks or System Settings takes effect after Papilot restarts.
  • GTK's per-app gtk-decoration-layout override in settings.ini isn't read. The window manager's setting is used.
  • I didn't run it on a native Linux desktop. Linux behavior is covered by unit tests, browser checks with mock layouts, and the Linux desktop CI job.

🤖 Generated with Claude Code

jiangsy and others added 5 commits November 27, 2026 10:20
Read the button layout from GNOME, Cinnamon and MATE (gsettings), KDE
Plasma (kwinrc) and Xfce (xfconf) when the desktop app starts, and show
those buttons in that order on that side. Windows keeps its buttons on the
right and macOS its traffic lights; neither lets people move them.

Lay out the window chrome by side rather than platform, size it by the
number of buttons, and keep narrow toolbars clear of the buttons: the
phone-width bar on the left, and the chat heading at the 900px minimum
window width on the right (also a Windows fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Read GNOME's button-layout only on GNOME, Unity, Budgie and Pantheon: other
desktops often install its schema without setting it, and its default would
leave a single close button. Layer system kwinrc files from XDG_CONFIG_DIRS
under the user's, and build those paths with POSIX separators so the tests
pass on Windows.

Start the backend before waiting for the layout; only the first window
waits. Keep the phone-width bar's own inset beside left-side controls, and
check macOS's traffic-light space in the browser layout check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parse each kwinrc on its own, least important first, so a group from one
file never carries into the next, and apply KConfig's [$i] locks on files,
groups and keys so an administrator's locked layout wins as it does in
KWin. Start the layout lookup only after taking the single-instance lock,
and describe the Linux behavior in the desktop README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Treat [group][subgroup] headers as their own groups and localized keys
such as ButtonsOnLeft[fr] as their own entries, as KConfig does. Give the
whole layout lookup a two-second limit, file reads included, since the
first window waits for it. Check the preload's copy of the argument
prefix, and say in the README that KDE and Xfce fall back to their own
defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stalled or failed lookup on KDE Plasma or Xfce now falls back to that
desktop's own default layout, as the README describes. Ignore relative
XDG directories, skip nameless headers inside a kwinrc, dedupe button
names in the page, and keep the test machine's system kwinrc out of the
Linux smoke test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant