Skip to content

Commit c5f360a

Browse files
committed
only one expanded at a time
1 parent 0306938 commit c5f360a

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

App/Controls/ExpandContent.xaml

-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@
1818
<VisualStateGroup>
1919
<VisualState x:Name="ExpandedState">
2020
<Storyboard>
21-
<ObjectAnimationUsingKeyFrames
22-
Storyboard.TargetName="CollapsiblePanel"
23-
Storyboard.TargetProperty="Visibility">
24-
25-
<DiscreteObjectKeyFrame KeyTime="0">
26-
<DiscreteObjectKeyFrame.Value>
27-
<Visibility>Visible</Visibility>
28-
</DiscreteObjectKeyFrame.Value>
29-
</DiscreteObjectKeyFrame>
30-
</ObjectAnimationUsingKeyFrames>
3121
<DoubleAnimation
3222
Storyboard.TargetName="CollapsiblePanel"
3323
Storyboard.TargetProperty="Opacity"

App/ViewModels/TrayWindowViewModel.cs

+10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ private void UpdateFromRpcModel(RpcModel rpcModel)
190190
credentialModel.CoderUrl,
191191
workspace.Name));
192192

193+
foreach (var agent in agents)
194+
agent.PropertyChanged += (_, args) =>
195+
{
196+
// When an agent is expanded:
197+
if (args.PropertyName == nameof(AgentViewModel.IsExpanded) && agent.IsExpanded)
198+
// Collapse every other agent.
199+
foreach (var otherAgent in Agents.Where(a => a.Id != agent.Id && a.IsExpanded))
200+
otherAgent.IsExpanded = false;
201+
};
202+
193203
// Sort by status green, red, gray, then by hostname.
194204
ModelUpdate.ApplyLists(Agents, agents, (a, b) =>
195205
{

App/Views/Pages/TrayWindowMainPage.xaml

+12-6
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,22 @@
232232
</Grid>
233233

234234
<controls:ExpandContent IsOpen="{x:Bind IsExpanded, Mode=OneWay}">
235-
<TextBlock
236-
Text="{x:Bind ExpandAppsMessage, Mode=OneWay}"
237-
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
238-
Margin="10,8,10,16"
239-
TextAlignment="Center"
240-
Visibility="{x:Bind ShowExpandAppsMessage, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
235+
<Grid
236+
Height="34"
237+
Visibility="{x:Bind ShowExpandAppsMessage, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
238+
239+
<TextBlock
240+
Text="{x:Bind ExpandAppsMessage, Mode=OneWay}"
241+
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
242+
TextAlignment="Center"
243+
VerticalAlignment="Center"
244+
Margin="0,-1,0,0" />
245+
</Grid>
241246

242247
<ItemsRepeater
243248
ItemsSource="{x:Bind VisibleApps, Mode=OneWay}"
244249
Visibility="{x:Bind ShowExpandAppsMessage, Converter={StaticResource InverseBoolToVisibilityConverter}, Mode=OneWay}"
250+
Height="34"
245251
Margin="17,0">
246252

247253
<ItemsRepeater.Layout>

App/Views/TrayWindow.xaml.cs

+32-21
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)