File indexing completed on 2024-05-19 16:33:59

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "core/inputbackend.h"
0012 #include "core/inputdevice.h"
0013 #include "core/outputbackend.h"
0014 
0015 #include <kwin_export.h>
0016 
0017 #include <QObject>
0018 #include <QSize>
0019 
0020 #include <xcb/xcb.h>
0021 
0022 struct _XDisplay;
0023 typedef struct _XDisplay Display;
0024 typedef struct _XCBKeySymbols xcb_key_symbols_t;
0025 class NETWinInfo;
0026 class QSocketNotifier;
0027 
0028 namespace KWin
0029 {
0030 class X11WindowedBackend;
0031 class X11WindowedOutput;
0032 
0033 class X11WindowedInputDevice : public InputDevice
0034 {
0035     Q_OBJECT
0036 
0037 public:
0038     explicit X11WindowedInputDevice() = default;
0039 
0040     void setPointer(bool set);
0041     void setKeyboard(bool set);
0042     void setTouch(bool set);
0043     void setName(const QString &name);
0044 
0045     QString sysName() const override;
0046     QString name() const override;
0047 
0048     bool isEnabled() const override;
0049     void setEnabled(bool enabled) override;
0050 
0051     LEDs leds() const override;
0052     void setLeds(LEDs leds) override;
0053 
0054     bool isKeyboard() const override;
0055     bool isAlphaNumericKeyboard() const override;
0056     bool isPointer() const override;
0057     bool isTouchpad() const override;
0058     bool isTouch() const override;
0059     bool isTabletTool() const override;
0060     bool isTabletPad() const override;
0061     bool isTabletModeSwitch() const override;
0062     bool isLidSwitch() const override;
0063 
0064 private:
0065     QString m_name;
0066     bool m_pointer = false;
0067     bool m_keyboard = false;
0068     bool m_touch = false;
0069 };
0070 
0071 class X11WindowedInputBackend : public InputBackend
0072 {
0073     Q_OBJECT
0074 
0075 public:
0076     explicit X11WindowedInputBackend(X11WindowedBackend *backend);
0077 
0078     void initialize() override;
0079 
0080 private:
0081     X11WindowedBackend *m_backend;
0082 };
0083 
0084 struct X11WindowedBackendOptions
0085 {
0086     QString display;
0087     int outputCount = 1;
0088     qreal outputScale = 1;
0089     QSize outputSize = QSize(1024, 768);
0090 };
0091 
0092 class KWIN_EXPORT X11WindowedBackend : public OutputBackend
0093 {
0094     Q_OBJECT
0095 
0096 public:
0097     explicit X11WindowedBackend(const X11WindowedBackendOptions &options);
0098     ~X11WindowedBackend() override;
0099 
0100     Display *display() const;
0101     xcb_connection_t *connection() const;
0102     xcb_screen_t *screen() const;
0103     int screenNumer() const;
0104     xcb_window_t rootWindow() const;
0105 
0106     bool hasXInput() const;
0107 
0108     bool initialize() override;
0109     std::unique_ptr<OpenGLBackend> createOpenGLBackend() override;
0110     std::unique_ptr<QPainterBackend> createQPainterBackend() override;
0111     std::unique_ptr<InputBackend> createInputBackend() override;
0112     QVector<CompositingType> supportedCompositors() const override;
0113     Outputs outputs() const override;
0114 
0115     X11WindowedInputDevice *pointerDevice() const;
0116     X11WindowedInputDevice *keyboardDevice() const;
0117     X11WindowedInputDevice *touchDevice() const;
0118 
0119 private:
0120     void createOutputs();
0121     void grabKeyboard(xcb_timestamp_t time);
0122     void updateWindowTitle();
0123     void handleEvent(xcb_generic_event_t *event);
0124     void handleClientMessage(xcb_client_message_event_t *event);
0125     void handleButtonPress(xcb_button_press_event_t *event);
0126     void handleExpose(xcb_expose_event_t *event);
0127     void handleXinputEvent(xcb_ge_generic_event_t *event);
0128     void handlePresentEvent(xcb_ge_generic_event_t *event);
0129     void updateSize(xcb_configure_notify_event_t *event);
0130     void initXInput();
0131     X11WindowedOutput *findOutput(xcb_window_t window) const;
0132     void destroyOutputs();
0133 
0134     X11WindowedBackendOptions m_options;
0135     xcb_connection_t *m_connection = nullptr;
0136     xcb_screen_t *m_screen = nullptr;
0137     xcb_key_symbols_t *m_keySymbols = nullptr;
0138     int m_screenNumber = 0;
0139 
0140     std::unique_ptr<X11WindowedInputDevice> m_pointerDevice;
0141     std::unique_ptr<X11WindowedInputDevice> m_keyboardDevice;
0142     std::unique_ptr<X11WindowedInputDevice> m_touchDevice;
0143 
0144     xcb_atom_t m_protocols = XCB_ATOM_NONE;
0145     xcb_atom_t m_deleteWindowProtocol = XCB_ATOM_NONE;
0146     Display *m_display = nullptr;
0147     bool m_keyboardGrabbed = false;
0148     std::unique_ptr<QSocketNotifier> m_eventNotifier;
0149 
0150     bool m_hasXInput = false;
0151     int m_xiOpcode = 0;
0152     int m_majorVersion = 0;
0153     int m_minorVersion = 0;
0154 
0155     int m_presentOpcode = 0;
0156     int m_presentMajorVersion = 0;
0157     int m_presentMinorVersion = 0;
0158 
0159     bool m_hasShm = false;
0160 
0161     QVector<X11WindowedOutput *> m_outputs;
0162 };
0163 
0164 } // namespace KWin