File indexing completed on 2025-05-11 12:04:19

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 Compositor;
0037 class WorkspaceScene;
0038 class Window;
0039 
0040 class KWIN_EXPORT X11StandaloneBackend : public OutputBackend
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045     X11StandaloneBackend(QObject *parent = nullptr);
0046     ~X11StandaloneBackend() override;
0047     bool initialize() override;
0048 
0049     std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
0050     QVector<CompositingType> supportedCompositors() const override;
0051 
0052     void initOutputs();
0053     void scheduleUpdateOutputs();
0054     void updateOutputs();
0055 
0056     std::unique_ptr<Edge> createScreenEdge(ScreenEdges *parent);
0057     void createPlatformCursor(QObject *parent = nullptr);
0058     void startInteractiveWindowSelection(std::function<void(KWin::Window *)> callback, const QByteArray &cursorName = QByteArray());
0059     void startInteractivePositionSelection(std::function<void(const QPoint &)> callback);
0060     PlatformCursorImage cursorImage() const;
0061     std::unique_ptr<OutlineVisual> createOutline(Outline *outline);
0062     void createEffectsHandler(Compositor *compositor, WorkspaceScene *scene);
0063 
0064     X11Keyboard *keyboard() const;
0065     RenderLoop *renderLoop() const;
0066     Outputs outputs() const override;
0067 
0068 private:
0069     /**
0070      * Tests whether GLX is supported and returns @c true
0071      * in case KWin is compiled with OpenGL support and GLX
0072      * is available.
0073      *
0074      * If KWin is compiled with OpenGL ES or without OpenGL at
0075      * all, @c false is returned.
0076      * @returns @c true if GLX is available, @c false otherwise and if not build with OpenGL support.
0077      */
0078     static bool hasGlx();
0079 
0080     X11Output *findX11Output(const QString &name) const;
0081     template<typename T>
0082     void doUpdateOutputs();
0083     void updateRefreshRate();
0084     void updateCursor();
0085 
0086 #if HAVE_X11_XINPUT
0087     std::unique_ptr<XInputIntegration> m_xinputIntegration;
0088 #endif
0089     std::unique_ptr<QTimer> m_updateOutputsTimer;
0090     Display *m_x11Display;
0091     std::unique_ptr<WindowSelector> m_windowSelector;
0092     std::unique_ptr<X11EventFilter> m_screenEdgesFilter;
0093     std::unique_ptr<X11EventFilter> m_randrEventFilter;
0094     std::unique_ptr<X11Keyboard> m_keyboard;
0095     std::unique_ptr<RenderLoop> m_renderLoop;
0096     QVector<Output *> m_outputs;
0097 };
0098 
0099 }