File indexing completed on 2024-05-19 05:31:29

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <config-kwin.h>
0013 
0014 #include "core/outputbackend.h"
0015 #include <kwin_export.h>
0016 
0017 #include <QObject>
0018 
0019 #include <memory>
0020 
0021 #include <X11/Xlib-xcb.h>
0022 #include <fixx11h.h>
0023 
0024 namespace KWin
0025 {
0026 class RenderLoop;
0027 class XInputIntegration;
0028 class WindowSelector;
0029 class X11EventFilter;
0030 class X11Output;
0031 class X11Keyboard;
0032 class Edge;
0033 class ScreenEdges;
0034 class Outline;
0035 class OutlineVisual;
0036 class Cursor;
0037 class Compositor;
0038 class WorkspaceScene;
0039 class Window;
0040 
0041 class KWIN_EXPORT X11StandaloneBackend : public OutputBackend
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     X11StandaloneBackend(QObject *parent = nullptr);
0047     ~X11StandaloneBackend() override;
0048     bool initialize() override;
0049 
0050     ::Display *display() const;
0051     xcb_connection_t *connection() const;
0052     xcb_window_t rootWindow() const;
0053 
0054     std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
0055     QList<CompositingType> supportedCompositors() const override;
0056 
0057     void initOutputs();
0058     void scheduleUpdateOutputs();
0059     void updateOutputs();
0060 
0061     std::unique_ptr<Edge> createScreenEdge(ScreenEdges *parent);
0062     std::unique_ptr<Cursor> createPlatformCursor();
0063     void startInteractiveWindowSelection(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName = QByteArray());
0064     void startInteractivePositionSelection(std::function<void(const QPointF &)> callback);
0065     PlatformCursorImage cursorImage() const;
0066     std::unique_ptr<OutlineVisual> createOutline(Outline *outline);
0067     void createEffectsHandler(Compositor *compositor, WorkspaceScene *scene);
0068 
0069     X11Keyboard *keyboard() const;
0070     RenderLoop *renderLoop() const;
0071     Outputs outputs() const override;
0072 
0073     void setEglDisplay(std::unique_ptr<EglDisplay> &&display);
0074     EglDisplay *sceneEglDisplayObject() const override;
0075 
0076 private:
0077     /**
0078      * Tests whether GLX is supported and returns @c true
0079      * in case KWin is compiled with OpenGL support and GLX
0080      * is available.
0081      *
0082      * If KWin is compiled with OpenGL ES or without OpenGL at
0083      * all, @c false is returned.
0084      * @returns @c true if GLX is available, @c false otherwise and if not build with OpenGL support.
0085      */
0086     static bool hasGlx();
0087 
0088     X11Output *findX11Output(const QString &name) const;
0089     template<typename T>
0090     void doUpdateOutputs();
0091     void updateRefreshRate();
0092     void updateCursor();
0093 
0094 #if HAVE_X11_XINPUT
0095     std::unique_ptr<XInputIntegration> m_xinputIntegration;
0096 #endif
0097     std::unique_ptr<QTimer> m_updateOutputsTimer;
0098     ::Display *m_x11Display;
0099     std::unique_ptr<WindowSelector> m_windowSelector;
0100     std::unique_ptr<X11EventFilter> m_screenEdgesFilter;
0101     std::unique_ptr<X11EventFilter> m_randrEventFilter;
0102     std::unique_ptr<X11Keyboard> m_keyboard;
0103     std::unique_ptr<RenderLoop> m_renderLoop;
0104     QList<Output *> m_outputs;
0105     std::unique_ptr<EglDisplay> m_eglDisplay;
0106 };
0107 
0108 }