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

Automatically enable AdjustIndistinguishableColors if High Contrast mode enabled #17346

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlos-zamora
Copy link
Member

Summary of the Pull Request

If High Contrast mode is enabled in the OS settings, we now automatically enable adjustIndistinguishableColors. To accomplish this, a new AutomaticAlways and AutomaticIndexed value is added to adjustIndistinguishableColors. When these are chosen, color nudging doesn't occur in regular contrast sessions, but we interpret the value as Always and Indexed respectively.

The new default value is AutomaticIndexed. Meaning that regular contrast sessions will see no difference in behavior. However, if they switch to high contrast mode, Windows Terminal will interpret the value as Indexed at runtime. This was chosen because Always is more performance intensive.
  

References and Relevant Issues

#12999

Detailed Description of the Pull Request / Additional comments

The order of events is as follows:

  1. IslandWindow receives a WM_SETTINGCHANGE event where we check if High Contrast mode was enabled
  2. When that's the case, we raise a UpdateSettingsRequested with a bool HighContrast parameter
  3. That parameter is stored in CascadiaSettings as a static bool HighContrast
  4. TerminalPaneContent goes through the UpdateSettings process. However, now we stuff the CascadiaSettings::HighContrastMode value into the TerminalSettings, then tell the control to update its settings
  5. Stuff HighContrastMode in the Terminal object we're updating
  6. When Terminal updates its appearance, we evaluate AutomaticIndexed and AutomaticAlways as non-automatic values, then update the render settings appropriately.

Validation Steps Performed

⚠️ full feature is yet to be tested ⚠️
Individual components have been tested, however, including...

  • Using the WM_SETTINGCHANGE event to get the High Contrast setting value and storing it in CascadiaSettings
  • Evaluating the adjustIndistinguishableColors AutomaticX values as X at runtime

}

bool isCurrentlyHighContrast = []() {
HIGHCONTRAST hc = { 0 };

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

HIGHCONTRAST is not a recognized word. (unrecognized-spelling)

bool isCurrentlyHighContrast = []() {
HIGHCONTRAST hc = { 0 };
hc.cbSize = sizeof(HIGHCONTRAST);

Check failure

Code scanning / check-spelling

Unrecognized Spelling Error

HIGHCONTRAST is not a recognized word. (unrecognized-spelling)
@carlos-zamora
Copy link
Member Author

For the record, AcessibilitySettings didn't work. Wasn't able to get the correct HighContrast value or be notified via HighContrastChanged. So I had to go the WM_SETTINGCHANGE route

https://learn.microsoft.com/en-us/uwp/api/windows.ui.viewmanagement.accessibilitysettings?view=winrt-22621

Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (1)

HIGHCONTRAST

Previously acknowledged words that are now absent CRLFs Redir wcsicmp 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/cazamor/auto-high-contrast branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/9325600191/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (2212) from .github/actions/spelling/expect/04cdb9b77d6827c0202f51acd4205b017015bfff.txt
.github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt and unrecognized words (1)

Dictionary Entries Covers Uniquely
cspell:cpp/src/lang-jargon.txt 11 1 1
cspell:swift/src/swift.txt 53 1 1
cspell:gaming-terms/dict/gaming-terms.txt 59 1 1
cspell:monkeyc/src/monkeyc_keywords.txt 123 1 1
cspell:cryptocurrencies/cryptocurrencies.txt 125 1 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

      with:
        extra_dictionaries:
          cspell:cpp/src/lang-jargon.txt
          cspell:swift/src/swift.txt
          cspell:gaming-terms/dict/gaming-terms.txt
          cspell:monkeyc/src/monkeyc_keywords.txt
          cspell:cryptocurrencies/cryptocurrencies.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/[email protected] in its with:

check_extra_dictionaries: ''
Errors (1)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ ignored-expect-variant 3

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

@carlos-zamora
Copy link
Member Author

Why is this a draft?

Looks like the feature flag stuff decided to fail on me halfway through the implementation (it wasn't failing when I started working on it, and I haven't pulled any new changes).

I'm thinking this might be because AdjustIndistinguishableColors does have a feature flag? Maybe I need to wrap some of my code behind the feature flag? 🤷

Build Output
1>------ Build started: Project: RendererAtlas, Configuration: Debug x64 ------
1>dev/cazamor/auto-high-contrast
1>AtlasEngine.api.cpp
1>AtlasEngine.r.cpp
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.r.cpp(493,19): error C2653: 'Feature_AtlasEnginePresentFallback': is not a class or namespace name
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.r.cpp(493,55): error C3861: 'IsEnabled': identifier not found
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.r.cpp(493,64): error C2131: expression did not evaluate to a constant
1>D:\projects\terminal\src\renderer\base\FontCache.h(20,27): error C2653: 'Feature_NearbyFontLoading': is not a class or namespace name
1>D:\projects\terminal\src\renderer\base\FontCache.h(20,54): error C3861: 'IsEnabled': identifier not found
1>D:\projects\terminal\src\renderer\base\FontCache.h(20,63): error C2131: expression did not evaluate to a constant
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(510,19): error C2653: 'Feature_NearbyFontLoading': is not a class or namespace name
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(510,46): error C3861: 'IsEnabled': identifier not found
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(510,55): error C2131: expression did not evaluate to a constant
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(676,23): error C2653: 'Feature_NearbyFontLoading': is not a class or namespace name
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(676,50): error C3861: 'IsEnabled': identifier not found
1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.api.cpp(676,59): error C2131: expression did not evaluate to a constant
1>Done building project "atlas.vcxproj" -- FAILED.
2>------ Build started: Project: RendererBase, Configuration: Debug x64 ------
2>RenderSettings.cpp
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(178,19): error C2653: 'Feature_AdjustIndistinguishableText': is not a class or namespace name
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(178,56): error C3861: 'IsEnabled': identifier not found
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(178,65): error C2131: expression did not evaluate to a constant
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(242,19): error C2653: 'Feature_AdjustIndistinguishableText': is not a class or namespace name
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(242,56): error C3861: 'IsEnabled': identifier not found
2>D:\projects\terminal\src\renderer\base\RenderSettings.cpp(242,65): error C2131: expression did not evaluate to a constant
2>Done building project "base.vcxproj" -- FAILED.
3>------ Build started: Project: TerminalInput, Configuration: Debug x64 ------
3>terminalInput.cpp
3>D:\projects\terminal\src\terminal\input\terminalInput.cpp(441,13): error C2653: 'Feature_KeypadModeEnabled': is not a class or namespace name
3>D:\projects\terminal\src\terminal\input\terminalInput.cpp(441,40): error C3861: 'IsEnabled': identifier not found
3>D:\projects\terminal\src\terminal\input\terminalInput.cpp(493,13): error C2653: 'Feature_KeypadModeEnabled': is not a class or namespace name
3>D:\projects\terminal\src\terminal\input\terminalInput.cpp(493,40): error C3861: 'IsEnabled': identifier not found
3>Done building project "terminalinput.vcxproj" -- FAILED.
4>------ Build started: Project: TerminalAdapter, Configuration: Debug x64 ------
4>adaptDispatch.cpp
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(1362,19): error C2653: 'Feature_VtChecksumReport': is not a class or namespace name
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(1362,45): error C3861: 'IsEnabled': identifier not found
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(1362,54): error C2131: expression did not evaluate to a constant
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3769,20): error C2653: 'Feature_ScrollbarMarks': is not a class or namespace name
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3769,44): error C3861: 'IsEnabled': identifier not found
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3769,53): error C2131: expression did not evaluate to a constant
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3813,20): error C2653: 'Feature_ScrollbarMarks': is not a class or namespace name
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3813,44): error C3861: 'IsEnabled': identifier not found
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3813,53): error C2131: expression did not evaluate to a constant
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3904,20): error C2653: 'Feature_ShellCompletions': is not a class or namespace name
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3904,46): error C3861: 'IsEnabled': identifier not found
4>D:\projects\terminal\src\terminal\adapter\adaptDispatch.cpp(3904,55): error C2131: expression did not evaluate to a constant
4>Done building project "adapter.vcxproj" -- FAILED.

