Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Avalonia@fda71e48 (May 15 2023) #32

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@

public Action LostFocus { get; set; }

public Action<Rect> Paint { get; set; }

Check warning on line 162 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Paint.set' doesn't match implicitly implemented member 'void ITopLevelImpl.Paint.set' (possibly because of nullability attributes).

Check warning on line 162 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Paint.set' doesn't match implicitly implemented member 'void ITopLevelImpl.Paint.set' (possibly because of nullability attributes).
public Action<Size, WindowResizeReason> Resized { get; set; }
public Action Closed { get; set; }
public IMouseDevice MouseDevice => _mouse;
Expand Down Expand Up @@ -220,17 +220,17 @@
_parent.PositionChanged?.Invoke(position.ToAvaloniaPixelPoint());
}

void IAvnWindowBaseEvents.RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta)
void IAvnWindowBaseEvents.RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta)
{
_parent.RawMouseEvent(type, timeStamp, modifiers, point, delta);
}

int IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key)
int IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, uint key)
{
return _parent.RawKeyEvent(type, timeStamp, modifiers, key).AsComBool();
}

int IAvnWindowBaseEvents.RawTextInputEvent(uint timeStamp, string text)
int IAvnWindowBaseEvents.RawTextInputEvent(ulong timeStamp, string text)
{
return _parent.RawTextInputEvent(timeStamp, text).AsComBool();
}
Expand Down Expand Up @@ -286,7 +286,7 @@
_native?.Activate();
}

public bool RawTextInputEvent(uint timeStamp, string text)
public bool RawTextInputEvent(ulong timeStamp, string text)
{
//if (_inputRoot is null)
// return false;
Expand All @@ -300,7 +300,7 @@
return args.Handled;
}

public bool RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key)
public bool RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, uint key)
{
//if (_inputRoot is null)
// return false;
Expand All @@ -319,7 +319,7 @@
return false;
}

