Repository: microsoft/terminal (language: cpp)

Issue:
How can I prevent Windows Terminal Preview getting brighter when I click on it?  
Currently:

- when I click OFF Windows Terminal Preview, it gets darker  
- when I click ON Windows Terminal Preview, it gets brighter

I like the darker color.  

How can I prevent Windows Terminal Preview getting brighter when I click on it?  

I use Git Bash for all my panes.  

I have tried playing around with setting at:

Settings > Git Bash > Appearance > 'Unfocused Appearance'

But that doesn't seem to get me where I want to go.  

I suppose because I want to control the 'Focussed' appearance, and not the 'Unfocussed' appearance.  








Discussion / hints:
Could you share your [settings.json file](https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ)#where-can-i-find-the-settings-file)?

It sounds like you've got acrylic enabled for your settings, so when you focus the Terminal, it goes from "acrylic disabled" -> "acrylic enabled", which is giving the appearance that the background is getting lighter. 
i just checked and don't have:

- `Unfocussed Appearance` properties defined for `Git Bash` or `Default` profiles 
- `Acrylic` enabled for `Git Bash` or `Default` profiles  

Here is contents of `state.json`:  
```js
{
	"generatedProfiles" : 
	[
		"{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
		"{3ba66c68-babf-5432-84e4-b0550d2b2360}",
		"{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}"
	],
	"persistedWindowLayouts" : 
	[
		{
			"initialPosition" : "-1919,0",
			"initialSize" : 
			{
				"height" : 958.0,
				"width" : 1916.0
			},
			"tabLayout" : 
			[
				{
					"action" : "newTab",
					"commandline" : "C:/Program Files/Git/bin/bash.exe -i -l",
					"profile" : "Git Bash",
					"startingDirectory" : "D:\\REPOS",
					"suppressApplicationTitle" : false,
					"tabTitle" : "Git Bash"
				},
				{
					"action" : "splitPane",
					"commandline" : "C:/Program Files/Git/bin/bash.exe -i -l",
					"profile" : "Git Bash",
					"size" : 0.75000005960464478,
					"split" : "right",
					"splitMode" : "manual",
					"startingDirectory" : "D:\\REPOS",
					"suppressApplicationTitle" : false,
					"tabTitle" : "Git Bash"
				},
				{
					"action" : "splitPane",
					"commandline" : "C:/Program Files/Git/bin/bash.exe -i -l",
					"profile" : "Git Bash",
					"size" : 0.34999996423721313,
					"split" : "down",
					"splitMode" : "manual",
					"startingDirectory" : "D:\\REPOS",
					"suppressApplicationTitle" : false,
					"tabTitle" : "Git Bash"
				},
				{
					"action" : "focusPane",
					"id" : 1
				},
				{
					"action" : "openSettings",
					"target" : "settingsUI"
				}
			]
		}
	]
}
```

