| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2016 The Qt Company Ltd. |
| 4 |
** Contact: https://www.qt.io/licensing/ |
| 5 |
** |
| 6 |
** This file is part of the plugins of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 9 |
** Commercial License Usage |
| 10 |
** Licensees holding valid commercial Qt licenses may use this file in |
| 11 |
** accordance with the commercial license agreement provided with the |
| 12 |
** Software or, alternatively, in accordance with the terms contained in |
| 13 |
** a written agreement between you and The Qt Company. For licensing terms |
| 14 |
** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 |
** information use the contact form at https://www.qt.io/contact-us. |
| 16 |
** |
| 17 |
** GNU Lesser General Public License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 |
** General Public License version 3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 |
** packaging of this file. Please review the following information to |
| 22 |
** ensure the GNU Lesser General Public License version 3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 |
** |
| 25 |
** GNU General Public License Usage |
| 26 |
** Alternatively, this file may be used under the terms of the GNU |
| 27 |
** General Public License version 2.0 or (at your option) the GNU General |
| 28 |
** Public license version 3 or any later version approved by the KDE Free |
| 29 |
** Qt Foundation. The licenses are as published by the Free Software |
| 30 |
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 |
** included in the packaging of this file. Please review the following |
| 32 |
** information to ensure the GNU General Public License requirements will |
| 33 |
** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 |
** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 |
** |
| 36 |
** $QT_END_LICENSE$ |
| 37 |
** |
| 38 |
****************************************************************************/ |
| 39 |
|
| 40 |
#ifndef QXCBSCREEN_H |
| 41 |
#define QXCBSCREEN_H |
| 42 |
|
| 43 |
#include <qpa/qplatformscreen.h> |
| 44 |
#include <QtCore/QString> |
| 45 |
|
| 46 |
#include <xcb/xcb.h> |
| 47 |
#include <xcb/randr.h> |
| 48 |
#include <xcb/xfixes.h> |
| 49 |
#include <xcb/xinerama.h> |
| 50 |
|
| 51 |
#include "qxcbobject.h" |
| 52 |
#include "qxcbscreen.h" |
| 53 |
|
| 54 |
#include <private/qfontengine_p.h> |
| 55 |
|
| 56 |
#include <QtEdidSupport/private/qedidparser_p.h> |
| 57 |
|
| 58 |
QT_BEGIN_NAMESPACE |
| 59 |
|
| 60 |
class QXcbConnection; |
| 61 |
class QXcbCursor; |
| 62 |
class QXcbXSettings; |
| 63 |
#ifndef QT_NO_DEBUG_STREAM |
| 64 |
class QDebug; |
| 65 |
#endif |
| 66 |
|
| 67 |
class QXcbVirtualDesktop : public QXcbObject |
| 68 |
{ |
| 69 |
public: |
| 70 |
QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t *screen, int number); |
| 71 |
~QXcbVirtualDesktop(); |
| 72 |
|
| 73 |
xcb_screen_t *screen() const { return m_screen; } |
| 74 |
int number() const { return m_number; } |
| 75 |
QSize size() const { return QSize(m_screen->width_in_pixels, m_screen->height_in_pixels); } |
| 76 |
QSize physicalSize() const { return QSize(m_screen->width_in_millimeters, m_screen->height_in_millimeters); } |
| 77 |
QDpi dpi() const; |
| 78 |
xcb_window_t root() const { return m_screen->root; } |
| 79 |
QXcbScreen *screenAt(const QPoint &pos) const; |
| 80 |
|
| 81 |
QList<QPlatformScreen *> screens() const { return m_screens; } |
| 82 |
void setScreens(QList<QPlatformScreen *> &&sl) { m_screens = std::move(sl); } |
| 83 |
void removeScreen(QPlatformScreen *s) { m_screens.removeOne(s); } |
| 84 |
void addScreen(QPlatformScreen *s); |
| 85 |
void setPrimaryScreen(QPlatformScreen *s); |
| 86 |
|
| 87 |
QXcbXSettings *xSettings() const; |
| 88 |
|
| 89 |
bool compositingActive() const; |
| 90 |
|
| 91 |
void updateWorkArea(); |
| 92 |
QRect availableGeometry(const QRect &screenGeometry) const; |
| 93 |
|
| 94 |
void handleXFixesSelectionNotify(xcb_xfixes_selection_notify_event_t *notify_event); |
| 95 |
void subscribeToXFixesSelectionNotify(); |
| 96 |
|
| 97 |
void handleScreenChange(xcb_randr_screen_change_notify_event_t *change_event); |
| 98 |
|
| 99 |
int forcedDpi() const { return m_forcedDpi; } |
| 100 |
QFontEngine::HintStyle hintStyle() const { return m_hintStyle; } |
| 101 |
QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_subpixelType; } |
| 102 |
int antialiasingEnabled() const { return m_antialiasingEnabled; } |
| 103 |
|
| 104 |
QString windowManagerName() const { return m_windowManagerName; } |
| 105 |
|
| 106 |
QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const; |
| 107 |
|
| 108 |
const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const; |
| 109 |
const xcb_visualtype_t *visualForId(xcb_visualid_t) const; |
| 110 |
quint8 depthOfVisual(xcb_visualid_t) const; |
| 111 |
xcb_colormap_t colormapForVisual(xcb_visualid_t) const; |
| 112 |
|
| 113 |
private: |
| 114 |
QRect getWorkArea() const; |
| 115 |
|
| 116 |
static bool xResource(const QByteArray &identifier, |
| 117 |
const QByteArray &expectedIdentifier, |
| 118 |
QByteArray &stringValue); |
| 119 |
void readXResources(); |
| 120 |
|
| 121 |
bool setDpiFromXSettings(const QVariant &property); |
| 122 |
|
| 123 |
xcb_screen_t *m_screen; |
| 124 |
const int m_number; |
| 125 |
QList<QPlatformScreen *> m_screens; |
| 126 |
|
| 127 |
QXcbXSettings *m_xSettings = nullptr; |
| 128 |
xcb_atom_t m_net_wm_cm_atom = 0; |
| 129 |
bool m_compositingActive = false; |
| 130 |
|
| 131 |
QRect m_workArea; |
| 132 |
|
| 133 |
int m_forcedDpi = -1; |
| 134 |
QFontEngine::HintStyle m_hintStyle = QFontEngine::HintStyle(-1); |
| 135 |
QFontEngine::SubpixelAntialiasingType m_subpixelType = QFontEngine::SubpixelAntialiasingType(-1); |
| 136 |
int m_antialiasingEnabled = -1; |
| 137 |
QString m_windowManagerName; |
| 138 |
QMap<xcb_visualid_t, xcb_visualtype_t> m_visuals; |
| 139 |
QMap<xcb_visualid_t, quint8> m_visualDepths; |
| 140 |
mutable QMap<xcb_visualid_t, xcb_colormap_t> m_visualColormaps; |
| 141 |
uint16_t m_rotation = 0; |
| 142 |
}; |
| 143 |
|
| 144 |
class Q_XCB_EXPORT QXcbScreen : public QXcbObject, public QPlatformScreen |
| 145 |
{ |
| 146 |
public: |
| 147 |
QXcbScreen(QXcbConnection *connection, QXcbVirtualDesktop *virtualDesktop, |
| 148 |
xcb_randr_output_t outputId, xcb_randr_get_output_info_reply_t *outputInfo, |
| 149 |
const xcb_xinerama_screen_info_t *xineramaScreenInfo = nullptr, int xineramaScreenIdx = -1); |
| 150 |
~QXcbScreen(); |
| 151 |
|
| 152 |
QString getOutputName(xcb_randr_get_output_info_reply_t *outputInfo); |
| 153 |
|
| 154 |
QPixmap grabWindow(WId window, int x, int y, int width, int height) const override; |
| 155 |
|
| 156 |
QWindow *topLevelAt(const QPoint &point) const override; |
| 157 |
|
| 158 |
QString manufacturer() const override; |
| 159 |
QString model() const override; |
| 160 |
QString serialNumber() const override; |
| 161 |
|
| 162 |
QRect geometry() const override { return m_geometry; } |
| 163 |
QRect availableGeometry() const override; |
| 164 |
int depth() const override { return screen()->root_depth; } |
| 165 |
QImage::Format format() const override; |
| 166 |
QSizeF physicalSize() const override { return m_sizeMillimeters; } |
| 167 |
QDpi logicalDpi() const override; |
| 168 |
QDpi logicalBaseDpi() const override { return QDpi(96, 96); }; |
| 169 |
QPlatformCursor *cursor() const override; |
| 170 |
qreal refreshRate() const override { return m_refreshRate; } |
| 171 |
Qt::ScreenOrientation orientation() const override { return m_orientation; } |
| 172 |
QList<QPlatformScreen *> virtualSiblings() const override { return m_virtualDesktop->screens(); } |
| 173 |
QXcbVirtualDesktop *virtualDesktop() const { return m_virtualDesktop; } |
| 174 |
|
| 175 |
void setPrimary(bool primary) { m_primary = primary; } |
| 176 |
bool isPrimary() const { return m_primary; } |
| 177 |
|
| 178 |
int screenNumber() const { return m_virtualDesktop->number(); } |
| 179 |
static int virtualDesktopNumberStatic(const QScreen *screen); |
| 180 |
|
| 181 |
xcb_screen_t *screen() const { return m_virtualDesktop->screen(); } |
| 182 |
xcb_window_t root() const { return screen()->root; } |
| 183 |
xcb_randr_output_t output() const { return m_output; } |
| 184 |
xcb_randr_crtc_t crtc() const { return m_crtc; } |
| 185 |
xcb_randr_mode_t mode() const { return m_mode; } |
| 186 |
|
| 187 |
void setOutput(xcb_randr_output_t outputId, |
| 188 |
xcb_randr_get_output_info_reply_t *outputInfo); |
| 189 |
void setCrtc(xcb_randr_crtc_t crtc) { m_crtc = crtc; } |
| 190 |
|
| 191 |
void windowShown(QXcbWindow *window); |
| 192 |
QString windowManagerName() const { return m_virtualDesktop->windowManagerName(); } |
| 193 |
|
| 194 |
QSurfaceFormat surfaceFormatFor(const QSurfaceFormat &format) const; |
| 195 |
|
| 196 |
const xcb_visualtype_t *visualForFormat(const QSurfaceFormat &format) const { return m_virtualDesktop->visualForFormat(format); } |
| 197 |
const xcb_visualtype_t *visualForId(xcb_visualid_t visualid) const; |
| 198 |
xcb_colormap_t colormapForVisual(xcb_visualid_t visualid) const { return m_virtualDesktop->colormapForVisual(visualid); } |
| 199 |
quint8 depthOfVisual(xcb_visualid_t visualid) const { return m_virtualDesktop->depthOfVisual(visualid); } |
| 200 |
|
| 201 |
QString name() const override { return m_outputName; } |
| 202 |
|
| 203 |
void updateGeometry(const QRect &geometry, uint8_t rotation); |
| 204 |
void updateGeometry(xcb_timestamp_t timestamp = XCB_TIME_CURRENT_TIME); |
| 205 |
void updateAvailableGeometry(); |
| 206 |
void updateRefreshRate(xcb_randr_mode_t mode); |
| 207 |
|
| 208 |
QFontEngine::HintStyle hintStyle() const { return m_virtualDesktop->hintStyle(); } |
| 209 |
QFontEngine::SubpixelAntialiasingType subpixelType() const { return m_virtualDesktop->subpixelType(); } |
| 210 |
int antialiasingEnabled() const { return m_virtualDesktop->antialiasingEnabled(); } |
| 211 |
|
| 212 |
QXcbXSettings *xSettings() const; |
| 213 |
|
| 214 |
private: |
| 215 |
void sendStartupMessage(const QByteArray &message) const; |
| 216 |
int forcedDpi() const; |
| 217 |
|
| 218 |
QByteArray getOutputProperty(xcb_atom_t atom) const; |
| 219 |
QByteArray getEdid() const; |
| 220 |
|
| 221 |
QXcbVirtualDesktop *m_virtualDesktop; |
| 222 |
xcb_randr_output_t m_output; |
| 223 |
xcb_randr_crtc_t m_crtc; |
| 224 |
xcb_randr_mode_t m_mode = XCB_NONE; |
| 225 |
bool m_primary = false; |
| 226 |
|
| 227 |
QString m_outputName; |
| 228 |
QSizeF m_outputSizeMillimeters; |
| 229 |
QSizeF m_sizeMillimeters; |
| 230 |
QRect m_geometry; |
| 231 |
QRect m_availableGeometry; |
| 232 |
Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; |
| 233 |
QXcbCursor *m_cursor; |
| 234 |
qreal m_refreshRate = 60.0; |
| 235 |
QEdidParser m_edid; |
| 236 |
}; |
| 237 |
|
| 238 |
#ifndef QT_NO_DEBUG_STREAM |
| 239 |
Q_GUI_EXPORT QDebug operator<<(QDebug, const QXcbScreen *); |
| 240 |
#endif |
| 241 |
|
| 242 |
QT_END_NAMESPACE |
| 243 |
|
| 244 |
#endif |