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

Stop rendering when the terminal has been minimized/control has been hidden #1989

Open
Tracked by #9600
zadjii-msft opened this issue Jul 16, 2019 · 4 comments
Open
Tracked by #9600
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Milestone

Comments

@zadjii-msft
Copy link
Member

Ported from MSFT:21315817

We shouldn't render the XAML island when we're minimized.

I don't remember any more of the context on this one. It was assigned to @DHowett-MSFT, so he might remember.

@zadjii-msft zadjii-msft added Area-User Interface Issues pertaining to the user interface of the Console or Terminal Product-Terminal The new Windows Terminal. Issue-Task It's a feature request, but it doesn't really need a major design. labels Jul 16, 2019
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Jul 16, 2019
@ghost ghost added the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Jul 16, 2019
@DHowett-MSFT
Copy link
Contributor

Notes: when the terminal is minimized, we should just stop rendering. Right now, we don't do any detection that the app is not visible or that the tab the terminal is on has lost focus. We're probably spinning a lot of resources in the background to render invisible things.

@DHowett-MSFT DHowett-MSFT added Help Wanted We encourage anyone to jump in on these. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 20, 2019
@AmineI
Copy link

AmineI commented Jun 16, 2020

I'll add that heavy background gifs also continue using resources when the window is minimized. However a simple workaround is to switch to a tab with a static background before minimizing !

@mailinglists35
Copy link

When you work on fixing this, please also consider the case where the app is not minimized, but it has scrolling activity in inactive tabs.

Here's a quick reproductible case:

Open two WSL1 tabs on windows 10
on first tab use ssh command to remote login to a linux server, on remote server issue journalctl -f / tail -f to watch logs
change to second tab

open System Informer, formerly known as Process Hacker, find and double click the WindowsTerminal.exe process, then switch to Performance tab.

intervals with zero cpu usage at the beginning and end of the graph are when text scrolling is happening in the inactive invisible tab
middle interval with cpu usage is when the scrolling is not happening in that tab (before invoking log watching command/after stopping command)

image

@zadjii-msft
Copy link
Member Author

zadjii-msft commented Feb 21, 2023

Note

Walkthrough

Most of this would be plumbing.

  • Determine if the window was minimized or hidden, or not in IslandWindow. I think we already have a handler for this to minimize to the tray.
  • Plumb that through a WINRT_CALLBACK to AppHost, who would then plumb that to the AppLogic (or TerminalWindow after Split AppLogic into "App logic" and "Window logic" #14825 merges), and from there into the TerminalPage.
  • In TerminalPage, track that state, and use WalkTree to update each of the TermControls when the minimized state changes
  • Also in TerminalPage / TabManagement.cpp, track when the active tab changes. Each control should only have rendering enabled if (!_windowMinimized) && (tab.IsActive()) (variables / method manes made up in this case)
  • In TermControl, plumb the "rendering active" state into ControlCore
  • Here's where it gets tricky: how exactly do we pause / re-enable the renderer? Do we need to stop the Renderer? The AtlasEngine/DxEngine? Not really sure there. Seems like it'd be easy for the engines to have a flag set and just no-op on any paintframe. 1
  • We'll almost certainly need to do an InvalidateAll / TriggerRedrawAll when re-enabling rendering.

Another method we considered was registering some event in TermControl to auto-detect when a control is added / removed from the UI tree. Turns out this is a Hard problem in WinUI, and probably not the way to go.

Notes about this
  • There's no event that's good for this. Visibility doesn't get changed in this case.
  • There's an internal mail thread titled Quick questions about detecting UI element visibility that might be relevant here.
  • That thread linked Loaded/Unloaded/IsLoaded APIs break down on quick swapping microsoft-ui-xaml#1900
  • It also recommended code like:
      Element.OnLoaded += () => { LoadedChanged(element); }
      Element.Loaded += () => { LoadedChanged(element); }
    
      void LoadedChanged(element)
      {
          if (element.IsLoaded) { /*do idempotent loaded things*/ }
          else { /*do idempotent unloaded things*/ }
      }
    • However:

      Aw crud, I see that in the code too ☹ This is more difficult that I realized. From the code, looks like if it’s going from loaded to unloaded, IsLoaded will be correct, but if it’s going from unloaded to loaded, it won’t be true until the Loaded event fires.

    • just check Parent for non-null rather than checking IsLoaded


Footnotes

  1. Someone once noted "Seems like toggling requiresContinuousRedraw in AtlasEngine would be a straightforward path.". I dunno if that's true or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-User Interface Issues pertaining to the user interface of the Console or Terminal Help Wanted We encourage anyone to jump in on these. Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
Status: Walkthrough in issue
Development

No branches or pull requests

4 participants