140 bool hasConfigFile =
false;
141 QString configFilePath;
142 for (
const QString ¶m : paramList) {
144 QString configPrefix(
"configfile="_L1);
145 if (param.startsWith(configPrefix)) {
146 hasConfigFile =
true;
147 configFilePath = param.mid(configPrefix.size());
154 if (configFilePath.isEmpty())
155 qFatal(
"Missing file path for -configfile platform option");
156 QFile configFile(configFilePath);
157 if (!configFile.exists())
158 qFatal(
"Could not find platform config file %s", qPrintable(configFilePath));
159 if (!configFile.open(QIODevice::ReadOnly))
160 qFatal(
"Could not open platform config file for reading %s, %s", qPrintable(configFilePath), qPrintable(configFile.errorString()));
162 QByteArray json = configFile.readAll();
163 QJsonParseError error;
164 QJsonDocument config = QJsonDocument::fromJson(json, &error);
166 qFatal(
"Platform config file parse error: %s", qPrintable(error.errorString()));
168 return config.object();
176 const bool synchronousWindowSystemEvents = configuration[
"synchronousWindowSystemEvents"].toBool(
177 m_configuration[
"synchronousWindowSystemEvents"].toBool(
false));
178 QWindowSystemInterface::setSynchronousWindowSystemEvents(synchronousWindowSystemEvents);
180 m_windowFrameMarginsEnabled = configuration[
"windowFrameMargins"].toBool(
181 m_configuration[
"windowFrameMargins"].toBool(
true));
184 QJsonArray currentScreens = m_configuration[
"screens"].toArray();
185 QJsonArray newScreens = configuration[
"screens"].toArray();
187 auto getScreenNames = [](
const QJsonArray &screens) -> QList<QString> {
188 QList<QString> names;
189 for (QJsonValue screen : screens) {
190 names.append(screen[
"name"].toString());
192 std::sort(names.begin(), names.end());
196 auto currentNames = getScreenNames(currentScreens);
197 auto newNames = getScreenNames(newScreens);
199 QList<QString> present;
200 std::set_intersection(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
201 std::inserter(present, present.begin()));
202 QList<QString> added;
203 std::set_difference(newNames.begin(), newNames.end(), currentNames.begin(), currentNames.end(),
204 std::inserter(added, added.begin()));
205 QList<QString> removed;
206 std::set_difference(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
207 std::inserter(removed, removed.begin()));
209 auto platformScreenByName = [](
const QString &name, QList<QOffscreenScreen *> screens) ->
QOffscreenScreen * {
210 for (QOffscreenScreen *screen : screens) {
211 if (screen->m_name == name)
217 auto screenConfigByName = [](
const QString &name, QJsonArray screenConfigs) -> QJsonValue {
218 for (QJsonValue screenConfig : screenConfigs) {
219 if (screenConfig[
"name"].toString() == name)
225 auto geometryFromConfig = [](
const QJsonObject &config) -> QRect {
226 return QRect(config[
"x"].toInt(0), config[
"y"].toInt(0), config[
"width"].toInt(640), config[
"height"].toInt(480));
230 for (
const QString &remove : removed) {
231 QOffscreenScreen *screen = platformScreenByName(remove, m_screens);
232 m_screens.removeAll(screen);
233 QWindowSystemInterface::handleScreenRemoved(screen);
237 for (
const QString &add : added) {
238 QJsonValue configValue = screenConfigByName(add, newScreens);
239 QJsonObject config = configValue.toObject();
240 if (config.isEmpty()) {
241 qWarning(
"empty screen object");
244 QOffscreenScreen *offscreenScreen =
new QOffscreenScreen(
this);
245 offscreenScreen->m_name = config[
"name"].toString();
246 offscreenScreen->m_geometry = geometryFromConfig(config);
247 offscreenScreen->m_logicalDpi = config[
"logicalDpi"].toInt(96);
248 offscreenScreen->m_logicalBaseDpi = config[
"logicalBaseDpi"].toInt(96);
249 offscreenScreen->m_dpr = config[
"dpr"].toDouble(1.0);
250 m_screens.append(offscreenScreen);
251 QWindowSystemInterface::handleScreenAdded(offscreenScreen);
255 for (
const QString &pres : present) {
256 QOffscreenScreen *screen = platformScreenByName(pres, m_screens);
258 QJsonObject currentConfig = screenConfigByName(pres, currentScreens).toObject();
259 QJsonObject newConfig = screenConfigByName(pres, newScreens).toObject();
262 Q_ASSERT(currentConfig[
"name"] == newConfig[
"name"]);
265 QRect currentGeomtry = geometryFromConfig(currentConfig);
266 QRect newGeomtry = geometryFromConfig(newConfig);
267 if (currentGeomtry != newGeomtry) {
268 screen->m_geometry = newGeomtry;
269 QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), newGeomtry, newGeomtry);
273 int currentLogicalDpi = currentConfig[
"logicalDpi"].toInt(96);
274 int newLogicalDpi = newConfig[
"logicalDpi"].toInt(96);
275 if (currentLogicalDpi != newLogicalDpi) {
276 screen->m_logicalDpi = newLogicalDpi;
277 QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->screen(), newLogicalDpi, newLogicalDpi);
282 int currentLogicalBaseDpi = currentConfig[
"logicalBaseDpi"].toInt(96);
283 int newLogicalBaseDpi = newConfig[
"logicalBaseDpi"].toInt(96);
284 if (currentLogicalBaseDpi != newLogicalBaseDpi) {
285 screen->m_logicalBaseDpi = newLogicalBaseDpi;
286 qWarning(
"You ain't supposed to change logicalBaseDpi - its a platform constant. Qt may not react to the change");
292 double currentDpr = currentConfig[
"dpr"].toDouble(1);
293 double newDpr = newConfig[
"dpr"].toDouble(1);
294 if (currentDpr != newDpr) {
295 screen->m_dpr = newDpr;
296 qWarning(
"DPR change notifications is not implemented - Qt may not react to the change");
301 m_configuration = configuration;