예제 #1
0
 public Randr15ScreensImpl(AvaloniaX11Platform platform, X11ScreensUserSettings settings)
 {
     _settings = settings;
     _x11      = platform.Info;
     _window   = CreateEventWindow(platform, OnEvent);
     XRRSelectInput(_x11.Display, _window, RandrEventMask.RRScreenChangeNotify);
 }
예제 #2
0
        public static IntPtr CreateEventWindow(AvaloniaX11Platform plat, X11PlatformThreading.EventHandler handler)
        {
            var win = XCreateSimpleWindow(plat.Display, plat.Info.DefaultRootWindow,
                                          0, 0, 1, 1, 0, IntPtr.Zero, IntPtr.Zero);

            plat.Windows[win] = handler;
            return(win);
        }
        internal X11PlatformLifetimeEvents(AvaloniaX11Platform platform)
        {
            _platform = platform;

            if (ICELib.IceAddConnectionWatch(
                    Marshal.GetFunctionPointerForDelegate(s_iceWatchProcDelegate),
                    IntPtr.Zero) == 0)
            {
                Logger.TryGet(LogEventLevel.Warning, LogArea.X11Platform)?.Log(this,
                                                                               "SMLib was unable to add an ICE connection watcher.");
                return;
            }

            byte[] errorBuf    = new byte[255];
            IntPtr clientIdRet = IntPtr.Zero;
            var    smcConn     = SMLib.SmcOpenConnection(null,
                                                         IntPtr.Zero, 1, 0,
                                                         SmcSaveYourselfProcMask |
                                                         SmcSaveCompleteProcMask |
                                                         SmcShutdownCancelledProcMask |
                                                         SmcDieProcMask,
                                                         ref s_callbacks,
                                                         null,
                                                         ref clientIdRet,
                                                         errorBuf.Length,
                                                         errorBuf);

            if (smcConn == IntPtr.Zero)
            {
                Logger.TryGet(LogEventLevel.Warning, LogArea.X11Platform)?.Log(this,
                                                                               $"SMLib/ICELib reported a new error: {Encoding.ASCII.GetString(errorBuf)}");
                return;
            }

            if (!s_nativeToManagedMapper.TryAdd(smcConn, this))
            {
                Logger.TryGet(LogEventLevel.Warning, LogArea.X11Platform)?.Log(this,
                                                                               "SMLib was unable to add this instance to the native to managed map.");
                return;
            }

            _ = SMLib.SmcSetErrorHandler(Marshal.GetFunctionPointerForDelegate(s_smcErrorHandlerDelegate));
            _ = ICELib.IceSetErrorHandler(Marshal.GetFunctionPointerForDelegate(s_iceErrorHandlerDelegate));
            _ = ICELib.IceSetIOErrorHandler(Marshal.GetFunctionPointerForDelegate(s_iceIoErrorHandlerDelegate));

            _currentSmcConn = smcConn;
            _currentIceConn = SMLib.SmcGetIceConnection(smcConn);

            Task.Run(() =>
            {
                var token = _cancellationTokenSource.Token;
                while (!token.IsCancellationRequested)
                {
                    HandleRequests();
                }
            }, _cancellationTokenSource.Token);
        }
예제 #4
0
        public static IX11Screens Init(AvaloniaX11Platform platform)
        {
            var info     = platform.Info;
            var settings = X11ScreensUserSettings.Detect();
            var impl     = (info.RandrVersion != null && info.RandrVersion >= new Version(1, 5))
                ? new Randr15ScreensImpl(platform, settings)
                : (IX11Screens) new FallbackScreensImpl(info, settings);

            return(impl);
        }
예제 #5
0
 public X11Globals(AvaloniaX11Platform plat)
 {
     _plat                     = plat;
     _x11                      = plat.Info;
     _screenNumber             = XDefaultScreen(_x11.Display);
     _rootWindow               = XRootWindow(_x11.Display, _screenNumber);
     plat.Windows[_rootWindow] = OnRootWindowEvent;
     XSelectInput(_x11.Display, _rootWindow,
                  new IntPtr((int)(EventMask.StructureNotifyMask | EventMask.PropertyChangeMask)));
     _compositingAtom = XInternAtom(_x11.Display, "_NET_WM_CM_S" + _screenNumber, false);
     UpdateWmName();
     UpdateCompositingAtomOwner();
 }
