예제 #1
0
        private void UpdateFrameExtents(XlibDispatchProvider dispatchProvider, IntPtr display, nuint window)
        {
            if (dispatchProvider.GetAtomIsSupported(_NET_FRAME_EXTENTS))
            {
                nuint actualType;
                int   actualFormat;
                nuint itemCount;
                nuint bytesRemaining;
                nint *cardinals;

                _ = XGetWindowProperty(
                    display,
                    window,
                    dispatchProvider.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, XlibDispatchProvider dispatchProvider)
        {
            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(XlibDispatchProvider dispatchProvider, IntPtr display, nuint window)
        {
            if (dispatchProvider.GetAtomIsSupported(_NET_WM_NAME))
            {
                nuint  actualType;
                int    actualFormat;
                nuint  itemCount;
                nuint  bytesRemaining;
                sbyte *wmName;

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

                if ((actualType == dispatchProvider.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(XlibDispatchProvider dispatchProvider, IntPtr display, nuint window)
        {
            if (dispatchProvider.GetAtomIsSupported(_NET_WM_STATE))
            {
                nuint  actualType;
                int    actualFormat;
                nuint  itemCount;
                nuint  bytesRemaining;
                nuint *netWmState;

                _ = XGetWindowProperty(
                    display,
                    window,
                    dispatchProvider.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] == dispatchProvider.GetAtom(_NET_WM_STATE_FOCUSED))
                        {
                            foundNetWmStateFocused = true;
                        }
                        else if (netWmState[i] == dispatchProvider.GetAtom(_NET_WM_STATE_HIDDEN))
                        {
                            foundNetWmStateHidden = true;
                        }
                        else if (netWmState[i] == dispatchProvider.GetAtom(_NET_WM_STATE_MAXIMIZED_HORZ))
                        {
                            foundNetWmStateMaximizedHorz = true;
                        }
                        else if (netWmState[i] == dispatchProvider.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, XlibDispatchProvider dispatchProvider)
 => UpdateWindowState(dispatchProvider, xproperty->display, xproperty->window);
예제 #6
0
 private void HandleXPropertyNetWmName(XPropertyEvent *xproperty, XlibDispatchProvider dispatchProvider)
 => UpdateWindowTitle(dispatchProvider, xproperty->display, xproperty->window);
예제 #7
0
 private void HandleXPropertyNetFrameExtents(XPropertyEvent *xproperty, XlibDispatchProvider dispatchProvider)
 => UpdateFrameExtents(dispatchProvider, xproperty->display, xproperty->window);
예제 #8
0
        private static XlibWindow RemoveWindow(Dictionary <nuint, XlibWindow> windows, IntPtr display, nuint windowHandle, XlibDispatchProvider dispatchProvider)
        {
            _ = windows.Remove(windowHandle, out var window);
            AssertNotNull(window);

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

            return(window);
        }
예제 #9
0
 internal XlibDispatcher(XlibDispatchProvider dispatchProvider, Thread parentThread)
     : base(dispatchProvider, parentThread)
 {
 }