Skip to content

refactor: rebase Linux frame view classes on FrameViewLinux - #50707

Closed
aiddya wants to merge 3 commits into
electron:mainfrom
aiddya:fvl-refactor
Closed

aiddya wants to merge 3 commits into
electron:mainfrom
aiddya:fvl-refactor

Conversation

@aiddya

@aiddya aiddya commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Description of Change

This is a PR demonstrating that ClientFrameViewLinux and OpaqueFrameView can be rebased on top of two new proposed classes in Chromium: FrameViewLinux and NativeFrameViewLinux. This change is not meant to land as it is, its only purpose is to seek feedback.

ClientFrameViewLinux has been entirely replaced by a thin wrapper over NativeFrameViewLinux to integrate with Electron. OpaqueFrameView has been rebased on FrameViewLinux as ElectronFrameViewLinux. I chose to rename this class as it handles transparent windows too. ElectronFrameViewLinux handles drawing while ElectronFrameViewLayoutLinux handles layout decisions for frameless (with or without shadow, with or without WCO) and transparent modes. As the base FrameViewLinux class respects user preferences on window controls, ElectronFrameViewLinux has been changed to match. WCO can now show user-configured buttons in either all-trailing, all-leading or a mix of leading and trailing order.

Instead of drawing an inside resize border for frameless without shadow mode, we instead set shadow to none and let the frame border insets collapse to the resize band. This ensures consistent resize behavior across modes, which is a 10 px band all around the client/frame area. It also allows us to do neat things like runtime toggling of shadows, which has now been implemented on Linux.

Checklist

Release Notes

Notes: none

@aiddya
aiddya requested a review from a team as a code owner April 6, 2026 04:51
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 6, 2026
@aiddya
aiddya marked this pull request as draft April 6, 2026 04:51
@aiddya

aiddya commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

@mitchchn Here's the refactor PR.

@mitchchn

mitchchn commented Apr 6, 2026

Copy link
Copy Markdown
Member

@aiddya thank you so much for this, it definitely looks like the right direction and I'm going to test to help inform the Chromium changes.

One question I have right away: would it be easy to support rounded corners (on all four edges, not just the top) in ElectronFrameViewLinux? I have a branch to add them to OpaqueFrameView but it could benefit from upstream flexibility.

@aiddya

aiddya commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor Author

It should be easy on the frame side, once I make a small change in FrameViewLinux. I need to make GetRestoredClipRegion() virtual so that ElectronFrameViewLinux can override it with rounded corners on all four sides. I have no idea what it'd take to round the client view, but that's unrelated to these changes.

Edit: On second thought, having GetCornerRadius() return a gfx::RoundedCornersF would be cleaner. I can make this change in the CL.

@mitchchn

mitchchn commented Apr 7, 2026

Copy link
Copy Markdown
Member

The client view can be masked by setting it to transparent and then designating an opaque region using the same corner values, but yeah, that will happen in the tree host, not the frame. As long as the frame can round the edges and shadows to a provided arbitrary radius that’s fine.

@aiddya

aiddya commented Apr 7, 2026

Copy link
Copy Markdown
Contributor Author

I've updated the CLs and this PR. You should be able to modify ElectronFrameViewLayoutLinux::GetCornerRadii() to any arbitrary radii.

@mitchchn

mitchchn commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

@aiddya works well with client view clipping but I'll save that for a follow-up ;)

image

@mitchchn

mitchchn commented Apr 9, 2026

Copy link
Copy Markdown
Member

@aiddya this branch already passes all but 2 tests in the BrowserWindow test spec, both to do with WCO:

Failure in test: "BrowserWindow module "titleBarStyle" option sets Window Control Overlay with hidden title bar"
AssertionError: expected 10 to equal +0
    at testWindowsOverlay (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3360:32)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3404:7)
Retrying test (1/3)...
Failure in test: "BrowserWindow module "titleBarStyle" option sets Window Control Overlay with hidden title bar"
AssertionError: expected 10 to equal +0
    at testWindowsOverlay (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3360:32)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3404:7)
Retrying test (2/3)...
Failure in test: "BrowserWindow module "titleBarStyle" option sets Window Control Overlay with hidden title bar"
AssertionError: expected 10 to equal +0
    at testWindowsOverlay (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3360:32)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3404:7)
Retrying test (3/3)...
not ok 259 BrowserWindow module "titleBarStyle" option sets Window Control Overlay with hidden title bar
  expected 10 to equal +0
  AssertionError: expected 10 to equal +0
      at testWindowsOverlay (electron/spec/api-browser-window-spec.ts:3360:32)
      at Context.<anonymous> (electron/spec/api-browser-window-spec.ts:3404:7)