예제 #6
0
 public X11Clipboard(AvaloniaX11Platform platform)
 {
     _x11    = platform.Info;
     _handle = CreateEventWindow(platform, OnEvent);
     _avaloniaSaveTargetsAtom = XInternAtom(_x11.Display, "AVALONIA_SAVE_TARGETS_PROPERTY_ATOM", false);
     _textAtoms = new[]
     {
         _x11.Atoms.XA_STRING,
         _x11.Atoms.OEMTEXT,
         _x11.Atoms.UTF8_STRING,
         _x11.Atoms.UTF16_STRING
     }.Where(a => a != IntPtr.Zero).ToArray();
 }
예제 #7
0
        public bool Init(AvaloniaX11Platform platform)
        {
            _platform   = platform;
            _x11        = platform.Info;
            _multitouch = platform.Options?.EnableMultiTouch ?? false;
            var devices = (XIDeviceInfo *)XIQueryDevice(_x11.Display,
                                                        (int)XiPredefinedDeviceId.XIAllMasterDevices, out int num);

            for (var c = 0; c < num; c++)
            {
                if (devices[c].Use == XiDeviceType.XIMasterPointer)
                {
                    _pointerDevice = new PointerDeviceInfo(devices[c]);
                    break;
                }
            }
            if (_pointerDevice == null)
            {
                return(false);
            }

            /*
             * int mask = 0;
             *
             * XISetMask(ref mask, XiEventType.XI_DeviceChanged);
             * var emask = new XIEventMask
             * {
             *  Mask = &mask,
             *  Deviceid = _pointerDevice.Id,
             *  MaskLen = XiEventMaskLen
             * };
             *
             * if (XISelectEvents(_x11.Display, _x11.RootWindow, &emask, 1) != Status.Success)
             *  return false;
             * return true;
             */
            return(XiSelectEvents(_x11.Display, _x11.RootWindow, new Dictionary <int, List <XiEventType> >
            {
                [_pointerDevice.Id] = new List <XiEventType>
                {
                    XiEventType.XI_DeviceChanged
                }
            }) == Status.Success);
        }
예제 #8
0
        public X11PlatformThreading(AvaloniaX11Platform platform)
        {
            _platform      = platform;
            _display       = platform.Display;
            _eventHandlers = platform.Windows;
            _mainThread    = Thread.CurrentThread;
            var fd = XLib.XConnectionNumber(_display);
            var ev = new epoll_event()
            {
                events = EPOLLIN,
                data   = { u32 = (int)EventCodes.X11 }
            };

            _epoll = epoll_create1(0);
            if (_epoll == -1)
            {
                throw new X11Exception("epoll_create1 failed");
            }

            if (epoll_ctl(_epoll, EPOLL_CTL_ADD, fd, ref ev) == -1)
            {
                throw new X11Exception("Unable to attach X11 connection handle to epoll");
            }

            var fds = stackalloc int[2];

            pipe2(fds, O_NONBLOCK);
            _sigread  = fds[0];
            _sigwrite = fds[1];

            ev = new epoll_event
            {
                events = EPOLLIN,
                data   = { u32 = (int)EventCodes.Signal }
            };
            if (epoll_ctl(_epoll, EPOLL_CTL_ADD, _sigread, ref ev) == -1)
            {
                throw new X11Exception("Unable to attach signal pipe to epoll");
            }
        }