@lhecker
Copy link
Member

lhecker commented May 31, 2024

1>D:\projects\terminal\src\renderer\atlas\AtlasEngine.r.cpp(493,19): error C2653: 'Feature_AtlasEnginePresentFallback': is not a class or namespace name

Hmm that's odd. Your PR doesn't touch anything like that. You may have to just do a good 'ol git clean -xfd and recompile from scratch, or maybe it's already sufficient to just build-clean the entire solution.

src/cascadia/WindowsTerminal/IslandWindow.cpp Show resolved Hide resolved

if (updateSettings)
{
UpdateSettingsRequested.raise(_currentHighContrastModeState);
Copy link
Member

Choose a reason for hiding this comment

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

Why does the IslandWindow of all things need to remember whether we were in dark mode or not? Also, why does it result in ReloadSettings when none of the settings changed? An alternative idea:

  • Add a bool CascadiaSettings::ReloadingSystemConfig() function (or similar).
    • It reads the dark-mode-ness and the high-contrast-ness of the OS.
    • It caches the 2 results inside (for instance) GlobalAppSettings.
    • If checks if either of 2 have changed and returns true if they did, false otherwise.
    • The cached values replace any use of IsSystemInDarkTheme() inside the settings code (currently in 2 locations).
  • Add an alternative to ReloadSettings(), e.g. ReloadingSystemConfigRelatedSettings() (lol) and call that in WindowEmperor::_windowRequestUpdateSettings().
  • In ReloadingSystemConfigRelatedSettings() call _settings.ReloadingSystemConfig() and check if it returned true. If it did: Raise a SettingsChanged event, just like we do in ReloadSettings.

@DHowett
Copy link
Member

DHowett commented Jun 5, 2024

I think @PankajBhojwani has some research on this with JTippet

@PankajBhojwani
Copy link
Contributor

I wonder if we also want to increase the delta e threshold we use when we detect high contrast mode! That was what we discussed with Jeffrey Tippet (3 years ago at this point wow), his response was along the lines of "that makes sense, though know that this isn't the way win32 apps work". I think how color nudging should work with HC is something that likely needs more discussion/potentially a spec, but automatically turning on the feature when in HC mode makes sense as a start.

@carlos-zamora
Copy link
Member Author

Ah, sounds like you're talking about this. 😏

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.

4 participants