|
@@ -16,6 +16,7 @@ namespace Avalonia.Native
|
|
|
class AvaloniaNativePlatform : IPlatformSettings, IWindowingPlatform
|
|
|
{
|
|
|
private readonly IAvaloniaNativeFactory _factory;
|
|
|
+ private AvaloniaNativePlatformOptions _options;
|
|
|
|
|
|
[DllImport("libAvaloniaNative")]
|
|
|
static extern IntPtr CreateAvaloniaNative();
|
|
@@ -27,29 +28,31 @@ namespace Avalonia.Native
|
|
|
|
|
|
public TimeSpan DoubleClickTime => TimeSpan.FromMilliseconds(500); //TODO
|
|
|
|
|
|
- public static void Initialize(IntPtr factory, Action<AvaloniaNativeOptions> configure)
|
|
|
+ public static void Initialize(IntPtr factory, AvaloniaNativePlatformOptions options)
|
|
|
{
|
|
|
new AvaloniaNativePlatform(new IAvaloniaNativeFactory(factory))
|
|
|
- .DoInitialize(configure);
|
|
|
+ .DoInitialize(options);
|
|
|
}
|
|
|
|
|
|
delegate IntPtr CreateAvaloniaNativeDelegate();
|
|
|
|
|
|
- public static void Initialize(string library, Action<AvaloniaNativeOptions> configure)
|
|
|
+ public static void Initialize(AvaloniaNativePlatformOptions options)
|
|
|
{
|
|
|
- var loader = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
|
- ? (IDynLoader)new Win32Loader() : new UnixLoader();
|
|
|
- var lib = loader.LoadLibrary(library);
|
|
|
- var proc = loader.GetProcAddress(lib, "CreateAvaloniaNative", false);
|
|
|
- var d = Marshal.GetDelegateForFunctionPointer<CreateAvaloniaNativeDelegate>(proc);
|
|
|
+ if (options.AvaloniaNativeLibraryPath != null)
|
|
|
+ {
|
|
|
+ var loader = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
|
|
|
+ (IDynLoader)new Win32Loader() :
|
|
|
+ new UnixLoader();
|
|
|
|
|
|
+ var lib = loader.LoadLibrary(options.AvaloniaNativeLibraryPath);
|
|
|
+ var proc = loader.GetProcAddress(lib, "CreateAvaloniaNative", false);
|
|
|
+ var d = Marshal.GetDelegateForFunctionPointer<CreateAvaloniaNativeDelegate>(proc);
|
|
|
|
|
|
- Initialize(d(), configure);
|
|
|
- }
|
|
|
|
|
|
- public static void Initialize(Action<AvaloniaNativeOptions> configure)
|
|
|
- {
|
|
|
- Initialize(CreateAvaloniaNative(), configure);
|
|
|
+ Initialize(d(), options);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ Initialize(CreateAvaloniaNative(), options);
|
|
|
}
|
|
|
|
|
|
private AvaloniaNativePlatform(IAvaloniaNativeFactory factory)
|
|
@@ -57,14 +60,20 @@ namespace Avalonia.Native
|
|
|
_factory = factory;
|
|
|
}
|
|
|
|
|
|
- void DoInitialize(Action<AvaloniaNativeOptions> configure)
|
|
|
+ void DoInitialize(AvaloniaNativePlatformOptions options)
|
|
|
{
|
|
|
- var opts = new AvaloniaNativeOptions(_factory);
|
|
|
- configure?.Invoke(opts);
|
|
|
+ _options = options;
|
|
|
_factory.Initialize();
|
|
|
+ if (_factory.MacOptions != null)
|
|
|
+ {
|
|
|
+ var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>();
|
|
|
+ if (macOpts != null)
|
|
|
+ _factory.MacOptions.ShowInDock = macOpts.ShowInDock ? 1 : 0;
|
|
|
+ }
|
|
|
|
|
|
AvaloniaLocator.CurrentMutable
|
|
|
- .Bind<IPlatformThreadingInterface>().ToConstant(new PlatformThreadingInterface(_factory.CreatePlatformThreadingInterface()))
|
|
|
+ .Bind<IPlatformThreadingInterface>()
|
|
|
+ .ToConstant(new PlatformThreadingInterface(_factory.CreatePlatformThreadingInterface()))
|
|
|
.Bind<IStandardCursorFactory>().ToConstant(new CursorFactory(_factory.CreateCursorFactory()))
|
|
|
.Bind<IPlatformIconLoader>().ToSingleton<IconLoader>()
|
|
|
.Bind<IKeyboardDevice>().ToConstant(KeyboardDevice)
|
|
@@ -76,13 +85,13 @@ namespace Avalonia.Native
|
|
|
.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
|
|
|
.Bind<ISystemDialogImpl>().ToConstant(new SystemDialogs(_factory.CreateSystemDialogs()))
|
|
|
.Bind<IWindowingPlatformGlFeature>().ToConstant(new GlPlatformFeature(_factory.ObtainGlFeature()))
|
|
|
- .Bind<PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(InputModifiers.Windows))
|
|
|
- .Bind<AvaloniaNativeOptions>().ToConstant(opts);
|
|
|
+ .Bind<PlatformHotkeyConfiguration>()
|
|
|
+ .ToConstant(new PlatformHotkeyConfiguration(InputModifiers.Windows));
|
|
|
}
|
|
|
|
|
|
public IWindowImpl CreateWindow()
|
|
|
{
|
|
|
- return new WindowImpl(_factory);
|
|
|
+ return new WindowImpl(_factory, _options);
|
|
|
}
|
|
|
|
|
|
public IEmbeddableWindowImpl CreateEmbeddableWindow()
|
|
@@ -92,7 +101,7 @@ namespace Avalonia.Native
|
|
|
|
|
|
public IPopupImpl CreatePopup()
|
|
|
{
|
|
|
- return new PopupImpl(_factory);
|
|
|
+ return new PopupImpl(_factory, _options);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -116,18 +125,4 @@ namespace Avalonia.Native
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public class AvaloniaNativeOptions
|
|
|
- {
|
|
|
- public AvaloniaNativeMacOptions MacOptions { get; set; }
|
|
|
- public bool UseDeferredRendering { get; set; } = true;
|
|
|
- public bool UseGpu { get; set; } = true;
|
|
|
- internal AvaloniaNativeOptions(IAvaloniaNativeFactory factory)
|
|
|
- {
|
|
|
- var mac = factory.GetMacOptions();
|
|
|
- if (mac != null)
|
|
|
- MacOptions = new AvaloniaNativeMacOptions(mac);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
}
|