@@ -25,6 +25,7 @@ public sealed partial class TrayWindow : Window
2525 private const int WIDTH = 300 ;
2626
2727 private NativeApi . POINT ? _lastActivatePosition ;
28+ private int _maxHeightSinceLastActivation ;
2829
2930 private readonly IRpcController _rpcController ;
3031 private readonly ICredentialManager _credentialManager ;
@@ -139,30 +140,22 @@ public void SetRootFrame(Page page)
139140
140141 private void RootFrame_SizeChanged ( object sender , SizedFrameEventArgs e )
141142 {
142- ResizeWindow ( e . NewSize . Height ) ;
143- MoveWindow ( ) ;
143+ MoveAndResize ( e . NewSize . Height ) ;
144144 }
145145
146- private void ResizeWindow ( )
146+ private void MoveAndResize ( double height )
147147 {
148- ResizeWindow ( RootFrame . GetContentSize ( ) . Height ) ;
149- }
150-
151- private void ResizeWindow ( double height )
152- {
153- if ( height <= 0 ) height = 100 ; // will be resolved next frame typically
154-
155- var scale = DisplayScale . WindowScale ( this ) ;
156- var newWidth = ( int ) ( WIDTH * scale ) ;
157- var newHeight = ( int ) ( height * scale ) ;
158- AppWindow . Resize ( new SizeInt32 ( newWidth , newHeight ) ) ;
148+ var size = CalculateWindowSize ( height ) ;
149+ var pos = CalculateWindowPosition ( size ) ;
150+ var rect = new RectInt32 ( pos . X , pos . Y , size . Width , size . Height ) ;
151+ AppWindow . MoveAndResize ( rect ) ;
159152 }
160153
161154 private void MoveResizeAndActivate ( )
162155 {
163156 SaveCursorPos ( ) ;
164- ResizeWindow ( ) ;
165- MoveWindow ( ) ;
157+ _maxHeightSinceLastActivation = 0 ;
158+ MoveAndResize ( RootFrame . GetContentSize ( ) . Height ) ;
166159 AppWindow . Show ( ) ;
167160 NativeApi . SetForegroundWindow ( WindowNative . GetWindowHandle ( this ) ) ;
168161 }
@@ -179,15 +172,33 @@ private void SaveCursorPos()
179172 _lastActivatePosition = null ;
180173 }
181174
182- private void MoveWindow ( )
175+ private SizeInt32 CalculateWindowSize ( double height )
183176 {
184- AppWindow . Move ( GetWindowPosition ( ) ) ;
177+ if ( height <= 0 ) height = 100 ; // will be resolved next frame typically
178+
179+ var scale = DisplayScale . WindowScale ( this ) ;
180+ var newWidth = ( int ) ( WIDTH * scale ) ;
181+ var newHeight = ( int ) ( height * scale ) ;
182+ // Store the maximum height we've seen for positioning purposes.
183+ if ( newHeight > _maxHeightSinceLastActivation )
184+ _maxHeightSinceLastActivation = newHeight ;
185+
186+ return new SizeInt32 ( newWidth , newHeight ) ;
185187 }
186188
187- private PointInt32 GetWindowPosition ( )
189+ private PointInt32 CalculateWindowPosition ( SizeInt32 size )
188190 {
189- var height = AppWindow . Size . Height ;
190- var width = AppWindow . Size . Width ;
191+ var width = size . Width ;
192+ var height = size . Height ;
193+ // For positioning purposes, pretend the window is the maximum size it
194+ // has been since it was last activated. This has the affect of
195+ // allowing the window to move up to accomodate more content, but
196+ // prevents it from moving back down when the window shrinks again.
197+ //
198+ // Prevents a lot of jittery behavior with app drawers.
199+ if ( height < _maxHeightSinceLastActivation )
200+ height = _maxHeightSinceLastActivation ;
201+
191202 var cursorPosition = _lastActivatePosition ;
192203 if ( cursorPosition is null )
193204 {
0 commit comments