Skip to content

Commit ba83f36

Browse files
committed
refactor: replace Border with MacOSTrafficLightsSpacer to hold the area of macOS traffic lights
Signed-off-by: leo <longshuang@msn.cn>
1 parent ec6736a commit ba83f36

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

src/Views/ChromelessWindow.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using Avalonia;
2+
33
using Avalonia.Controls;
44
using Avalonia.Controls.Primitives;
55
using Avalonia.Input;
@@ -8,15 +8,6 @@ namespace SourceGit.Views
88
{
99
public class ChromelessWindow : Window
1010
{
11-
public static readonly StyledProperty<double> MacOSWindowButtonWidthProperty =
12-
AvaloniaProperty.Register<ChromelessWindow, double>(nameof(MacOSWindowButtonWidth), 76.0);
13-
14-
public double MacOSWindowButtonWidth
15-
{
16-
get => GetValue(MacOSWindowButtonWidthProperty);
17-
set => SetValue(MacOSWindowButtonWidthProperty, value);
18-
}
19-
2011
public bool UseSystemWindowFrame
2112
{
2213
get => Native.OS.UseSystemWindowFrame;
@@ -32,7 +23,6 @@ public bool CloseOnESC
3223

3324
public ChromelessWindow()
3425
{
35-
MacOSWindowButtonWidth = 76.0 / Math.Max(1.0, ViewModels.Preferences.Instance.Zoom);
3626
Focusable = true;
3727
Native.OS.SetupForWindow(this);
3828
}
@@ -104,14 +94,12 @@ protected override void OnKeyDown(KeyEventArgs e)
10494
{
10595
var zoom = Math.Min(ViewModels.Preferences.Instance.Zoom + 0.05, 2.5);
10696
ViewModels.Preferences.Instance.Zoom = zoom;
107-
MacOSWindowButtonWidth = 76.0 / zoom;
10897
e.Handled = true;
10998
}
11099
else if (e.Key == Key.OemMinus)
111100
{
112101
var zoom = Math.Max(ViewModels.Preferences.Instance.Zoom - 0.05, 1);
113102
ViewModels.Preferences.Instance.Zoom = zoom;
114-
MacOSWindowButtonWidth = 76.0 / zoom;
115103
e.Handled = true;
116104
}
117105
}

src/Views/Launcher.axaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
PointerPressed="BeginMoveWindow"/>
2929

3030
<!-- Caption Buttons (macOS) -->
31-
<Border Grid.Column="0" Width="{Binding #ThisControl.MacOSWindowButtonWidth}" IsVisible="{Binding #ThisControl.HasLeftCaptionButton}"/>
31+
<v:MacOSTrafficLightsSpacer Grid.Column="0"
32+
Zoom="{Binding Source={x:Static vm:Preferences.Instance}, Path=Zoom, Mode=OneWay}"
33+
IsVisible="{Binding #ThisControl.HasLeftCaptionButton}"/>
3234

3335
<!-- Menu (Windows/Linux) -->
3436
<Button Grid.Column="0" Classes="icon_button" VerticalAlignment="Bottom" Margin="6,0,0,3" IsVisible="{OnPlatform True, macOS=False}">
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
4+
namespace SourceGit.Views
5+
{
6+
public class MacOSTrafficLightsSpacer : Control
7+
{
8+
public static readonly StyledProperty<double> ZoomProperty =
9+
AvaloniaProperty.Register<MacOSTrafficLightsSpacer, double>(nameof(Zoom), 1.0);
10+
11+
public double Zoom
12+
{
13+
get => GetValue(ZoomProperty);
14+
set => SetValue(ZoomProperty, value);
15+
}
16+
17+
public MacOSTrafficLightsSpacer()
18+
{
19+
IsHitTestVisible = false;
20+
}
21+
22+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
23+
{
24+
base.OnPropertyChanged(change);
25+
26+
if (change.Property == ZoomProperty)
27+
InvalidateMeasure();
28+
}
29+
30+
protected override Size MeasureOverride(Size availableSize)
31+
{
32+
return new Size(76.0 / Zoom, 24.0);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)