@@ -25,6 +25,7 @@ public sealed partial class TrayWindow : Window
25
25
private const int WIDTH = 300 ;
26
26
27
27
private NativeApi . POINT ? _lastActivatePosition ;
28
+ private int _maxHeightSinceLastActivation ;
28
29
29
30
private readonly IRpcController _rpcController ;
30
31
private readonly ICredentialManager _credentialManager ;
@@ -139,30 +140,22 @@ public void SetRootFrame(Page page)
139
140
140
141
private void RootFrame_SizeChanged ( object sender , SizedFrameEventArgs e )
141
142
{
142
- ResizeWindow ( e . NewSize . Height ) ;
143
- MoveWindow ( ) ;
143
+ MoveAndResize ( e . NewSize . Height ) ;
144
144
}
145
145
146
- private void ResizeWindow ( )
146
+ private void MoveAndResize ( double height )
147
147
{
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 ) ;
159
152
}
160
153
161
154
private void MoveResizeAndActivate ( )
162
155
{
163
156
SaveCursorPos ( ) ;
164
- ResizeWindow ( ) ;
165
- MoveWindow ( ) ;
157
+ _maxHeightSinceLastActivation = 0 ;
158
+ MoveAndResize ( RootFrame . GetContentSize ( ) . Height ) ;
166
159
AppWindow . Show ( ) ;
167
160
NativeApi . SetForegroundWindow ( WindowNative . GetWindowHandle ( this ) ) ;
168
161
}
@@ -179,15 +172,33 @@ private void SaveCursorPos()
179
172
_lastActivatePosition = null ;
180
173
}
181
174
182
- private void MoveWindow ( )
175
+ private SizeInt32 CalculateWindowSize ( double height )
183
176
{
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 ) ;
185
187
}
186
188
187
- private PointInt32 GetWindowPosition ( )
189
+ private PointInt32 CalculateWindowPosition ( SizeInt32 size )
188
190
{
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
+
191
202
var cursorPosition = _lastActivatePosition ;
192
203
if ( cursorPosition is null )
193
204
{
0 commit comments