200 const bool synchronousWindowSystemEvents = configuration[
"synchronousWindowSystemEvents"].toBool(
201 m_configuration[
"synchronousWindowSystemEvents"].toBool(
false));
202 QWindowSystemInterface::setSynchronousWindowSystemEvents(synchronousWindowSystemEvents);
205 m_configuration[
"windowFrameMargins"].toBool(
true));
208 QJsonArray currentScreens = m_configuration[
"screens"].toArray();
209 QJsonArray newScreens = configuration[
"screens"].toArray();
211 auto getScreenNames = [](
const QJsonArray &screens) -> QList<QString> {
212 QList<QString> names;
213 for (
const QJsonValue &screen : screens) {
214 names.append(screen[
"name"].toString());
216 std::sort(names.begin(), names.end());
220 auto currentNames = getScreenNames(currentScreens);
221 auto newNames = getScreenNames(newScreens);
223 QList<QString> present;
224 std::set_intersection(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
225 std::inserter(present, present.begin()));
226 QList<QString> added;
227 std::set_difference(newNames.begin(), newNames.end(), currentNames.begin(), currentNames.end(),
228 std::inserter(added, added.begin()));
229 QList<QString> removed;
230 std::set_difference(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
231 std::inserter(removed, removed.begin()));
233 auto platformScreenByName = [](
const QString &name,
const QList<QOffscreenScreen *> &screens) ->
QOffscreenScreen * {
234 for (QOffscreenScreen *screen : screens) {
235 if (screen->m_name == name)
241 auto screenConfigByName = [](
const QString &name,
const QJsonArray &screenConfigs) -> QJsonValue {
242 for (
const QJsonValue &screenConfig : screenConfigs) {
243 if (screenConfig[
"name"].toString() == name)
249 auto geometryFromConfig = [](
const QJsonObject &config) -> QRect {
250 return QRect(config[
"x"].toInt(0), config[
"y"].toInt(0), config[
"width"].toInt(640), config[
"height"].toInt(480));
253 auto availableGeometryFromConfig = [](
const QJsonObject &config, QRect geometry) -> QRect {
254 const QJsonValue value = config[
"availableGeometry"];
255 if (!value.isObject())
257 const QJsonObject a = value.toObject();
258 return QRect(a[
"x"].toInt(geometry.x()), a[
"y"].toInt(geometry.y()),
259 a[
"width"].toInt(geometry.width()), a[
"height"].toInt(geometry.height()));
263 for (
const QString &remove : std::as_const(removed)) {
264 QOffscreenScreen *screen = platformScreenByName(remove, m_screens);
265 m_screens.removeAll(screen);
266 QWindowSystemInterface::handleScreenRemoved(screen);
270 for (
const QString &add : std::as_const(added)) {
271 QJsonValue configValue = screenConfigByName(add, newScreens);
272 QJsonObject config = configValue.toObject();
273 if (config.isEmpty()) {
274 qWarning(
"empty screen object");
277 QOffscreenScreen *offscreenScreen =
new QOffscreenScreen(
this);
278 offscreenScreen->m_name = config[
"name"].toString();
279 offscreenScreen->m_geometry = geometryFromConfig(config);
280 offscreenScreen->m_availableGeometry = availableGeometryFromConfig(config, offscreenScreen->m_geometry);
281 offscreenScreen->m_logicalDpi = config[
"logicalDpi"].toInt(96);
282 offscreenScreen->m_logicalBaseDpi = config[
"logicalBaseDpi"].toInt(96);
283 offscreenScreen->m_dpr = config[
"dpr"].toDouble(1.0);
284 m_screens.append(offscreenScreen);
285 QWindowSystemInterface::handleScreenAdded(offscreenScreen);
289 for (
const QString &pres : std::as_const(present)) {
290 QOffscreenScreen *screen = platformScreenByName(pres, m_screens);
292 QJsonObject currentConfig = screenConfigByName(pres, currentScreens).toObject();
293 QJsonObject newConfig = screenConfigByName(pres, newScreens).toObject();
296 Q_ASSERT(currentConfig[
"name"] == newConfig[
"name"]);
299 QRect currentGeomtry = geometryFromConfig(currentConfig);
300 QRect newGeomtry = geometryFromConfig(newConfig);
301 if (currentGeomtry != newGeomtry) {
302 screen->m_geometry = newGeomtry;
303 QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), newGeomtry, newGeomtry);
307 int currentLogicalDpi = currentConfig[
"logicalDpi"].toInt(96);
308 int newLogicalDpi = newConfig[
"logicalDpi"].toInt(96);
309 if (currentLogicalDpi != newLogicalDpi) {
310 screen->m_logicalDpi = newLogicalDpi;
311 QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->screen(), newLogicalDpi, newLogicalDpi);
316 int currentLogicalBaseDpi = currentConfig[
"logicalBaseDpi"].toInt(96);
317 int newLogicalBaseDpi = newConfig[
"logicalBaseDpi"].toInt(96);
318 if (currentLogicalBaseDpi != newLogicalBaseDpi) {
319 screen->m_logicalBaseDpi = newLogicalBaseDpi;
320 qWarning(
"You ain't supposed to change logicalBaseDpi - its a platform constant. Qt may not react to the change");
326 double currentDpr = currentConfig[
"dpr"].toDouble(1);
327 double newDpr = newConfig[
"dpr"].toDouble(1);
328 if (currentDpr != newDpr) {
329 screen->m_dpr = newDpr;
330 qWarning(
"DPR change notifications is not implemented - Qt may not react to the change");
335 m_configuration = configuration;