File indexing completed on 2024-05-12 05:38:44
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2023 Quang NgĂ´ <ngoquang2708@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-only 0005 * 0006 */ 0007 0008 #include "ddcutildisplay.h" 0009 0010 #define BRIGHTNESS_VCP_FEATURE_CODE 0x10 0011 0012 #ifdef WITH_DDCUTIL 0013 DDCutilDisplay::DDCutilDisplay(DDCA_Display_Info displayInfo, DDCA_Display_Handle displayHandle) 0014 : m_displayInfo(displayInfo) 0015 , m_displayHandle(displayHandle) 0016 , m_brightness(-1) 0017 , m_maxBrightness(-1) 0018 , m_supportsBrightness(false) 0019 { 0020 Q_ASSERT(displayHandle); 0021 0022 DDCA_Non_Table_Vcp_Value value; 0023 0024 if (ddca_get_non_table_vcp_value(m_displayHandle, BRIGHTNESS_VCP_FEATURE_CODE, &value) == DDCRC_OK) { 0025 m_brightness = value.sh << 8 | value.sl; 0026 m_maxBrightness = value.mh << 8 | value.ml; 0027 m_supportsBrightness = true; 0028 } 0029 } 0030 #endif 0031 0032 DDCutilDisplay::~DDCutilDisplay() 0033 { 0034 #ifdef WITH_DDCUTIL 0035 ddca_close_display(m_displayHandle); 0036 #endif 0037 } 0038 0039 QString DDCutilDisplay::label() const 0040 { 0041 #ifdef WITH_DDCUTIL 0042 return m_displayInfo.model_name; 0043 #else 0044 return QString(); 0045 #endif 0046 } 0047 0048 int DDCutilDisplay::brightness() 0049 { 0050 QReadLocker lock(&m_lock); 0051 0052 return m_brightness; 0053 } 0054 0055 int DDCutilDisplay::maxBrightness() 0056 { 0057 QReadLocker lock(&m_lock); 0058 0059 return m_maxBrightness; 0060 } 0061 0062 void DDCutilDisplay::setBrightness(int value) 0063 { 0064 QWriteLocker lock(&m_lock); 0065 0066 #ifdef WITH_DDCUTIL 0067 uint8_t sh = value >> 8 & 0xff; 0068 uint8_t sl = value & 0xff; 0069 0070 if (ddca_set_non_table_vcp_value(m_displayHandle, BRIGHTNESS_VCP_FEATURE_CODE, sh, sl) == DDCRC_OK) { 0071 m_brightness = value; 0072 } 0073 #endif 0074 } 0075 0076 bool DDCutilDisplay::supportsBrightness() const 0077 { 0078 return m_supportsBrightness; 0079 } 0080 0081 #include "moc_ddcutildisplay.cpp"