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
qtx11extras.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2016 Richard Moore <rich@kde.org>
3// Copyright (C) 2016 David Faure <david.faure@kdab.com>
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
6#include "qtx11extras_p.h"
7
8#include <qpa/qplatformnativeinterface.h>
9#include <qpa/qplatformwindow.h>
10#include <qpa/qplatformscreen_p.h>
11#include <qpa/qplatformscreen.h>
12#include <qscreen.h>
13#include <qwindow.h>
14#include <qguiapplication.h>
15#include <xcb/xcb.h>
16#include <QtCore/qdebug.h>
17
19
20using namespace Qt::StringLiterals;
21
22static QScreen *findScreenForVirtualDesktop(int virtualDesktopNumber)
23{
24 const auto screens = QGuiApplication::screens();
25 for (QScreen *screen : screens) {
26 auto *qxcbScreen = dynamic_cast<QNativeInterface::Private::QXcbScreen *>(screen->handle());
27 if (qxcbScreen && qxcbScreen->virtualDesktopNumber() == virtualDesktopNumber)
28 return screen;
29 }
30 return nullptr;
31}
32
53QX11Info::QX11Info()
54{
55}
56
63{
64 return QGuiApplication::platformName() == "xcb"_L1;
65}
66
79{
80 if (screen == -1) {
82 if (!scr)
83 return 75;
84 return qRound(scr->logicalDotsPerInchX());
85 }
86
88 if (!scr)
89 return 0;
90
91 return scr->logicalDotsPerInchX();
92}
93
106{
107 if (screen == -1) {
109 if (!scr)
110 return 75;
111 return qRound(scr->logicalDotsPerInchY());
112 }
113
115 if (!scr)
116 return 0;
117
118 return scr->logicalDotsPerInchY();
119}
120
130{
131 if (!qApp)
132 return 0;
133 QPlatformNativeInterface *native = qApp->platformNativeInterface();
134 if (!native)
135 return 0;
137 if (!scr)
138 return 0;
139 return static_cast<xcb_window_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen(QByteArrayLiteral("rootwindow"), scr)));
140}
141
160{
161 if (!qApp)
162 return 0;
163 QPlatformNativeInterface *native = qApp->platformNativeInterface();
164 if (!native)
165 return 0;
166 return reinterpret_cast<qintptr>(native->nativeResourceForIntegration(QByteArrayLiteral("x11screen")));
167}
168
175{
176 if (!qApp)
177 return 0;
178 QPlatformNativeInterface *native = qApp->platformNativeInterface();
179 if (!native)
180 return 0;
182 return static_cast<xcb_timestamp_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen("apptime", screen)));
183}
184
191{
192 if (!qApp)
193 return 0;
194 QPlatformNativeInterface *native = qApp->platformNativeInterface();
195 if (!native)
196 return 0;
198 return static_cast<xcb_timestamp_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen("appusertime", screen)));
199}
200
207{
208 if (!qApp)
209 return;
210 QPlatformNativeInterface *native = qApp->platformNativeInterface();
211 if (!native)
212 return;
213 typedef void (*SetAppTimeFunc)(QScreen *, xcb_timestamp_t);
215 SetAppTimeFunc func = reinterpret_cast<SetAppTimeFunc>(reinterpret_cast<void *>(native->nativeResourceFunctionForScreen("setapptime")));
216 if (func)
217 func(screen, time);
218 else
219 qWarning("Internal error: QPA plugin doesn't implement setAppTime");
220}
221
228{
229 if (!qApp)
230 return;
231 QPlatformNativeInterface *native = qApp->platformNativeInterface();
232 if (!native)
233 return;
234 typedef void (*SetAppUserTimeFunc)(QScreen *, xcb_timestamp_t);
236 SetAppUserTimeFunc func = reinterpret_cast<SetAppUserTimeFunc>(reinterpret_cast<void *>(native->nativeResourceFunctionForScreen("setappusertime")));
237 if (func)
238 func(screen, time);
239 else
240 qWarning("Internal error: QPA plugin doesn't implement setAppUserTime");
241}
242
250{
251 if (!qApp)
252 return 0;
253 QPlatformNativeInterface *native = qApp->platformNativeInterface();
254 if (!native)
255 return 0;
257 return static_cast<xcb_timestamp_t>(reinterpret_cast<quintptr>(native->nativeResourceForScreen("gettimestamp", screen)));
258}
259
270{
271 if (!qApp)
272 return QByteArray();
273 QPlatformNativeInterface *native = qApp->platformNativeInterface();
274 if (!native)
275 return QByteArray();
276 return static_cast<char *>(native->nativeResourceForIntegration("startupid"));
277}
278
291{
292 if (!qApp)
293 return;
294 QPlatformNativeInterface *native = qApp->platformNativeInterface();
295 if (!native)
296 return;
297 typedef void (*SetStartupIdFunc)(const char*);
298 SetStartupIdFunc func = reinterpret_cast<SetStartupIdFunc>(reinterpret_cast<void *>(native->nativeResourceFunctionForIntegration("setstartupid")));
299 if (func)
300 func(id.constData());
301 else
302 qWarning("Internal error: QPA plugin doesn't implement setStartupId");
303}
304
311{
312 if (!qApp)
313 return nullptr;
314 QPlatformNativeInterface *native = qApp->platformNativeInterface();
315 if (!native)
316 return nullptr;
317
318 void *display = native->nativeResourceForIntegration(QByteArray("display"));
319 return reinterpret_cast<Display *>(display);
320}
321
327xcb_connection_t *QX11Info::connection()
328{
329 if (!qApp)
330 return nullptr;
331 QPlatformNativeInterface *native = qApp->platformNativeInterface();
332 if (!native)
333 return nullptr;
334
335 void *connection = native->nativeResourceForIntegration(QByteArray("connection"));
336 return reinterpret_cast<xcb_connection_t *>(connection);
337}
338
346{
347 if (!qApp)
348 return false;
349 QPlatformNativeInterface *native = qApp->platformNativeInterface();
350 if (!native)
351 return false;
352
354 if (!scr) {
355 qWarning() << "isCompositingManagerRunning: Could not find screen number" << screen;
356 return false;
357 }
358
359 return native->nativeResourceForScreen(QByteArray("compositingEnabled"), scr);
360}
361
372{
373 if (!qApp)
374 return -1;
375 QPlatformNativeInterface *native = qApp->platformNativeInterface();
376 if (!native)
377 return -1;
378
379 typedef qint32 (*GeneratePeekerIdFunc)(void);
380 GeneratePeekerIdFunc generatepeekerid = reinterpret_cast<GeneratePeekerIdFunc>(
381 reinterpret_cast<void *>(native->nativeResourceFunctionForIntegration("generatepeekerid")));
382 if (!generatepeekerid) {
383 qWarning("Internal error: QPA plugin doesn't implement generatePeekerId");
384 return -1;
385 }
386
387 return generatepeekerid();
388}
389
399{
400 if (!qApp)
401 return false;
402 QPlatformNativeInterface *native = qApp->platformNativeInterface();
403 if (!native)
404 return false;
405
406 typedef bool (*RemovePeekerIdFunc)(qint32);
407 RemovePeekerIdFunc removePeekerId = reinterpret_cast<RemovePeekerIdFunc>(
408 reinterpret_cast<void *>(native->nativeResourceFunctionForIntegration("removepeekerid")));
409 if (!removePeekerId) {
410 qWarning("Internal error: QPA plugin doesn't implement removePeekerId");
411 return false;
412 }
413
414 return removePeekerId(peekerId);
415}
416
494bool QX11Info::peekEventQueue(PeekerCallback peeker, void *peekerData, PeekOptions option,
495 qint32 peekerId)
496{
497 if (!peeker || !qApp)
498 return false;
499 QPlatformNativeInterface *native = qApp->platformNativeInterface();
500 if (!native)
501 return false;
502
503 typedef bool (*PeekEventQueueFunc)(PeekerCallback, void *, PeekOptions, qint32);
504 PeekEventQueueFunc peekeventqueue = reinterpret_cast<PeekEventQueueFunc>(
505 reinterpret_cast<void *>(native->nativeResourceFunctionForIntegration("peekeventqueue")));
506 if (!peekeventqueue) {
507 qWarning("Internal error: QPA plugin doesn't implement peekEventQueue");
508 return false;
509 }
510
511 return peekeventqueue(peeker, peekerData, option, peekerId);
512}
513
\inmodule QtCore
Definition qbytearray.h:57
QScreen * primaryScreen
the primary (or default) screen of the application.
QString platformName
The name of the underlying platform plugin.
static QList< QScreen * > screens()
Returns a list of all the screens associated with the windowing system the application is connected t...
The QPlatformNativeInterface class provides an abstraction for retrieving native resource handles.
virtual NativeResourceForScreenFunction nativeResourceFunctionForScreen(const QByteArray &resource)
virtual void * nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
virtual void * nativeResourceForIntegration(const QByteArray &resource)
virtual NativeResourceForIntegrationFunction nativeResourceFunctionForIntegration(const QByteArray &resource)
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
qreal logicalDotsPerInchY
the number of logical dots or pixels per inch in the vertical direction
Definition qscreen.h:57
qreal logicalDotsPerInchX
the number of logical dots or pixels per inch in the horizontal direction
Definition qscreen.h:56
QPlatformScreen * handle() const
Get the platform screen handle.
Definition qscreen.cpp:83
static void setAppTime(quint32 time)
Sets the X11 time to the value specified by time.
static xcb_connection_t * connection()
Returns the default XCB connection for the application.
static bool isCompositingManagerRunning(int screen=-1)
Returns true if there is a compositing manager running for the connection attached to screen.
static quint32 appTime()
Returns the X11 time.
static quint32 appUserTime()
Returns the X11 user time.
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch.
static quint32 getTimestamp()
Fetches the current X11 time stamp from the X Server.
static Display * display()
Returns the default display for the application.
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch.
static bool isPlatformX11()
Returns true if the application is currently running on X11.
static void setAppUserTime(quint32 time)
Sets the X11 user time as specified by time.
bool(* PeekerCallback)(xcb_generic_event_t *event, void *peekerData)
Typedef for a pointer to a function with the following signature:
static void setNextStartupId(const QByteArray &id)
Sets the next startup ID to id.
static quint32 appRootWindow(int screen=-1)
Returns a handle for the applications root window on the given screen.
static bool removePeekerId(qint32 peekerId)
Removes peekerId, which was earlier obtained via generatePeekerId().
static int appScreen()
Returns the number of the screen where the application is being displayed.
static QByteArray nextStartupId()
Returns the startup ID that will be used for the next window to be shown by this process.
static qint32 generatePeekerId()
Returns a new peeker id or -1 if some internal error has occurred.
static bool peekEventQueue(PeekerCallback peeker, void *peekerData=nullptr, PeekOptions option=PeekDefault, qint32 peekerId=-1)
Peek into the buffered XCB event queue.
struct wl_display * display
Definition linuxdmabuf.h:41
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
#define qApp
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define qWarning
Definition qlogging.h:166
GLenum func
Definition qopenglext.h:663
GLuint GLenum option
QScreen * screen
[1]
Definition main.cpp:29
static QScreen * findScreenForVirtualDesktop(int virtualDesktopNumber)
struct _XDisplay Display
unsigned int quint32
Definition qtypes.h:50
size_t quintptr
Definition qtypes.h:167
int qint32
Definition qtypes.h:49
ptrdiff_t qintptr
Definition qtypes.h:166