예제 #9
0
파일: X11Window.cs 프로젝트: yatli/Avalonia
        public X11Window(AvaloniaX11Platform platform, IWindowImpl popupParent)
        {
            _platform = platform;
            _popup    = popupParent != null;
            _x11      = platform.Info;
            _mouse    = new MouseDevice();
            _touch    = new TouchDevice();
            _keyboard = platform.KeyboardDevice;

            var glfeature             = AvaloniaLocator.Current.GetService <IPlatformOpenGlInterface>();
            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (_popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            XVisualInfo?visualInfo = null;

            // OpenGL seems to be do weird things to it's current window which breaks resize sometimes
            _useRenderWindow = glfeature != null;

            var glx = glfeature as GlxPlatformOpenGlInterface;

            if (glx != null)
            {
                visualInfo = *glx.Display.VisualInfo;
            }
            else if (glfeature == null)
            {
                visualInfo = _x11.TransparentVisualInfo;
            }

            var egl = glfeature as EglPlatformOpenGlInterface;

            var visual = IntPtr.Zero;
            var depth  = 24;

            if (visualInfo != null)
            {
                visual        = visualInfo.Value.visual;
                depth         = (int)visualInfo.Value.depth;
                attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
                valueMask    |= SetWindowValuemask.ColorMap;
            }

            int defaultWidth = 0, defaultHeight = 0;

            if (!_popup && Screen != null)
            {
                var monitor = Screen.AllScreens.OrderBy(x => x.PixelDensity)
                              .FirstOrDefault(m => m.Bounds.Contains(Position));

                if (monitor != null)
                {
                    // Emulate Window 7+'s default window size behavior.
                    defaultWidth  = (int)(monitor.WorkingArea.Width * 0.75d);
                    defaultHeight = (int)(monitor.WorkingArea.Height * 0.7d);
                }
            }

            // check if the calculated size is zero then compensate to hardcoded resolution
            defaultWidth  = Math.Max(defaultWidth, 300);
            defaultHeight = Math.Max(defaultHeight, 200);

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, defaultWidth, defaultHeight, 0,
                                    depth,
                                    (int)CreateWindowArgs.InputOutput,
                                    visual,
                                    new UIntPtr((uint)valueMask), ref attr);

            if (_useRenderWindow)
            {
                _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, defaultWidth, defaultHeight, 0, depth,
                                              (int)CreateWindowArgs.InputOutput,
                                              visual,
                                              new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                                 SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
            else
            {
                _renderHandle = _handle;
            }

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(defaultWidth, defaultHeight);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            if (platform.Options.WmClass != null)
            {
                SetWmClass(platform.Options.WmClass);
            }

            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle,
                                          depth, () => RenderScaling)
            };

            if (egl != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface(egl,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            if (glx != null)
            {
                surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext,
                                                            new SurfaceInfo(this, _x11.Display, _handle, _renderHandle)));
            }

            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            UpdateSizeHints(null);
            _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                             XNames.XNClientWindow, _handle, IntPtr.Zero);
            _transparencyHelper = new TransparencyHelper(_x11, _handle, platform.Globals);
            _transparencyHelper.SetTransparencyRequest(WindowTransparencyLevel.None);

            XFlush(_x11.Display);
            if (_popup)
            {
                PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(popupParent, MoveResize));
            }
            if (platform.Options.UseDBusMenu)
            {
                NativeMenuExporter = DBusMenuExporter.TryCreate(_handle);
            }
            NativeControlHost = new X11NativeControlHost(_platform, this);
            DispatcherTimer.Run(() =>
            {
                Paint?.Invoke(default);
예제 #10
0
        public X11Window(AvaloniaX11Platform platform, bool popup)
        {
            _platform = platform;
            _popup    = popup;
            _x11      = platform.Info;
            _mouse    = platform.MouseDevice;
            _keyboard = platform.KeyboardDevice;

            var glfeature             = AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();
            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            XVisualInfo?visualInfo = null;

            // OpenGL seems to be do weird things to it's current window which breaks resize sometimes
            _useRenderWindow = glfeature != null;

            var glx = glfeature as GlxGlPlatformFeature;

            if (glx != null)
            {
                visualInfo = *glx.Display.VisualInfo;
            }
            else if (glfeature == null)
            {
                visualInfo = _x11.TransparentVisualInfo;
            }

            var egl = glfeature as EglGlPlatformFeature;

            var visual = IntPtr.Zero;
            var depth  = 24;

            if (visualInfo != null)
            {
                visual        = visualInfo.Value.visual;
                depth         = (int)visualInfo.Value.depth;
                attr.colormap = XCreateColormap(_x11.Display, _x11.RootWindow, visualInfo.Value.visual, 0);
                valueMask    |= SetWindowValuemask.ColorMap;
            }

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0,
                                    depth,
                                    (int)CreateWindowArgs.InputOutput,
                                    visual,
                                    new UIntPtr((uint)valueMask), ref attr);

            if (_useRenderWindow)
            {
                _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, depth,
                                              (int)CreateWindowArgs.InputOutput,
                                              visual,
                                              new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                                 SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);
            }
            else
            {
                _renderHandle = _handle;
            }

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(300, 200);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            if (platform.Options.WmClass != null)
            {
                SetWmClass(platform.Options.WmClass);
            }

            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle,
                                          depth, () => Scaling)
            };

            if (egl != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface((EglDisplay)egl.Display, egl.DeferredContext,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            if (glx != null)
            {
                surfaces.Insert(0, new GlxGlPlatformSurface(glx.Display, glx.DeferredContext,
                                                            new SurfaceInfo(this, _x11.Display, _handle, _renderHandle)));
            }

            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            _xic = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                             XNames.XNClientWindow, _handle, IntPtr.Zero);
            XFlush(_x11.Display);
        }
