Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
Browse files Browse the repository at this point in the history
…g-2022-prototype
  • Loading branch information
zadjii-msft committed Apr 27, 2022
2 parents bc8bb8e + 6b936d9 commit 446e17b
Show file tree
Hide file tree
Showing 62 changed files with 1,076 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ serializer
SETVERSION
SHELLEXECUTEINFOW
shobjidl
SHOWHIDE
SHOWMINIMIZED
SHOWTIP
SINGLEUSE
Expand Down
11 changes: 11 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ DEFFACE
defing
DEFPUSHBUTTON
defterm
deiconify
DELAYLOAD
deletable
DELETEONRELEASE
Expand Down Expand Up @@ -670,6 +671,7 @@ dwl
DWLP
dwm
dwmapi
DWMWA
dword
dwrite
dwriteglyphrundescriptionclustermap
Expand Down Expand Up @@ -1062,6 +1064,7 @@ ico
IComponent
ICONERROR
Iconified
Iconify
ICONINFORMATION
IConsole
ICONSTOP
Expand Down Expand Up @@ -1200,6 +1203,7 @@ IWin
IWindow
IXaml
IXMP
IXP
ixx
jconcpp
JOBOBJECT
Expand Down Expand Up @@ -1936,6 +1940,7 @@ qos
QRSTU
qsort
queryable
QUERYOPEN
QUESTIONMARK
quickedit
QUZ
Expand Down Expand Up @@ -2191,8 +2196,10 @@ shlobj
shlwapi
SHORTPATH
SHOWCURSOR
SHOWDEFAULT
SHOWMAXIMIZED
SHOWMINNOACTIVE
SHOWNA
SHOWNOACTIVATE
SHOWNORMAL
SHOWWINDOW
Expand Down Expand Up @@ -2424,10 +2431,12 @@ tofrom
tokenhelpers
tokenized
tokenizing
toolbar
toolbars
TOOLINFO
Toolset
tooltip
TOOLWINDOW
TOPDOWNDIB
TOPLEFT
toplevel
Expand Down Expand Up @@ -2738,6 +2747,7 @@ windowsdeveloper
windowsinternalstring
WINDOWSIZE
windowsx
windowsterminal
WINDOWTEXT
windowtheme
WINDOWTITLE
Expand Down Expand Up @@ -2880,6 +2890,7 @@ xutr
xvalue
XVIRTUALSCREEN
XWalk
XTWINOPS
Xzn
yact
YAML
Expand Down
15 changes: 15 additions & 0 deletions build/pipelines/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ parameters:

variables:
TerminalInternalPackageVersion: "0.0.7"
# If we are building a branch called "release-*", change the NuGet suffix
# to "preview". If we don't do that, XES will set the suffix to "release1"
# because it truncates the value after the first period.
# We also want to disable the suffix entirely if we're Release branded while
# on a release branch.
# In effect:
# BRANCH / BRANDING | Release | Preview
# ------------------|------------------------|------------------------
# release-* | 1.12.20220427 | 1.13.20220427-preview
# all others | 1.14.20220427-mybranch | 1.14.20220427-mybranch
${{ if startsWith(variables['Build.SourceBranchName'], 'release-') }}:
${{ if eq(parameters.branding, 'Release') }}:
NoNuGetPackBetaVersion: true
${{ else }}:
NuGetPackBetaVersion: preview

name: $(BuildDefinitionName)_$(date:yyMM).$(date:dd)$(rev:rrr)
resources:
Expand Down
370 changes: 370 additions & 0 deletions doc/specs/#12570 - Show Hide operations on GetConsoleWindow via PTY.md

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,22 @@ namespace winrt::TerminalApp::implementation
}
}

// Method Description:
// - Used to tell the PTY connection that the window visibility has changed.
// The underlying PTY might need to expose window visibility status to the
// client application for the `::GetConsoleWindow()` API.
// Arguments:
// - showOrHide - True is show; false is hide.
// Return Value:
// - <none>
void AppLogic::WindowVisibilityChanged(const bool showOrHide)
{
if (_root)
{
_root->WindowVisibilityChanged(showOrHide);
}
}