Here is contents of `settings.json`:  
```js
{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": 
    [
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        {
            "command": "find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        }
    ],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
    "firstWindowPreference": "persistedWindowLayout",
    "profiles": 
    {
        "defaults": 
        {
            "startingDirectory": "D:\\REPOS"
        },
        "list": 
        [
            {
                "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "commandline": "%SystemRoot%\\System32\\cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "Command Prompt"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{3ba66c68-babf-5432-84e4-b0550d2b2360}",
                "hidden": false,
                "name": "Developer Command Prompt for VS 2017",
                "source": "Windows.Terminal.VisualStudio"
            },
            {
                "adjustIndistinguishableColors": false,
                "backgroundImage": "C:\\Users\\My-Name\\Documents\\some_image.jpg",
                "backgroundImageOpacity": 0.5,
                "colorScheme": "Tango Dark",
                "cursorShape": "vintage",
                "experimental.retroTerminalEffect": true,
                "font": 
                {
                    "size": 16
                },
                "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
                "hidden": false,
                "name": "Git Bash",
                "opacity": 25,
                "padding": "15",
                "source": "Git",
                "startingDirectory": "D:\\REPOS"
            }
        ]
    },
    "schemes": 
    [
        {
            "background": "#0C0C0C",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#012456",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell Powershell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#282C34",
            "black": "#282C34",
            "blue": "#61AFEF",
            "brightBlack": "#5A6374",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B6C2",
            "brightGreen": "#98C379",
            "brightPurple": "#C678DD",
            "brightRed": "#E06C75",
            "brightWhite": "#DCDFE4",
            "brightYellow": "#E5C07B",
            "cursorColor": "#FFFFFF",
            "cyan": "#56B6C2",
            "foreground": "#DCDFE4",
            "green": "#98C379",
            "name": "One Half Dark",
            "purple": "#C678DD",
            "red": "#E06C75",
            "selectionBackground": "#FFFFFF",
            "white": "#DCDFE4",
            "yellow": "#E5C07B"
        },
        {
            "background": "#FAFAFA",
            "black": "#383A42",
            "blue": "#0184BC",
            "brightBlack": "#4F525D",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B5C1",
            "brightGreen": "#98C379",
            "brightPurple": "#C577DD",
            "brightRed": "#DF6C75",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#E4C07A",
            "cursorColor": "#4F525D",
            "cyan": "#0997B3",
            "foreground": "#383A42",
            "green": "#50A14F",
            "name": "One Half Light",
            "purple": "#A626A4",
            "red": "#E45649",
            "selectionBackground": "#FFFFFF",
            "white": "#FAFAFA",
            "yellow": "#C18301"
        },
        {
            "background": "#002B36",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#FFFFFF",
            "cyan": "#2AA198",
            "foreground": "#839496",
            "green": "#859900",
            "name": "Solarized Dark",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#FDF6E3",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#002B36",
            "cyan": "#2AA198",
            "foreground": "#657B83",
            "green": "#859900",
            "name": "Solarized Light",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#FFFFFF",
            "cyan": "#06989A",
            "foreground": "#D3D7CF",
            "green": "#4E9A06",
            "name": "Tango Dark",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#FFFFFF",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#000000",
            "cyan": "#06989A",
            "foreground": "#555753",
            "green": "#4E9A06",
            "name": "Tango Light",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#000080",
            "brightBlack": "#808080",
            "brightBlue": "#0000FF",
            "brightCyan": "#00FFFF",
            "brightGreen": "#00FF00",
            "brightPurple": "#FF00FF",
            "brightRed": "#FF0000",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FFFF00",
            "cursorColor": "#FFFFFF",
            "cyan": "#008080",
            "foreground": "#C0C0C0",
            "green": "#008000",
            "name": "Vintage",
            "purple": "#800080",
            "red": "#800000",
            "selectionBackground": "#FFFFFF",
            "white": "#C0C0C0",
            "yellow": "#808000"
        }
    ]
}
```

Oh you know, I bet I know what's going on here. Are you on Windows 10, and running Terminal Preview, 1.12?

Unblurred opacity only works on windows 11, but if you set `opacity` to any profile, we just turn on acrylic on your behalf (to try and support some sort of opacity on windows 10)
I have half another fear - I think we automatically had `acrylicOpacity` defaulted to .5 before, but it did nothing for users who didn't enable `useAcrylic`. But now that actually _will_ do something, because it'll get read as `oapcity=.5` which we'll then use to fall back to acrylic. 

We may want to take out the "fall back to acrylic on Windows 10" logic. 

Even more scary - when we do fix the issues with unblurred transparency on Windows 10, there's a chance that the transparency might be on for users with fresh settings. I'm not sure about this last part, haven't really looked too carefully. But we might want to make **sure** that the userDefaults, when round-tripped, don't accidentally enable transparency for folks.  
Yes, confirming:

Windows 10
Windows Terminal Preview Version: 1.12.2931.0

I currently have:

- Background Image Opacity at 50%  
- Transparency (with subtitle 'Background opacity') at 25%  

