Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/manager.cpp
Show All 19 Lines | |||||
20 | #include "manager.h" | 20 | #include "manager.h" | ||
21 | #include "colorcorrectdbusinterface.h" | 21 | #include "colorcorrectdbusinterface.h" | ||
22 | #include "suncalc.h" | 22 | #include "suncalc.h" | ||
23 | #include "gammaramp.h" | 23 | #include "gammaramp.h" | ||
24 | #include <colorcorrect_logging.h> | 24 | #include <colorcorrect_logging.h> | ||
25 | 25 | | |||
26 | #include <main.h> | 26 | #include <main.h> | ||
27 | #include <platform.h> | 27 | #include <platform.h> | ||
28 | #include <output.h> | ||||
28 | #include <screens.h> | 29 | #include <screens.h> | ||
29 | #include <workspace.h> | 30 | #include <workspace.h> | ||
30 | #include <logind.h> | 31 | #include <logind.h> | ||
31 | 32 | | |||
32 | #include <colorcorrect_settings.h> | 33 | #include <colorcorrect_settings.h> | ||
33 | 34 | | |||
34 | #include <QTimer> | 35 | #include <QTimer> | ||
35 | #include <QDBusConnection> | 36 | #include <QDBusConnection> | ||
▲ Show 20 Lines • Show All 468 Lines • ▼ Show 20 Line(s) | 504 | if (daylight()) { | |||
504 | return f(m_nightTargetTemp, m_dayTargetTemp); | 505 | return f(m_nightTargetTemp, m_dayTargetTemp); | ||
505 | } else { | 506 | } else { | ||
506 | return f(m_dayTargetTemp, m_nightTargetTemp); | 507 | return f(m_dayTargetTemp, m_nightTargetTemp); | ||
507 | } | 508 | } | ||
508 | } | 509 | } | ||
509 | 510 | | |||
510 | void Manager::commitGammaRamps(int temperature) | 511 | void Manager::commitGammaRamps(int temperature) | ||
511 | { | 512 | { | ||
512 | int nscreens = Screens::self()->count(); | 513 | const auto outs = kwinApp()->platform()->outputs(); | ||
513 | 514 | | |||
514 | for (int screen = 0; screen < nscreens; screen++) { | 515 | for (auto *o : outs) { | ||
515 | int rampsize = kwinApp()->platform()->gammaRampSize(screen); | 516 | int rampsize = o->getGammaRampSize(); | ||
516 | GammaRamp ramp(rampsize); | 517 | GammaRamp ramp(rampsize); | ||
517 | 518 | | |||
518 | /* | 519 | /* | ||
519 | * The gamma calculation below is based on the Redshift app: | 520 | * The gamma calculation below is based on the Redshift app: | ||
520 | * https://github.com/jonls/redshift | 521 | * https://github.com/jonls/redshift | ||
521 | */ | 522 | */ | ||
522 | 523 | | |||
523 | // linear default state | 524 | // linear default state | ||
Show All 13 Lines | |||||
537 | whitePoint[2] = (1. - alpha) * blackbodyColor[bbCIndex + 2] + alpha * blackbodyColor[bbCIndex + 5]; | 538 | whitePoint[2] = (1. - alpha) * blackbodyColor[bbCIndex + 2] + alpha * blackbodyColor[bbCIndex + 5]; | ||
538 | 539 | | |||
539 | for (int i = 0; i < rampsize; i++) { | 540 | for (int i = 0; i < rampsize; i++) { | ||
540 | ramp.red[i] = (double)ramp.red[i] / (UINT16_MAX+1) * whitePoint[0] * (UINT16_MAX+1); | 541 | ramp.red[i] = (double)ramp.red[i] / (UINT16_MAX+1) * whitePoint[0] * (UINT16_MAX+1); | ||
541 | ramp.green[i] = (double)ramp.green[i] / (UINT16_MAX+1) * whitePoint[1] * (UINT16_MAX+1); | 542 | ramp.green[i] = (double)ramp.green[i] / (UINT16_MAX+1) * whitePoint[1] * (UINT16_MAX+1); | ||
542 | ramp.blue[i] = (double)ramp.blue[i] / (UINT16_MAX+1) * whitePoint[2] * (UINT16_MAX+1); | 543 | ramp.blue[i] = (double)ramp.blue[i] / (UINT16_MAX+1) * whitePoint[2] * (UINT16_MAX+1); | ||
543 | } | 544 | } | ||
544 | 545 | | |||
545 | if (kwinApp()->platform()->setGammaRamp(screen, ramp)) { | 546 | if (o->setGammaRamp(ramp)) { | ||
546 | m_currentTemp = temperature; | 547 | m_currentTemp = temperature; | ||
547 | m_failedCommitAttempts = 0; | 548 | m_failedCommitAttempts = 0; | ||
548 | } else { | 549 | } else { | ||
549 | m_failedCommitAttempts++; | 550 | m_failedCommitAttempts++; | ||
550 | if (m_failedCommitAttempts < 10) { | 551 | if (m_failedCommitAttempts < 10) { | ||
551 | qCWarning(KWIN_COLORCORRECTION).nospace() << "Committing Gamma Ramp failed for screen " << screen << | 552 | qCWarning(KWIN_COLORCORRECTION).nospace() << "Committing Gamma Ramp failed for output " << o->name() << | ||
552 | ". Trying " << (10 - m_failedCommitAttempts) << " times more."; | 553 | ". Trying " << (10 - m_failedCommitAttempts) << " times more."; | ||
553 | } else { | 554 | } else { | ||
554 | // TODO: On multi monitor setups we could try to rollback earlier changes for already commited outputs | 555 | // TODO: On multi monitor setups we could try to rollback earlier changes for already commited outputs | ||
555 | qCWarning(KWIN_COLORCORRECTION) << "Gamma Ramp commit failed too often. Deactivating color correction for now."; | 556 | qCWarning(KWIN_COLORCORRECTION) << "Gamma Ramp commit failed too often. Deactivating color correction for now."; | ||
556 | m_failedCommitAttempts = 0; // reset so we can try again later (i.e. after suspend phase or config change) | 557 | m_failedCommitAttempts = 0; // reset so we can try again later (i.e. after suspend phase or config change) | ||
557 | m_running = false; | 558 | m_running = false; | ||
558 | cancelAllTimers(); | 559 | cancelAllTimers(); | ||
559 | } | 560 | } | ||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |