Skip to content
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

When the window is summoned and is already active, minimize it. #9963

Merged
merged 109 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
3bef7bb
Get all the projects created and hooked up to the sln
zadjii-msft Dec 16, 2020
1f52d35
Yank all the M/P files, this builds?!
zadjii-msft Dec 16, 2020
5a9cdc8
Shockingly, this works, it works elevated, and it works unpackaged
zadjii-msft Dec 16, 2020
36539cf
This won't work, but I'm committing this becaus I finally got it to c…
zadjii-msft Dec 16, 2020
27ace16
whoop, we pass the commandline from the peasant, to the monarch, and …
zadjii-msft Dec 16, 2020
9a41647
HOLY SHIT I GOT THE COMANDLINE TO EXECUTE IN THE CURRENT WINDOW!!!!!!…
zadjii-msft Dec 17, 2020
5cabcfb
add a note to future me
zadjii-msft Dec 17, 2020
03bfc6e
This works as a unittest, but not a local test. That's batty
zadjii-msft Dec 17, 2020
590b9ff
this macro makes me feel dirty
zadjii-msft Dec 17, 2020
0579b24
LocalTests_Remoting -> UnitTests_Remoting
zadjii-msft Dec 17, 2020
a3faed6
finish renaming this test
zadjii-msft Dec 17, 2020
9c6eac4
Clean up a lot for review
zadjii-msft Dec 17, 2020
0103331
cleanup Peasant for review
zadjii-msft Dec 17, 2020
b4fe1bf
Final cleanup for review
zadjii-msft Dec 17, 2020
d08e65c
_final_ final cleanup for review
zadjii-msft Dec 17, 2020
e101efd
pr nits
zadjii-msft Dec 18, 2020
e1402d8
This seems to work to create a thread listening for the monarch, and …
zadjii-msft Dec 18, 2020
f978a9c
it's hard to believe he's gone / were it so easy
zadjii-msft Dec 18, 2020
5939636
Oh yea actually remove the thing
zadjii-msft Dec 18, 2020
c088895
last commit before the holidays
zadjii-msft Dec 18, 2020
fa2df47
Merge remote-tracking branch 'origin/main' into dev/migrie/f/remoting…
zadjii-msft Jan 5, 2021
0f5c24f
Enable audit mode
zadjii-msft Jan 5, 2021
921d915
nits
zadjii-msft Jan 5, 2021
00184e7
Merge branch 'dev/migrie/f/remoting.dll' into dev/migrie/f/the-first-…
zadjii-msft Jan 5, 2021
658db6b
Ask the TerminalApp to parse the commandline, and tell us what the wi…
zadjii-msft Jan 6, 2021
977db46
Holy bajesus, this works like a charm
zadjii-msft Jan 6, 2021
bcbef34
Add a note about commiting suicide
zadjii-msft Jan 6, 2021
813dbc6
notes, comments, cleanup
zadjii-msft Jan 6, 2021
0f0df5e
activate windows
zadjii-msft Jan 6, 2021
9fc2f0e
add some tracelogging
zadjii-msft Jan 6, 2021
6537686
The peasant will now correctly inform the monarch when it re-connects
zadjii-msft Jan 7, 2021
a75da0a
mostly just notes
zadjii-msft Jan 7, 2021
c02f25a
peasants now switch to the cwd that was requested
zadjii-msft Jan 7, 2021
3e39ab9
more comments
zadjii-msft Jan 7, 2021
52b2cb6
Allow the user to provide ids on the commandline
zadjii-msft Jan 7, 2021
bc492f1
Code cleanup
zadjii-msft Jan 7, 2021
88ffc6f
Merge remote-tracking branch 'origin/main' into dev/migrie/f/remoting…
zadjii-msft Jan 7, 2021
be74b2e
putting var in headers is bad, mkay?
zadjii-msft Jan 7, 2021
2a7bc94
branding
zadjii-msft Jan 7, 2021
81c09d9
Merge branch 'dev/migrie/f/remoting.dll' into dev/migrie/f/the-first-…
zadjii-msft Jan 8, 2021
c34e4ce
Merge remote-tracking branch 'origin/main' into dev/migrie/f/the-firs…
zadjii-msft Jan 8, 2021
5b8ace2
A bunch of tests for Monarch::ProposeCommandline
zadjii-msft Jan 8, 2021
689c385
sure yea that's a doc comment
zadjii-msft Jan 8, 2021
59deca1
Merge branch 'main' into dev/migrie/f/the-first-galactic-empire
zadjii-msft Jan 26, 2021
f02969b
More tests, more redundancy
zadjii-msft Jan 26, 2021
b2db317
man I can't spel
zadjii-msft Jan 26, 2021
d2a3438
Add try/catch's throughout Monarch.cpp
zadjii-msft Jan 27, 2021
a65f341
trycatch the window manager. A lot more going on there.
zadjii-msft Jan 27, 2021
1c2f8e5
This will always summon the monarch window
zadjii-msft Jan 28, 2021
71f6b58
RegisterHotKey will be more robust
zadjii-msft Jan 28, 2021
18d1a20
Add support for the `win` key in keybindings
zadjii-msft Jan 28, 2021
a41bee6
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
6e7ea61
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
18099d2
Summon the most recent window
zadjii-msft Jan 28, 2021
3e5d927
Cleanup, now that this isn't needed
zadjii-msft Jan 28, 2021
91b52d4
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
848682a
Oh hey SetForegroundWindow might be the thing
zadjii-msft Jan 28, 2021
1dcb4cb
man this is crisp
zadjii-msft Jan 28, 2021
fee6473
Still trying to figure this out exactly. For linking: #653
zadjii-msft Jan 28, 2021
342d3f2
This works if the window _isn't_ minimized
zadjii-msft Jan 29, 2021
5052d31
deal with minimized windows too
zadjii-msft Jan 29, 2021
eff18d1
more cleanup
zadjii-msft Jan 29, 2021
5c039ea
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 12, 2021
10779ca
We caan now summon based on window name or just use the MRU one. Note…
zadjii-msft Apr 12, 2021
25b31ff
Allow the user to set multiple globalSummon keys, and quakeMode for s…
zadjii-msft Apr 12, 2021
7c2a514
if there is no window with the name, then make a new window with the …
zadjii-msft Apr 12, 2021
ac8fef0
THATS RIGHT, IT HOT-RELOADS
zadjii-msft Apr 12, 2021
1fdb6b1
Tests and doc comments
zadjii-msft Apr 14, 2021
784ec73
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 14, 2021
b20222f
More comments
zadjii-msft Apr 14, 2021
9d76c62
Some dead code cleanup
zadjii-msft Apr 14, 2021
2a2f5cb
pre emptive spellbot
zadjii-msft Apr 14, 2021
71577fc
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 16, 2021
f892752
Add some tracelogging to find a heisenbug that might not have ever be…
zadjii-msft Apr 16, 2021
4166afa
Okay that was bad pre-emptive spelling
zadjii-msft Apr 16, 2021
717db81
Again, nobody's got disk space to build x86. This is a guess
zadjii-msft Apr 19, 2021
1b2e7a7
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 19, 2021
305e627
oh man, this will magic summon the window to the current desktop. I'm…
zadjii-msft Apr 19, 2021
9f9eacb
!! THIS NEEDS TO GO TO THE PARENT BRANCH !!
zadjii-msft Apr 19, 2021
f71c948
Add support for summoning to the current virtual desktop
zadjii-msft Apr 19, 2021
51617cf
cache these results
zadjii-msft Apr 20, 2021
2eec961
All of carlos's feedback
zadjii-msft Apr 21, 2021
15a8a9c
!! THIS NEEDS TO GO TO THE PARENT BRANCH !!
zadjii-msft Apr 19, 2021
8370789
replace todo with comment
zadjii-msft Apr 21, 2021
4eb1d3a
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 23, 2021
c215a97
Merge branch 'dev/migrie/f/653-QUAKE-MODE' into dev/migrie/f/quake-to…
zadjii-msft Apr 23, 2021
26d5194
this test is _fantastic_
zadjii-msft Apr 23, 2021
91372ea
more tests, because I like being thorough
zadjii-msft Apr 23, 2021
045a8db
fix a build break
zadjii-msft Apr 23, 2021
c95a429
Give Clint the credit they deserce
zadjii-msft Apr 26, 2021
b5e0f2d
When the window is summoned and is already active, minimize it.
zadjii-msft Apr 26, 2021
6c4238b
Toggle the visibility with an optional argument
zadjii-msft Apr 26, 2021
0abd963
update the comment
zadjii-msft Apr 26, 2021
643b860
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 27, 2021
84c1bd9
Merge remote-tracking branch 'origin/main' into dev/migrie/f/quake-to…
zadjii-msft Apr 28, 2021
24bfbe6
BODGY fix for newer builds
zadjii-msft Apr 28, 2021
4c2e6d2
Merge remote-tracking branch 'origin/main' into dev/migrie/f/quake-to…
zadjii-msft Apr 28, 2021
aec2561
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 28, 2021
22036c2
Merge branch 'dev/migrie/f/653-QUAKE-MODE' into dev/migrie/f/quake-to…
zadjii-msft Apr 28, 2021
5940f05
Merge remote-tracking branch 'origin/main' into dev/migrie/f/653-QUAK…
zadjii-msft Apr 28, 2021
06cb41b
Address Dustin's PR comments
zadjii-msft Apr 28, 2021
783be75
Merge branch 'dev/migrie/f/653-QUAKE-MODE' into dev/migrie/f/quake-to…
zadjii-msft Apr 28, 2021
6c424f7
pr nits
zadjii-msft Apr 28, 2021
387d675
Merge branch 'dev/migrie/f/quake-toCurrent-desktop' into dev/migrie/f…
zadjii-msft Apr 28, 2021
1032dbb
Squash merge of Toggle Visibility
DHowett Apr 28, 2021
242f3e2
Merge branch 'dev/migrie/f/quake-toggleVisibility' of https://github.…
zadjii-msft Apr 28, 2021
3e3cb1d
that's what I get for making changes w/o building
zadjii-msft Apr 28, 2021
53e3fe9
Fix calling convention for COM impls
DHowett Apr 28, 2021
fffda9f
surprised we didn't already have one of these..
DHowett Apr 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ICustom
IDialog
IDirect
IExplorer
IFACEMETHOD
IFile
IInheritable
IMap
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/Peasant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TraceLoggingWrite(g_hRemotingProvider,
"Peasant_Summon",
TraceLoggingUInt64(GetID(), "peasantID", "Our ID"),
TraceLoggingUInt64(localCopy->MoveToCurrentDesktop(), "MoveToCurrentDesktop", "true if we should move to the current desktop"),
TraceLoggingUInt64(localCopy.MoveToCurrentDesktop(), "MoveToCurrentDesktop", "true if we should move to the current desktop"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

_SummonRequestedHandlers(*this, localCopy);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Microsoft.Terminal.Remoting
[default_interface] runtimeclass SummonWindowBehavior {
SummonWindowBehavior();
Boolean MoveToCurrentDesktop;
Boolean ToggleVisibility;
// Other options:
// * CurrentMonitor
}
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/Remoting/SummonWindowBehavior.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
public:
SummonWindowBehavior() = default;
WINRT_PROPERTY(bool, MoveToCurrentDesktop, true);
WINRT_PROPERTY(bool, ToggleVisibility, true);

public:
SummonWindowBehavior(const Remoting::SummonWindowBehavior& other) :
_MoveToCurrentDesktop{ other.MoveToCurrentDesktop() } {};
_MoveToCurrentDesktop{ other.MoveToCurrentDesktop() },
_ToggleVisibility{ other.ToggleVisibility() } {};
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
GlobalSummonArgs() = default;
WINRT_PROPERTY(winrt::hstring, Name, L"");
WINRT_PROPERTY(Model::DesktopBehavior, Desktop, Model::DesktopBehavior::ToCurrent);
WINRT_PROPERTY(bool, ToggleVisibility, true);

static constexpr std::string_view NameKey{ "name" };
static constexpr std::string_view DesktopKey{ "desktop" };
static constexpr std::string_view ToggleVisibilityKey{ "toggleVisibility" };

public:
hstring GenerateName() const;
Expand All @@ -1057,7 +1059,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
if (auto otherAsUs = other.try_as<GlobalSummonArgs>())
{
return otherAsUs->_Name == _Name &&
otherAsUs->_Desktop == _Desktop;
otherAsUs->_Desktop == _Desktop &&
otherAsUs->_ToggleVisibility == _ToggleVisibility;
}
return false;
};
Expand All @@ -1067,13 +1070,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto args = winrt::make_self<GlobalSummonArgs>();
JsonUtils::GetValueForKey(json, NameKey, args->_Name);
JsonUtils::GetValueForKey(json, DesktopKey, args->_Desktop);
JsonUtils::GetValueForKey(json, ToggleVisibilityKey, args->_ToggleVisibility);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<GlobalSummonArgs>() };
copy->_Name = _Name;
copy->_Desktop = _Desktop;
copy->_ToggleVisibility = _ToggleVisibility;
return *copy;
}
// SPECIAL! This deserializer creates a GlobalSummonArgs with the
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,6 @@ namespace Microsoft.Terminal.Settings.Model
{
String Name { get; };
DesktopBehavior Desktop { get; };
Boolean ToggleVisibility { get; };
};
}
9 changes: 6 additions & 3 deletions src/cascadia/UnitTests_Remoting/RemotingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ namespace RemotingUnitTests
{
struct MockDesktopManager : implements<MockDesktopManager, IVirtualDesktopManager>
{
HRESULT GetWindowDesktopId(HWND /*topLevelWindow*/, GUID* /*desktopId*/)
IFACEMETHOD(GetWindowDesktopId)
(HWND /*topLevelWindow*/, GUID* /*desktopId*/)
{
VERIFY_IS_TRUE(false, L"We shouldn't need GetWindowDesktopId in the tests.");
return E_FAIL;
}
HRESULT MoveWindowToDesktop(HWND /*topLevelWindow*/, REFGUID /*desktopId*/)
IFACEMETHOD(MoveWindowToDesktop)
(HWND /*topLevelWindow*/, REFGUID /*desktopId*/)
{
VERIFY_IS_TRUE(false, L"We shouldn't need GetWindowDesktopId in the tests.");
return E_FAIL;
}
HRESULT IsWindowOnCurrentVirtualDesktop(HWND topLevelWindow, BOOL* onCurrentDesktop)
IFACEMETHOD(IsWindowOnCurrentVirtualDesktop)
Copy link
Member

Choose a reason for hiding this comment

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

yes clang-format did this no i don't like it but oh well

(HWND topLevelWindow, BOOL* onCurrentDesktop)
{
if (pfnIsWindowOnCurrentVirtualDesktop)
{
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ void AppHost::_DispatchCommandline(winrt::Windows::Foundation::IInspectable /*se
{
// Summon the window whenever we dispatch a commandline to it. This will
// make it obvious when a new tab/pane is created in a window.
_window->SummonWindow();
_window->SummonWindow(false);
_logic.ExecuteCommandline(args.Commandline(), args.CurrentDirectory());
}

Expand Down Expand Up @@ -692,6 +692,7 @@ void AppHost::_GlobalHotkeyPressed(const long hotkeyIndex)
// desktop:onCurrent - MoveToCurrentDesktop=false, OnCurrentDesktop=true
args.OnCurrentDesktop(summonArgs.Desktop() == Settings::Model::DesktopBehavior::OnCurrent);
args.SummonBehavior().MoveToCurrentDesktop(summonArgs.Desktop() == Settings::Model::DesktopBehavior::ToCurrent);
args.SummonBehavior().ToggleVisibility(summonArgs.ToggleVisibility());

_windowManager.SummonWindow(args);
if (args.FoundMatch())
Expand Down Expand Up @@ -774,7 +775,7 @@ bool AppHost::_LazyLoadDesktopManager()
void AppHost::_HandleSummon(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const Remoting::SummonWindowBehavior& args)
{
_window->SummonWindow();
_window->SummonWindow(args.ToggleVisibility());

if (args != nullptr && args.MoveToCurrentDesktop())
{
Expand Down
44 changes: 40 additions & 4 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,33 @@ void IslandWindow::SetGlobalHotkeys(const std::vector<winrt::Microsoft::Terminal
}
}

// Method Description:
// - Summon the window, or possibly dismiss it. If toggleVisibility is true,
// then we'll dismiss (minimize) the window if it's currently active.
// Otherwise, we'll always just try to activate the window.
// Arguments:
// - toggleVisibility: controls how we should behave when already in the foreground.
// Return Value:
// - <none>
winrt::fire_and_forget IslandWindow::SummonWindow(const bool toggleVisibility)
{
// On the foreground thread:
co_await winrt::resume_foreground(_rootGrid.Dispatcher());

// * If the user doesn't want to toggleVisibility, then just always try to
// activate.
// * If the user does want to toggleVisibility, then dismiss the window if
// we're the current foreground window.
if (toggleVisibility && GetForegroundWindow() == _window.get())
{
_globalDismissWindow();
}
else
{
_globalActivateWindow();
}
}

// Method Description:
// - Force activate this window. This method will bring us to the foreground and
// activate us. If the window is minimized, it will restore the window. If the
Expand All @@ -1007,11 +1034,8 @@ void IslandWindow::SetGlobalHotkeys(const std::vector<winrt::Microsoft::Terminal
// - <none>
// Return Value:
// - <none>
winrt::fire_and_forget IslandWindow::SummonWindow()
void IslandWindow::_globalActivateWindow()
{
// On the foreground thread:
co_await winrt::resume_foreground(_rootGrid.Dispatcher());

// From: https://stackoverflow.com/a/59659421
// > The trick is to make windows ‘think’ that our process and the target
// > window (hwnd) are related by attaching the threads (using
Expand Down Expand Up @@ -1039,6 +1063,18 @@ winrt::fire_and_forget IslandWindow::SummonWindow()
LOG_LAST_ERROR_IF_NULL(SetActiveWindow(_window.get()));
}

// Method Description:
// - Minimize the window. This is called when the window is summoned, but is
// already active
// Arguments:
// - <none>
// Return Value:
// - <none>
void IslandWindow::_globalDismissWindow()
{
LOG_IF_WIN32_BOOL_FALSE(ShowWindow(_window.get(), SW_MINIMIZE));
}

bool IslandWindow::IsQuakeWindow() const noexcept
{
return _isQuakeWindow;
Expand Down
5 changes: 4 additions & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IslandWindow :
void UnsetHotkeys(const std::vector<winrt::Microsoft::Terminal::Control::KeyChord>& hotkeyList);
void SetGlobalHotkeys(const std::vector<winrt::Microsoft::Terminal::Control::KeyChord>& hotkeyList);

winrt::fire_and_forget SummonWindow();
winrt::fire_and_forget SummonWindow(const bool toggleVisibility);

bool IsQuakeWindow() const noexcept;
void IsQuakeWindow(bool isQuakeWindow) noexcept;
Expand Down Expand Up @@ -93,6 +93,9 @@ class IslandWindow :
void _OnGetMinMaxInfo(const WPARAM wParam, const LPARAM lParam);
long _calculateTotalSize(const bool isWidth, const long clientSize, const long nonClientSize);

void _globalActivateWindow();
void _globalDismissWindow();

bool _isQuakeWindow{ false };
void _enterQuakeMode();

Expand Down