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: add window shadow for frameless window on Wayland and WCO on Linux #41840

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

Conversation

ruihe774
Copy link

Description of Change

This PR fixes #39664.

To reproduce, create a BrowserWindow with frame: false, and pass --ozone-platform=wayland as a commandline argument.

Before

image

After

image

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes

Release Notes

Notes: Fixed drop shadow for frameless window on Wayland.

Copy link

welcome bot commented Apr 12, 2024

💖 Thanks for opening this pull request! 💖

We use semantic commit messages to streamline the release process. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix.

Examples of commit messages with semantic prefixes:

  • fix: don't overwrite prevent_default if default wasn't prevented
  • feat: add app.isPackaged() method
  • docs: app.isDefaultProtocolClient is now available on Linux

Things that will help get your PR across the finish line:

  • Follow the JavaScript, C++, and Python coding style.
  • Run npm run lint locally to catch formatting errors earlier.
  • Document any user-facing changes you've made following the documentation styleguide.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Apr 12, 2024
@ruihe774 ruihe774 force-pushed the wayland-shadow branch 3 times, most recently from f284719 to 9285c84 Compare April 12, 2024 15:02
@ruihe774 ruihe774 requested a review from a team as a code owner April 12, 2024 15:02
@VerteDinde VerteDinde self-requested a review April 12, 2024 17:31
@ruihe774
Copy link
Author

@codebytere Seems this is not very compatible with #41769. How can we handle drop shadow when WCO is enabled?

@ruihe774 ruihe774 force-pushed the wayland-shadow branch 2 times, most recently from c62047b to 5a73bd5 Compare April 13, 2024 11:57
@ruihe774
Copy link
Author

Update: I've added support thickFrame to control whether to show window shadow on Wayland.

@ruihe774 ruihe774 changed the title fix: add drop shadow for frameless window on Wayland feat: add window shadow and WCO for frameless window on Wayland Apr 16, 2024
@ruihe774
Copy link
Author

ruihe774 commented Apr 16, 2024

@codebytere I've added an implementation of GTK native WCO in 6ece5db. Would you plz have a look at it? IMO it looks more integrated with system look & feel.

Screenshot

Screenshot from 2024-04-16 13-25-29

PS: I copied some code from your implementation. Please don't mind that :)

@ruihe774
Copy link
Author

ruihe774 commented Apr 16, 2024

BTW I found hasShadow has no effect on both X11 and Wayland. On main branch, X11 will always show shadow and Wayland will not despite the setting of hasShadow. I'm not sure if GNOME is to blame or it's a regression.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 19, 2024
@VerteDinde
Copy link
Member

