Skip to content

Commit

Permalink
Option to default to show icon in tab, hide tabicon or make icon in t…
Browse files Browse the repository at this point in the history
…ab monochrome. (#15948)

Adding enum iconstyle for hiding the icon in the tab #8157 

## Summary of the Pull Request
Please confirm if I am on the right track.
## References and Relevant Issues

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed

## PR Checklist
- [ ] Closes #8157
- [x] Tests added/passed
- [ ] Documentation updated
- If checked, please file a pull request on [our docs
repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
- [ ] Schema updated (if necessary)
  • Loading branch information
bundgaard authored Sep 19, 2023
1 parent 59248de commit 394b942
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/cascadia/LocalTests_SettingsModel/ThemeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace SettingsModelLocalTests
"tabRow":
{
"background": "#FFFF8800",
"unfocusedBackground": "#FF8844"
"unfocusedBackground": "#FF8844",
"iconStyle": "default"
},
"window":
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/SettingsTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace winrt::TerminalApp::implementation

// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
Icon(winrt::hstring{ glyph });
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph));
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(glyph, false));
}

winrt::Windows::UI::Xaml::Media::Brush SettingsTab::_BackgroundBrush()
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ namespace winrt::TerminalApp::implementation
{
if (!profile.Icon().empty())
{
newTabImpl->UpdateIcon(profile.Icon());
newTabImpl->UpdateIcon(profile.Icon(), _settings.GlobalSettings().CurrentTheme().Tab().IconStyle());
}
}

Expand Down Expand Up @@ -241,7 +241,7 @@ namespace winrt::TerminalApp::implementation
{
if (const auto profile = tab.GetFocusedProfile())
{
tab.UpdateIcon(profile.Icon());
tab.UpdateIcon(profile.Icon(), _settings.GlobalSettings().CurrentTheme().Tab().IconStyle());
}
}

Expand Down
25 changes: 17 additions & 8 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,17 @@ namespace winrt::TerminalApp::implementation
// - iconPath: The new path string to use as the IconPath for our TabViewItem
// Return Value:
// - <none>
void TerminalTab::UpdateIcon(const winrt::hstring iconPath)
void TerminalTab::UpdateIcon(const winrt::hstring iconPath, const winrt::Microsoft::Terminal::Settings::Model::IconStyle iconStyle)
{
ASSERT_UI_THREAD();

// Don't reload our icon if it hasn't changed.
if (iconPath == _lastIconPath)
// Don't reload our icon and iconStyle hasn't changed.
if (iconPath == _lastIconPath && iconStyle == _lastIconStyle)
{
return;
}

_lastIconPath = iconPath;
_lastIconStyle = iconStyle;

// If the icon is currently hidden, just return here (but only after setting _lastIconPath to the new path
// for when we show the icon again)
Expand All @@ -299,9 +299,18 @@ namespace winrt::TerminalApp::implementation
return;
}

// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
Icon(_lastIconPath);
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath));
if (iconStyle == IconStyle::Hidden)
{
// The TabViewItem Icon needs MUX while the IconSourceElement in the CommandPalette needs WUX...
Icon({});
TabViewItem().IconSource(IconSource{ nullptr });
}
else
{
Icon(_lastIconPath);
bool isMonochrome = iconStyle == IconStyle::Monochrome;
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath, isMonochrome));
}
}

// Method Description:
Expand All @@ -323,7 +332,7 @@ namespace winrt::TerminalApp::implementation
else
{
Icon(_lastIconPath);
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath));
TabViewItem().IconSource(IconPathConverter::IconSourceMUX(_lastIconPath, _lastIconStyle == IconStyle::Monochrome));
}
_iconHidden = hide;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace winrt::TerminalApp::implementation
std::shared_ptr<Pane> newPane);

void ToggleSplitOrientation();
void UpdateIcon(const winrt::hstring iconPath);
void UpdateIcon(const winrt::hstring iconPath, const winrt::Microsoft::Terminal::Settings::Model::IconStyle iconStyle);
void HideIcon(const bool hide);

void ShowBellIndicator(const bool show);
Expand Down Expand Up @@ -111,6 +111,7 @@ namespace winrt::TerminalApp::implementation
Windows::UI::Xaml::Controls::MenuFlyoutItem _closePaneMenuItem;
Windows::UI::Xaml::Controls::MenuFlyoutItem _restartConnectionMenuItem;