// Method Description:
// - Implements the F7 handler (per GH#638)
// - Implements the Alt handler (per GH#6421)
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace winrt::TerminalApp::implementation
bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

void CloseWindow(Microsoft::Terminal::Settings::Model::LaunchPosition position);
void WindowVisibilityChanged(const bool showOrHide);

winrt::TerminalApp::TaskbarState TaskbarState();
winrt::Windows::UI::Xaml::Media::Brush TitlebarBrush();
Expand Down Expand Up @@ -215,6 +216,7 @@ namespace winrt::TerminalApp::implementation
FORWARDED_TYPED_EVENT(CloseRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, CloseRequested);
FORWARDED_TYPED_EVENT(OpenSystemMenu, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, OpenSystemMenu);
FORWARDED_TYPED_EVENT(QuitRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, QuitRequested);
FORWARDED_TYPED_EVENT(ShowWindowChanged, Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs, _root, ShowWindowChanged);

#ifdef UNIT_TESTING
friend class TerminalAppLocalTests::CommandlineTest;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace TerminalApp
Single CalcSnappedDimension(Boolean widthOrHeight, Single dimension);
void TitlebarClicked();
void CloseWindow(Microsoft.Terminal.Settings.Model.LaunchPosition position);
void WindowVisibilityChanged(Boolean showOrHide);

TaskbarState TaskbarState{ get; };
Windows.UI.Xaml.Media.Brush TitlebarBrush { get; };
Expand Down Expand Up @@ -136,5 +137,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> OpenSystemMenu;
event Windows.Foundation.TypedEventHandler<Object, Object> QuitRequested;
event Windows.Foundation.TypedEventHandler<Object, TerminalApp.SystemMenuChangeArgs> SystemMenuChangeRequested;
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Control.ShowWindowArgs> ShowWindowChanged;
}
}
18 changes: 18 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ namespace winrt::TerminalApp::implementation
// SetTaskbarProgress event here, to get tell the hosting
// application to re-query this value from us.
page->_SetTaskbarProgressHandlers(*page, nullptr);

auto profile = tab->GetFocusedProfile();
page->_UpdateBackground(profile);
}
});

Expand Down Expand Up @@ -909,10 +912,25 @@ namespace winrt::TerminalApp::implementation
}

_updateTabRowColors();

auto tab_impl = _GetTerminalTabImpl(tab);
if (tab_impl)
{
auto profile = tab_impl->GetFocusedProfile();
_UpdateBackground(profile);
}
}
CATCH_LOG();
}

void TerminalPage::_UpdateBackground(const winrt::Microsoft::Terminal::Settings::Model::Profile& profile)
{
if (profile && _settings.GlobalSettings().UseBackgroundImageForWindow())
{
_SetBackgroundImage(profile.DefaultAppearance());
}
}

// Method Description:
// - Responds to the TabView control's Selection Changed event (to move a
// new terminal control into focus) when not in in the middle of a tab rearrangement.
Expand Down
107 changes: 107 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

Expand Down Expand Up @@ -1403,6 +1404,8 @@ namespace winrt::TerminalApp::implementation
}
}
});

term.ShowWindowChanged({ get_weak(), &TerminalPage::_ShowWindowChangedHandler });
}

// Method Description:
Expand Down Expand Up @@ -2287,6 +2290,17 @@ namespace winrt::TerminalApp::implementation
_SetTaskbarProgressHandlers(*this, nullptr);
}

// Method Description:
// - Send an event (which will be caught by AppHost) to change the show window state of the entire hosting window
// Arguments:
// - sender (not used)
// - args: the arguments specifying how to set the display status to ShowWindow for our window handle
winrt::fire_and_forget TerminalPage::_ShowWindowChangedHandler(const IInspectable /*sender*/, const Microsoft::Terminal::Control::ShowWindowArgs args)
{
co_await resume_foreground(Dispatcher());
_ShowWindowChangedHandlers(*this, args);
}

// Method Description:
// - Paste text from the Windows Clipboard to the focused terminal
void TerminalPage::_PasteText()
Expand Down Expand Up @@ -2363,6 +2377,9 @@ namespace winrt::TerminalApp::implementation
// TermControl will copy the settings out of the settings passed to it.
TermControl term{ settings.DefaultSettings(), settings.UnfocusedSettings(), connection };

