Repository: microsoft/terminal (language: cpp)

Issue:
Windows Terminal Alt+F4 behaviour
### Windows Terminal version

1.20.11781.0

### Windows build number

10.0.22631.3880

### Other Software

Also reproducible in:
Windows Terminal Preview
Version: 1.21.1772.0

### Steps to reproduce

1. Start Windows Terminal.
2. Open Settings -> Interaction -> Warn when closing more than one tab -> On -> Save.
3. Close Settings tab and open any second terminal tab.
4. Try to close terminal window with the X button in the upper right corner. It will ask for confirmation.
5. Try to close terminal window with Alt+F4 shortcut. It will close window without confirmation.
6. When Settings tab is active, it sometimes asks for confilmation when I press Alt+F4, but mostly not.

### Expected Behavior

Windows Terminal should ask for confirmation when closing window in any way: titlebar button, Alt+F4, Alt+Space menu, Taskbar menu, etc.

### Actual Behavior

Pressing Alt+F4 shortcut will close Window Terminal window without confirmation, but pressing title bar 'close' button shows confirmation according to "Settings -> Interaction -> Warn when closing more than one tab" configuration.


Discussion / hints:
I think this may be a known problem, because there are a few open issues related to the close confirmation that could potentially cover this scenario. Possibly #2976 or #6549.
Indeed, looks like those are similar, but I think this case is quite straightforward and could be fixed directly, without discussion of complex logic and consequences.
Actually, Alt+F4 seems to be the only unhandled way of closing the window. Alt+Space menu, taskbar menu and close button all show confirmations correctly.
So this was fixed a long time ago (see #2526), but it creeped up again?

I did a work-around by reassigning `alt+f4` to [`quit`](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#quit):

```json
{ "command": "quit", "keys": "alt+f4" }
```

`quit` shows a confirmation dialog asking to close the window, regardless if [`confirmCloseAllTabs`](https://learn.microsoft.com/en-us/windows/terminal/customize-settings/appearance#show-close-all-tabs-popup) setting is explicitly set to `false` or not present.
@codenotworking , thanks, with this workaround it indeed asks confirmation, but it's for the whole app now. Still, its better than nothing. Feels safer with confirmation :)
Can't wait for this to be added. 

When you have 4 tabs open, and some of the tabs have 6 carefully arranged panes, some monitoring active processes 

And you have 4 screens, so you think your Alt-F4 is going to the app under your mouse pointer, but you haven't actually clicked it yet...

...BAM! LOST ALL THAT WORK! OMG

Can't wait for this to be fixed :) 
I'd like to work on this issue. 

Fix patch:
diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp
index 7b4893fef1a..b2ae698205a 100644
--- a/src/cascadia/TerminalApp/AppActionHandlers.cpp
+++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp
@@ -118,7 +118,7 @@ namespace winrt::TerminalApp::implementation
     void TerminalPage::_HandleCloseWindow(const IInspectable& /*sender*/,
                                           const ActionEventArgs& args)
     {
-        CloseRequested.raise(nullptr, nullptr);
+        CloseWindow();
         args.Handled(true);
     }
 
diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h
index 87e7b17437b..23258c25095 100644
--- a/src/cascadia/TerminalApp/TerminalPage.h
+++ b/src/cascadia/TerminalApp/TerminalPage.h
@@ -182,7 +182,6 @@ namespace winrt::TerminalApp::implementation
         til::typed_event<IInspectable, IInspectable> SummonWindowRequested;
         til::typed_event<IInspectable, winrt::Microsoft::Terminal::Control::WindowSizeChangedEventArgs> WindowSizeChanged;
 
-        til::typed_event<IInspectable, IInspectable> CloseRequested;
         til::typed_event<IInspectable, IInspectable> OpenSystemMenu;
         til::typed_event<IInspectable, IInspectable> QuitRequested;
         til::typed_event<IInspectable, winrt::Microsoft::Terminal::Control::ShowWindowArgs> ShowWindowChanged;
diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl
index 2679d775b09..2788cedd10c 100644
--- a/src/cascadia/TerminalApp/TerminalPage.idl
+++ b/src/cascadia/TerminalApp/TerminalPage.idl
@@ -95,7 +95,6 @@ namespace TerminalApp
         event Windows.Foundation.TypedEventHandler<Object, Object> SummonWindowRequested;
         event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Control.WindowSizeChangedEventArgs> WindowSizeChanged;
 
-        event Windows.Foundation.TypedEventHandler<Object, Object> CloseRequested;
         event Windows.Foundation.TypedEventHandler<Object, Object> OpenSystemMenu;
         event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Control.ShowWindowArgs> ShowWindowChanged;
 
diff --git a/src/cascadia/TerminalApp/TerminalWindow.h b/src/cascadia/TerminalApp/TerminalWindow.h
index a722468a547..7467b64241d 100644
--- a/src/cascadia/TerminalApp/TerminalWindow.h
+++ b/src/cascadia/TerminalApp/TerminalWindow.h
@@ -219,7 +219,6 @@ namespace winrt::TerminalApp::implementation
         FORWARDED_TYPED_EVENT(SetTaskbarProgress, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, SetTaskbarProgress);
         FORWARDED_TYPED_EVENT(IdentifyWindowsRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IdentifyWindowsRequested);
         FORWARDED_TYPED_EVENT(SummonWindowRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, SummonWindowRequested);
-        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);
diff --git a/src/cascadia/TerminalApp/TerminalWindow.idl b/src/cascadia/TerminalApp/TerminalWindow.idl
index 24ce090e378..f0bf2a98bd2 100644
--- a/src/cascadia/TerminalApp/TerminalWindow.idl
+++ b/src/cascadia/TerminalApp/TerminalWindow.idl
@@ -122,7 +122,6 @@ namespace TerminalApp
         event Windows.Foundation.TypedEventHandler<Object, Object> IdentifyWindowsRequested;
         event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
         event Windows.Foundation.TypedEventHandler<Object, Object> SummonWindowRequested;
-        event Windows.Foundation.TypedEventHandler<Object, Object> CloseRequested;
         event Windows.Foundation.TypedEventHandler<Object, Object> OpenSystemMenu;
         event Windows.Foundation.TypedEventHandler<Object, Object> QuitRequested;
         event Windows.Foundation.TypedEventHandler<Object, TerminalApp.SystemMenuChangeArgs> SystemMenuChangeRequested;
diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp
index ac255aa95b2..0fd623aad61 100644
--- a/src/cascadia/WindowsTerminal/AppHost.cpp
+++ b/src/cascadia/WindowsTerminal/AppHost.cpp
@@ -213,9 +213,6 @@ void AppHost::Initialize()
     _windowCallbacks.WindowCloseButtonClicked = _window->WindowCloseButtonClicked([this]() {
         _windowLogic.CloseWindow();
     });
-    // If the user requests a close in another way handle the same as if the 'X'
-    // was clicked.
-    _revokers.CloseRequested = _windowLogic.CloseRequested(winrt::auto_revoke, { this, &AppHost::_CloseRequested });
 
     // Add an event handler to plumb clicks in the titlebar area down to the
     // application layer.
diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h
index fba8274b176..be987ef0c7a 100644
--- a/src/cascadia/WindowsTerminal/AppHost.h
+++ b/src/cascadia/WindowsTerminal/AppHost.h
@@ -138,7 +138,6 @@ class AppHost : public std::enable_shared_from_this<AppHost>
     struct Revokers
     {
         winrt::TerminalApp::TerminalWindow::Initialized_revoker Initialized;
-        winrt::TerminalApp::TerminalWindow::CloseRequested_revoker CloseRequested;
         winrt::TerminalApp::TerminalWindow::RequestedThemeChanged_revoker RequestedThemeChanged;
         winrt::TerminalApp::TerminalWindow::FullscreenChanged_revoker FullscreenChanged;
         winrt::TerminalApp::TerminalWindow::FocusModeChanged_revoker FocusModeChanged;


Test patch: