Changeset View
Changeset View
Standalone View
Standalone View
kded/output.cpp
Show First 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | 343 | { | |||
---|---|---|---|---|---|
346 | if (!output->edid() || !output->edid()->isValid()) { | 346 | if (!output->edid() || !output->edid()->isValid()) { | ||
347 | return metadata; | 347 | return metadata; | ||
348 | } | 348 | } | ||
349 | 349 | | |||
350 | metadata[QStringLiteral("fullname")] = output->edid()->deviceId(); | 350 | metadata[QStringLiteral("fullname")] = output->edid()->deviceId(); | ||
351 | return metadata; | 351 | return metadata; | ||
352 | } | 352 | } | ||
353 | 353 | | |||
354 | bool Output::writeGlobalPart(const KScreen::OutputPtr &output, QVariantMap &info) | 354 | bool Output::writeGlobalPart(const KScreen::OutputPtr &output, QVariantMap &info, | ||
355 | const KScreen::OutputPtr &fallback) | ||||
355 | { | 356 | { | ||
356 | if (!output->isEnabled()) { | | |||
357 | return false; | | |||
358 | } | | |||
359 | const KScreen::ModePtr mode = output->currentMode(); | | |||
360 | if (!mode) { | | |||
361 | qWarning() << "CurrentMode is null" << output->name(); | | |||
362 | return false; | | |||
363 | } | | |||
364 | 357 | | |||
365 | info[QStringLiteral("id")] = output->hash(); | 358 | info[QStringLiteral("id")] = output->hash(); | ||
359 | info[QStringLiteral("metadata")] = metadata(output); | ||||
366 | info[QStringLiteral("rotation")] = output->rotation(); | 360 | info[QStringLiteral("rotation")] = output->rotation(); | ||
367 | 361 | | |||
368 | // Round scale to one digit. | 362 | // Round scale to one digit. | ||
369 | info[QStringLiteral("scale")] = int(output->scale() * 10 + 0.5) / 10.; | 363 | info[QStringLiteral("scale")] = int(output->scale() * 10 + 0.5) / 10.; | ||
370 | 364 | | |||
371 | info[QStringLiteral("metadata")] = metadata(output); | | |||
372 | | ||||
373 | QVariantMap modeInfo; | 365 | QVariantMap modeInfo; | ||
374 | modeInfo[QStringLiteral("refresh")] = mode->refreshRate(); | 366 | float refreshRate = -1.; | ||
367 | QSize modeSize; | ||||
368 | if (output->currentMode() && output->isEnabled()) { | ||||
369 | refreshRate = output->currentMode()->refreshRate(); | ||||
370 | modeSize = output->currentMode()->size(); | ||||
371 | } else if (fallback && fallback->currentMode()) { | ||||
372 | refreshRate = fallback->currentMode()->refreshRate(); | ||||
373 | modeSize = fallback->currentMode()->size(); | ||||
374 | } | ||||
375 | | ||||
376 | if (refreshRate < 0 || !modeSize.isValid()) { | ||||
377 | return false; | ||||
378 | } | ||||
379 | | ||||
380 | modeInfo[QStringLiteral("refresh")] = refreshRate; | ||||
375 | 381 | | |||
376 | QVariantMap modeSize; | 382 | QVariantMap modeSizeMap; | ||
377 | modeSize[QStringLiteral("width")] = mode->size().width(); | 383 | modeSizeMap[QStringLiteral("width")] = modeSize.width(); | ||
378 | modeSize[QStringLiteral("height")] = mode->size().height(); | 384 | modeSizeMap[QStringLiteral("height")] = modeSize.height(); | ||
379 | modeInfo[QStringLiteral("size")] = modeSize; | 385 | modeInfo[QStringLiteral("size")] = modeSizeMap; | ||
380 | 386 | | |||
381 | info[QStringLiteral("mode")] = modeInfo; | 387 | info[QStringLiteral("mode")] = modeInfo; | ||
382 | 388 | | |||
383 | return true; | 389 | return true; | ||
384 | } | 390 | } | ||
385 | 391 | | |||
386 | void Output::writeGlobal(const KScreen::OutputPtr &output) | 392 | void Output::writeGlobal(const KScreen::OutputPtr &output) | ||
387 | { | 393 | { | ||
388 | // get old values and subsequently override | 394 | // get old values and subsequently override | ||
389 | QVariantMap info = getGlobalData(output); | 395 | QVariantMap info = getGlobalData(output); | ||
390 | if (!writeGlobalPart(output, info)) { | 396 | if (!writeGlobalPart(output, info, nullptr)) { | ||
391 | return; | 397 | return; | ||
392 | } | 398 | } | ||
393 | 399 | | |||
394 | QFile file(globalFileName(output->hashMd5())); | 400 | QFile file(globalFileName(output->hashMd5())); | ||
395 | if (!file.open(QIODevice::WriteOnly)) { | 401 | if (!file.open(QIODevice::WriteOnly)) { | ||
396 | qCWarning(KSCREEN_KDED) << "Failed to open global output file for writing! " << file.errorString(); | 402 | qCWarning(KSCREEN_KDED) << "Failed to open global output file for writing! " << file.errorString(); | ||
397 | return; | 403 | return; | ||
398 | } | 404 | } | ||
399 | 405 | | |||
400 | file.write(QJsonDocument::fromVariant(info).toJson()); | 406 | file.write(QJsonDocument::fromVariant(info).toJson()); | ||
401 | return; | 407 | return; | ||
402 | } | 408 | } |