// GH#12515: ConPTY assumes it's hidden at the start. If we're not, let it know now.
term.WindowVisibilityChanged(_visible);

if (_hostingHwnd.has_value())
{
term.OwningHwnd(reinterpret_cast<uint64_t>(*_hostingHwnd));
Expand Down Expand Up @@ -2472,6 +2489,57 @@ namespace winrt::TerminalApp::implementation
return resultPane;
}

// Method Description:
// - Sets background image and applies its settings (stretch, opacity and alignment)
// - Checks path validity
// Arguments:
// - newAppearance
// Return Value:
// - <none>
void TerminalPage::_SetBackgroundImage(const winrt::Microsoft::Terminal::Settings::Model::IAppearanceConfig& newAppearance)
{
if (newAppearance.BackgroundImagePath().empty())
{
_tabContent.Background(nullptr);
return;
}

Windows::Foundation::Uri imageUri{ nullptr };
try
{
imageUri = Windows::Foundation::Uri{ newAppearance.BackgroundImagePath() };
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
_tabContent.Background(nullptr);
return;
}
// Check if the image brush is already pointing to the image
// in the modified settings; if it isn't (or isn't there),
// set a new image source for the brush

auto brush = _tabContent.Background().try_as<Media::ImageBrush>();
Media::Imaging::BitmapImage imageSource = brush == nullptr ? nullptr : brush.ImageSource().try_as<Media::Imaging::BitmapImage>();

if (imageSource == nullptr ||
imageSource.UriSource() == nullptr ||
imageSource.UriSource().RawUri() != imageUri.RawUri())
{
Media::ImageBrush b{};
// Note that BitmapImage handles the image load asynchronously,
// which is especially important since the image
// may well be both large and somewhere out on the
// internet.
Media::Imaging::BitmapImage image(imageUri);
b.ImageSource(image);
_tabContent.Background(b);

b.Stretch(newAppearance.BackgroundImageStretchMode());
b.Opacity(newAppearance.BackgroundImageOpacity());
}
}

// Method Description:
// - Hook up keybindings, and refresh the UI of the terminal.
// This includes update the settings of all the tabs according
Expand Down Expand Up @@ -2502,6 +2570,18 @@ namespace winrt::TerminalApp::implementation
profileGuidSettingsMap.insert_or_assign(newProfile.Guid(), std::pair{ newProfile, nullptr });
}

if (_settings.GlobalSettings().UseBackgroundImageForWindow())
{
const auto focusedTab{ _GetFocusedTabImpl() };
if (focusedTab)
{
auto profile = focusedTab->GetFocusedProfile();
if (profile)
{
_SetBackgroundImage(profile.DefaultAppearance());
}
}
}
for (const auto& tab : _tabs)
{
if (auto terminalTab{ _GetTerminalTabImpl(tab) })
Expand Down Expand Up @@ -2739,6 +2819,33 @@ namespace winrt::TerminalApp::implementation
_DismissTabContextMenus();
}

// Method Description:
// - Notifies all attached console controls that the visibility of the
// hosting window has changed. The underlying PTYs may need to know this
// for the proper response to `::GetConsoleWindow()` from a Win32 console app.
// Arguments:
// - showOrHide: Show is true; hide is false.
// Return Value:
// - <none>
void TerminalPage::WindowVisibilityChanged(const bool showOrHide)
{
_visible = showOrHide;
for (const auto& tab : _tabs)
{
if (auto terminalTab{ _GetTerminalTabImpl(tab) })
{
// Manually enumerate the panes in each tab; this will let us recycle TerminalSettings
// objects but only have to iterate one time.
terminalTab->GetRootPane()->WalkTree([&](auto&& pane) {
if (auto control = pane->GetTerminalControl())
{
control.WindowVisibilityChanged(showOrHide);
}
});
}
}
}

// Method Description:
// - Called when the user tries to do a search using keybindings.
// This will tell the current focused terminal control to create
Expand Down
Loading

1 comment on commit 446e17b

@github-actions

This comment was marked as outdated.

Please sign in to comment.