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
Add support for naming windows with the -w
parameter
#9300
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c7da00
Rebase all the changes on main
zadjii-msft 97818c6
fix a bug and fix the tests
zadjii-msft 2ec9415
fix tests
zadjii-msft e13e1e7
Good ole Java
zadjii-msft 136ce6d
finish that test
zadjii-msft 27d12a2
THIS NEEDS TO GO TO THE PARENT
zadjii-msft c202257
feedback from review
zadjii-msft eaaa204
initial review feedback
zadjii-msft 9f54229
Merge remote-tracking branch 'origin/main' into dev/migrie/f/name-win…
zadjii-msft bba09e3
Address PR concerns
zadjii-msft 1105328
That's better
zadjii-msft File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,59 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
} | ||
} | ||
|
||
// Method Description: | ||
// - Find the ID of the peasant with the given name. If no such peasant | ||
// exists, then we'll return 0. If we encounter any peasants who have died | ||
// during this process, then we'll remove them from the set of _peasants | ||
// Arguments: | ||
// - name: The window name to look for | ||
// Return Value: | ||
// - 0 if we didn't find the given peasant, otherwise a positive number for | ||
// the window's ID. | ||
uint64_t Monarch::_lookupPeasantIdForName(std::wstring_view name) | ||
{ | ||
if (name.empty()) | ||
{ | ||
return 0; | ||
} | ||
|
||
std::vector<uint64_t> peasantsToErase{}; | ||
uint64_t result = 0; | ||
for (const auto& [id, p] : _peasants) | ||
{ | ||
try | ||
{ | ||
auto otherName = p.WindowName(); | ||
if (otherName == name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Case sensitive compare? Are you sure? Lots of people love to be lazy on the capitalization when doing a command line thing and I suspect that might apply to |
||
{ | ||
result = id; | ||
break; | ||
} | ||
} | ||
catch (...) | ||
{ | ||
LOG_CAUGHT_EXCEPTION(); | ||
// Normally, we'd just erase the peasant here. However, we can't | ||
// erase from the map while we're iterating over it like this. | ||
// Instead, pull a good ole Java and collect this id for removal | ||
// later. | ||
peasantsToErase.push_back(id); | ||
} | ||
} | ||
|
||
// Remove the dead peasants we came across while iterating. | ||
for (const auto& id : peasantsToErase) | ||
{ | ||
// Remove the peasant from the list of peasants | ||
_peasants.erase(id); | ||
// Remove the peasant from the list of MRU windows. They're dead. | ||
// They can't be the MRU anymore. | ||
_clearOldMruEntries(id); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Method Description: | ||
// - Handler for the `Peasant::WindowActivated` event. We'll make a in-proc | ||
// copy of the WindowActivatedArgs from the peasant. That way, we won't | ||
|
@@ -400,6 +453,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
// After the event was handled, ResultTargetWindow() will be filled with | ||
// the parsed result. | ||
const auto targetWindow = findWindowArgs->ResultTargetWindow(); | ||
const auto targetWindowName = findWindowArgs->ResultTargetWindowName(); | ||
|
||
TraceLoggingWrite(g_hRemotingProvider, | ||
"Monarch_ProposeCommandline", | ||
|
@@ -410,6 +464,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
// that goes with it. Alternatively, if we were given a magic windowing | ||
// constant, we can use that to look up an appropriate peasant. | ||
if (targetWindow >= 0 || | ||
targetWindow == WindowingBehaviorUseName || | ||
targetWindow == WindowingBehaviorUseExisting || | ||
targetWindow == WindowingBehaviorUseAnyExisting) | ||
{ | ||
|
@@ -429,6 +484,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
case WindowingBehaviorUseAnyExisting: | ||
windowID = _getMostRecentPeasantID(false); | ||
break; | ||
case WindowingBehaviorUseName: | ||
windowID = _lookupPeasantIdForName(targetWindowName); | ||
break; | ||
default: | ||
windowID = ::base::saturated_cast<uint64_t>(targetWindow); | ||
break; | ||
|
@@ -449,7 +507,6 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
if (auto targetPeasant{ _getPeasant(windowID) }) | ||
{ | ||
auto result{ winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(false) }; | ||
|
||
try | ||
{ | ||
// This will raise the peasant's ExecuteCommandlineRequested | ||
|
@@ -463,6 +520,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
// If we fail to propose the commandline to the peasant (it | ||
// died?) then just tell this process to become a new window | ||
// instead. | ||
result->WindowName(targetWindowName); | ||
result->ShouldCreateWindow(true); | ||
|
||
// If this fails, it'll be logged in the following | ||
|
@@ -497,6 +555,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
|
||
auto result{ winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(true) }; | ||
result->Id(windowID); | ||
result->WindowName(targetWindowName); | ||
return *result; | ||
} | ||
} | ||
|
@@ -508,6 +567,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation | |
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); | ||
|
||
// In this case, no usable ID was provided. Return { true, nullopt } | ||
return winrt::make<Remoting::implementation::ProposeCommandlineResult>(true); | ||
auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(true); | ||
result->WindowName(targetWindowName); | ||
return *result; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to a future debugger to leave either a general comment or a
Log
comment per block here as to the general gist of each test section.