Repository: microsoft/terminal (language: cpp)

Issue:
Windows Terminal Preview - Read-only pane pop-up on tab switch
### Windows Terminal version

Windows Terminal Preview Version: 1.15.1862.0

### Windows build number

10.0.19044.1766

### Other Software

Seems to be on anything I have open in terminal

### Steps to reproduce

Open 3 terminal tabs, PowerShell 7.2.5, Windows PowerShell 5.1, or command prompt. Set a keybind to toggle pane read-only mode (mine is set to ctrl-shift-\), then toggle one of the tabs to read-only.  Click on the 3 tabs in any order.  Pop-up stating "Read-only mode enabled" appears both switching to AND from that read-only tab to/from other tabs.
![image](https://user-images.githubusercontent.com/10885147/178005974-cfd12cb6-97fe-4d85-b09e-a0a0461b1913.png)
![image](https://user-images.githubusercontent.com/10885147/178006790-82ea5764-ea65-4b8a-9aaf-5903485eede1.png)

This doesn't happen in my currently installed non-preview version Windows Terminal Version: 1.13.11431.0 (I should probably update, but I don't use the non-preview version much)

### Expected Behavior

Personally, no popups at all, but if you have to, only when switching to the read-only tab.  I did not try with split panes, I don't use them much, though I like the feature in theory.

### Actual Behavior

Pop-up stating "Read-only mode enabled" appears both switching to AND from that read-only tab to/from other tabs.

I did discover that you can't set the settings tab to read-only, though I can live without that :) 


Discussion / hints:
_oh my god_, I'm confident that this is because of the focus in/out events. We should probably not suppress those, even in read only mode. Trick is, can we get the input generated for those events past the read-only guard simply?
I just updated my non-preview version to 1.14.1861.0 and I get the same bad behavior, just FYI.

Thank you for all the work you all do on making this otherwise awesome software!

Fix patch:
diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp
index 89512563e4c..f71eef421f7 100644
--- a/src/cascadia/TerminalControl/ControlCore.cpp
+++ b/src/cascadia/TerminalControl/ControlCore.cpp
@@ -1912,13 +1912,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
     // - This is related to work done for GH#2988.
     void ControlCore::GotFocus()
     {
-        _terminal->FocusChanged(true);
+        _focusChanged(true);
     }
 
     // See GotFocus.
     void ControlCore::LostFocus()
     {
-        _terminal->FocusChanged(false);
+        _focusChanged(false);
+    }
+
+    void ControlCore::_focusChanged(bool focused)
+    {
+        // GH#13461 - temporarily turn off read-only mode, send the focus event,
+        // then turn it back on. Even in focus mode, focus events are fine to
+        // send. We don't want to pop a warning every time the control is
+        // focused.
+        const auto previous = std::exchange(_isReadOnly, false);
+        const auto restore = wil::scope_exit([&]() { _isReadOnly = previous; });
+        _terminal->FocusChanged(focused);
     }
 
     bool ControlCore::_isBackgroundTransparent()
diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h
index 4208798e10d..948a591bfc4 100644
--- a/src/cascadia/TerminalControl/ControlCore.h
+++ b/src/cascadia/TerminalControl/ControlCore.h
@@ -311,6 +311,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
         void _setOpacity(const double opacity);
 
         bool _isBackgroundTransparent();
+        void _focusChanged(bool focused);
 
         inline bool _IsClosing() const noexcept
         {


Test patch: