Skip to content

Commit e3c0f7d

Browse files
committed
refactor: rewrite chromeless window (#634)
* use system chrome instead of custom caption button on macOS * move `BeginMoveWindow` and `MaximizeOrRestoreWindow` to `ChromelessWindow` * better supports for fullscreen mode on macOS * redesign the layout of title bar for all windows Signed-off-by: leo <[email protected]>
1 parent 1999e4b commit e3c0f7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+224
-666
lines changed

src/Resources/Icons.axaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@
7171
<StreamGeometry x:Key="Icons.Loading">M512 0C233 0 7 223 0 500C6 258 190 64 416 64c230 0 416 200 416 448c0 53 43 96 96 96s96-43 96-96c0-283-229-512-512-512zm0 1023c279 0 505-223 512-500c-6 242-190 436-416 436c-230 0-416-200-416-448c0-53-43-96-96-96s-96 43-96 96c0 283 229 512 512 512z</StreamGeometry>
7272
<StreamGeometry x:Key="Icons.Local">M976 0h-928A48 48 0 000 48v652a48 48 0 0048 48h416V928H200a48 48 0 000 96h624a48 48 0 000-96H560v-180h416a48 48 0 0048-48V48A48 48 0 00976 0zM928 652H96V96h832v556z</StreamGeometry>
7373
<StreamGeometry x:Key="Icons.Lock">M832 464h-68V240a128 128 0 00-128-128h-248a128 128 0 00-128 128v224H192c-18 0-32 14-32 32v384c0 18 14 32 32 32h640c18 0 32-14 32-32v-384c0-18-14-32-32-32zm-292 237v53a8 8 0 01-8 8h-40a8 8 0 01-8-8v-53a48 48 0 1156 0zm152-237H332V240a56 56 0 0156-56h248a56 56 0 0156 56v224z</StreamGeometry>
74-
<StreamGeometry x:Key="Icons.MacOS.Close">M887 774 625 511l263-260c11-11 11-28 0-39l-75-75c-5-5-12-8-20-8-7 0-14 3-20 8L512 396 250 137c-5-5-12-8-20-8-7 0-14 3-20 8L136 212c-11 11-11 28 0 39l263 260L137 774c-5 5-8 12-8 20 0 7 3 14 8 20l75 75c5 5 12 8 20 8 7 0 14-3 20-8L512 626l261 262c5 5 12 8 20 8 7 0 14-3 20-8l75-75c5-5 8-12 8-20C895 786 892 779 887 774z</StreamGeometry>
75-
<StreamGeometry x:Key="Icons.MacOS.Minimize">M1024 750v110c0 50-41 91-91 91h-841A92 92 0 010 859v-110C0 699 41 658 91 658h841c50 0 91 41 91 91z</StreamGeometry>
76-
<StreamGeometry x:Key="Icons.MacOS.Maximize">M0 4 0 20 16 20 0 4M4 0 20 0 20 16 4 0z</StreamGeometry>
7774
<StreamGeometry x:Key="Icons.Menu">M192 192m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 512m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 832m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM864 160H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 480H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 800H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32z</StreamGeometry>
7875
<StreamGeometry x:Key="Icons.Merge">M824 645V307c0-56-46-102-102-102h-102V102l-154 154 154 154V307h102v338c-46 20-82 67-82 123 0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123zm-51 195c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72zM384 256c0-72-61-133-133-133-72 0-133 61-133 133 0 56 36 102 82 123v266C154 666 118 712 118 768c0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123V379C348 358 384 312 384 256zM323 768c0 41-31 72-72 72-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72zM251 328c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72z</StreamGeometry>
7976
<StreamGeometry x:Key="Icons.Modified">M896 64H128C96 64 64 96 64 128v768c0 32 32 64 64 64h768c32 0 64-32 64-64V128c0-32-32-64-64-64z m-64 736c0 16-17 32-32 32H224c-18 0-32-12-32-32V224c0-16 16-32 32-32h576c15 0 32 16 32 32v576zM512 384c-71 0-128 57-128 128s57 128 128 128 128-57 128-128-57-128-128-128z</StreamGeometry>

src/Views/AIAssistant.axaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,23 @@
1515
WindowStartupLocation="CenterOwner">
1616
<Grid RowDefinitions="Auto,Auto,Auto">
1717
<!-- TitleBar -->
18-
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
19-
<Border Grid.Column="0" Grid.ColumnSpan="3"
20-
Background="{DynamicResource Brush.TitleBar}"
18+
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
19+
<Border Background="{DynamicResource Brush.TitleBar}"
2120
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
2221
PointerPressed="BeginMoveWindow"/>
2322

24-
<Path Grid.Column="0"
25-
Width="14" Height="14"
23+
<Path Width="14" Height="14"
2624
Margin="10,0,0,0"
25+
HorizontalAlignment="Left"
2726
Data="{StaticResource Icons.AIAssist}"
2827
IsVisible="{OnPlatform True, macOS=False}"/>
2928

30-
<v:CaptionButtonsMacOS Grid.Column="0"
31-
Margin="0,2,0,0"
32-
IsCloseButtonOnly="True"
33-
IsVisible="{OnPlatform False, macOS=True}"/>
34-
35-
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
36-
Classes="bold"
29+
<TextBlock Classes="bold"
3730
Text="{DynamicResource Text.AIAssistant}"
3831
HorizontalAlignment="Center" VerticalAlignment="Center"
3932
IsHitTestVisible="False"/>
4033

41-
<v:CaptionButtons Grid.Column="2"
34+
<v:CaptionButtons HorizontalAlignment="Right"
4235
IsCloseButtonOnly="True"
4336
IsVisible="{OnPlatform True, macOS=False}"/>
4437
</Grid>

src/Views/AIAssistant.axaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55

66
using Avalonia.Controls;
7-
using Avalonia.Input;
87
using Avalonia.Threading;
98

109
namespace SourceGit.Views
@@ -55,11 +54,6 @@ protected override void OnClosing(WindowClosingEventArgs e)
5554
_cancel.Cancel();
5655
}
5756

