Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable Windows Control Overlay on Linux #41769

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Apr 3, 2024

Description of Change

Closes #23665.

This PR enables the Windows Control Overlay API on Linux. To do so, we create a new subclass of FramelessView. This primarily follows logic from upstream's implementation with modifications for our use case and stripped of logic irrelevant to Electron.

cc @bpasero @deepak1556

Todo:

  • Ensure existing WCO tests pass
  • Test with RTL and LTR
  • Test that color can be changed dynamically
  • Test that height can be changed dynamically

Functionality on Wayland will be approached as a follow-up as I don't currently have the requisite hardware to test this.

WCO RTL

Screenshot 2024-04-03 at 9 28 20 PM

WCO LTR

Screenshot 2024-04-03 at 9 29 06 PM

Dynamic WCO Update

Gif Demonstration with the following code:

const { app, BrowserWindow } = require('electron');

async function createWindow () {
  const mainWindow = new BrowserWindow({
    titleBarOverlay: {
      color: '#0000f0',
      symbolColor: '#f54260'
    },
    titleBarStyle: 'hidden'
  });

  await mainWindow.loadURL('data:text/html,<h1>Hello, World!</h1>');

  setTimeout(() => {
    console.log('Setting title bar overlay color!!!');
    mainWindow.setTitleBarOverlay({
      color: '#355E3B',
      symbolColor: '#99aebd',
      height: 40
    });
  }, 3000);
}

app.whenReady().then(() => {
  createWindow();

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit();
});

wco-update-linux

Checklist

Release Notes

Notes: Enabled the Windows Control Overlay API on Linux.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 3, 2024
@codebytere codebytere force-pushed the wco-linux branch 5 times, most recently from 7170094 to 8d1d279 Compare April 4, 2024 10:34
@codebytere codebytere added semver/minor backwards-compatible functionality target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. target/30-x-y PR should also be added to the "30-x-y" branch. labels Apr 4, 2024
@codebytere codebytere marked this pull request as ready for review April 4, 2024 15:19
Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

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

API LGTM

docs/api/structures/base-window-options.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

API LGTM

@deepak1556
Copy link
Member

Sorry for the delay here, need some time to verify the changes. I will have an update later this week.

@github-actions github-actions bot added the target/31-x-y PR should also be added to the "31-x-y" branch. label Apr 17, 2024
@ckerr
Copy link
Member

ckerr commented Apr 24, 2024

API LGTM

Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Works great, left feedback on the frame border.

// px on each side regardless of the system window border size. This is
// overridable by subclasses, so RestoredFrameBorderInsets() should be used
// instead of using this constant directly.
static constexpr int kFrameBorderThickness = 4;
Copy link
Member

Choose a reason for hiding this comment

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

This causes a think frame border for resizing outside the client area in window restored mode, also this seems chrome UI specific. Can we remove it ?

@deepak1556
Copy link
Member

deepak1556 commented Apr 24, 2024

There is also the issue with theme adjustment with the current implementation,

native titlebar:
Screenshot 2024-04-24 at 17 21 22

custom titlebar:

Screenshot 2024-04-24 at 17 21 35

I believe the issue arises from the class used to draw the caption buttons //ui/views/window/frame_caption_button.h which does not use any gtk api but rather has a generic Chrome specific implementation. On the other hand, ClientFrameViewLinux used for wayland CSD, relies on //ui/gtk/nav_button_provider_gtk which seems to work well across different themes. Is there a reason we cannot reuse ClientFrameViewLinux to support WCO on x11 ?

@ruihe774 since you have been working on this support for wayland, do you have thoughts on the above ? My question is mainly if the window caption container code can be shared between wayland and x11.

@ruihe774
Copy link

@ruihe774 since you have been working on this support for wayland, do you have thoughts on the above ? My question is mainly if the window caption container code can be shared between wayland and x11.

Yes. I've also used ClientFrameViewLinux to implement WCO for x11 in 426f5e1. The title of my PR has not updated yet, which is misleading. Sorry for that.

@deepak1556
Copy link
Member

Missed that, thanks for clarifying! If that works well for both x11 and wayland then seems like a better route. @codebytere thoughts ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review/approved ✅ semver/minor backwards-compatible functionality target/28-x-y PR should also be added to the "28-x-y" branch. target/29-x-y PR should also be added to the "29-x-y" branch. target/30-x-y PR should also be added to the "30-x-y" branch. target/31-x-y PR should also be added to the "31-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embed window controls ( - + x ) / traffic lights in the app when running on Linux
6 participants