Skip to content

Commit

Permalink
Update to Avalonia@07a1f681 (May 31 2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jul 12, 2023
1 parent 5588f67 commit 720ebe6
Show file tree
Hide file tree
Showing 45 changed files with 524 additions and 365 deletions.
21 changes: 8 additions & 13 deletions src/Modern.WindowKit/Avalonia.Mac/AvaloniaNativePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,18 @@ void DoInitialize(AvaloniaNativePlatformOptions options)
// .Bind<IWindowingPlatform>().ToConstant(this)
// .Bind<IClipboard>().ToConstant(new ClipboardImpl(_factory.CreateClipboard()))
// .Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
// .Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Meta, wholeWordTextActionModifiers: KeyModifiers.Alt))
// .Bind<IMountedVolumeInfoProvider>().ToConstant(new MacOSMountedVolumeInfoProvider())
// .Bind<IPlatformDragSource>().ToConstant(new AvaloniaNativeDragSource(_factory))
// .Bind<IPlatformLifetimeEventsImpl>().ToConstant(applicationPlatform)
// .Bind<INativeApplicationCommands>().ToConstant(new MacOSNativeMenuCommands(_factory.CreateApplicationCommands()));

//var renderLoop = new RenderLoop();
//AvaloniaLocator.CurrentMutable.Bind<IRenderLoop>().ToConstant(renderLoop);
//var hotkeys = new PlatformHotkeyConfiguration(KeyModifiers.Meta, wholeWordTextActionModifiers: KeyModifiers.Alt);
//hotkeys.MoveCursorToTheStartOfLine.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers));
//hotkeys.MoveCursorToTheStartOfLineWithSelection.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers | hotkeys.SelectionModifiers));
//hotkeys.MoveCursorToTheEndOfLine.Add(new KeyGesture(Key.Right, hotkeys.CommandModifiers));
//hotkeys.MoveCursorToTheEndOfLineWithSelection.Add(new KeyGesture(Key.Right, hotkeys.CommandModifiers | hotkeys.SelectionModifiers));

//var hotkeys = AvaloniaLocator.Current.GetService<PlatformHotkeyConfiguration>();
//if (hotkeys is not null)
//{
// hotkeys.MoveCursorToTheStartOfLine.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers));
// hotkeys.MoveCursorToTheStartOfLineWithSelection.Add(new KeyGesture(Key.Left, hotkeys.CommandModifiers | hotkeys.SelectionModifiers));
// hotkeys.MoveCursorToTheEndOfLine.Add(new KeyGesture(Key.Right, hotkeys.CommandModifiers));
// hotkeys.MoveCursorToTheEndOfLineWithSelection.Add(new KeyGesture(Key.Right, hotkeys.CommandModifiers | hotkeys.SelectionModifiers));
//}
//AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(hotkeys);

//if (_options.UseGpu)
//{
Expand All @@ -140,8 +135,8 @@ void DoInitialize(AvaloniaNativePlatformOptions options)
// // ignored
// }
//}

//Compositor = new Compositor(renderLoop, _platformGl);
//Compositor = new Compositor(_platformGl, true);
}

//public ITrayIconImpl CreateTrayIcon()
Expand Down
60 changes: 38 additions & 22 deletions src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ internal abstract partial class WindowBaseImpl : IWindowBaseImpl,
//private NativeControlHostImpl _nativeControlHost;
private IStorageProvider _storageProvider;
//private PlatformBehaviorInhibition _platformBehaviorInhibition;
private WindowTransparencyLevel _transparencyLevel = WindowTransparencyLevel.None;

internal WindowBaseImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts)
//AvaloniaNativeGlPlatformGraphics glFeature)
Expand Down Expand Up @@ -200,7 +201,7 @@ void IAvnWindowBaseEvents.Closed()

void IAvnWindowBaseEvents.Paint()
{
Dispatcher.UIThread.RunJobs(DispatcherPriority.Render);
Dispatcher.UIThread.RunJobs(DispatcherPriority.UiThreadRender);
var s = _parent.ClientSize;
_parent.Paint?.Invoke(new Rect(0, 0, s.Width, s.Height));
}
Expand Down Expand Up @@ -243,7 +244,7 @@ void IAvnWindowBaseEvents.ScalingChanged(double scaling)

void IAvnWindowBaseEvents.RunRenderPriorityJobs()
{
Dispatcher.UIThread.RunJobs(DispatcherPriority.Render);
Dispatcher.UIThread.RunJobs(DispatcherPriority.UiThreadRender);
}

void IAvnWindowBaseEvents.LostFocus()
Expand Down Expand Up @@ -365,13 +366,7 @@ public void Resize(Size clientSize, WindowResizeReason reason)
_native?.Resize(clientSize.Width, clientSize.Height, (AvnPlatformResizeReason)reason);
}

//public IRenderer CreateRenderer(IRenderRoot root)
//{
// return new CompositingRenderer(root, AvaloniaNativePlatform.Compositor, () => Surfaces)
// {
// RenderOnlyOnRenderThread = false
// };
//}
//public Compositor Compositor => AvaloniaNativePlatform.Compositor;

