1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 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 QCOCOASCREEN_H
41 #define QCOCOASCREEN_H
42 
43 #include <AppKit/AppKit.h>
44 
45 #include "qcocoacursor.h"
46 
47 #include <qpa/qplatformintegration.h>
48 
49 QT_BEGIN_NAMESPACE
50 
51 class QCocoaIntegration;
52 
53 class QCocoaScreen : public QPlatformScreen
54 {
55 public:
56     ~QCocoaScreen();
57 
58     // ----------------------------------------------------
59     // Virtual methods overridden from QPlatformScreen
60     QPixmap grabWindow(WId window, int x, int y, int width, int height) const override;
geometry()61     QRect geometry() const override { return m_geometry; }
availableGeometry()62     QRect availableGeometry() const override { return m_availableGeometry; }
depth()63     int depth() const override { return m_depth; }
format()64     QImage::Format format() const override { return m_format; }
devicePixelRatio()65     qreal devicePixelRatio() const override { return m_devicePixelRatio; }
physicalSize()66     QSizeF physicalSize() const override { return m_physicalSize; }
logicalDpi()67     QDpi logicalDpi() const override { return m_logicalDpi; }
logicalBaseDpi()68     QDpi logicalBaseDpi() const override { return m_logicalDpi; }
refreshRate()69     qreal refreshRate() const override { return m_refreshRate; }
name()70     QString name() const override { return m_name; }
cursor()71     QPlatformCursor *cursor() const override { return m_cursor; }
72     QWindow *topLevelAt(const QPoint &point) const override;
73     QList<QPlatformScreen *> virtualSiblings() const override;
74     QPlatformScreen::SubpixelAntialiasingType subpixelAntialiasingTypeHint() const override;
75 
76     // ----------------------------------------------------
77 
78     NSScreen *nativeScreen() const;
79 
80     void requestUpdate();
81     void deliverUpdateRequests();
82     bool isRunningDisplayLink() const;
83 
84     static QCocoaScreen *primaryScreen();
85     static QCocoaScreen *get(NSScreen *nsScreen);
86     static QCocoaScreen *get(CGDirectDisplayID displayId);
87     static QCocoaScreen *get(CFUUIDRef uuid);
88 
89     static CGPoint mapToNative(const QPointF &pos, QCocoaScreen *screen = QCocoaScreen::primaryScreen());
90     static CGRect mapToNative(const QRectF &rect, QCocoaScreen *screen = QCocoaScreen::primaryScreen());
91     static QPointF mapFromNative(CGPoint pos, QCocoaScreen *screen = QCocoaScreen::primaryScreen());
92     static QRectF mapFromNative(CGRect rect, QCocoaScreen *screen = QCocoaScreen::primaryScreen());
93 
94 private:
95     static void initializeScreens();
96     static void updateScreens();
97     static void cleanupScreens();
98 
99     static bool updateScreensIfNeeded();
100     static NSArray *s_screenConfigurationBeforeUpdate;
101 
102     static void add(CGDirectDisplayID displayId);
103     QCocoaScreen(CGDirectDisplayID displayId);
104     void update(CGDirectDisplayID displayId);
105     void remove();
106 
107     bool isOnline() const;
108     bool isMirroring() const;
109 
110     CGDirectDisplayID m_displayId = kCGNullDirectDisplay;
displayId()111     CGDirectDisplayID displayId() const { return m_displayId; }
112 
113     QRect m_geometry;
114     QRect m_availableGeometry;
115     QDpi m_logicalDpi;
116     qreal m_refreshRate = 0;
117     int m_depth = 0;
118     QString m_name;
119     QImage::Format m_format;
120     QSizeF m_physicalSize;
121     QCocoaCursor *m_cursor;
122     qreal m_devicePixelRatio = 0;
123 
124     CVDisplayLinkRef m_displayLink = nullptr;
125     dispatch_source_t m_displayLinkSource = nullptr;
126     QAtomicInt m_pendingUpdates;
127 
128     friend class QCocoaIntegration;
129     friend class QCocoaWindow;
130     friend QDebug operator<<(QDebug debug, const QCocoaScreen *screen);
131 };
132 
133 #ifndef QT_NO_DEBUG_STREAM
134 QDebug operator<<(QDebug debug, const QCocoaScreen *screen);
135 #endif
136 
137 QT_END_NAMESPACE
138 
139 @interface NSScreen (QtExtras)
140 @property(readonly) CGDirectDisplayID qt_displayId;
141 @end
142 
143 #endif // QCOCOASCREEN_H
144