Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsnativeinterface.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qwindowswindow.h"
6#include "qwindowsscreen.h"
7#include "qwindowscontext.h"
8#include "qwindowscursor.h"
10#include "qwindowsintegration.h"
11#include "qwindowstheme.h"
12#include "qwin10helpers.h"
13
14#include <QtGui/qwindow.h>
15#include <QtGui/qopenglcontext.h>
16#include <QtGui/qscreen.h>
17#include <qpa/qplatformscreen.h>
18
20
29
30static int resourceType(const QByteArray &key)
31{
32 static const char *names[] = { // match ResourceType
33 "renderingcontext",
34 "handle",
35 "glhandle",
36 "getdc",
37 "releasedc",
38 "vkSurface"
39 };
40 const char ** const end = names + sizeof(names) / sizeof(names[0]);
41 const char **result = std::find(names, end, key);
42 if (result == end)
43 result = std::find(names, end, key.toLower());
44 return int(result - names);
45}
46
48{
49 if (!window || !window->handle()) {
50 qWarning("%s: '%s' requested for null window or window without handle.", __FUNCTION__, resource.constData());
51 return nullptr;
52 }
53 auto *bw = static_cast<QWindowsWindow *>(window->handle());
54 int type = resourceType(resource);
55 if (type == HandleType)
56 return bw->handle();
57 switch (window->surfaceType()) {
60 if (type == GetDCType)
61 return bw->getDC();
62 if (type == ReleaseDCType) {
63 bw->releaseDC();
64 return nullptr;
65 }
66 break;
68#if QT_CONFIG(vulkan)
69 if (type == VkSurface)
70 return bw->surface(nullptr, nullptr); // returns the address of the VkSurfaceKHR, not the value, as expected
71#endif
72 break;
73 default:
74 break;
75 }
76 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
77 return nullptr;
78}
79
81{
82 if (!screen || !screen->handle()) {
83 qWarning("%s: '%s' requested for null screen or screen without handle.", __FUNCTION__, resource.constData());
84 return nullptr;
85 }
86 auto *bs = static_cast<QWindowsScreen *>(screen->handle());
87 int type = resourceType(resource);
88 if (type == HandleType)
89 return bs->handle();
90
91 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
92 return nullptr;
93}
94
95#ifndef QT_NO_CURSOR
97{
98 if (resource == QByteArrayLiteral("hcursor")) {
99 if (const QScreen *primaryScreen = QGuiApplication::primaryScreen()) {
100 if (const QPlatformCursor *pCursor= primaryScreen->handle()->cursor())
101 return static_cast<const QWindowsCursor *>(pCursor)->hCursor(cursor);
102 }
103 }
104 return nullptr;
105}
106#endif // !QT_NO_CURSOR
107
109{
110#ifdef QT_NO_OPENGL
111 Q_UNUSED(resource);
112#else
113 if (resourceType(resource) == GlHandleType) {
115 return sc->moduleHandle();
116 }
117#endif
118
119 return nullptr;
120}
121
122#ifndef QT_NO_OPENGL
124{
125 if (!context || !context->handle()) {
126 qWarning("%s: '%s' requested for null context or context without handle.", __FUNCTION__, resource.constData());
127 return nullptr;
128 }
129
130 qWarning("%s: Invalid key '%s' requested.", __FUNCTION__, resource.constData());
131 return nullptr;
132}
133#endif // !QT_NO_OPENGL
134
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:124
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition qcursor.h:45
QScreen * primaryScreen
the primary (or default) screen of the application.
\inmodule QtGui
The QPlatformCursor class provides information about pointer device events (movement,...
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
@ RasterGLSurface
Definition qsurface.h:33
@ RasterSurface
Definition qsurface.h:31
@ VulkanSurface
Definition qsurface.h:35
\inmodule QtGui
Definition qwindow.h:63
Platform cursor implementation.
static QWindowsStaticOpenGLContext * staticOpenGLContext()
void * nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context) override
void * nativeResourceForWindow(const QByteArray &resource, QWindow *window) override
void * nativeResourceForCursor(const QByteArray &resource, const QCursor &cursor) override
void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen) override
void * nativeResourceForIntegration(const QByteArray &resource) override
Windows screen.
Raster or OpenGL Window.
QCursor cursor
Combined button and popup list for selecting options.
static int resourceType(const QByteArray &key)
static void * context
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
static int resourceType(const QByteArray &key)
#define qWarning
Definition qlogging.h:166
GLuint64 key
GLuint GLuint end
GLenum type
GLuint GLuint * names
GLuint64EXT * result
[6]
QScreen * screen
[1]
Definition main.cpp:29
#define Q_UNUSED(x)
aWidget window() -> setWindowTitle("New Window Title")
[2]