(I am not quite sure of the difference between "background image opacity" and "transparency (background opacity)")  

For reference, I am looking at these:

https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-appearance#background-image-opacity

https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-appearance#transparency  


EVEN MORE SCARY

I booted up a Windows 10 VM with the `1.13.3211` build and weirdly enough it didn't fall back to acrylic, but it did use 50% opacity. So we've got an issue here. 
![gh-11743-1 13-is-weird-004](https://user-images.githubusercontent.com/534075/151058406-90601297-718a-4085-bd35-c61459ef76bd.gif)

This might have just been fixed by accident in 1.13. That being said, we should probably figure out why, to make sure it's fixed for 1.12 stable
Or, is it working by design on 1.12 and not on 1.13?

On Windows 10, if you've got an opacity set, then we need to use acrylic to enable the opacity. So that would actually imply the "brighten when focused" is expected. The Terminal would gain focus and enable the acrylic layer, causing the apparent change in lightness.

Man this would be way easier if we knew when the transparency fix was coming to Windows 10, so we could stop playing these silly games....

<hr>

That's definitely it, or at least something. On Windows 10, we're not falling back to acrylic when opacity is below 100%. I'd bet on #12092 or more likely #11619

<hr> 

Lawd this code has never not been a disaster.

`TermControl::_changeBackgroundOpacity` is the handler for the `TransparencyChanged` event. In #11619, that was changed, so it no longer reinitializes the brushes. It just uses the one you already have. So....

Fix patch:
diff --git a/src/cascadia/TerminalControl/ControlCore.idl b/src/cascadia/TerminalControl/ControlCore.idl
index 4feef419afa..ee270096c4e 100644
--- a/src/cascadia/TerminalControl/ControlCore.idl
+++ b/src/cascadia/TerminalControl/ControlCore.idl
@@ -54,6 +54,7 @@ namespace Microsoft.Terminal.Control
         String FontFaceName { get; };
         UInt16 FontWeight { get; };
         Double Opacity { get; };
+        Boolean UseAcrylic { get; };
 
         Boolean TrySendKeyEvent(Int16 vkey,
                              Int16 scanCode,
diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp
index 8f6fea7063e..0d934394c82 100644
--- a/src/cascadia/TerminalControl/TermControl.cpp
+++ b/src/cascadia/TerminalControl/TermControl.cpp
@@ -451,7 +451,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
     {
         auto settings{ _core.Settings() };
         auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() };
-        if (settings.UseAcrylic())
+        // GH#11743: Make sure to use the Core's current UseAcrylic value, not
+        // the one from the settings. The Core's runtime UseAcrylic may have
+        // changed from what was in the original settings.
+        if (_core.UseAcrylic())
         {
             // See if we've already got an acrylic background brush
             // to avoid the flicker when setting up a new one
@@ -536,12 +539,30 @@ namespace winrt::Microsoft::Terminal::Control::implementation
     void TermControl::_changeBackgroundOpacity()
     {
         const auto opacity{ _core.Opacity() };
+        const auto useAcrylic{ _core.UseAcrylic() };
+
+        // GH#11743, #11619: If we're changing whether or not acrylic is used,
+        // then just entirely reinitialize the brush. The primary way that this
+        // happens is on Windows 10, where we need to enable acrylic when the
+        // user asks for <100% opacity. Even when we remove this Windows 10
+        // fallback, we may still need this for something like changing if
+        // acrylic is enabled at runtime (GH#2531)
         if (auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>())
         {
+            if (!useAcrylic)
+            {
+                _InitializeBackgroundBrush();
+                return;
+            }
             acrylic.TintOpacity(opacity);
         }
         else if (auto solidColor = RootGrid().Background().try_as<Media::SolidColorBrush>())
         {
+            if (useAcrylic)
+            {
+                _InitializeBackgroundBrush();
+                return;
+            }
             solidColor.Opacity(opacity);
         }
     }


Test patch: