Skip to content

Commit

Permalink
Merge 'dev/migrie/f/z-order-owner' into 'dev/migrie/b/2988-niksa-msgs…
Browse files Browse the repository at this point in the history
…-prototype'
  • Loading branch information
zadjii-msft committed Mar 29, 2022
1 parent b777c51 commit b742e93
Show file tree
Hide file tree
Showing 33 changed files with 423 additions and 10 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 @@ -144,6 +144,7 @@ REGCLS
RETURNCMD
rfind
roundf
ROOTOWNER
RSHIFT
SACL
schandle
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 @@ -65,6 +65,8 @@ namespace winrt::TerminalApp::implementation
void LoadSettings();
[[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept;

void SetOwnerHwnd(uint64_t owner) { _root->SetOwnerHwnd(owner); }

void Quit();

bool HasCommandlineArguments() const noexcept;
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 @@ -46,6 +46,8 @@ namespace TerminalApp
// registered?" when it definitely is.
void Create();

void SetOwnerHwnd(UInt64 owner);

Boolean IsUwp();
void RunAsUwp();
Boolean IsElevated();
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,9 @@ namespace winrt::TerminalApp::implementation
// create here.
// TermControl will copy the settings out of the settings passed to it.
TermControl term{ settings.DefaultSettings(), settings.UnfocusedSettings(), connection };
if (_hostingHwnd.has_value())
term.OwningHwnd(_ownerHwnd);
// term.OwningHwnd(reinterpret_cast<uint64_t>(_ownerHwnd));
return term;
}

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ namespace winrt::TerminalApp::implementation

void Create();

uint64_t _ownerHwnd{ 0 };
void SetOwnerHwnd(uint64_t owner) { _ownerHwnd = owner; };

bool ShouldUsePersistedLayout(Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const;
bool ShouldImmediatelyHandoffToElevated(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings) const;
void HandoffToElevated(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
Expand Down
16 changes: 16 additions & 0 deletions src/cascadia/TerminalConnection/ConptyConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
if (!_inPipe)
{
THROW_IF_FAILED(_CreatePseudoConsoleAndPipes(dimensions, PSEUDOCONSOLE_RESIZE_QUIRK | PSEUDOCONSOLE_WIN32_INPUT_MODE, &_inPipe, &_outPipe, &_hPC));
THROW_IF_FAILED(ConptyReparentPseudoConsole(_hPC.get(), reinterpret_cast<HWND>(_initialParentHwnd)));
THROW_IF_FAILED(_LaunchAttachedClient());
}
// But if it was an inbound handoff... attempt to synchronize the size of it with what our connection
Expand All @@ -313,6 +314,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance));

THROW_IF_FAILED(ConptyResizePseudoConsole(_hPC.get(), dimensions));
THROW_IF_FAILED(ConptyReparentPseudoConsole(_hPC.get(), reinterpret_cast<HWND>(_initialParentHwnd)));
}

_startTime = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -468,6 +470,20 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
}
}

void ConptyConnection::ReparentWindow(const uint64_t newParent)
{
// If we haven't started connecting at all, TODO!
if (!_isStateAtOrBeyond(ConnectionState::Connecting))
{
_initialParentHwnd = newParent;
}
// Otherwise, TODO!
else if (_isConnected())
{
THROW_IF_FAILED(ConptyReparentPseudoConsole(_hPC.get(), reinterpret_cast<HWND>(newParent)));
}
}

void ConptyConnection::Close() noexcept
try
{
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalConnection/ConptyConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation
void Resize(uint32_t rows, uint32_t columns);
void Close() noexcept;
void ClearBuffer();
void ReparentWindow(const uint64_t newParent);

winrt::guid Guid() const noexcept;
winrt::hstring Commandline() const;
Expand Down Expand Up @@ -65,6 +66,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation

uint32_t _initialRows{};
uint32_t _initialCols{};
uint64_t _initialParentHwnd{ 0 };
hstring _commandline{};
hstring _startingDirectory{};
hstring _startingTitle{};
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalConnection/ConptyConnection.idl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Microsoft.Terminal.TerminalConnection
Guid Guid { get; };
String Commandline { get; };
void ClearBuffer();
void ReparentWindow(UInt64 newParent);

static event NewConnectionHandler NewConnection;
static void StartInboundListener();
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
const auto height = vp.Height();
_connection.Resize(height, width);

if (auto conpty{ _connection.try_as<TerminalConnection::ConptyConnection>() })
{
conpty.ReparentWindow(_OwningHwnd);
}

// Override the default width and height to match the size of the swapChainPanel
_settings->InitialCols(width);
_settings->InitialRows(height);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void WindowVisibilityChanged(const bool showOrHide);

WINRT_PROPERTY(uint64_t, OwningHwnd, 0);

RUNTIME_SETTING(double, Opacity, _settings->Opacity());
RUNTIME_SETTING(bool, UseAcrylic, _settings->UseAcrylic());

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/ICoreState.idl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.TerminalConnection.ConnectionState ConnectionState { get; };

Microsoft.Terminal.Core.Scheme ColorScheme { get; set; };

UInt64 OwningHwnd;

};
}
10 changes: 10 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2790,4 +2790,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