public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta)
public void RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta)
{
//if (_inputRoot is null)
// return;
Expand Down Expand Up @@ -442,8 +442,8 @@

public double DesktopScaling => 1;

public Action Deactivated { get; set; }

Check warning on line 445 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Deactivated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Deactivated.set' (possibly because of nullability attributes).

Check warning on line 445 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Deactivated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Deactivated.set' (possibly because of nullability attributes).

Check warning on line 445 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Deactivated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Deactivated.set' (possibly because of nullability attributes).
public Action Activated { get; set; }

Check warning on line 446 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Activated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Activated.set' (possibly because of nullability attributes).

Check warning on line 446 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Activated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Activated.set' (possibly because of nullability attributes).

Check warning on line 446 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Activated.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.Activated.set' (possibly because of nullability attributes).

public void SetCursor(ICursorImpl cursor)
{
Expand All @@ -457,9 +457,9 @@
_native.SetCursor(newCursor.Cursor);
}

public Action<PixelPoint> PositionChanged { get; set; }

Check warning on line 460 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.PositionChanged.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.PositionChanged.set' (possibly because of nullability attributes).

Check warning on line 460 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.PositionChanged.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.PositionChanged.set' (possibly because of nullability attributes).

Check warning on line 460 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.PositionChanged.set' doesn't match implicitly implemented member 'void IWindowBaseImpl.PositionChanged.set' (possibly because of nullability attributes).

public Action<RawInputEventArgs> Input { get; set; }

Check warning on line 462 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Input.set' doesn't match implicitly implemented member 'void ITopLevelImpl.Input.set' (possibly because of nullability attributes).

Check warning on line 462 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Input.set' doesn't match implicitly implemented member 'void ITopLevelImpl.Input.set' (possibly because of nullability attributes).

Check warning on line 462 in src/Modern.WindowKit/Avalonia.Mac/WindowImplBase.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

Nullability of reference types in type of parameter 'value' of 'void WindowBaseImpl.Input.set' doesn't match implicitly implemented member 'void ITopLevelImpl.Input.set' (possibly because of nullability attributes).

public Action<double> ScalingChanged { get; set; }

Expand Down
4 changes: 3 additions & 1 deletion src/Modern.WindowKit/Avalonia.Skia/SkiaSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static SKFilterQuality ToSKFilterQuality(this BitmapInterpolationMode int
return SKFilterQuality.Medium;
case BitmapInterpolationMode.HighQuality:
return SKFilterQuality.High;
case BitmapInterpolationMode.Default:
case BitmapInterpolationMode.None:
case BitmapInterpolationMode.Unspecified:
return SKFilterQuality.None;
default:
throw new ArgumentOutOfRangeException(nameof(interpolationMode), interpolationMode, null);
Expand All @@ -30,6 +31,7 @@ public static SKFilterQuality ToSKFilterQuality(this BitmapInterpolationMode int
//{
// switch (blendingMode)
// {
// case BitmapBlendingMode.Unspecified:
// case BitmapBlendingMode.SourceOver:
// return SKBlendMode.SrcOver;
// case BitmapBlendingMode.Source:
Expand Down
2 changes: 1 addition & 1 deletion src/Modern.WindowKit/Avalonia.Skia/WriteableBitmapImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public WriteableBitmapImpl(PixelSize size, Vector dpi, PixelFormat format, Alpha
//}

/// <inheritdoc />
public void Dispose()
public virtual void Dispose()
{
_bitmap.Dispose();
}
Expand Down
12 changes: 7 additions & 5 deletions src/Modern.WindowKit/Avalonia.Win32/Win32StorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ private unsafe Task<IEnumerable<string>> ShowFilePicker(
}
frm.SetOptions(options);

if (defaultExtension is not null)
if (defaultExtension is null)
{
fixed (char* pExt = defaultExtension)
{
frm.SetDefaultExtension(pExt);
}
defaultExtension = String.Empty;
}

fixed (char* pExt = defaultExtension)
{
frm.SetDefaultExtension(pExt);
}

suggestedFileName ??= "";
Expand Down
10 changes: 6 additions & 4 deletions src/Modern.WindowKit/BitmapInterpolationMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
/// <summary>
/// Controls the performance and quality of bitmap scaling.
/// </summary>
public enum BitmapInterpolationMode
public enum BitmapInterpolationMode : byte
{
Unspecified,

/// <summary>
/// Uses the default behavior of the underling render backend.
/// Disable interpolation.
/// </summary>
Default,
None,

/// <summary>
/// The best performance but worst image quality.
Expand All @@ -18,7 +20,7 @@ public enum BitmapInterpolationMode
/// <summary>
/// Good performance and decent image quality.
/// </summary>
MediumQuality,
MediumQuality,

/// <summary>
/// Highest quality but worst performance.
Expand Down
3 changes: 2 additions & 1 deletion src/Modern.WindowKit/DataFormats.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;

namespace Modern.WindowKit.Input
{
Expand All @@ -17,7 +18,7 @@ public static class DataFormats
/// <summary>
/// Dataformat for one or more filenames
/// </summary>
[Obsolete("Use DataFormats.Files, this format is supported only on desktop platforms.")]
[Obsolete("Use DataFormats.Files, this format is supported only on desktop platforms."), EditorBrowsable(EditorBrowsableState.Never)]
public static readonly string FileNames = nameof(FileNames);
}
}
3 changes: 2 additions & 1 deletion src/Modern.WindowKit/DataObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Modern.WindowKit.Platform.Storage;

Expand All @@ -25,7 +26,7 @@ public static class DataObjectExtensions
/// <returns>
/// Collection of file names. If format isn't available, returns null.
/// </returns>
[System.Obsolete("Use GetFiles, this method is supported only on desktop platforms.")]
[System.Obsolete("Use GetFiles, this method is supported only on desktop platforms."), EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<string>? GetFileNames(this IDataObject dataObject)
{
return (dataObject.Get(DataFormats.FileNames) as IEnumerable<string>)
Expand Down
42 changes: 36 additions & 6 deletions src/Modern.WindowKit/Dispatcher.Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public TResult Invoke<TResult>(Func<TResult> callback, DispatcherPriority priori
/// An operation representing the queued delegate to be invoked.
/// </returns>
/// <remarks>
/// Note that the default priority is DispatcherPriority.Normal.
/// Note that the default priority is DispatcherPriority.Default.
/// </remarks>
public DispatcherOperation InvokeAsync(Action callback)
{
return InvokeAsync(callback, DispatcherPriority.Normal, CancellationToken.None);
return InvokeAsync(callback, default, CancellationToken.None);
}

/// <summary>
Expand Down Expand Up @@ -326,11 +326,11 @@ public DispatcherOperation InvokeAsync(Action callback, DispatcherPriority prior
/// An operation representing the queued delegate to be invoked.
/// </returns>
/// <remarks>
/// Note that the default priority is DispatcherPriority.Normal.
/// Note that the default priority is DispatcherPriority.Default.
/// </remarks>
public DispatcherOperation<TResult> InvokeAsync<TResult>(Func<TResult> callback)
{
return InvokeAsync(callback, DispatcherPriority.Normal, CancellationToken.None);
return InvokeAsync(callback, DispatcherPriority.Default, CancellationToken.None);
}

/// <summary>
Expand Down Expand Up @@ -541,6 +541,18 @@ public void Post(Action action, DispatcherPriority priority = default)
InvokeAsyncImpl(new DispatcherOperation(this, priority, action, true), CancellationToken.None);
}

/// <summary>
/// Executes the specified Func&lt;Task&gt; asynchronously on the
/// thread that the Dispatcher was created on
/// </summary>
/// <param name="callback">
/// A Func&lt;Task&gt; delegate to invoke through the dispatcher.
/// </param>
/// <returns>
/// An task that completes after the task returned from callback finishes.
/// </returns>
public Task InvokeAsync(Func<Task> callback) => InvokeAsync(callback, DispatcherPriority.Default);

/// <summary>
/// Executes the specified Func&lt;Task&gt; asynchronously on the
/// thread that the Dispatcher was created on
Expand All @@ -556,11 +568,29 @@ public void Post(Action action, DispatcherPriority priority = default)
/// <returns>
/// An task that completes after the task returned from callback finishes
/// </returns>
public Task InvokeAsync(Func<Task> callback, DispatcherPriority priority = default)
public Task InvokeAsync(Func<Task> callback, DispatcherPriority priority)
{
_ = callback ?? throw new ArgumentNullException(nameof(callback));
return InvokeAsync<Task>(callback, priority).GetTask().Unwrap();
}

/// <summary>
/// Executes the specified Func&lt;Task&lt;TResult&gt;&gt; asynchronously on the
/// thread that the Dispatcher was created on
/// </summary>
/// <param name="action">
/// A Func&lt;Task&lt;TResult&gt;&gt; delegate to invoke through the dispatcher.
/// </param>
/// <param name="priority">
/// The priority that determines in what order the specified
/// callback is invoked relative to the other pending operations
/// in the Dispatcher.
/// </param>
/// <returns>
/// An task that completes after the task returned from callback finishes
/// </returns>
public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> action) =>
InvokeAsync(action, DispatcherPriority.Default);

/// <summary>
/// Executes the specified Func&lt;Task&lt;TResult&gt;&gt; asynchronously on the
Expand All @@ -577,7 +607,7 @@ public Task InvokeAsync(Func<Task> callback, DispatcherPriority priority = defau
/// <returns>
/// An task that completes after the task returned from callback finishes
/// </returns>
public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> action, DispatcherPriority priority = default)
public Task<TResult> InvokeAsync<TResult>(Func<Task<TResult>> action, DispatcherPriority priority)
{
_ = action ?? throw new ArgumentNullException(nameof(action));
return InvokeAsync<Task<TResult>>(action, priority).GetTask().Unwrap();
Expand Down
55 changes: 34 additions & 21 deletions src/Modern.WindowKit/DispatcherFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,44 @@ public bool Continue

internal void Run(IControlledDispatcherImpl impl)
{
// Since the actual platform run loop is controlled by a Cancellation token, we are restarting
// it if frame still needs to run
while (Continue)
RunCore(impl);
}

private void RunCore(IControlledDispatcherImpl impl)
{
if (_isRunning)
throw new InvalidOperationException("This frame is already running");
_isRunning = true;
try
Dispatcher.VerifyAccess();

// Since the actual platform run loop is controlled by a Cancellation token, we have an
// outer loop that restarts the platform one in case Continue was set to true after being set to false
while (true)
{
_cancellationTokenSource = new CancellationTokenSource();
// Wake up the dispatcher in case it has pending jobs
Dispatcher.RequestProcessing();
impl.RunLoop(_cancellationTokenSource.Token);
// Take the instance lock since `Continue` is changed from one too
lock (Dispatcher.InstanceLock)
{
if (!Continue)
return;

if (_isRunning)
throw new InvalidOperationException("This frame is already running");

_cancellationTokenSource = new CancellationTokenSource();
_isRunning = true;
}
finally
{
_isRunning = false;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource = null;

try
{
// Wake up the dispatcher in case it has pending jobs
Dispatcher.RequestProcessing();
impl.RunLoop(_cancellationTokenSource.Token);
}
finally
{
lock (Dispatcher.InstanceLock)
{
_isRunning = false;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}
}
}
}


internal void MaybeExitOnDispatcherRequest()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Modern.WindowKit/DispatcherOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ public DispatcherOperation(Dispatcher dispatcher, DispatcherPriority priority, F

private TaskCompletionSource<T> TaskCompletionSource => (TaskCompletionSource<T>)TaskSource!;

public new TaskAwaiter<T> GetAwaiter() => GetTask().GetAwaiter();

public new Task<T> GetTask() => TaskCompletionSource!.Task;

protected override Task GetTaskCore() => GetTask();
Expand Down
3 changes: 2 additions & 1 deletion src/Modern.WindowKit/DispatcherPriority.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;

namespace Modern.WindowKit.Threading
{
Expand Down Expand Up @@ -100,7 +101,7 @@ private DispatcherPriority(int value)
/// <summary>
/// The job will be processed with the same priority as data binding.
/// </summary>
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = new(Layout);
[Obsolete("WPF compatibility"), EditorBrowsable(EditorBrowsableState.Never)] public static readonly DispatcherPriority DataBind = new(Layout);

/// <summary>
/// The job will be processed with normal priority.
Expand Down
6 changes: 6 additions & 0 deletions src/Modern.WindowKit/ManagedDispatcherImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public void UpdateTimer(long? dueTimeInMs)

public void RunLoop(CancellationToken token)
{
CancellationTokenRegistration registration = default;
if (token.CanBeCanceled)
registration = token.Register(() => _wakeup.Set());

while (!token.IsCancellationRequested)
{
bool signaled;
Expand Down Expand Up @@ -105,5 +109,7 @@ public void RunLoop(CancellationToken token)
else
_wakeup.WaitOne();
}

registration.Dispose();
}
}
2 changes: 1 addition & 1 deletion src/Modern.WindowKit/Modern.WindowKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Modern.WindowKit.Backend" Version="[0.4.0-alpha03]" />
<PackageReference Include="Modern.WindowKit.Backend" Version="[0.4.0-alpha04]" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.3" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
Expand Down
5 changes: 3 additions & 2 deletions src/Modern.WindowKit/Screen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;

namespace Modern.WindowKit.Platform
{
Expand All @@ -17,7 +18,7 @@ public class Screen
public double Scaling { get; }

/// <inheritdoc cref="Scaling"/>
[Obsolete("Use the Scaling property instead.")]
[Obsolete("Use the Scaling property instead."), EditorBrowsable(EditorBrowsableState.Never)]
public double PixelDensity => Scaling;

/// <summary>
Expand All @@ -43,7 +44,7 @@ public class Screen
public bool IsPrimary { get; }

/// <inheritdoc cref="IsPrimary"/>
[Obsolete("Use the IsPrimary property instead.")]
[Obsolete("Use the IsPrimary property instead."), EditorBrowsable(EditorBrowsableState.Never)]
public bool Primary => IsPrimary;

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Modern.WindowKit/Screens.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Modern.WindowKit.Platform;

Expand Down Expand Up @@ -68,7 +69,7 @@ public Screens(IScreenImpl iScreenImpl)
/// </summary>
/// <param name="window">The window impl for which to retrieve the Screen.</param>
/// <returns>The <see cref="Screen"/>.</returns>
[Obsolete("Use ScreenFromWindow(WindowBase) overload.")]
[Obsolete("Use ScreenFromWindow(WindowBase) overload."), EditorBrowsable(EditorBrowsableState.Never)]
public Screen? ScreenFromWindow(IWindowBaseImpl window)
{
return _iScreenImpl.ScreenFromWindow(window);
Expand Down
Loading
Loading