Warning: That file was not part of the compilation database. It may have many parsing errors.
| 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 | #include "qwaylandscreen_p.h" |
| 41 | |
| 42 | #include "qwaylanddisplay_p.h" |
| 43 | #include "qwaylandcursor_p.h" |
| 44 | #include "qwaylandwindow_p.h" |
| 45 | |
| 46 | #include <QtGui/QGuiApplication> |
| 47 | |
| 48 | #include <qpa/qwindowsysteminterface.h> |
| 49 | #include <qpa/qplatformwindow.h> |
| 50 | |
| 51 | QT_BEGIN_NAMESPACE |
| 52 | |
| 53 | namespace QtWaylandClient { |
| 54 | |
| 55 | QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id) |
| 56 | : QPlatformScreen() |
| 57 | , QtWayland::wl_output(waylandDisplay->wl_registry(), id, qMin(version, 2)) |
| 58 | , m_outputId(id) |
| 59 | , mWaylandDisplay(waylandDisplay) |
| 60 | , mScale(1) |
| 61 | , mDepth(32) |
| 62 | , mRefreshRate(60000) |
| 63 | , mTransform(-1) |
| 64 | , mFormat(QImage::Format_ARGB32_Premultiplied) |
| 65 | , mOutputName(QStringLiteral("Screen%1").arg(id)) |
| 66 | , m_orientation(Qt::PrimaryOrientation) |
| 67 | #if QT_CONFIG(cursor) |
| 68 | , mWaylandCursor(0) |
| 69 | #endif |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | QWaylandScreen::~QWaylandScreen() |
| 74 | { |
| 75 | #if QT_CONFIG(cursor) |
| 76 | delete mWaylandCursor; |
| 77 | #endif |
| 78 | } |
| 79 | |
| 80 | void QWaylandScreen::init() |
| 81 | { |
| 82 | #if QT_CONFIG(cursor) |
| 83 | mWaylandCursor = new QWaylandCursor(this); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | QWaylandDisplay * QWaylandScreen::display() const |
| 88 | { |
| 89 | return mWaylandDisplay; |
| 90 | } |
| 91 | |
| 92 | QString QWaylandScreen::manufacturer() const |
| 93 | { |
| 94 | return mManufacturer; |
| 95 | } |
| 96 | |
| 97 | QString QWaylandScreen::model() const |
| 98 | { |
| 99 | return mModel; |
| 100 | } |
| 101 | |
| 102 | QRect QWaylandScreen::geometry() const |
| 103 | { |
| 104 | // Scale geometry for QScreen. This makes window and screen |
| 105 | // geometry be in the same coordinate system. |
| 106 | return QRect(mGeometry.topLeft(), mGeometry.size() / mScale); |
| 107 | } |
| 108 | |
| 109 | int QWaylandScreen::depth() const |
| 110 | { |
| 111 | return mDepth; |
| 112 | } |
| 113 | |
| 114 | QImage::Format QWaylandScreen::format() const |
| 115 | { |
| 116 | return mFormat; |
| 117 | } |
| 118 | |
| 119 | QSizeF QWaylandScreen::physicalSize() const |
| 120 | { |
| 121 | if (mPhysicalSize.isEmpty()) |
| 122 | return QPlatformScreen::physicalSize(); |
| 123 | else |
| 124 | return mPhysicalSize; |
| 125 | } |
| 126 | |
| 127 | QDpi QWaylandScreen::logicalDpi() const |
| 128 | { |
| 129 | static int force_dpi = !qgetenv("QT_WAYLAND_FORCE_DPI").isEmpty() ? qgetenv( "QT_WAYLAND_FORCE_DPI").toInt() : -1; |
| 130 | if (force_dpi > 0) |
| 131 | return QDpi(force_dpi, force_dpi); |
| 132 | |
| 133 | return QPlatformScreen::logicalDpi(); |
| 134 | } |
| 135 | |
| 136 | QList<QPlatformScreen *> QWaylandScreen::virtualSiblings() const |
| 137 | { |
| 138 | QList<QPlatformScreen *> list; |
| 139 | const QList<QWaylandScreen*> screens = mWaylandDisplay->screens(); |
| 140 | list.reserve(screens.count()); |
| 141 | foreach (QWaylandScreen *screen, screens) |
| 142 | list << screen; |
| 143 | return list; |
| 144 | } |
| 145 | |
| 146 | void QWaylandScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask) |
| 147 | { |
| 148 | foreach (QWindow *window, QGuiApplication::allWindows()) { |
| 149 | QWaylandWindow *w = static_cast<QWaylandWindow *>(window->handle()); |
| 150 | if (w && w->waylandScreen() == this) |
| 151 | w->setOrientationMask(mask); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | Qt::ScreenOrientation QWaylandScreen::orientation() const |
| 156 | { |
| 157 | return m_orientation; |
| 158 | } |
| 159 | |
| 160 | int QWaylandScreen::scale() const |
| 161 | { |
| 162 | return mScale; |
| 163 | } |
| 164 | |
| 165 | qreal QWaylandScreen::devicePixelRatio() const |
| 166 | { |
| 167 | return qreal(mScale); |
| 168 | } |
| 169 | |
| 170 | qreal QWaylandScreen::refreshRate() const |
| 171 | { |
| 172 | return mRefreshRate / 1000.f; |
| 173 | } |
| 174 | |
| 175 | #if QT_CONFIG(cursor) |
| 176 | QPlatformCursor *QWaylandScreen::cursor() const |
| 177 | { |
| 178 | return mWaylandCursor; |
| 179 | } |
| 180 | #endif |
| 181 | |
| 182 | QWaylandScreen * QWaylandScreen::waylandScreenFromWindow(QWindow *window) |
| 183 | { |
| 184 | QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(window); |
| 185 | return static_cast<QWaylandScreen *>(platformScreen); |
| 186 | } |
| 187 | |
| 188 | QWaylandScreen *QWaylandScreen::fromWlOutput(::wl_output *output) |
| 189 | { |
| 190 | auto wlOutput = static_cast<QtWayland::wl_output *>(wl_output_get_user_data(output)); |
| 191 | return static_cast<QWaylandScreen *>(wlOutput); |
| 192 | } |
| 193 | |
| 194 | void QWaylandScreen::output_mode(uint32_t flags, int width, int height, int refresh) |
| 195 | { |
| 196 | if (!(flags & WL_OUTPUT_MODE_CURRENT)) |
| 197 | return; |
| 198 | |
| 199 | QSize size(width, height); |
| 200 | |
| 201 | if (size != mGeometry.size()) |
| 202 | mGeometry.setSize(size); |
| 203 | |
| 204 | if (refresh != mRefreshRate) |
| 205 | mRefreshRate = refresh; |
| 206 | } |
| 207 | |
| 208 | void QWaylandScreen::output_geometry(int32_t x, int32_t y, |
| 209 | int32_t width, int32_t height, |
| 210 | int subpixel, |
| 211 | const QString &make, |
| 212 | const QString &model, |
| 213 | int32_t transform) |
| 214 | { |
| 215 | Q_UNUSED(subpixel); |
| 216 | |
| 217 | mManufacturer = make; |
| 218 | mModel = model; |
| 219 | |
| 220 | mTransform = transform; |
| 221 | |
| 222 | mPhysicalSize = QSize(width, height); |
| 223 | mGeometry.moveTopLeft(QPoint(x, y)); |
| 224 | } |
| 225 | |
| 226 | void QWaylandScreen::output_scale(int32_t factor) |
| 227 | { |
| 228 | mScale = factor; |
| 229 | } |
| 230 | |
| 231 | void QWaylandScreen::output_done() |
| 232 | { |
| 233 | // the done event is sent after all the geometry and the mode events are sent, |
| 234 | // and the last mode event to be sent is the active one, so we can trust the |
| 235 | // values of mGeometry and mRefreshRate here |
| 236 | |
| 237 | if (mTransform >= 0) { |
| 238 | bool isPortrait = mGeometry.height() > mGeometry.width(); |
| 239 | switch (mTransform) { |
| 240 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 241 | m_orientation = isPortrait ? Qt::PortraitOrientation : Qt::LandscapeOrientation; |
| 242 | break; |
| 243 | case WL_OUTPUT_TRANSFORM_90: |
| 244 | m_orientation = isPortrait ? Qt::InvertedLandscapeOrientation : Qt::PortraitOrientation; |
| 245 | break; |
| 246 | case WL_OUTPUT_TRANSFORM_180: |
| 247 | m_orientation = isPortrait ? Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation; |
| 248 | break; |
| 249 | case WL_OUTPUT_TRANSFORM_270: |
| 250 | m_orientation = isPortrait ? Qt::LandscapeOrientation : Qt::InvertedPortraitOrientation; |
| 251 | break; |
| 252 | // Ignore these ones, at least for now |
| 253 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 254 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 255 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 256 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | QWindowSystemInterface::handleScreenOrientationChange(screen(), m_orientation); |
| 261 | mTransform = -1; |
| 262 | } |
| 263 | QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), geometry()); |
| 264 | QWindowSystemInterface::handleScreenRefreshRateChange(screen(), refreshRate()); |
| 265 | } |
| 266 | |
| 267 | } |
| 268 | |
| 269 | QT_END_NAMESPACE |
| 270 |
Warning: That file was not part of the compilation database. It may have many parsing errors.