58-
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
59-
{
60-
BeginMoveDrag(e);
61-
}
62-
6357
private void SetDescription(string message)
6458
{
6559
Dispatcher.UIThread.Invoke(() => ProgressMessage.Text = message);

src/Views/About.axaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,23 @@
1313
WindowStartupLocation="CenterScreen">
1414
<Grid RowDefinitions="Auto,*">
1515
<!-- TitleBar -->
16-
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !UseSystemWindowFrame}">
17-
<Border Grid.Column="0" Grid.ColumnSpan="3"
18-
Background="{DynamicResource Brush.TitleBar}"
16+
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !UseSystemWindowFrame}">
17+
<Border Background="{DynamicResource Brush.TitleBar}"
1918
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
2019
PointerPressed="BeginMoveWindow"/>
2120

22-
<Path Grid.Column="0"
23-
Width="14" Height="14"
21+
<Path Width="14" Height="14"
2422
Margin="10,0,0,0"
23+
HorizontalAlignment="Left"
2524
Data="{StaticResource Icons.Info}"
2625
IsVisible="{OnPlatform True, macOS=False}"/>
27-
28-
<v:CaptionButtonsMacOS Grid.Column="0"
29-
Margin="0,2,0,0"
30-
IsCloseButtonOnly="True"
31-
IsVisible="{OnPlatform False, macOS=True}"/>
3226

33-
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
34-
Classes="bold"
27+
<TextBlock Classes="bold"
3528
Text="{DynamicResource Text.About}"
3629
HorizontalAlignment="Center" VerticalAlignment="Center"
3730
IsHitTestVisible="False"/>
3831

39-
<v:CaptionButtons Grid.Column="2"
32+
<v:CaptionButtons HorizontalAlignment="Right"
4033
IsCloseButtonOnly="True"
4134
IsVisible="{OnPlatform True, macOS=False}"/>
4235
</Grid>

src/Views/About.axaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ public About()
2121
InitializeComponent();
2222
}
2323

24-
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
25-
{
26-
BeginMoveDrag(e);
27-
}
28-
2924
private void OnVisitAvaloniaUI(object _, PointerPressedEventArgs e)
3025
{
3126
Native.OS.OpenBrowser("https://www.avaloniaui.net/");

src/Views/Askpass.axaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,23 @@
1313
WindowStartupLocation="CenterScreen">
1414
<Grid RowDefinitions="Auto,*">
1515
<!-- TitleBar -->
16-
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !UseSystemWindowFrame}">
17-
<Border Grid.Column="0" Grid.ColumnSpan="3"
18-
Background="{DynamicResource Brush.TitleBar}"
16+
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !UseSystemWindowFrame}">
17+
<Border Background="{DynamicResource Brush.TitleBar}"
1918
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
2019
PointerPressed="BeginMoveWindow"/>
2120

22-
<Path Grid.Column="0"
23-
Width="14" Height="14"
21+
<Path Width="14" Height="14"
2422
Margin="10,0,0,0"
23+
HorizontalAlignment="Left"
2524
Data="{StaticResource Icons.Password}"
2625
IsVisible="{OnPlatform True, macOS=False}"/>
27-
28-
<v:CaptionButtonsMacOS Grid.Column="0"
29-
Margin="0,2,0,0"
30-
IsCloseButtonOnly="True"
31-
IsVisible="{OnPlatform False, macOS=True}"/>
3226

33-
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
34-
Classes="bold"
27+
<TextBlock Classes="bold"
3528
Text="{DynamicResource Text.Askpass}"
3629
HorizontalAlignment="Center" VerticalAlignment="Center"
3730
IsHitTestVisible="False"/>
3831

39-
<v:CaptionButtons Grid.Column="2"
32+
<v:CaptionButtons HorizontalAlignment="Right"
4033
IsCloseButtonOnly="True"
4134
IsVisible="{OnPlatform True, macOS=False}"/>
4235
</Grid>

src/Views/Askpass.axaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22

33
using Avalonia;
4-
using Avalonia.Input;
54
using Avalonia.Interactivity;
65