@ruihe774 Thanks so much for implementing this, this is amazing work! Could I ask you to rebase this PR against main so we can get the tests running green again? 🙂 We have another PR that is about to land (#41769) - if you wouldn't mind rebasing after that PR lands, that would be great! Also more than happy to work with you to resolve that once it lands.

@ruihe774
Copy link
Author

We have another PR that is about to land (#41769) - if you wouldn't mind rebasing after that PR lands, that would be great!

@VerteDinde As I've pointed out earlier, I'm afraid that these two PRs are not very compatible, in that they are implementing WCO in different ways. I'd like to have a discussion about how we can deal with it, but the OP of that PR has not responded.

@ruihe774 ruihe774 changed the title feat: add window shadow and WCO for frameless window on Wayland feat: add window shadow for frameless window on Wayland and WCO on Linux Apr 24, 2024
@ruihe774
Copy link
Author

Could I ask you to rebase this PR against main so we can get the tests running green again?

I've done rebasing. The build fails for Windows. I'll fix it later.

@codebytere
Copy link
Member

@ruihe774 after some discussion myself and Deepak have come to the tentative conclusion that it's likely more
expedient in the short term to try to land my initial PR for x11. This PR combines two discrete goals:

  1. window shadow for frameless window on Wayland
  2. WCO on Linux

which should be split into two PRs. I understand my PR adds some duplication and extra code, but the longer-term plan would be to combine the two classes where possible. At the moment, the need for this feature outweighs the cost of some medium-term duplication. The other issue is that this class is more than two years old, and is notably lesser tested owing to its being Wayland-only thus far and being an opt-in feature even beyond that. I agree with @deepak1556's comment over on my PR that we should look to DRY out the code, but the severe drift between these changes and upstream leaves me concerned about the ability to accomplish the intended goal of prod use of WCO on linux without potentially introducing a host of new bugs from the drift. We'd like to continue working with you to land this code - in the short term, could you split out the window shadow changes?

@ruihe774
Copy link
Author

ruihe774 commented Apr 26, 2024

@codebytere @deepak1556

its being Wayland-only thus far

Well, ClientFrameView can work on X11, though it is not the default.

accomplish the intended goal of prod use of WCO on linux

I wonder what is the long-term solution to implement WCO: draw by ourselves (what you've implemented), or draw by GTK (my implementation)?

could you split out the window shadow changes?

I'm OK for that. But there's still question: how can I add window shadow to your OpaqueFrameView? Do you want to implement window shadow for OpaqueFrameView yourself? BTW, giving there's no GTK drawing logic in OpaqueFrameView, I think it's hard to implement a consistent window shadow with it.

FWIW, I think we'd better pause the merge of #41769 until we come up with a consensus.

@deepak1556
Copy link
Member

draw by GTK (my implementation)?

I think this what we want for WCO so that controls can adjust properly to the system theme. I guess the question now is the reliability of the implementations,

  • ClientFrameViewLinux which has only been an opt-in on Wayland but uses gtk to draw window controls
  • OpaqueFrameView which is mostly adjusted for Chrome/ChromeOS UI but has been used for X11 quite sometime in upstream. @codebytere how confident are we in removing the Chrome specific changes and have parity with FramelessView + WCO support integrated ?

Would like some more opinion from linux experts /cc @ckerr

@ruihe774
Copy link
Author

FWIW, if WCO drawed by GTK is the ultimate goal, my another concern about #41769 is that after it is merged, the users (I mean, app developers) will get used to the self-drawing WCO, and we may break things when we ultimately switch to GTK-drawing WCO.

To be clear, I'm not against unifying code and OpaqueFrameView. I think a tentative solution is to get OpaqueFrameView merged but disable its WCO support. However, we still need to come up with a way to draw window shadow with OpaqueFrameView.

@aiddya
Copy link
Contributor

aiddya commented Apr 27, 2024

I don't think it's a good idea to use GTK just to draw the window controls. GTK does not offer stable APIs for drawing window frames and controls to external surfaces, so Chromium has to use lots of workarounds to make it happen. ClientFrameViewLinux already breaks quite often between Chromium version upgrades, even though it mostly copies code from Chromium. Chromium itself does not use GTK to draw window controls in WCO mode, so it would require more fragile code to support titleBarOverlay options such as color and symbolColor.

Supporting arbitrary GTK themes is a lot of work even when using GTK directly and GNOME developers have given up on it. When you add in the need to support overriding colors, it would not be worth it anymore. I think the best path forward for a more native look and feel is to pick a particular GTK theme like Adwaita or Yaru and use its window control icons in OpaqueFrameView. This should be much simpler, it's just a matter of converting SVGs to Chromium's custom .icon format and using the new icons in OpaqueFrameView.

OpaqueFrameView is also probably a better foundation to deduplicate the window frame drawing code as OpaqueBrowserFrameView is a common base class in Chromium. Window shadows in borderless mode can be supported the same way as BrowserFrameViewLinux. ClientFrameViewLinux can be refactored to use OpaqueFrameView by following the same pattern as BrowserFrameViewLinuxNative. This should also make it easier to keep ClientFrameViewLinux aligned with upstream.

@ruihe774
Copy link
Author

I don't think it's a good idea to use GTK just to draw the window controls. GTK does not offer stable APIs for drawing window frames and controls to external surfaces, so Chromium has to use lots of workarounds to make it happen.

I shall make it clear that it is not GTK that is actually drawing window frames. The actual stuff behind the scene is that WindowFrameProviderGtk obtains bitmaps from GTK and draw it by itself. Although there are workarounds, it work fine for now.

so it would require more fragile code to support titleBarOverlay options such as color and symbolColor.

Electron on macOS does not support color and symbolColor, either. I don't think it is a thing that needs to be considered for now.

color is the background of WCO, which, on Linux and macOS, are always transparent. App developers can easily put background underneath. This is also what they do on macOS.

Supporting arbitrary GTK themes is a lot of work even when using GTK directly and GNOME developers have given up on it. When you add in the need to support overriding colors, it would not be worth it anymore.

"Supporting arbitrary GTK themes" is not my goal in this PR.

I think the best path forward for a more native look and feel is to pick a particular GTK theme like Adwaita or Yaru and use its window control icons in OpaqueFrameView. This should be much simpler, it's just a matter of converting SVGs to Chromium's custom .icon format and using the new icons in OpaqueFrameView.

I cannot agree with "this should be much simpler". Anyway, this should be done for OpaqueFrameView. Before that, I think the immature implementation of WCO in #41769 should not be shipped.

IMO, I think this is acceptable:

  • Merge OpaqueFrameView, disabling its WCO support.
  • Use my implementation of window shadow in ClientFrameView as a transitional solution.
  • Use my WCO implementation in ClientFrameView as a transitional solution (optional).
  • Implement a self-drawing native look & feel WCO and window shadow in OpaqueFrameView as the long-term solution and switch to it after it is finished.

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.

[Bug]: Frameless windows don't have drop shadow on Wayland
5 participants