Skip to content

Commit

Permalink
Add SnapLayout Options support for Win11 (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull authored Aug 7, 2024
1 parent 49bdc48 commit f1e4fcb
Show file tree
Hide file tree
Showing 4 changed files with 645 additions and 32 deletions.
57 changes: 30 additions & 27 deletions dnSpy/dnSpy/Controls/WinSysButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public CurrentWinSysType CurrentWinSysType {

static WinSysButton() => DefaultStyleKeyProperty.OverrideMetadata(typeof(WinSysButton), new FrameworkPropertyMetadata(typeof(WinSysButton)));

public WinSysButton() => Loaded += WinSysButton_Loaded;
public WinSysButton() {
Loaded += WinSysButton_Loaded;
Click += WinSysButton_Click;
}

void WinSysButton_Loaded(object? sender, RoutedEventArgs e) {
Loaded -= WinSysButton_Loaded;
Expand All @@ -67,6 +70,32 @@ void WinSysButton_Loaded(object? sender, RoutedEventArgs e) {
window.StateChanged += window_StateChanged;
}

void WinSysButton_Click(object sender, RoutedEventArgs e) {
if (window is null)
return;

switch (CurrentWinSysType) {
case CurrentWinSysType.Minimize:
WindowUtils.Minimize(window);
break;

case CurrentWinSysType.Maximize:
WindowUtils.Maximize(window);
break;

case CurrentWinSysType.Restore:
WindowUtils.Restore(window);
break;

case CurrentWinSysType.Close:
window.Close();
break;

default:
throw new ArgumentException("Invalid CurrentWinSysType");
}
}

void window_StateChanged(object? sender, EventArgs e) => OnWinSysTypeChanged(WinSysType);
static void OnWinSysTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
((WinSysButton)d).OnWinSysTypeChanged((WinSysType)e.NewValue);
Expand Down Expand Up @@ -97,31 +126,5 @@ void OnWinSysTypeChanged(WinSysType newValue) {
throw new ArgumentException("Invalid WinSysType");
}
}

protected override void OnClick() {
if (window is null)
return;

switch (CurrentWinSysType) {
case CurrentWinSysType.Minimize:
WindowUtils.Minimize(window);
break;

case CurrentWinSysType.Maximize:
WindowUtils.Maximize(window);
break;

case CurrentWinSysType.Restore:
WindowUtils.Restore(window);
break;

case CurrentWinSysType.Close:
window.Close();
break;

default:
throw new ArgumentException("Invalid CurrentWinSysType");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Runtime.InteropServices;

namespace EleCho.WpfSuite {
public partial class WindowOption {
internal static class NativeDefinition {
public const nint WM_NCHITTEST = 0x0084;
public const nint WM_NCMOUSELEAVE = 0x02A2;
public const nint WM_NCLBUTTONDOWN = 0x00A1;
public const nint WM_NCLBUTTONUP = 0x00A2;
public const nint WM_MOUSEMOVE = 0x0200;

public const nint HTCLOSE = 20;
public const nint HTMAXBUTTON = 9;
public const nint HTMINBUTTON = 8;
}
}
}
Loading

0 comments on commit f1e4fcb

Please sign in to comment.