void TermControl::OwningHwnd(uint64_t owner)
{
_core.OwningHwnd(owner);
}

uint64_t TermControl::OwningHwnd()
{
return _core.OwningHwnd();
}

}
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool BracketedPasteEnabled() const noexcept;

double BackgroundOpacity() const;

uint64_t OwningHwnd();
void OwningHwnd(uint64_t owner);
#pragma endregion

void ScrollViewport(int viewTop);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ void AppHost::Initialize()
if (auto withWindow{ _logic.try_as<IInitializeWithWindow>() })
{
withWindow->Initialize(_window->GetHandle());
// _logic.SetOwnerHwnd(reinterpret_cast<uint64_t>(_window->GetInteropHandle()));
_logic.SetOwnerHwnd(reinterpret_cast<uint64_t>(_window->GetHandle()));
}

if (_useNonClientArea)
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ IslandWindow::~IslandWindow()
_source.Close();
}

HWND IslandWindow::GetInteropHandle() const
{
return _interopWindowHandle;
}

// Method Description:
// - Create the actual window that we'll use for the application.
// Arguments:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class IslandWindow :
virtual void MakeWindow() noexcept;
void Close();
virtual void OnSize(const UINT width, const UINT height);
HWND GetInteropHandle() const;

[[nodiscard]] virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
void OnResize(const UINT width, const UINT height) override;
Expand Down
29 changes: 29 additions & 0 deletions src/host/PtySignalInputThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void PtySignalInputThread::ConnectConsole() noexcept
{
_DoResizeWindow(*_earlyResize);
}
if (_earlyReparent)
{
_DoSetWindowParent(*_earlyReparent);
}
}

// Method Description:
Expand Down Expand Up @@ -119,6 +123,26 @@ void PtySignalInputThread::ConnectConsole() noexcept

break;
}
case PtySignal::SetParent:
{
SetParentData reparentMessage = { 0 };
_GetData(&reparentMessage, sizeof(reparentMessage));

LockConsole();
auto Unlock = wil::scope_exit([&] { UnlockConsole(); });

// todo
if (!_consoleConnected)
{
_earlyReparent = reparentMessage;
}
else
{
_DoSetWindowParent(reparentMessage);
}

break;
}
default:
{
THROW_HR(E_UNEXPECTED);
Expand Down Expand Up @@ -147,6 +171,11 @@ void PtySignalInputThread::_DoClearBuffer()
_pConApi->ClearBuffer();
}

void PtySignalInputThread::_DoSetWindowParent(const SetParentData& data)
{
_pConApi->ReparentWindow(data.handle);
}

// Method Description:
// - Retrieves bytes from the file stream and exits or throws errors should the pipe state
// be compromised.
Expand Down
9 changes: 9 additions & 0 deletions src/host/PtySignalInputThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Microsoft::Console
enum class PtySignal : unsigned short
{
ClearBuffer = 2,
SetParent = 3,
ResizeWindow = 8
};

Expand All @@ -49,10 +50,15 @@ namespace Microsoft::Console
unsigned short sx;
unsigned short sy;
};
struct SetParentData
{
uint64_t handle;
};

[[nodiscard]] HRESULT _InputThread();
bool _GetData(_Out_writes_bytes_(cbBuffer) void* const pBuffer, const DWORD cbBuffer);
void _DoResizeWindow(const ResizeWindowData& data);
void _DoSetWindowParent(const SetParentData& data);
void _DoClearBuffer();
void _Shutdown();

Expand All @@ -62,5 +68,8 @@ namespace Microsoft::Console
bool _consoleConnected;
std::optional<ResizeWindowData> _earlyResize;
std::unique_ptr<Microsoft::Console::VirtualTerminal::ConGetSet> _pConApi;

public:
std::optional<SetParentData> _earlyReparent;
};
}
10 changes: 10 additions & 0 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,16 @@ bool VtIo::IsUsingVt() const

if (_pPtySignalInputThread)
{
// IMPORTANT! Start the pseudo window on this thread. This thread has a
// message pump. If you DON'T, then a DPI change in the parent hwnd will
// cause us to get a dpi change as well, which we'll never deque and
// handle, effectively HANGING THE PARENT HWND. super bad.
//
// TODO! clean this up
if (_pPtySignalInputThread->_earlyReparent.has_value())
{
ServiceLocator::LocatePseudoWindow(reinterpret_cast<HWND>(_pPtySignalInputThread->_earlyReparent.value().handle));
}
// Let the signal thread know that the console is connected
_pPtySignalInputThread->ConnectConsole();
}
Expand Down
10 changes: 10 additions & 0 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,13 @@ void ConhostInternalGetSet::UpdateSoftFont(const gsl::span<const uint16_t> bitPa
pRender->UpdateSoftFont(bitPattern, cellSize, centeringHint);
}
}

