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