public static void Initialize() { if (!s_gtkInitialized) { try { X11.XInitThreads(); }catch {} Resolver.Resolve(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { using (var backends = new Utf8Buffer("x11")) Native.GdkSetAllowedBackends?.Invoke(backends); } Native.GtkInit(0, IntPtr.Zero); var disp = Native.GdkGetDefaultDisplay(); DisplayClassName = Utf8Buffer.StringFromPtr(Native.GTypeName(Marshal.ReadIntPtr(Marshal.ReadIntPtr(disp)))); using (var utf = new Utf8Buffer("avalonia.app." + Guid.NewGuid())) App = Native.GtkApplicationNew(utf, 0); //Mark current thread as UI thread s_tlsMarker = true; s_gtkInitialized = true; } AvaloniaLocator.CurrentMutable.Bind <IWindowingPlatform>().ToConstant(Instance) .Bind <IClipboard>().ToSingleton <ClipboardImpl>() .Bind <IStandardCursorFactory>().ToConstant(new CursorFactory()) .Bind <IKeyboardDevice>().ToConstant(Keyboard) .Bind <IPlatformSettings>().ToConstant(Instance) .Bind <IPlatformThreadingInterface>().ToConstant(Instance) .Bind <ISystemDialogImpl>().ToSingleton <SystemDialog>() .Bind <IRenderLoop>().ToConstant(new DefaultRenderLoop(60)) .Bind <IPlatformIconLoader>().ToConstant(new PlatformIconLoader()); }
void GtkThread(TaskCompletionSource <bool> tcs) { try { X11.XInitThreads(); }catch {} Resolver.Resolve(); if (Native.GdkWindowForeignNewForDisplay == null) { throw new Exception("gdk_x11_window_foreign_new_for_display is not found in your libgdk-3.so"); } using (var backends = new Utf8Buffer("x11")) Native.GdkSetAllowedBackends?.Invoke(backends); if (!Native.GtkInitCheck(0, IntPtr.Zero)) { tcs.SetResult(false); return; } using (var utf = new Utf8Buffer($"avalonia.app.a{Guid.NewGuid().ToString("N")}")) App = Native.GtkApplicationNew(utf, 0); if (App == IntPtr.Zero) { tcs.SetResult(false); return; } GdkDisplay = Native.GdkGetDefaultDisplay(); tcs.SetResult(true); while (true) { Native.GtkMainIteration(); } }
public static void Initialize(Gtk3PlatformOptions options) { Resolver.Custom = options.CustomResolver; UseDeferredRendering = EnvOption("USE_DEFERRED_RENDERING", true, options.UseDeferredRendering); var useGpu = EnvOption("USE_GPU", false, options.UseGpuAcceleration); if (!s_gtkInitialized) { try { X11.XInitThreads(); }catch {} Resolver.Resolve(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { using (var backends = new Utf8Buffer("x11")) Native.GdkSetAllowedBackends?.Invoke(backends); } Native.GtkInit(0, IntPtr.Zero); var disp = Native.GdkGetDefaultDisplay(); DisplayClassName = Utf8Buffer.StringFromPtr(Native.GTypeName(Marshal.ReadIntPtr(Marshal.ReadIntPtr(disp)))); using (var utf = new Utf8Buffer("avalonia.app." + Guid.NewGuid())) App = Native.GtkApplicationNew(utf, 0); //Mark current thread as UI thread s_tlsMarker = true; s_gtkInitialized = true; } AvaloniaLocator.CurrentMutable.Bind <IWindowingPlatform>().ToConstant(Instance) .Bind <IClipboard>().ToSingleton <ClipboardImpl>() .Bind <IStandardCursorFactory>().ToConstant(new CursorFactory()) .Bind <IKeyboardDevice>().ToConstant(Keyboard) .Bind <IPlatformSettings>().ToConstant(Instance) .Bind <IPlatformThreadingInterface>().ToConstant(Instance) .Bind <ISystemDialogImpl>().ToSingleton <SystemDialog>() .Bind <IRenderLoop>().ToConstant(new RenderLoop()) .Bind <IRenderTimer>().ToConstant(new DefaultRenderTimer(60)) .Bind <PlatformHotkeyConfiguration>().ToSingleton <PlatformHotkeyConfiguration>() .Bind <IPlatformIconLoader>().ToConstant(new PlatformIconLoader()); if (useGpu) { EglGlPlatformFeature.TryInitialize(); } }