diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,9 +59,10 @@ TYPE OPTIONAL PURPOSE "Set monitor settings over DDC/CI channel" ) -else() - add_feature_info("DDCUtil" "Off" "DDCUtil library support is disabled by default as recomemded by authors, add -DWITH_DDCUTIL=On to enable") + add_definitions(-DWITH_DDCUTIL=true) endif() +add_feature_info("DDCUtil" WITH_DDCUTIL "Set monitor settings over DDC/CI channel") + include_directories ( ${CMAKE_CURRENT_BINARY_DIR} diff --git a/daemon/backends/upower/ddcutilbrightness.h b/daemon/backends/upower/ddcutilbrightness.h --- a/daemon/backends/upower/ddcutilbrightness.h +++ b/daemon/backends/upower/ddcutilbrightness.h @@ -24,7 +24,7 @@ #include #include -#ifdef WITH_DDCUTIL +#if WITH_DDCUTIL #include #endif @@ -43,14 +43,14 @@ void setBrightnessAfterFilter(); private: -#ifdef WITH_DDCUTIL +#if WITH_DDCUTIL QVector m_displayHandleList; QVector m_displayInfoList; #endif //ifdef WITH_DDCUTIL //Per display properties //destription mapped to vcp values for easy retrieval - QVector > m_descrToVcp_perDisp; - QVector > > m_vcpTovcpValueWithDescr_perDisp; + QVector m_usedVcp; + QVector> m_supportedVcp_perDisp; long m_tmpCurrentBrightness; diff --git a/daemon/backends/upower/ddcutilbrightness.cpp b/daemon/backends/upower/ddcutilbrightness.cpp --- a/daemon/backends/upower/ddcutilbrightness.cpp +++ b/daemon/backends/upower/ddcutilbrightness.cpp @@ -23,6 +23,7 @@ DDCutilBrightness::DDCutilBrightness() { + QVector m_usedVcp = {0x10}; m_setBrightnessEventFilter.setInterval(100); m_setBrightnessEventFilter.setSingleShot(true); connect(&m_setBrightnessEventFilter, &QTimer::timeout, this, &DDCutilBrightness::setBrightnessAfterFilter); @@ -30,10 +31,7 @@ void DDCutilBrightness::detect() { -#ifndef WITH_DDCUTIL - qCInfo(POWERDEVIL) << "[DDCutilBrightness] compiled without DDC/CI support"; - return; -#else + #if WITH_DDCUTIL DDCA_Status rc; qCDebug(POWERDEVIL) << "Check for monitors using ddca_get_displays()..."; @@ -43,8 +41,7 @@ qCInfo(POWERDEVIL) << "[DDCutilBrightness] " << dlist->ct << "display(s) were detected"; for (int iDisp=0;iDispct;iDisp++) { - DDCA_Display_Identifier did; - DDCA_Display_Ref dref; + DDCA_Display_Handle dh = nullptr; // initialize to avoid clang analyzer warning qCDebug(POWERDEVIL) << "Create a Display Identifier for display"<info[iDisp]); - rc = ddca_create_dispno_display_identifier(iDisp+1, &did); // ddcutil uses 1 paded indexing for displays - - char * did_repr = ddca_did_repr(did); - - qCDebug(POWERDEVIL) << "did="<info[iDisp].dref, &dh); if (rc != 0) { qCWarning(POWERDEVIL) << "[DDCutilBrightness]: ddct_open_display"<< rc; continue; @@ -80,81 +58,47 @@ qCDebug(POWERDEVIL) << "adding handle to list"; m_displayHandleList.append(dh); - qCDebug(POWERDEVIL) << "handles nb: "<vcp_code_ct << "capabilities parsed"; - - - m_descrToVcp_perDisp.append(QMap()); - m_vcpTovcpValueWithDescr_perDisp.append(QMap >() ); - //fill the feature description to vcp LUT - - DDCA_Version_Feature_Info* featureInfo; - for (int iVcp=0;iVcpvcp_code_ct;iVcp++) { - - int vcpCode=parsedCapabilities->vcp_codes[iVcp].feature_code; - - m_vcpTovcpValueWithDescr_perDisp[iDisp].insert(vcpCode, QMap()); + m_supportedVcp_perDisp.append(QVector()); - m_descrToVcp_perDisp[iDisp].insert( - QString(ddca_get_feature_name(vcpCode)), vcpCode); - - - ddca_get_feature_info_by_display(m_displayHandleList.at(iDisp), vcpCode, &featureInfo); - if (featureInfo == nullptr) { - continue; + for (int iVcp=0; iVcpfeature_code<<":"<desc; - if ((featureInfo->feature_flags & DDCA_SIMPLE_NC) != DDCA_SIMPLE_NC) { - continue; - } - for (int iVcpVal=0;featureInfo->sl_values[iVcpVal].value_code!=0;++iVcpVal) { - - qCDebug(POWERDEVIL) << "\t"<sl_values[iVcpVal].value_code - <<":"<< featureInfo->sl_values[iVcpVal].value_name; - - bool thisVcpValIsSupported=false; - - for (int iSupportedVcpVal=0; iSupportedVcpValvcp_codes[iVcp].value_ct; iSupportedVcpVal++) { - if(parsedCapabilities->vcp_codes[iVcp].values[iSupportedVcpVal] - ==featureInfo->sl_values[iVcpVal].value_code) { - thisVcpValIsSupported=true; - } - } - - if (thisVcpValIsSupported) { - (m_vcpTovcpValueWithDescr_perDisp[iDisp])[vcpCode].insert( - featureInfo->sl_values[iVcpVal].value_code, - featureInfo->sl_values[iVcpVal].value_name); - } + else { + m_supportedVcp_perDisp[iDisp].append(m_usedVcp[iVcp]); } } - ddca_free_display_identifier(did); - ddca_free_parsed_capabilities(parsedCapabilities); } -#endif + + #else + qCInfo(POWERDEVIL) << "[DDCutilBrightness] compiled without DDC/CI support"; + return; + #endif } bool DDCutilBrightness::isSupported() const { -#ifndef WITH_DDCUTIL - return false; -#else + #if WITH_DDCUTIL return !m_displayHandleList.isEmpty(); -#endif + #else + return false; + #endif } long DDCutilBrightness::brightness() { -#ifdef WITH_DDCUTIL + #if WITH_DDCUTIL + if (m_supportedVcp_perDisp.at(0).contains(0x10)) { + qCDebug(POWERDEVIL) << "[DDCutilBrightness::brightness]: trying to get brightness for monitor that does not support it"; + return 0; + } //we check wether the timer is running, this means we received new values but did not send them yet to the monitor - //not checking that results in the brightness slider jump to the previous vqlue when changing. - if(m_setBrightnessEventFilter.isActive()) { + //not checking that results in the brightness slider jump to the previous value when changing. + if (m_setBrightnessEventFilter.isActive()) { m_lastBrightnessKnown = m_tmpCurrentBrightness; } else { //FIXME: gets value for display 1 @@ -162,7 +106,7 @@ DDCA_Single_Vcp_Value *returnValue; rc = ddca_get_vcp_value(m_displayHandleList.at(0), - m_descrToVcp_perDisp.at(0).value("Brightness"), + 0x10, DDCA_NON_TABLE_VCP_VALUE, &returnValue); qCDebug(POWERDEVIL) << "[DDCutilBrightness::brightness]: ddca_get_vcp_value returned" << rc; @@ -172,19 +116,23 @@ } } return m_lastBrightnessKnown; -#else + #else return 0; -#endif + #endif } long DDCutilBrightness::brightnessMax() { -#ifdef WITH_DDCUTIL + #if WITH_DDCUTIL + if (m_supportedVcp_perDisp.at(0).contains(0x10)) { + qCDebug(POWERDEVIL) << "[DDCutilBrightness::brightnessMax]: trying to set brightness for monitor that does not support it"; + return 0; + } + DDCA_Status rc; DDCA_Single_Vcp_Value *returnValue; - rc = ddca_get_vcp_value(m_displayHandleList.at(0), - m_descrToVcp_perDisp.at(0).value("Brightness"), + rc = ddca_get_vcp_value(m_displayHandleList.at(0), 0x10, DDCA_NON_TABLE_VCP_VALUE, &returnValue); qCDebug(POWERDEVIL) << "[DDCutilBrightness::brightnessMax]: ddca_get_vcp_value returned" << rc; @@ -194,9 +142,9 @@ } return m_lastMaxBrightnessKnown; -#else + #else return 100.0; -#endif + #endif } void DDCutilBrightness::setBrightness(long value) @@ -208,13 +156,17 @@ void DDCutilBrightness::setBrightnessAfterFilter() { -#ifdef WITH_DDCUTIL + #if WITH_DDCUTIL + if (m_supportedVcp_perDisp.at(0).contains(0x10)) { + qCDebug(POWERDEVIL) << "[DDCutilBrightness::brightness]: trying to set brightness for monitor that does not support it"; + return; + } + DDCA_Status rc; for (int iDisp=0;iDisp