76
namespace SourceGit.Views
@@ -42,11 +41,6 @@ public Askpass(string description)
4241
InitializeComponent();
4342
}
4443

45-
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
46-
{
47-
BeginMoveDrag(e);
48-
}
49-
5044
private void CloseWindow(object _1, RoutedEventArgs _2)
5145
{
5246
Console.Out.WriteLine("No passphrase entered.");

src/Views/AssumeUnchangedManager.axaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,23 @@
1616
WindowStartupLocation="CenterOwner">
1717
<Grid RowDefinitions="Auto,*">
1818
<!-- TitleBar -->
19-
<Grid Grid.Row="0" ColumnDefinitions="Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
20-
<Border Grid.Column="0" Grid.ColumnSpan="3"
21-
Background="{DynamicResource Brush.TitleBar}"
19+
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
20+
<Border Background="{DynamicResource Brush.TitleBar}"
2221
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border0}"
2322
PointerPressed="BeginMoveWindow"/>
2423

25-
<Path Grid.Column="0"
26-
Width="14" Height="14"
24+
<Path Width="14" Height="14"
2725
Margin="10,0,0,0"
26+
HorizontalAlignment="Left"
2827
Data="{StaticResource Icons.File.Ignore}"
2928
IsVisible="{OnPlatform True, macOS=False}"/>
3029

31-
<v:CaptionButtonsMacOS Grid.Column="0"
32-
Margin="0,2,0,0"
33-
IsCloseButtonOnly="True"
34-
IsVisible="{OnPlatform False, macOS=True}"/>
35-
36-
<TextBlock Grid.Column="0" Grid.ColumnSpan="3"
37-
Classes="bold"
30+
<TextBlock Classes="bold"
3831
Text="{DynamicResource Text.AssumeUnchanged}"
3932
HorizontalAlignment="Center" VerticalAlignment="Center"
4033
IsHitTestVisible="False"/>
4134

42-
<v:CaptionButtons Grid.Column="2"
35+
<v:CaptionButtons HorizontalAlignment="Right"
4336
IsCloseButtonOnly="True"
4437
IsVisible="{OnPlatform True, macOS=False}"/>
4538
</Grid>

src/Views/AssumeUnchangedManager.axaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Avalonia.Controls;
2-
using Avalonia.Input;
32
using Avalonia.Interactivity;
43

54
namespace SourceGit.Views
@@ -11,11 +10,6 @@ public AssumeUnchangedManager()
1110
InitializeComponent();
1211
}
1312

14-
private void BeginMoveWindow(object _, PointerPressedEventArgs e)
15-
{
16-
BeginMoveDrag(e);
17-
}
18-
1913
private void OnRemoveButtonClicked(object sender, RoutedEventArgs e)
2014
{
2115
if (DataContext is ViewModels.AssumeUnchangedManager vm && sender is Button button)

src/Views/Blame.axaml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,26 @@
1919
</Grid.RowDefinitions>
2020

2121
<!-- TitleBar -->
22-
<Grid Grid.Row="0" ColumnDefinitions="Auto,Auto,*,Auto" Height="30" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
22+
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
2323
<!-- Bottom border -->
24-
<Border Grid.Column="0" Grid.ColumnSpan="4"
25-
Background="{DynamicResource Brush.TitleBar}"
24+
<Border Background="{DynamicResource Brush.TitleBar}"
2625
BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}"
2726
DoubleTapped="MaximizeOrRestoreWindow"
2827
PointerPressed="BeginMoveWindow"/>
2928

30-
<!-- Caption Buttons (macOS) -->
31-
<Border Grid.Column="0" IsVisible="{OnPlatform False, macOS=True}">
32-
<v:CaptionButtonsMacOS/>
33-
</Border>
34-
35-
<!-- Icon -->
36-
<Path Grid.Column="1" Margin="8,0,0,0" Width="12" Height="12" Data="{StaticResource Icons.Blame}"/>
37-
38-
<!-- Title -->
39-
<TextBlock Grid.Column="2" Margin="8,0,0,0" Text="{DynamicResource Text.Blame}" FontWeight="Bold" IsHitTestVisible="False" VerticalAlignment="Center"/>
29+
<Path Width="12" Height="12"
30+
Margin="10,0,0,0"
31+
HorizontalAlignment="Left"
32+
Data="{StaticResource Icons.Blame}"
33+
IsVisible="{OnPlatform True, macOS=False}"/>
4034

35+
<TextBlock Classes="bold"
36+
Text="{DynamicResource Text.Blame}"
37+
HorizontalAlignment="Center" VerticalAlignment="Center"
38+
IsHitTestVisible="False"/>
39+
4140
<!-- Caption Buttons (Windows/Linux) -->
42-
<Border Grid.Column="3" IsVisible="{OnPlatform True, macOS=False}">
43-
<v:CaptionButtons/>
44-
</Border>
41+
<v:CaptionButtons HorizontalAlignment="Right" IsVisible="{OnPlatform True, macOS=False}"/>
4542
</Grid>
4643

4744
<!-- File -->

0 commit comments

Comments
 (0)