[PR #4577] [CLOSED] Draw top border ourselves to remove white borders on the window #25842

Open
opened 2026-01-31 09:12:11 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/4577
Author: @beviu
Created: 2/13/2020
Status: ❌ Closed

Base: master ← Head: custom-top-border


📝 Commits (10+)

📊 Changes

7 files changed (+328 additions, -121 deletions)

View changed files

➕ src/cascadia/WindowsTerminal/NativeFrameColor.cpp (+114 -0)
➕ src/cascadia/WindowsTerminal/NativeFrameColor.h (+31 -0)
📝 src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp (+115 -113)
📝 src/cascadia/WindowsTerminal/NonClientIslandWindow.h (+16 -8)
➕ src/cascadia/WindowsTerminal/SolidBrushCache.cpp (+24 -0)
➕ src/cascadia/WindowsTerminal/SolidBrushCache.h (+24 -0)
📝 src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj (+4 -0)

📄 Description

Summary of the Pull Request

Previously we used DwmExtendFrameIntoClientArea to let DWM draw the native top frame border behind our custom title bar. But calling this makes the window border white (I don't know why). So instead now, we just stop using DwmExtendFrameIntoClientArea and try to draw the border like DWM ourselves (see https://github.com/microsoft/terminal/issues/3425#issuecomment-558943616).

I took the code from Chromium to get the correct border color:
af5c81b48f/chrome/browser/themes/theme_service_win.cc (L193)

Issue: When this setting is disabled:
image
The result is not perfect because then the border should be transparent and I don't know how to make it transparent.
So it will look the same on a white background than on a black background and that means that depending the background behind the window, the top border can look slightly off, especially when the custom tab color PR get merged and the title bar's color can be changed.

This is a temporary solution to the white border problem.

I'm sorry if I explain this badly. If you don't understand a part, make sure to let me know and I will explain it better.

References

PR Checklist

  • Closes a part of #3425 (the "Terminal has white borders in dark mode" part, but not the "Update ThemeUtils::SetWindowFrameDarkMode to use new DWM API" part)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

In the issue liked above (#3425) there were two ideas to solve the problem:

Imitation of the system top border (this PR, https://github.com/microsoft/terminal/issues/3425#issuecomment-558943616):

  • Done by Chromium and it looks like also Firefox and the thing that powers UWP apps (because they are affected by the same weird bugs, see below)
  • Not perfect in this PR (see PR description)
  • Must be updated if an OS update changes the behavior (like 1809 which removed accented borders when "Title bars and window borders" is disabled)
  • No one seems to do it correctly when the accent color setting is disabled
    • Chrome (continues to paint the top border with the accent color even when the setting is disabled): Chrome
    • Firefox (no transparency, wrong color): image
    • UWP apps, the best imitation (have transparency ✔️ but the color isn't the exact same, really hard to notice):
      UWP apps
  • BTW, weird bugs start happening once you starting switching between light/dark mode (I'm running 1903)
    • Settings app: UWP Settings
    • Firefox: Firefox
  • But you have to be looking really hard to notice any difference

DwmExtendFrameIntoClientArea + DWM API to force dark border (the original idea in the title of the issue):

  • Makes sure that all of the borders are consistent at least
  • Solution used by explorer.exe (I think) when dark mode is enabled to not have a white border across the window like we have now
  • Unofficial API = might break = must be updated if the API changes

Validation Steps Performed

I launched the app with dark/light and accent color enabled/disabled combinations.

But I had a bug where Windows would put a white border on every window after I switch from dark to white mode so every app including the Terminal was bugged until the next sign out. I will test it again better later, by signing out every time to "reset" that bug (to do). EDIT: done.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/4577 **Author:** [@beviu](https://github.com/beviu) **Created:** 2/13/2020 **Status:** ❌ Closed **Base:** `master` ← **Head:** `custom-top-border` --- ### 📝 Commits (10+) - [`2f964ea`](https://github.com/microsoft/terminal/commit/2f964ead741d6b30cc2550ba45e6a56778b56959) Draw the top frame border ourselves - [`07a3bce`](https://github.com/microsoft/terminal/commit/07a3bcef784a77b2f0dc96f38a2fdb714637250c) Refactor GDI brushes into GdiSolidBrush - [`c9e8acb`](https://github.com/microsoft/terminal/commit/c9e8acba19825884e74695bd75489ef6febd8cb1) Remove dead code - [`5ca4ae0`](https://github.com/microsoft/terminal/commit/5ca4ae012688688c670788ee5d3c86798243a833) Fix top border when holding left button on title bar without moving - [`830a8bc`](https://github.com/microsoft/terminal/commit/830a8bcc727e1cba315d9550d1f48144c9764fee) Merge branch 'master' of https://github.com/microsoft/terminal into custom-top-border - [`09bcdb2`](https://github.com/microsoft/terminal/commit/09bcdb271452d80cdd2b0e374027a210233a25f2) Format & GH issue - [`b9b292c`](https://github.com/microsoft/terminal/commit/b9b292c13f8570461eb9259739557a15b512df14) Add different top border colors for light mode - [`4ad09a7`](https://github.com/microsoft/terminal/commit/4ad09a7e0b6a1d487c86b03ffd54f5ff301b50e4) Merge branch 'master' of https://github.com/microsoft/terminal into custom-top-border - [`3eb4c22`](https://github.com/microsoft/terminal/commit/3eb4c22cf0f858af16eecb0895965865e8c5f1b4) Remove top border update lag when window active -> inactive - [`6584fac`](https://github.com/microsoft/terminal/commit/6584fac80337fbd5c94860337b0f0e5ee4c9e7e4) Change size of top border depending on DPI setting ### 📊 Changes **7 files changed** (+328 additions, -121 deletions) <details> <summary>View changed files</summary> ➕ `src/cascadia/WindowsTerminal/NativeFrameColor.cpp` (+114 -0) ➕ `src/cascadia/WindowsTerminal/NativeFrameColor.h` (+31 -0) 📝 `src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp` (+115 -113) 📝 `src/cascadia/WindowsTerminal/NonClientIslandWindow.h` (+16 -8) ➕ `src/cascadia/WindowsTerminal/SolidBrushCache.cpp` (+24 -0) ➕ `src/cascadia/WindowsTerminal/SolidBrushCache.h` (+24 -0) 📝 `src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj` (+4 -0) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Previously we used `DwmExtendFrameIntoClientArea` to let DWM draw the native top frame border behind our custom title bar. But calling this makes the window border white (I don't know why). So instead now, we just stop using `DwmExtendFrameIntoClientArea` and try to draw the border like DWM ourselves (see https://github.com/microsoft/terminal/issues/3425#issuecomment-558943616). I took the code from Chromium to get the correct border color: https://github.com/chromium/chromium/blob/af5c81b48faf773c19b7f3c495a1c0202f9c5b00/chrome/browser/themes/theme_service_win.cc#L193 **Issue:** When this setting is disabled: ![image](https://user-images.githubusercontent.com/56923875/74485466-1b2ce780-4ebb-11ea-8edf-f630c4e50060.png) The result is not perfect because then the border should be transparent and I don't know how to make it transparent. So it will look the same on a white background than on a black background and that means that depending the background behind the window, the top border can look slightly off, especially when the custom tab color PR get merged and the title bar's color can be changed. **This is a temporary solution to the white border problem.** I'm sorry if I explain this badly. If you don't understand a part, make sure to let me know and I will explain it better. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes a part of #3425 (the "Terminal has white borders in dark mode" part, but not the "Update ThemeUtils::SetWindowFrameDarkMode to use new DWM API" part) * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments In the issue liked above (#3425) there were two ideas to solve the problem: **Imitation of the system top border (this PR, https://github.com/microsoft/terminal/issues/3425#issuecomment-558943616):** - Done by Chromium and it looks like also Firefox and the thing that powers UWP apps (because they are affected by the same weird bugs, see below) - Not perfect in this PR (see PR description) - Must be updated if an OS update changes the behavior (like 1809 which removed accented borders when "Title bars and window borders" is disabled) - No one seems to do it correctly when the accent color setting is disabled - Chrome (continues to paint the top border with the accent color even when the setting is disabled): ![Chrome](https://user-images.githubusercontent.com/56923875/74543318-76a3b780-4f45-11ea-9fc6-d92b897ca197.png) - Firefox (no transparency, wrong color): ![image](https://user-images.githubusercontent.com/56923875/74544965-56c1c300-4f48-11ea-8d71-2c3166c9bd33.png) - UWP apps, the best imitation (have transparency ✔️ but the color isn't the exact same, really hard to notice): ![UWP apps](https://user-images.githubusercontent.com/56923875/74544728-ea46c400-4f47-11ea-8da7-973955451e94.png) - BTW, weird bugs start happening once you starting switching between light/dark mode (I'm running 1903) - Settings app: ![UWP Settings](https://user-images.githubusercontent.com/56923875/74543007-ee251700-4f44-11ea-888d-2de0bbc87ff3.png) - Firefox: ![Firefox](https://user-images.githubusercontent.com/56923875/74543601-f03ba580-4f45-11ea-897e-f1f190af4b88.png) - But you have to be looking really hard to notice any difference **`DwmExtendFrameIntoClientArea` + DWM API to force dark border (the original idea in the title of the issue):** - Makes sure that all of the borders are consistent at least - Solution used by explorer.exe (I think) when dark mode is enabled to not have a white border across the window like we have now - Unofficial API = might break = must be updated if the API changes <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed I launched the app with dark/light and accent color enabled/disabled combinations. But I had a bug where Windows would put a white border on every window after I switch from dark to white mode so every app including the Terminal was bugged until the next sign out. I will test it again better later, by signing out every time to "reset" that bug (to do). **EDIT:** done. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:12:11 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#25842