예제 #11
0
 public X11NativeControlHost(AvaloniaX11Platform platform, X11Window window)
 {
     _platform = platform;
     Window    = window;
 }
예제 #12
0
파일: X11Window.cs 프로젝트: mcjt/Avalonia
        public X11Window(AvaloniaX11Platform platform, bool popup)
        {
            _platform = platform;
            _popup    = popup;
            _x11      = platform.Info;
            _mouse    = platform.MouseDevice;
            _keyboard = platform.KeyboardDevice;
            _xic      = XCreateIC(_x11.Xim, XNames.XNInputStyle, XIMProperties.XIMPreeditNothing | XIMProperties.XIMStatusNothing,
                                  XNames.XNClientWindow, _handle, IntPtr.Zero);

            XSetWindowAttributes attr = new XSetWindowAttributes();
            var valueMask             = default(SetWindowValuemask);

            attr.backing_store = 1;
            attr.bit_gravity   = Gravity.NorthWestGravity;
            attr.win_gravity   = Gravity.NorthWestGravity;
            valueMask         |= SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel
                                 | SetWindowValuemask.BackPixmap | SetWindowValuemask.BackingStore
                                 | SetWindowValuemask.BitGravity | SetWindowValuemask.WinGravity;

            if (popup)
            {
                attr.override_redirect = true;
                valueMask |= SetWindowValuemask.OverrideRedirect;
            }

            _handle = XCreateWindow(_x11.Display, _x11.RootWindow, 10, 10, 300, 200, 0,
                                    24,
                                    (int)CreateWindowArgs.InputOutput, IntPtr.Zero,
                                    new UIntPtr((uint)valueMask), ref attr);
            _renderHandle = XCreateWindow(_x11.Display, _handle, 0, 0, 300, 200, 0, 24,
                                          (int)CreateWindowArgs.InputOutput,
                                          IntPtr.Zero,
                                          new UIntPtr((uint)(SetWindowValuemask.BorderPixel | SetWindowValuemask.BitGravity |
                                                             SetWindowValuemask.WinGravity | SetWindowValuemask.BackingStore)), ref attr);

            Handle    = new PlatformHandle(_handle, "XID");
            _realSize = new PixelSize(300, 200);
            platform.Windows[_handle] = OnEvent;
            XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
                                     | XEventMask.ResizeRedirectMask
                                     | XEventMask.PointerMotionHintMask;

            if (platform.XI2 != null)
            {
                ignoredMask |= platform.XI2.AddWindow(_handle, this);
            }
            var mask = new IntPtr(0xffffff ^ (int)ignoredMask);

            XSelectInput(_x11.Display, _handle, mask);
            var protocols = new[]
            {
                _x11.Atoms.WM_DELETE_WINDOW
            };

            XSetWMProtocols(_x11.Display, _handle, protocols, protocols.Length);
            XChangeProperty(_x11.Display, _handle, _x11.Atoms._NET_WM_WINDOW_TYPE, _x11.Atoms.XA_ATOM,
                            32, PropertyMode.Replace, new[] { _x11.Atoms._NET_WM_WINDOW_TYPE_NORMAL }, 1);

            var feature  = (EglGlPlatformFeature)AvaloniaLocator.Current.GetService <IWindowingPlatformGlFeature>();
            var surfaces = new List <object>
            {
                new X11FramebufferSurface(_x11.DeferredDisplay, _renderHandle, () => Scaling)
            };

            if (feature != null)
            {
                surfaces.Insert(0,
                                new EglGlPlatformSurface((EglDisplay)feature.Display, feature.DeferredContext,
                                                         new SurfaceInfo(this, _x11.DeferredDisplay, _handle, _renderHandle)));
            }
            Surfaces = surfaces.ToArray();
            UpdateMotifHints();
            XFlush(_x11.Display);
        }