ok 260 BrowserWindow module "titleBarStyle" option sets Window Control Overlay with hidden inset title bar # SKIP -
ok 261 BrowserWindow module "titleBarStyle" option when an invalid titleBarStyle is initially set does not crash changing minimizability 
ok 262 BrowserWindow module "titleBarStyle" option when an invalid titleBarStyle is initially set does not crash changing maximizability
Failure in test: "BrowserWindow module "titleBarOverlay" option sets Window Control Overlay with title bar height of 40"
AssertionError: expected 10 to equal +0
    at testWindowsOverlayHeight (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3477:38)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3507:7)
Retrying test (1/3)...
Failure in test: "BrowserWindow module "titleBarOverlay" option sets Window Control Overlay with title bar height of 40"
AssertionError: expected 10 to equal +0
    at testWindowsOverlayHeight (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3477:38)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3507:7)
Retrying test (2/3)...
Failure in test: "BrowserWindow module "titleBarOverlay" option sets Window Control Overlay with title bar height of 40"
AssertionError: expected 10 to equal +0
    at testWindowsOverlayHeight (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3477:38)
    at Context.<anonymous> (/run/host/home/mitch/data/Projects/electron/src/electron/spec/api-browser-window-spec.ts:3507:7)
Retrying test (3/3)...
not ok 263 BrowserWindow module "titleBarOverlay" option sets Window Control Overlay with title bar height of 40
  expected 10 to equal +0
  AssertionError: expected 10 to equal +0
      at testWindowsOverlayHeight (electron/spec/api-browser-window-spec.ts:3477:38)
      at Context.<anonymous> (electron/spec/api-browser-window-spec.ts:3507:7)

@aiddya

aiddya commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Great, I'll look into the two remaining failures.

trailing_button_container_ =
AddChildView(std::make_unique<CaptionButtonPlaceholderContainer>());

FrameViewLinux::CreateCaptionButtons();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about WCO: someday Electron (and maybe Chromium?) may want to draw native-looking buttons for WCO, e.g. using icons from GTK/Qt but without the full titlebar (similar to how WCO works on macOS and Windows). I guess if Electron wanted to experiment with this it would just override this method?

@aiddya aiddya Apr 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd depend on what the goal is. If the goal is support the full customization possibilities such as control over the icon color, background color, etc., then you'd have to duplicate or patch NavButtonProviderGtk to override icon colors to match the parameters from WCO.

If the goal is to go macOS route of only drawing the icons with a transparent background, you can reuse NavButtonProviderGtk as-is. However, you'd have to contend with contrast issues as the icons may not always have sufficient contrast unlike macOS traffic lights.

After that point, it's just a matter of overriding this to create image buttons and Layout to use views::MaybeUpdateCachedFrameButtonImages, same as NativeFrameViewLinux.

bg_color = obc;
}
leading_button_container_->SetBackground(
views::CreateSolidBackground(bg_color));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a transparent container possible to support if the user sets the color using RGBA? (it works on Windows and helps with frameless views that change color, e.g. dimming when they show modals.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should be possible. We'd need to have a different way of communicating transparency and default value like optionals.

aiddya added 3 commits April 11, 2026 14:25
Replace ClientFrameViewLinux with electron::NativeFrameViewLinux, a thin
wrapper over the views::NativeFrameViewLinux base class. The wrapper
provides Electron integration, such as draggable region support in
NonClientHitTest and the window title updates.

ElectronDesktopWindowTreeHostLinux and NativeWindowViews now use
FrameViewLinux to query frame geometry and update window states in
addition to LinuxFrameLayout.

Assisted-By: Claude Opus 4.6, Claude Code
Replace OpaqueFrameView with ElectronFrameViewLinux, rebased on the new
Chromium FrameViewLinux base class. This orphans LinuxFrameLayout, which
is now removed. ElectronDesktopWindowTreeHostLinux now invokes
FrameViewLinux methods on window changes like transparency and shadows.

ElectronFrameViewLayoutLinux extends FrameViewLayoutLinux to handle
three modes: shadow-only, WCO, and transparent. It overrides frame
geometry methods from the base class for these modes and adds a few new
ones for WCO.

Assisted-By: Claude Opus 4.6, Claude Code
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Apr 13, 2026
@mitchchn mitchchn mentioned this pull request Apr 16, 2026
4 of 7 tasks
@mitchchn

Copy link
Copy Markdown
Member

@aiddya What are the next steps now that the upstream code is merged?

@aiddya

aiddya commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #51160 and #51161

@aiddya aiddya closed this Apr 20, 2026
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.

2 participants