public virtual void Dispose()
{
Expand Down Expand Up @@ -485,26 +480,47 @@ internal void BeginDraggingSession(AvnDragDropEffects effects, AvnPoint point, I
_native?.BeginDragAndDropOperation(effects, point, clipboard, callback, sourceHandle);
}

public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel)
public void SetTransparencyLevelHint(IReadOnlyList<WindowTransparencyLevel> transparencyLevels)
{
if (TransparencyLevel != transparencyLevel)
foreach (var level in transparencyLevels)
{
if (transparencyLevel > WindowTransparencyLevel.Transparent)
transparencyLevel = WindowTransparencyLevel.AcrylicBlur;
AvnWindowTransparencyMode? mode = null;

TransparencyLevel = transparencyLevel;
if (level == WindowTransparencyLevel.None)
mode = AvnWindowTransparencyMode.Opaque;
if (level == WindowTransparencyLevel.Transparent)
mode = AvnWindowTransparencyMode.Transparent;
else if (level == WindowTransparencyLevel.AcrylicBlur)
mode = AvnWindowTransparencyMode.Blur;

_native.SetTransparencyMode(transparencyLevel == WindowTransparencyLevel.None
? AvnWindowTransparencyMode.Opaque
: transparencyLevel == WindowTransparencyLevel.Transparent
? AvnWindowTransparencyMode.Transparent
: AvnWindowTransparencyMode.Blur);
if (mode.HasValue && level != TransparencyLevel)
{
_native?.SetTransparencyMode(mode.Value);
TransparencyLevel = level;
return;
}
}

TransparencyLevelChanged?.Invoke(TransparencyLevel);
}
// If we get here, we didn't find a supported level. Use the default of None.
if (TransparencyLevel != WindowTransparencyLevel.None)
{
_native?.SetTransparencyMode(AvnWindowTransparencyMode.Opaque);
TransparencyLevel = WindowTransparencyLevel.None;
}
}

public WindowTransparencyLevel TransparencyLevel { get; private set; } = WindowTransparencyLevel.None;
public WindowTransparencyLevel TransparencyLevel
{
get => _transparencyLevel;
private set
{
if (_transparencyLevel != value)
{
_transparencyLevel = value;
TransparencyLevelChanged?.Invoke(value);
}
}
}

public void SetFrameThemeVariant(PlatformThemeVariant themeVariant)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Modern.WindowKit/Avalonia.Skia/SkiaSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public static SKFilterQuality ToSKFilterQuality(this BitmapInterpolationMode int
{
switch (interpolationMode)
{
case BitmapInterpolationMode.Unspecified:
case BitmapInterpolationMode.LowQuality:
return SKFilterQuality.Low;
case BitmapInterpolationMode.MediumQuality:
return SKFilterQuality.Medium;
case BitmapInterpolationMode.HighQuality:
return SKFilterQuality.High;
case BitmapInterpolationMode.None:
case BitmapInterpolationMode.Unspecified:
return SKFilterQuality.None;
default:
throw new ArgumentOutOfRangeException(nameof(interpolationMode), interpolationMode, null);
Expand Down
7 changes: 4 additions & 3 deletions src/Modern.WindowKit/Avalonia.Win32/PlatformConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Modern.WindowKit.Win32
{
public static class PlatformConstants
internal static class PlatformConstants
{
public const string WindowHandleType = "HWND";
public const string CursorHandleType = "HCURSOR";

internal static readonly Version Windows8 = new Version(6, 2);
internal static readonly Version Windows7 = new Version(6, 1);
public static readonly Version Windows10 = new Version(10, 0);
public static readonly Version Windows8 = new Version(6, 2);
public static readonly Version Windows7 = new Version(6, 1);
}
}
5 changes: 2 additions & 3 deletions src/Modern.WindowKit/Avalonia.Win32/Win32Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ public static void Initialize(Win32PlatformOptions options)
// .Bind<IKeyboardDevice>().ToConstant(WindowsKeyboardDevice.Instance)
// .Bind<IPlatformSettings>().ToSingleton<Win32PlatformSettings>()
// .Bind<IDispatcherImpl>().ToConstant(s_instance._dispatcher)
// .Bind<IRenderLoop>().ToConstant(new RenderLoop())
// .Bind<IRenderTimer>().ToConstant(renderTimer)
// .Bind<IWindowingPlatform>().ToConstant(s_instance)
// .Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control)
// {
// {
// OpenContextMenu =
// {
// // Add Shift+F10
Expand All @@ -181,7 +180,7 @@ public static void Initialize(Win32PlatformOptions options)
//if (OleContext.Current != null)
// AvaloniaLocator.CurrentMutable.Bind<IPlatformDragSource>().ToSingleton<DragSource>();

//s_compositor = new Compositor(AvaloniaGlobals.GetRequiredService<IRenderLoop>(), platformGraphics);
//s_compositor = new Compositor( platformGraphics);
}

public event EventHandler<ShutdownRequestedEventArgs>? ShutdownRequested;
Expand Down
12 changes: 1 addition & 11 deletions src/Modern.WindowKit/Avalonia.Win32/WindowImpl.AppWndProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
case WindowsMessage.WM_PAINT:
{
//using (NonPumpingSyncContext.Use(NonPumpingWaitHelperImpl.Instance))
//using (_rendererLock.Lock())
//{
if (BeginPaint(_hwnd, out PAINTSTRUCT ps) != IntPtr.Zero)
{
Expand All @@ -616,12 +615,6 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,

case WindowsMessage.WM_SIZE:
{
//using (NonPumpingSyncContext.Use(NonPumpingWaitHelperImpl.Instance))
//using (_rendererLock.Lock())
//{
// // Do nothing here, just block until the pending frame render is completed on the render thread
//}

var size = (SizeCommand)wParam;

if (Resized != null &&
Expand Down Expand Up @@ -838,10 +831,7 @@ protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam,
}
}

//using (_rendererLock.Lock())
// {
return DefWindowProc(hWnd, msg, wParam, lParam);
//}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

//private Lazy<IReadOnlyList<RawPointerPoint>?>? CreateLazyIntermediatePoints(POINTER_INFO info)
Expand Down
Loading

0 comments on commit 720ebe6

Please sign in to comment.