Пример #1
0
        private void UpdateFrameExtents(XlibDispatchService dispatchService, IntPtr display, nuint window)
        {
            if (dispatchService.GetAtomIsSupported(_NET_FRAME_EXTENTS))
            {
                nuint actualType;
                int   actualFormat;
                nuint itemCount;
                nuint bytesRemaining;
                nint *cardinals;

                _ = XGetWindowProperty(
                    display,
                    window,
                    dispatchService.GetAtom(_NET_FRAME_EXTENTS),
                    0,
                    4,
                    False,
                    XA_CARDINAL,
                    &actualType,
                    &actualFormat,
                    &itemCount,
                    &bytesRemaining,
                    (byte **)&cardinals
                    );

                if ((actualType == XA_CARDINAL) && (actualFormat == 32) && (itemCount == 4) && (bytesRemaining == 0))
                {
                    // The cardinals given are left, right, top and bottom; respectively
                    // Using these, we construct a rectangle that specifies the adjustments
                    // made to a given client rectangle to compute the non-client size and
                    // location.

                    _frameExtents = new Rectangle(
                        -cardinals[0],
                        -cardinals[2],
                        cardinals[1] + cardinals[0],
                        cardinals[3] + cardinals[2]
                        );
                }
                else
                {
                    _frameExtents = default;
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #2
0
        private void HandleXPropertyWmHints(XPropertyEvent *xproperty, XlibDispatchService dispatchService)
        {
            XWMHints *wmHints = null;

            try
            {
                wmHints = XGetWMHints(xproperty->display, xproperty->window);

                _isEnabled = (wmHints != null) &&
                             ((wmHints->flags * InputHint) != 0) &&
                             (wmHints->input != False);
            }
            finally
            {
                if (wmHints != null)
                {
                    _ = XFree(wmHints);
                }
            }
        }
Пример #3
0
        private void UpdateWindowTitle(XlibDispatchService dispatchService, IntPtr display, nuint window)
        {
            if (dispatchService.GetAtomIsSupported(_NET_WM_NAME))
            {
                nuint  actualType;
                int    actualFormat;
                nuint  itemCount;
                nuint  bytesRemaining;
                sbyte *wmName;

                _ = XGetWindowProperty(
                    display,
                    window,
                    dispatchService.GetAtom(_NET_WM_NAME),
                    0,
                    nint.MaxValue,
                    False,
                    dispatchService.GetAtom(UTF8_STRING),
                    &actualType,
                    &actualFormat,
                    &itemCount,
                    &bytesRemaining,
                    (byte **)&wmName
                    );

                if ((actualType == dispatchService.GetAtom(UTF8_STRING)) && (actualFormat == 8) && (bytesRemaining == 0))
                {
                    _title = GetUtf8Span(wmName, checked ((int)itemCount)).GetString() ?? string.Empty;
                }
                else
                {
                    _title = string.Empty;
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #4
0
        private void UpdateWindowState(XlibDispatchService dispatchService, IntPtr display, nuint window)
        {
            if (dispatchService.GetAtomIsSupported(_NET_WM_STATE))
            {
                nuint  actualType;
                int    actualFormat;
                nuint  itemCount;
                nuint  bytesRemaining;
                nuint *netWmState;

                _ = XGetWindowProperty(
                    display,
                    window,
                    dispatchService.GetAtom(_NET_WM_STATE),
                    0,
                    nint.MaxValue,
                    False,
                    XA_ATOM,
                    &actualType,
                    &actualFormat,
                    &itemCount,
                    &bytesRemaining,
                    (byte **)&netWmState
                    );

                if ((actualType == XA_ATOM) && (actualFormat == 32) && (bytesRemaining == 0))
                {
                    var foundNetWmStateFocused       = false;
                    var foundNetWmStateHidden        = false;
                    var foundNetWmStateMaximizedHorz = false;
                    var foundNetWmStateMaximizedVert = false;

                    for (nuint i = 0; i < itemCount; i++)
                    {
                        if (netWmState[i] == dispatchService.GetAtom(_NET_WM_STATE_FOCUSED))
                        {
                            foundNetWmStateFocused = true;
                        }
                        else if (netWmState[i] == dispatchService.GetAtom(_NET_WM_STATE_HIDDEN))
                        {
                            foundNetWmStateHidden = true;
                        }
                        else if (netWmState[i] == dispatchService.GetAtom(_NET_WM_STATE_MAXIMIZED_HORZ))
                        {
                            foundNetWmStateMaximizedHorz = true;
                        }
                        else if (netWmState[i] == dispatchService.GetAtom(_NET_WM_STATE_MAXIMIZED_VERT))
                        {
                            foundNetWmStateMaximizedVert = true;
                        }
                    }

                    _isActive = foundNetWmStateFocused;

                    if (foundNetWmStateHidden)
                    {
                        _windowState = WindowState.Minimized;
                    }
                    else if (foundNetWmStateMaximizedHorz && foundNetWmStateMaximizedVert)
                    {
                        _windowState = WindowState.Maximized;
                    }
                    else
                    {
                        _windowState = WindowState.Normal;
                    }
                }
                else
                {
                    _isActive    = false;
                    _windowState = WindowState.Hidden;
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #5
0
 private void HandleXPropertyWmState(XPropertyEvent *xproperty, XlibDispatchService dispatchService)
 => UpdateWindowState(dispatchService, xproperty->display, xproperty->window);
Пример #6
0
 private void HandleXPropertyNetWmName(XPropertyEvent *xproperty, XlibDispatchService dispatchService)
 => UpdateWindowTitle(dispatchService, xproperty->display, xproperty->window);
Пример #7
0
 private void HandleXPropertyNetFrameExtents(XPropertyEvent *xproperty, XlibDispatchService dispatchService)
 => UpdateFrameExtents(dispatchService, xproperty->display, xproperty->window);
Пример #8
0
        private static XlibWindow RemoveWindow(Dictionary <nuint, XlibWindow> windows, IntPtr display, nuint windowHandle, XlibDispatchService dispatchService)
        {
            _ = windows.Remove(windowHandle, out var window);
            AssertNotNull(window);

            if (windows.Count == 0)
            {
                dispatchService.DispatcherForCurrentThread.OnExitRequested();
            }

            return(window);
        }
Пример #9
0
 internal XlibDispatcher(XlibDispatchService dispatchService, Thread parentThread)
     : base(dispatchService, parentThread)
 {
 }