void ConhostInternalGetSet::ReparentWindow(const uint64_t handle)
{
// This will initialize s_interactivityFactory for us. It will also
// conveniently return 0 when we're on OneCore.
if (const auto psuedoHwnd{ ServiceLocator::LocatePseudoWindow(reinterpret_cast<HWND>(handle)) })
{
LOG_LAST_ERROR_IF_NULL(::SetParent(psuedoHwnd, reinterpret_cast<HWND>(handle)));
}
}
2 changes: 2 additions & 0 deletions src/host/outputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal::
const SIZE cellSize,
const size_t centeringHint) override;

void ReparentWindow(const uint64_t handle);

private:
void _modifyLines(const size_t count, const bool insert);

Expand Down
2 changes: 2 additions & 0 deletions src/inc/conpty-static.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ HRESULT WINAPI ConptyResizePseudoConsole(HPCON hPC, COORD size);

HRESULT WINAPI ConptyClearPseudoConsole(HPCON hPC);

HRESULT WINAPI ConptyReparentPseudoConsole(HPCON hPC, HWND newParent);

VOID WINAPI ConptyClosePseudoConsole(HPCON hPC);

HRESULT WINAPI ConptyPackPseudoConsole(HANDLE hServerProcess, HANDLE hRef, HANDLE hSignal, HPCON* phPC);
Expand Down
20 changes: 18 additions & 2 deletions src/interactivity/base/InteractivityFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ using namespace Microsoft::Console::Interactivity;
// - hwnd: Receives the value of the newly created window's HWND.
// Return Value:
// - STATUS_SUCCESS on success, otherwise an appropriate error.
[[nodiscard]] NTSTATUS InteractivityFactory::CreatePseudoWindow(HWND& hwnd)
[[nodiscard]] NTSTATUS InteractivityFactory::CreatePseudoWindow(HWND& hwnd, const HWND owner)
{
hwnd = nullptr;
ApiLevel level;
Expand All @@ -313,9 +313,25 @@ using namespace Microsoft::Console::Interactivity;
pseudoClass.lpfnWndProc = s_PseudoWindowProc;
RegisterClass(&pseudoClass);

// const auto windowStyle = (owner == HWND_DESKTOP) ? WS_OVERLAPPEDWINDOW : WS_CHILD;
const auto windowStyle = WS_OVERLAPPEDWINDOW;

// Attempt to create window
hwnd = CreateWindowExW(
WS_EX_TOOLWINDOW, PSEUDO_WINDOW_CLASS, nullptr, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, HWND_DESKTOP, nullptr, nullptr, this);
WS_EX_TOOLWINDOW,
PSEUDO_WINDOW_CLASS,
nullptr,
windowStyle, //WS_CHILD, //WS_OVERLAPPEDWINDOW,
0,
0,
0,
0,
// Niksa just had the parent as HWND_DESKTOP always,
// This branch tests a merged version of the prototypes
owner /*(HWND)0x00070C6A*/ /*HWND_DESKTOP*/, // parent
nullptr,
nullptr,
this);
if (hwnd == nullptr)
{
DWORD const gle = GetLastError();
Expand Down
2 changes: 1 addition & 1 deletion src/interactivity/base/InteractivityFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft::Console::Interactivity
[[nodiscard]] NTSTATUS CreateAccessibilityNotifier(_Inout_ std::unique_ptr<IAccessibilityNotifier>& notifier);
[[nodiscard]] NTSTATUS CreateSystemConfigurationProvider(_Inout_ std::unique_ptr<ISystemConfigurationProvider>& provider);

[[nodiscard]] NTSTATUS CreatePseudoWindow(HWND& hwnd);
[[nodiscard]] NTSTATUS CreatePseudoWindow(HWND& hwnd, const HWND owner);
void SetPseudoWindowCallback(std::function<void(bool)> func);

// Wndproc
Expand Down
Loading

1 comment on commit b742e93

@github-actions
Copy link

@github-actions github-actions bot commented on b742e93 Mar 29, 2022

Choose a reason for hiding this comment

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

@check-spelling-bot Report

Unrecognized words, please review:

  • deiconify
  • IXP
  • messagebox
  • SHOWDEFAULT
  • SHOWNA
  • toolbar
Previously acknowledged words that are now absent azurewebsites cxcy DCompile debolden deconstructed devicefamily GETKEYSTATE guardxfg Iconify LLVM LPCHARSETINFO MAPVIRTUALKEY MSDL ned NOWAIT pgorepro pgort PGU redistributable Timeline timelines toolbars unintense UWA UWAs VKKEYSCAN WResult xfg
To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/migrie/b/2988-merged-prototypes branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect/b742e932858f997e6f40c79bae545d0735e75787.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/terminal/comments/69814241" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  
update_files
rm $comment_body
git add -u
✏️ 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.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

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 you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to a patterns/{file}.txt.

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.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

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).

Please sign in to comment.