192 const bool synchronousWindowSystemEvents = configuration[
"synchronousWindowSystemEvents"].toBool(
193 m_configuration[
"synchronousWindowSystemEvents"].toBool(
false));
194 QWindowSystemInterface::setSynchronousWindowSystemEvents(synchronousWindowSystemEvents);
197 m_configuration[
"windowFrameMargins"].toBool(
true));
200 QJsonArray currentScreens = m_configuration[
"screens"].toArray();
201 QJsonArray newScreens = configuration[
"screens"].toArray();
203 auto getScreenNames = [](
const QJsonArray &screens) -> QList<QString> {
204 QList<QString> names;
205 for (
const QJsonValue &screen : screens) {
206 names.append(screen[
"name"].toString());
208 std::sort(names.begin(), names.end());
212 auto currentNames = getScreenNames(currentScreens);
213 auto newNames = getScreenNames(newScreens);
215 QList<QString> present;
216 std::set_intersection(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
217 std::inserter(present, present.begin()));
218 QList<QString> added;
219 std::set_difference(newNames.begin(), newNames.end(), currentNames.begin(), currentNames.end(),
220 std::inserter(added, added.begin()));
221 QList<QString> removed;
222 std::set_difference(currentNames.begin(), currentNames.end(), newNames.begin(), newNames.end(),
223 std::inserter(removed, removed.begin()));
225 auto platformScreenByName = [](
const QString &name,
const QList<QOffscreenScreen *> &screens) ->
QOffscreenScreen * {
226 for (QOffscreenScreen *screen : screens) {
227 if (screen->m_name == name)
233 auto screenConfigByName = [](
const QString &name,
const QJsonArray &screenConfigs) -> QJsonValue {
234 for (
const QJsonValue &screenConfig : screenConfigs) {
235 if (screenConfig[
"name"].toString() == name)
241 auto geometryFromConfig = [](
const QJsonObject &config) -> QRect {
242 return QRect(config[
"x"].toInt(0), config[
"y"].toInt(0), config[
"width"].toInt(640), config[
"height"].toInt(480));
245 auto availableGeometryFromConfig = [](
const QJsonObject &config, QRect geometry) -> QRect {
246 const QJsonValue value = config[
"availableGeometry"];
247 if (!value.isObject())
249 const QJsonObject a = value.toObject();
250 return QRect(a[
"x"].toInt(geometry.x()), a[
"y"].toInt(geometry.y()),
251 a[
"width"].toInt(geometry.width()), a[
"height"].toInt(geometry.height()));
255 for (
const QString &remove : std::as_const(removed)) {
256 QOffscreenScreen *screen = platformScreenByName(remove, m_screens);
257 m_screens.removeAll(screen);
258 QWindowSystemInterface::handleScreenRemoved(screen);
262 for (
const QString &add : std::as_const(added)) {
263 QJsonValue configValue = screenConfigByName(add, newScreens);
264 QJsonObject config = configValue.toObject();
265 if (config.isEmpty()) {
266 qWarning(
"empty screen object");
269 QOffscreenScreen *offscreenScreen =
new QOffscreenScreen(
this);
270 offscreenScreen->m_name = config[
"name"].toString();
271 offscreenScreen->m_geometry = geometryFromConfig(config);
272 offscreenScreen->m_availableGeometry = availableGeometryFromConfig(config, offscreenScreen->m_geometry);
273 offscreenScreen->m_logicalDpi = config[
"logicalDpi"].toInt(96);
274 offscreenScreen->m_logicalBaseDpi = config[
"logicalBaseDpi"].toInt(96);
275 offscreenScreen->m_dpr = config[
"dpr"].toDouble(1.0);
276 m_screens.append(offscreenScreen);
277 QWindowSystemInterface::handleScreenAdded(offscreenScreen);
281 for (
const QString &pres : std::as_const(present)) {
282 QOffscreenScreen *screen = platformScreenByName(pres, m_screens);
284 QJsonObject currentConfig = screenConfigByName(pres, currentScreens).toObject();
285 QJsonObject newConfig = screenConfigByName(pres, newScreens).toObject();
288 Q_ASSERT(currentConfig[
"name"] == newConfig[
"name"]);
291 QRect currentGeomtry = geometryFromConfig(currentConfig);
292 QRect newGeomtry = geometryFromConfig(newConfig);
293 if (currentGeomtry != newGeomtry) {
294 screen->m_geometry = newGeomtry;
295 QWindowSystemInterface::handleScreenGeometryChange(screen->screen(), newGeomtry, newGeomtry);
299 int currentLogicalDpi = currentConfig[
"logicalDpi"].toInt(96);
300 int newLogicalDpi = newConfig[
"logicalDpi"].toInt(96);
301 if (currentLogicalDpi != newLogicalDpi) {
302 screen->m_logicalDpi = newLogicalDpi;
303 QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(screen->screen(), newLogicalDpi, newLogicalDpi);
308 int currentLogicalBaseDpi = currentConfig[
"logicalBaseDpi"].toInt(96);
309 int newLogicalBaseDpi = newConfig[
"logicalBaseDpi"].toInt(96);
310 if (currentLogicalBaseDpi != newLogicalBaseDpi) {
311 screen->m_logicalBaseDpi = newLogicalBaseDpi;
312 qWarning(
"You ain't supposed to change logicalBaseDpi - its a platform constant. Qt may not react to the change");
318 double currentDpr = currentConfig[
"dpr"].toDouble(1);
319 double newDpr = newConfig[
"dpr"].toDouble(1);
320 if (currentDpr != newDpr) {
321 screen->m_dpr = newDpr;
322 qWarning(
"DPR change notifications is not implemented - Qt may not react to the change");
327 m_configuration = configuration;