Repository: hyprwm/Hyprland
File: src/helpers/Monitor.cpp (C++)

Code before:

static NColorManagement::eTransferFunction chooseTF(NTransferFunction::eTF tf) {
    static auto PSDREOTF = CConfigValue<Hyprlang::STRING>("render:cm_sdr_eotf");

    switch (tf) {
        case NTransferFunction::TF_DEFAULT:
        case NTransferFunction::TF_GAMMA22:
        case NTransferFunction::TF_FORCED_GAMMA22: return NColorManagement::CM_TRANSFER_FUNCTION_GAMMA22;
        case NTransferFunction::TF_SRGB: return NColorManagement::CM_TRANSFER_FUNCTION_SRGB;

        case NTransferFunction::TF_AUTO: // use global setting
            const auto sdrEOTF = NTransferFunction::fromString(*PSDREOTF);
            switch (sdrEOTF) {
                case NTransferFunction::TF_AUTO: return NColorManagement::CM_TRANSFER_FUNCTION_GAMMA22;
                default: return chooseTF(sdrEOTF);
            }
    }
}

void CMonitor::applyCMType(NCMType::eCMType cmType, NTransferFunction::eTF cmSdrEotf) {
    auto       oldImageDescription = m_imageDescription;
    const auto chosenSdrEotf       = chooseTF(cmSdrEotf);

    switch (cmType) {
        case NCMType::CM_SRGB: m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf}); break; // assumes SImageDescription defaults to sRGB
        case NCMType::CM_WIDE:
            m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf,
                                                          .primariesNameSet = true,
                                                          .primariesNamed   = NColorManagement::CM_PRIMARIES_BT2020,
                                                          .primaries        = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_BT2020)});
            break;
        case NCMType::CM_DCIP3:
            m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf,
                                                          .primariesNameSet = true,
                                                          .primariesNamed   = NColorManagement::CM_PRIMARIES_DCI_P3,
                                                          .primaries        = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_DCI_P3)});
            break;
        case NCMType::CM_DP3:
            m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf,
                                                          .primariesNameSet = true,
                                                          .primariesNamed   = NColorManagement::CM_PRIMARIES_DISPLAY_P3,
                                                          .primaries        = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_DISPLAY_P3)});
            break;
        case NCMType::CM_ADOBE:
            m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf,
                                                          .primariesNameSet = true,
                                                          .primariesNamed   = NColorManagement::CM_PRIMARIES_ADOBE_RGB,
                                                          .primaries        = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_ADOBE_RGB)});
            break;
        case NCMType::CM_EDID:
            m_imageDescription =

Review comment (refactor):
Looks like build action isn't smart enough to handle a bit of recursion. Or am I missing some case?
```
/__w/Hyprland/Hyprland/src/helpers/Monitor.cpp: In function ‘NColorManagement::eTransferFunction chooseTF(NTransferFunction::eTF)’:
/__w/Hyprland/Hyprland/src/helpers/Monitor.cpp:494:1: error: control reaches end of non-void function [-Werror=return-type]
  494 | }
      | ^
```


Code after:
        }

        g_pHyprRenderer->m_mostHzMonitor = pMonitorMostHz;
    }

    std::erase_if(g_pCompositor->m_monitors, [&](PHLMONITOR& el) { return el.get() == this; });
}

static NColorManagement::eTransferFunction chooseTF(NTransferFunction::eTF tf) {
    const auto sdrEOTF = NTransferFunction::fromConfig();

    switch (tf) {
        case NTransferFunction::TF_DEFAULT:
        case NTransferFunction::TF_GAMMA22:
        case NTransferFunction::TF_FORCED_GAMMA22: return NColorManagement::CM_TRANSFER_FUNCTION_GAMMA22;
        case NTransferFunction::TF_SRGB: return NColorManagement::CM_TRANSFER_FUNCTION_SRGB;

        case NTransferFunction::TF_AUTO: // use global setting
            switch (sdrEOTF) {
                case NTransferFunction::TF_AUTO: return NColorManagement::CM_TRANSFER_FUNCTION_GAMMA22;
                default: return chooseTF(sdrEOTF);
            }

        default: UNREACHABLE();
    }
}

void CMonitor::applyCMType(NCMType::eCMType cmType, NTransferFunction::eTF cmSdrEotf) {
    auto                                                              oldImageDescription = m_imageDescription;
    const auto                                                        chosenSdrEotf       = chooseTF(cmSdrEotf);

    const auto                                                        masteringPrimaries  = getMasteringPrimaries();
    const NColorManagement::SImageDescription::SPCMasteringLuminances masteringLuminances = getMasteringLuminances();

    const auto                                                        maxFALL = this->maxFALL();
    const auto                                                        maxCLL  = this->maxCLL();

    switch (cmType) {
        case NCMType::CM_SRGB:
            m_imageDescription = CImageDescription::from({.transferFunction = chosenSdrEotf,
                                                          .primariesNamed   = NColorManagement::CM_PRIMARIES_SRGB,
                                                          .primaries        = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_SRGB)});
            break; // assumes SImageDescription defaults to sRGB
        case NCMType::CM_WIDE:
            m_imageDescription = CImageDescription::from({.transferFunction    = chosenSdrEotf,
                                                          .primariesNameSet    = true,
                                                          .primariesNamed      = NColorManagement::CM_PRIMARIES_BT2020,
                                                          .primaries           = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_BT2020),
                                                          .masteringPrimaries  = masteringPrimaries,
                                                          .masteringLuminances = masteringLuminances,
                                                          .maxCLL              = maxCLL,