winrt::Microsoft::Terminal::Settings::Model::IconStyle _lastIconStyle;
winrt::hstring _lastIconPath{};
std::optional<winrt::Windows::UI::Color> _runtimeTabColor{};
winrt::TerminalApp::TabHeaderControl _headerControl{};
Expand Down
21 changes: 11 additions & 10 deletions src/cascadia/TerminalSettingsModel/IconPathConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Return Value:
// - An IconElement with its IconSource set, if possible.
template<typename TIconSource>
TIconSource _getColoredBitmapIcon(const winrt::hstring& path)
TIconSource _getColoredBitmapIcon(const winrt::hstring& path, bool monochrome)
{
// FontIcon uses glyphs in the private use area, whereas valid URIs only contain ASCII characters.
// To skip throwing on Uri construction, we can quickly check if the first character is ASCII.
Expand All @@ -85,7 +85,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Make sure to set this to false, so we keep the RGB data of the
// image. Otherwise, the icon will be white for all the
// non-transparent pixels in the image.
iconSource.ShowAsMonochrome(false);
iconSource.ShowAsMonochrome(monochrome);
iconSource.UriSource(iconUri);
return iconSource;
}
Expand Down Expand Up @@ -121,14 +121,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// Return Value:
// - An IconElement with its IconSource set, if possible.
template<typename TIconSource>
TIconSource _getIconSource(const winrt::hstring& iconPath)
TIconSource _getIconSource(const winrt::hstring& iconPath, bool monochrome)
{
TIconSource iconSource{ nullptr };

if (iconPath.size() != 0)
{
const auto expandedIconPath{ _expandIconPath(iconPath) };
iconSource = _getColoredBitmapIcon<TIconSource>(expandedIconPath);
iconSource = _getColoredBitmapIcon<TIconSource>(expandedIconPath, monochrome);

// If we fail to set the icon source using the "icon" as a path,
// let's try it as a symbol/emoji.
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
const hstring& /* language */)
{
const auto& iconPath = winrt::unbox_value_or<winrt::hstring>(value, L"");
return _getIconSource<Controls::IconSource>(iconPath);
return _getIconSource<Controls::IconSource>(iconPath, false);
}

// unused for one-way bindings
Expand All @@ -211,12 +211,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

Windows::UI::Xaml::Controls::IconSource _IconSourceWUX(hstring path)
{
return _getIconSource<Windows::UI::Xaml::Controls::IconSource>(path);
return _getIconSource<Windows::UI::Xaml::Controls::IconSource>(path, false);
}

Microsoft::UI::Xaml::Controls::IconSource _IconSourceMUX(hstring path)
Microsoft::UI::Xaml::Controls::IconSource _IconSourceMUX(hstring path, bool monochrome)
{
return _getIconSource<Microsoft::UI::Xaml::Controls::IconSource>(path);
return _getIconSource<Microsoft::UI::Xaml::Controls::IconSource>(path, monochrome);
}

SoftwareBitmap _convertToSoftwareBitmap(HICON hicon,
Expand Down Expand Up @@ -329,13 +329,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return bitmapSource;
}

MUX::Controls::IconSource IconPathConverter::IconSourceMUX(const winrt::hstring& iconPath)
MUX::Controls::IconSource IconPathConverter::IconSourceMUX(const winrt::hstring& iconPath,
const bool monochrome)
{
std::wstring_view iconPathWithoutIndex;
const auto indexOpt = _getIconIndex(iconPath, iconPathWithoutIndex);
if (!indexOpt.has_value())
{
return _IconSourceMUX(iconPath);
return _IconSourceMUX(iconPath, monochrome);
}

const auto bitmapSource = _getImageIconSourceForBinary(iconPathWithoutIndex, indexOpt.value());
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/IconPathConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
const hstring& language);

static Windows::UI::Xaml::Controls::IconElement IconWUX(const winrt::hstring& iconPath);
static Microsoft::UI::Xaml::Controls::IconSource IconSourceMUX(const winrt::hstring& iconPath);
static Microsoft::UI::Xaml::Controls::IconSource IconSourceMUX(const winrt::hstring& iconPath, const bool convertToGrayscale);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsModel/IconPathConverter.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Terminal.Settings.Model
IconPathConverter();

static Windows.UI.Xaml.Controls.IconElement IconWUX(String path);
static Microsoft.UI.Xaml.Controls.IconSource IconSourceMUX(String path);
static Microsoft.UI.Xaml.Controls.IconSource IconSourceMUX(String path, Boolean convertToGrayscale);
};

}
7 changes: 4 additions & 3 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ Author(s):
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr)

#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr) \
#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::IconStyle, IconStyle, "iconStyle", winrt::Microsoft::Terminal::Settings::Model::IconStyle::Default) \
X(winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVisibility, ShowCloseButton, "showCloseButton", winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVisibility::Always)
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,15 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVi
};
};

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::IconStyle)
{
JSON_MAPPINGS(3) = {
pair_type{ "default", ValueType::Default },
pair_type{ "hidden", ValueType::Hidden },
pair_type{ "monochrome", ValueType::Monochrome },
};
};

// Possible ScrollToMarkDirection values
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Control::ScrollToMarkDirection)
{
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
namespace Microsoft.Terminal.Settings.Model
{

enum IconStyle
{
Default,
Hidden,
Monochrome
};

enum ThemeColorType
{
Accent,
Expand Down Expand Up @@ -63,6 +70,7 @@ namespace Microsoft.Terminal.Settings.Model
ThemeColor Background { get; };
ThemeColor UnfocusedBackground { get; };
TabCloseButtonVisibility ShowCloseButton { get; };
IconStyle IconStyle { get; };
}

[default_interface] runtimeclass Theme : Windows.Foundation.IStringable {
Expand Down

0 comments on commit 394b942

Please sign in to comment.