File indexing completed on 2024-04-28 09:26:06

0001 /*
0002  *  SPDX-FileCopyrightText: 2012, 2013 Daniel Vrátil <dvratil@redhat.com>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractNativeEventFilter>
0010 #include <QLoggingCategory>
0011 #include <QObject>
0012 #include <QRect>
0013 
0014 #include <xcb/randr.h>
0015 #include <xcb/xcb.h>
0016 
0017 class XCBEventListener : public QObject, public QAbstractNativeEventFilter
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     XCBEventListener();
0023     ~XCBEventListener() override;
0024 
0025     bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
0026 
0027 Q_SIGNALS:
0028     /* Emitted when only XRandR 1.1 or older is available */
0029     void screenChanged(xcb_randr_rotation_t rotation, const QSize &sizePx, const QSize &sizeMm);
0030     void outputsChanged();
0031 
0032     /* Emitted only when XRandR 1.2 or newer is available */
0033     void crtcChanged(xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_rotation_t rotation, const QRect &geom, xcb_timestamp_t timestamp);
0034     void outputChanged(xcb_randr_output_t output, xcb_randr_crtc_t crtc, xcb_randr_mode_t mode, xcb_randr_connection_t connection);
0035     void outputPropertyChanged(xcb_randr_output_t output);
0036 
0037 private:
0038     QString rotationToString(xcb_randr_rotation_t rotation);
0039     QString connectionToString(xcb_randr_connection_t connection);
0040     void handleScreenChange(xcb_generic_event_t *e);
0041     void handleXRandRNotify(xcb_generic_event_t *e);
0042 
0043 protected:
0044     bool m_isRandrPresent;
0045     bool m_event11;
0046     uint8_t m_randrBase;
0047     uint8_t m_randrErrorBase;
0048     uint8_t m_majorOpcode;
0049     uint32_t m_versionMajor;
0050     uint32_t m_versionMinor;
0051 
0052     uint32_t m_window;
0053 };
0054 
0055 Q_DECLARE_LOGGING_CATEGORY(KSCREEN_XCB_HELPER)