Beispiel #1
0
        public void Initialize(X11PlatformOptions options)
        {
            XInitThreads();
            Display         = XOpenDisplay(IntPtr.Zero);
            DeferredDisplay = XOpenDisplay(IntPtr.Zero);
            if (Display == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }
            XError.Init();
            Info = new X11Info(Display, DeferredDisplay);

            AvaloniaLocator.CurrentMutable.BindToSelf(this)
            .Bind <IWindowingPlatform>().ToConstant(this)
            .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
            .Bind <IRenderTimer>().ToConstant(new DefaultRenderTimer(60))
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(InputModifiers.Control))
            .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice)
            .Bind <IStandardCursorFactory>().ToConstant(new X11CursorFactory(Display))
            .Bind <IClipboard>().ToConstant(new X11Clipboard(this))
            .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub())
            .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
            .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog());

            X11Screens = Avalonia.X11.X11Screens.Init(this);
            Screens    = new X11Screens(X11Screens);
            if (Info.XInputVersion != null)
            {
                var xi2 = new XI2Manager();
                if (xi2.Init(this))
                {
                    XI2 = xi2;
                }
            }

            if (options.UseGpu)
            {
                if (options.UseEGL)
                {
                    EglGlPlatformFeature.TryInitialize();
                }
                else
                {
                    GlxGlPlatformFeature.TryInitialize(Info);
                }
            }

            Options = options;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the avalonia options.
        /// </summary>
        /// <param name="app">The application.</param>
        private static void InitAvaloniaOptions(AppBuilder app)
        {
            void configureLinux()
            {
                var configuration        = DIResolver.Get <IConfigurationRoot>();
                var linuxSection         = configuration.GetSection("LinuxOptions");
                var useGPU               = linuxSection.GetSection("UseGPU").Get <bool?>();
                var useEGL               = linuxSection.GetSection("UseEGL").Get <bool?>();
                var useDBusMenu          = linuxSection.GetSection("UseDBusMenu").Get <bool?>();
                var useDeferredRendering = linuxSection.GetSection("UseDeferredRendering").Get <bool?>();

                if (useGPU.HasValue || useEGL.HasValue || useDBusMenu.HasValue || useDeferredRendering.HasValue)
                {
                    var opts = new X11PlatformOptions();
                    if (useGPU.HasValue)
                    {
                        opts.UseGpu = useGPU.GetValueOrDefault();
                    }
                    if (useEGL.HasValue)
                    {
                        opts.UseEGL = useEGL.GetValueOrDefault();
                    }
                    if (useDBusMenu.HasValue)
                    {
                        opts.UseDBusMenu = useDBusMenu.GetValueOrDefault();
                    }
                    if (useDeferredRendering.HasValue)
                    {
                        opts.UseDeferredRendering = useDeferredRendering.GetValueOrDefault();
                    }
                    app.With(opts);
                }
            }

            configureLinux();
        }
Beispiel #3
0
        public void Initialize(X11PlatformOptions options)
        {
            Options = options;

            bool useXim = false;

            if (EnableIme(options))
            {
                // Attempt to configure DBus-based input method and check if we can fall back to XIM
                if (!X11DBusImeHelper.DetectAndRegister() && ShouldUseXim())
                {
                    useXim = true;
                }
            }

            // XIM doesn't work at all otherwise
            if (useXim)
            {
                setlocale(0, "");
            }

            XInitThreads();
            Display = XOpenDisplay(IntPtr.Zero);
            if (Display == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }
            DeferredDisplay = XOpenDisplay(IntPtr.Zero);
            if (DeferredDisplay == IntPtr.Zero)
            {
                throw new Exception("XOpenDisplay failed");
            }

            OrphanedWindow = XCreateSimpleWindow(Display, XDefaultRootWindow(Display), 0, 0, 1, 1, 0, IntPtr.Zero,
                                                 IntPtr.Zero);
            XError.Init();

            Info    = new X11Info(Display, DeferredDisplay, useXim);
            Globals = new X11Globals(this);
            //TODO: log
            if (options.UseDBusMenu)
            {
                DBusHelper.TryInitialize();
            }
            AvaloniaLocator.CurrentMutable.BindToSelf(this)
            .Bind <IWindowingPlatform>().ToConstant(this)
            .Bind <IPlatformThreadingInterface>().ToConstant(new X11PlatformThreading(this))
            .Bind <IRenderTimer>().ToConstant(new SleepLoopRenderTimer(60))
            .Bind <IRenderLoop>().ToConstant(new RenderLoop())
            .Bind <PlatformHotkeyConfiguration>().ToConstant(new PlatformHotkeyConfiguration(KeyModifiers.Control))
            .Bind <IKeyboardDevice>().ToFunc(() => KeyboardDevice)
            .Bind <ICursorFactory>().ToConstant(new X11CursorFactory(Display))
            .Bind <IClipboard>().ToConstant(new X11Clipboard(this))
            .Bind <IPlatformSettings>().ToConstant(new PlatformSettingsStub())
            .Bind <IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
            .Bind <ISystemDialogImpl>().ToConstant(new GtkSystemDialog())
            .Bind <IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider());

            X11Screens = Avalonia.X11.X11Screens.Init(this);
            Screens    = new X11Screens(X11Screens);
            if (Info.XInputVersion != null)
            {
                var xi2 = new XI2Manager();
                if (xi2.Init(this))
                {
                    XI2 = xi2;
                }
            }

            if (options.UseGpu)
            {
                if (options.UseEGL)
                {
                    EglPlatformOpenGlInterface.TryInitialize();
                }
                else
                {
                    GlxPlatformOpenGlInterface.TryInitialize(Info, Options.GlProfiles);
                }
            }
        }
 /// <summary>
 /// Initializes the irony X11 platform.
 /// </summary>
 /// <param name="options">The options.</param>
 public static void InitializeIronyX11Platform(X11PlatformOptions options = null) =>
 new AvaloniaX11Platform().Initialize(options ?? new X11PlatformOptions());