| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 4 |
|
| 5 |
#ifndef QXCBSCREEN_H |
| 6 |
#define QXCBSCREEN_H |
| 7 |
|
| 8 |
#include <qpa/qplatformscreen.h> |
| 9 |
#include <QtCore/QString> |
| 10 |
|
| 11 |
#include <xcb/xcb.h> |
| 12 |
#include <xcb/randr.h> |
| 13 |
#include <xcb/xfixes.h> |
| 14 |
#include <xcb/xinerama.h> |
| 15 |
|
| 16 |
#include "qxcbobject.h" |
| 17 |
#include "qxcbscreen.h" |
| 18 |
|
| 19 |
#include <private/qfontengine_p.h> |
| 20 |
|
| 21 |
QT_BEGIN_NAMESPACE |
| 22 |
|
| 23 |
class QXcbConnection; |
| 24 |
class QXcbCursor; |
| 25 |
class QXcbXSettings; |
| 26 |
#ifndef QT_NO_DEBUG_STREAM |
| 27 |
class QDebug; |
| 28 |
#endif |
| 29 |
|
| 30 |
class QXcbVirtualDesktop : public QXcbObject |
| 31 |
{ |
| 32 |
public: |
| 33 |
QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t *screen, int number); |
| 34 |
~QXcbVirtualDesktop(); |
| 35 |
|
| 36 |
xcb_screen_t *screen() const { return m_screen; } |
| 37 |
int number() const { return m_number; } |
| 38 |
QSize size() const { return QSize(m_screen->width_in_pixels, m_screen->height_in_pixels); } |
| 39 |
QSize physicalSize() const { return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters); } |
| 40 |
xcb_window_t root() const { return m_screen->root; } |
| 41 |
QXcbScreen *screenAt(const QPoint &pos) const; |
| 42 |
|
| 43 |
QList<QPlatformScreen *> screens() const { return m_screens; } |
| 44 |
void setScreens(QList<QPlatformScreen *> sl) { m_screens = sl; } |
| 45 |
void removeScreen(QPlatformScreen *s) { m_screens.removeOne(s); } |
| 46 |
void addScreen(QPlatformScreen *s); |
| 47 |
void setPrimaryScreen(QPlatformScreen *s); |
| 48 |
|
| 49 |
QXcbXSettings *xSettings() const; |
| 50 |
|
| 51 |
bool compositingActive() const; |
| 52 |
|
| 53 |
QRect workArea() const { return m_workArea; } |
| 54 |
void updateWorkArea(); |
| 55 |
|
| 56 |
void handleXFixesSelectionNotify(xcb_xfixes_selection_notify_event_t *notify_event); |
| 57 |
void subscribeToXFixesSelectionNotify(); |
| 58 |
|
| 59 |
private: |
| 60 |
QRect getWorkArea() const; |
| 61 |
|
| 62 |
xcb_screen_t *m_screen; |
| 63 |
int m_number; |
| 64 |
QList<QPlatformScreen *> m_screens; |
| 65 |
|
| 66 |
QXcbXSettings *m_xSettings; |
| 67 |
xcb_atom_t m_net_wm_cm_atom; |
| 68 |
bool m_compositingActive; |
| 69 |
|
| 70 |
QRect m_workArea; |
| 71 |
}; |
| 72 |
|
| 73 |
class Q_XCB_EXPORT QXcbScreen : public QXcbObject, public QPlatformScreen |
| 74 |
{ |
| 75 |
public: |
| 76 |
QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop, |
| 77 |
xcb_randr_output_t outputId, xcb_randr_get_output_info_reply_t *outputInfo, |
| 78 |
const xcb_xinerama_screen_info_t *xineramaScreenInfo = Q_NULLPTR, int xineramaScreenIdx = -1); |
| 79 |
~QXcbScreen(); |
| 80 |
|
| 81 |
QString getOutputName(xcb_randr_get_output_info_reply_t *outputInfo); |
| 82 |
|
| 83 |
QPixmap grabWindow(WId window, int x, int y, int width, int height) const Q_DECL_OVERRIDE; |
| 84 |
|
| 85 |
QWindow *topLevelAt(const QPoint &point) const Q_DECL_OVERRIDE; |
| 86 |
|
| 87 |
QRect geometry() const Q_DECL_OVERRIDE { return m_geometry; } |
| 88 |
QRect availableGeometry() const Q_DECL_OVERRIDE {return m_availableGeometry;} |
| 89 |
int depth() const Q_DECL_OVERRIDE { return screen()->root_depth; } |
| 90 |
QImage::Format format() const Q_DECL_OVERRIDE; |
| 91 |
QSizeF physicalSize() const Q_DECL_OVERRIDE { return m_sizeMillimeters; } |
| 92 |
QSize virtualSize() const { return m_virtualSize; } |
| 93 |
QSizeF physicalVirtualSize() const { return m_virtualSizeMillimeters; } |
| 94 |
QDpi virtualDpi() const; |
| 95 |
QDpi logicalDpi() const Q_DECL_OVERRIDE; |
| 96 |
qreal pixelDensity() const Q_DECL_OVERRIDE; |
| 97 |
QPlatformCursor *cursor() const Q_DECL_OVERRIDE; |
| 98 |
qreal refreshRate() const Q_DECL_OVERRIDE { return m_refreshRate; } |
| 99 |
Qt::ScreenOrientation orientation() const Q_DECL_OVERRIDE { return m_orientation; } |
| 100 |
QList<QPlatformScreen *> virtualSiblings() const Q_DECL_OVERRIDE { return m_virtualDesktop->screens(); } |
| 101 |
QXcbVirtualDesktop *virtualDesktop() const { return m_virtualDesktop; } |
| 102 |
|
| 103 |
void setPrimary(bool primary) { m_primary = primary; } |
| 104 |
bool isPrimary() const { return m_primary; } |
| 105 |
|
| 106 |
int screenNumber() const { return m_virtualDesktop->number(); } |
| 107 |
static int virtualDesktopNumberStatic(const QScreen *screen); |
| 108 |
|
| 109 |
xcb_screen_t *screen() const { return m_virtualDesktop->screen(); } |
| 110 |
xcb_window_t root() const { return screen()->root; } |
| 111 |
xcb_randr_output_t output() const { return m_output; } |
| 112 |
xcb_randr_crtc_t crtc() const { return m_crtc; } |
| 113 |
xcb_randr_mode_t mode() const { return m_mode; } |
| 114 |
|
| 115 |
void setOutput(xcb_randr_output_t outputId, |
| 116 |
xcb_randr_get_output_info_reply_t *outputInfo); |
| 117 |
void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; } |
| 118 |
|
| 119 |
void windowShown(QXcbWindow *window); |
| 120 |
QString windowManagerName() const { return m_windowManagerName; } |
| 121 |
bool syncRequestSupported() const { return m_syncRequestSupported; } |
| 122 |
|
| 123 |
QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const; |
| 124 |
|
| 125 |
const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const; |
| 126 |
const xcb_visualtype_t *visualForId(xcb_visualid_t) const; |
| 127 |
quint8 depthOfVisual(xcb_visualid_t) const; |
| 128 |
|
| 129 |
QString name() const Q_DECL_OVERRIDE { return m_outputName; } |
| 130 |
|
| 131 |
void handleScreenChange(xcb_randr_screen_change_notify_event_t *change_event); |
| 132 |
void updateGeometry(const QRect &geom, uint8_t rotation); |
| 133 |
void updateGeometry(xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME); |
| 134 |
void updateAvailableGeometry(); |
| 135 |
void updateRefreshRate(xcb_randr_mode_t mode); |
| 136 |
|
| 137 |
void readXResources(); |
| 138 |
|
| 139 |
QFontEngine::HintStyle hintStyle() const { return m_hintStyle; } |
| 140 |
bool noFontHinting() const { return m_noFontHinting; } |
| 141 |
QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_subpixelType; } |
| 142 |
int antialiasingEnabled() const { return m_antialiasingEnabled; } |
| 143 |
|
| 144 |
QXcbXSettings *xSettings() const; |
| 145 |
|
| 146 |
private: |
| 147 |
static bool xResource(const QByteArray &identifier, |
| 148 |
const QByteArray &expectedIdentifier, |
| 149 |
QByteArray &stringValue); |
| 150 |
void sendStartupMessage(const QByteArray &message) const; |
| 151 |
|
| 152 |
QXcbVirtualDesktop *m_virtualDesktop; |
| 153 |
xcb_randr_output_t m_output; |
| 154 |
xcb_randr_crtc_t m_crtc; |
| 155 |
xcb_randr_mode_t m_mode; |
| 156 |
bool m_primary; |
| 157 |
uint8_t m_rotation; |
| 158 |
|
| 159 |
QString m_outputName; |
| 160 |
QSizeF m_outputSizeMillimeters; |
| 161 |
QSizeF m_sizeMillimeters; |
| 162 |
QRect m_geometry; |
| 163 |
QRect m_availableGeometry; |
| 164 |
QSize m_virtualSize; |
| 165 |
QSizeF m_virtualSizeMillimeters; |
| 166 |
Qt::ScreenOrientation m_orientation; |
| 167 |
QString m_windowManagerName; |
| 168 |
bool m_syncRequestSupported; |
| 169 |
QMap<xcb_visualid_t, xcb_visualtype_t> m_visuals; |
| 170 |
QMap<xcb_visualid_t, quint8> m_visualDepths; |
| 171 |
QXcbCursor *m_cursor; |
| 172 |
int m_refreshRate; |
| 173 |
int m_forcedDpi; |
| 174 |
int m_pixelDensity; |
| 175 |
QFontEngine::HintStyle m_hintStyle; |
| 176 |
bool m_noFontHinting; |
| 177 |
QFontEngine::SubpixelAntialiasingType m_subpixelType; |
| 178 |
int m_antialiasingEnabled; |
| 179 |
}; |
| 180 |
|
| 181 |
#ifndef QT_NO_DEBUG_STREAM |
| 182 |
Q_GUI_EXPORT QDebug operator<<(QDebug, const QXcbScreen *); |
| 183 |
#endif |
| 184 |
|
| 185 |
QT_END_NAMESPACE |
| 186 |
|
| 187 |
#endif |