Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qfakexdgportalfixture_p.h
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
#
ifndef
QFAKEXDGPORTALFIXTURE_P_H
5
#
define
QFAKEXDGPORTALFIXTURE_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtCore
/
qsize
.
h
>
19
#
include
<
QtCore
/
qstring
.
h
>
20
#
include
<
QtCore
/
private
/
qexpected_p
.
h
>
21
22
#
include
<
private
/
qfakexdgportal_p
.
h
>
23
#
include
<
private
/
qsyntheticvideoscene_p
.
h
>
24
25
#
include
<
memory
>
26
27
QT_BEGIN_NAMESPACE
28
29
/*!
30
\internal
31
32
Runs an unattended stand-in for xdg-desktop-portal, so that tests can exercise
33
the portal-backed PipeWire code paths end to end without a human approving a
34
consent dialog. Today it implements the ScreenCast and Camera interfaces; the
35
intent is that every portal interface qtmultimedia talks to is faked here.
36
37
It brings up, and tears down:
38
\list
39
\li a private pipewire daemon, with no session manager and no access to any
40
real hardware;
41
\li a helper process (this test binary, re-executed with
42
QtFakeXdgPortal::HelperArgument) which owns
43
\c org.freedesktop.portal.Desktop on a private D-Bus session bus and
44
publishes a synthetic video source rendering a SyntheticVideoScene.
45
\endlist
46
47
Usage from a test's main():
48
\code
49
#define main testlib_main
50
QTEST_MAIN(tst_Foo)
51
#undef main
52
53
int main(int argc, char *argv[])
54
{
55
if (QFakeXdgPortalFixture::isHelperProcess(argc, argv))
56
return QFakeXdgPortalFixture::runHelperProcess(argc, argv);
57
QFakeXdgPortalFixture::reexecUnderPrivateBusIfRequested(argc, argv);
58
return testlib_main(argc, argv);
59
}
60
\endcode
61
62
The re-exec must happen before QApplication is constructed: QApplication opens
63
the session bus, and QDBusConnection caches it for the lifetime of the process.
64
*/
65
class
QFakeXdgPortalFixture
66
{
67
public
:
68
QFakeXdgPortalFixture();
69
~QFakeXdgPortalFixture();
70
71
Q_DISABLE_COPY_MOVE(QFakeXdgPortalFixture)
72
73
//! True when this process was started as the fake portal helper.
74
static
bool
isHelperProcess(
int
argc,
char
**argv);
75
static
int
runHelperProcess(
int
argc,
char
**argv);
76
77
/*!
78
Whether the fixture should be used at all. Controlled by
79
QT_MULTIMEDIA_TEST_XDG_PORTAL_FIXTURE: "fake" forces it on, "none" forces it
80
off, and the default "auto" enables it on Linux for non-X11 sessions, where
81
the real portal would otherwise block on a consent dialog.
82
*/
83
//! Whether QT_MULTIMEDIA_TEST_XDG_PORTAL_FIXTURE explicitly forces the fixture on.
84
static
bool
isForced();
85
86
static
bool
isRequested(QtFakeXdgPortal::Role role = QtFakeXdgPortal::Role::ScreenCast);
87
88
//! Whether the external pieces (pipewire, dbus-run-session) are present.
89
static
bool
prerequisitesAvailable(QString *unavailableReason =
nullptr
);
90
91
/*!
92
Re-executes the test binary under dbus-run-session when isRequested() and the
93
prerequisites hold, so the whole test runs against a private session bus.
94
Returns normally when no re-exec is needed or possible.
95
*/
96
static
void
reexecUnderPrivateBusIfRequested(
97
int
argc,
char
**argv, QtFakeXdgPortal::Role role = QtFakeXdgPortal::Role::ScreenCast);
98
99
//! True if the current process is already running on the fixture's private bus.
100
static
bool
isRunningOnPrivateBus();
101
102
q23::expected<
void
, QString>
103
start(
const
SyntheticVideoScene &initialScene,
104
QtFakeXdgPortal::Role role = QtFakeXdgPortal::Role::ScreenCast);
105
void
stop();
106
[[nodiscard]]
bool
isActive()
const
;
107
108
//! The node id the fake portal reports from Start(). Mostly useful for diagnostics.
109
[[nodiscard]] quint32 nodeId()
const
;
110
111
//! Replaces the content published by the synthetic source.
112
q23::expected<
void
, QString> setScene(
const
SyntheticVideoScene &scene);
113
114
//! Revokes the portal session mid-stream, as a compositor would.
115
q23::expected<
void
, QString> closeSessions();
116
117
private
:
118
q23::expected<
void
, QString> startHelper(QSize frameSize);
119
void
stopHelper();
120
121
class
Private;
122
std::unique_ptr<Private> d;
123
};
124
125
QT_END_NAMESPACE
126
127
#
endif
// QFAKEXDGPORTALFIXTURE_P_H
QFakeXdgPortalFixture::Private
Definition
qfakexdgportalfixture.cpp:147
QFakeXdgPortalFixture::Private::daemon
QProcess daemon
Definition
qfakexdgportalfixture.cpp:151
QFakeXdgPortalFixture::Private::nodeId
QtPipeWire::ObjectId nodeId
Definition
qfakexdgportalfixture.cpp:156
QFakeXdgPortalFixture::Private::helperOutput
QByteArray helperOutput
Definition
qfakexdgportalfixture.cpp:153
QFakeXdgPortalFixture::Private::environment
QProcessEnvironment environment
Definition
qfakexdgportalfixture.cpp:150
QFakeXdgPortalFixture::Private::helper
QProcess helper
Definition
qfakexdgportalfixture.cpp:152
QFakeXdgPortalFixture::Private::role
QtFakeXdgPortal::Role role
Definition
qfakexdgportalfixture.cpp:155
QFakeXdgPortalFixture::Private::runtimeDir
QString runtimeDir
Definition
qfakexdgportalfixture.cpp:149
QFakeXdgPortalFixture::Private::frameSize
QSize frameSize
Definition
qfakexdgportalfixture.cpp:154
QFakeXdgPortalFixture::Private::active
bool active
Definition
qfakexdgportalfixture.cpp:157
QFakeXdgPortalFixture::Private::removeRuntimeDir
void removeRuntimeDir()
Definition
qfakexdgportalfixture.cpp:159
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtmultimedia
src
multimediatestlib
qfakexdgportalfixture_p.h
Generated on
for Qt by
1.18.0