diff --git a/deepin-devicemanager-server/customgpuinfo/main.cpp b/deepin-devicemanager-server/customgpuinfo/main.cpp index ec961e91..c26460bd 100644 --- a/deepin-devicemanager-server/customgpuinfo/main.cpp +++ b/deepin-devicemanager-server/customgpuinfo/main.cpp @@ -10,11 +10,12 @@ #include -// 名称("Name") 厂商("Vendor") 型号("Model") 显存("Graphics Memory") +// 名称("Name") 厂商("Vendor") 型号("Model") 版本(Version) 显存("Graphics Memory") constexpr char kName[] { "Name" }; constexpr char kVendor[] { "Vendor" }; constexpr char kModel[] { "Model" }; +constexpr char kVersion[] { "Version" }; constexpr char kGraphicsMemory[] { "Graphics Memory" }; bool getGpuBaseInfo(QMap &mapInfo) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp b/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp index dfacb3f2..d0c004d3 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp @@ -353,13 +353,25 @@ void DeviceGpu::setGpuInfo(const QMap &mapInfo) getOtherMapInfo(mapInfo); } -// 名称(Name) 厂商(Vendor) 型号(Model) 显存(Graphics Memory) +// 名称(Name) 厂商(Vendor) 型号(Model) 版本(Version) 显存(Graphics Memory) void DeviceGpu::setGpuInfoByCustom(const QMap &mapInfo) { - setAttribute(mapInfo, "Name", m_Name); - setAttribute(mapInfo, "Vendor", m_Vendor); - setAttribute(mapInfo, "Model", m_Model); - setAttribute(mapInfo, "Graphics Memory", m_GraphicsMemory); + QMap::const_iterator it = mapInfo.constBegin(); + for (; it != mapInfo.constEnd(); ++it) { + if (it.key() == "Name") { + m_Name = it.value(); + } else if (it.key() == "Vendor") { + m_Vendor = it.value(); + } else if (it.key() == "Model") { + m_Model = it.value(); + } else if (it.key() == "Version") { + m_Version = it.value(); + } else if (it.key() == "Graphics Memory") { + m_GraphicsMemory = it.value(); + } else { + m_extraInfo.insert(it.key(), it.value()); + } + } } const QString &DeviceGpu::name() const @@ -426,6 +438,9 @@ void DeviceGpu::loadOtherDeviceInfo() // 将QMap内容转存为QList> mapInfoToList(); + + // 将m_extraInfo追加到m_LstOtherInfo中 + appendExtraInfoToOtherInfo(); } void DeviceGpu::loadTableData() @@ -442,3 +457,12 @@ void DeviceGpu::loadTableData() m_TableData.append(m_Model); qCDebug(appLog) << "Table data loaded."; } + +void DeviceGpu::appendExtraInfoToOtherInfo() +{ + QMap::const_iterator iter = m_extraInfo.constBegin(); + for (; iter != m_extraInfo.constEnd(); ++iter) { + if (isValueValid(iter.value())) + m_LstOtherInfo.append(QPair(iter.key(), iter.value())); + } +} diff --git a/deepin-devicemanager/src/DeviceManager/DeviceGpu.h b/deepin-devicemanager/src/DeviceManager/DeviceGpu.h index 857c4372..cbc34068 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceGpu.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceGpu.h @@ -110,6 +110,9 @@ class DeviceGpu: public DeviceBaseInfo */ void loadTableData() override; +private: + void appendExtraInfoToOtherInfo(); + private: QString m_Model; // m_extraInfo; }; #endif // DEVICEGPU_H diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp index 8261c45c..b68edbaa 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp @@ -151,7 +151,7 @@ QString DeviceBaseInfo::subTitle() return QString(""); } -bool DeviceBaseInfo::isValueValid(QString &value) +bool DeviceBaseInfo::isValueValid(const QString &value) { // qCDebug(appLog) << "DeviceBaseInfo::isValueValid called for value: " << value; // 判断属性值是否有效 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.h b/deepin-devicemanager/src/DeviceManager/DeviceInfo.h index 6be90b65..e3d6c875 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.h @@ -263,7 +263,7 @@ class DeviceBaseInfo : public QObject * @param value:属性值 * @return true:属性值有效 */ - bool isValueValid(QString &value); + bool isValueValid(const QString &value); /** * @brief setForcedDisplay:设置强制显示 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp index 2cc08177..c1a000ff 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp @@ -1162,7 +1162,7 @@ void DeviceManager::addMonitor(DeviceMonitor *const device) m_ListDeviceMonitor.append(device); } -void DeviceManager::setMonitorInfoFromXrandr(const QString &main, const QString &edid, const QString &rate) +void DeviceManager::setMonitorInfoFromXrandr(const QString &main, const QString &edid, const QString &rate, const QString &xrandr) { qCDebug(appLog) << "Setting monitor info from xrandr"; // 从xrandr中添加显示设备信息 @@ -1172,7 +1172,7 @@ void DeviceManager::setMonitorInfoFromXrandr(const QString &main, const QString if (!device) continue; - if (device->setInfoFromXradr(main, edid, rate)) + if (device->setInfoFromXradr(main, edid, rate, xrandr)) return; } } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.h b/deepin-devicemanager/src/DeviceManager/DeviceManager.h index 0d4ea7d8..c58503b9 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.h @@ -266,7 +266,7 @@ class DeviceManager : public QObject * @param main:主显示器信息 * @param edid:edid信息 */ - void setMonitorInfoFromXrandr(const QString &main, const QString &edid, const QString &rate = ""); + void setMonitorInfoFromXrandr(const QString &main, const QString &edid, const QString &rate = "", const QString &xrandr = ""); /** * @brief setMonitorInfoFromDbus:设置由 dbus 获取的显示设备信息 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp index 6a7746b8..e7a2ab2d 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp @@ -18,6 +18,7 @@ #include // 其它头文件 #include +#include DWIDGET_USE_NAMESPACE using namespace DDLog; @@ -136,7 +137,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap &mapInfo) setAttribute(mapInfo, "", m_DisplayInput); setAttribute(mapInfo, "Size", m_ScreenSize); setAttribute(mapInfo, "", m_MainScreen); - setAttribute(mapInfo, "Resolution", m_SupportResolution); + // setAttribute(mapInfo, "Resolution", m_SupportResolution); qCDebug(appLog) << "Basic monitor attributes set - Name:" << m_Name << "Vendor:" << m_Vendor << "Model:" << m_Model; double inch = 0.0; @@ -146,22 +147,22 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap &mapInfo) qCDebug(appLog) << "Screen size parsed:" << m_ScreenSize << "Width:" << size.width() << "Height:" << size.height(); // 获取当前分辨率 和 当前支持分辨率 - QStringList listResolution = m_SupportResolution.split(" "); - m_SupportResolution = ""; - foreach (const QString &word, listResolution) { - if (word.contains("@")) { - m_SupportResolution.append(word); - m_SupportResolution.append(", "); - } - } +// QStringList listResolution = m_SupportResolution.split(" "); +// m_SupportResolution = ""; +// foreach (const QString &word, listResolution) { +// if (word.contains("@")) { +// m_SupportResolution.append(word); +// m_SupportResolution.append(", "); +// } +// } // 计算显示比例 caculateScreenRatio(); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - m_SupportResolution.replace(QRegExp(", $"), ""); + // m_SupportResolution.replace(QRegExp(", $"), ""); #else - m_SupportResolution.replace(QRegularExpression(", $"), ""); + // m_SupportResolution.replace(QRegularExpression(", $"), ""); #endif qCDebug(appLog) << "Supported resolutions processed:" << m_SupportResolution; @@ -239,7 +240,7 @@ QString DeviceMonitor::transWeekToDate(const QString &year, const QString &week) return date.toString("yyyy-MM"); } -bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, const QString &rate) +bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, const QString &rate, const QString &xrandr) { qCDebug(appLog) << "Setting monitor info from xrandr"; if(m_IsTomlSet) { @@ -281,6 +282,23 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c } } } + + QMap monitorResolutionMap = getMonitorResolutionMap(xrandr, m_RawInterface); + + if (monitorResolutionMap.size() == 1) { + m_SupportResolution.clear(); + foreach (const QString &word, monitorResolutionMap.value(m_RawInterface)) { + if (word.contains("@")) { + m_SupportResolution.append(word); + m_SupportResolution.append(", "); + } + } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + m_SupportResolution.remove(QRegExp(", $")); +#else + m_SupportResolution.remove(QRegularExpression(", $")); +#endif + } qCDebug(appLog) << "Interface already processed, returning false"; return false; } @@ -425,6 +443,13 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra m_Interface = match.captured(1); } + if (info.contains("connected")) { + QStringList monitorInfoList = info.split(" ", QT_SKIP_EMPTY_PARTS); + if (monitorInfoList.size() > 0){ + m_RawInterface = monitorInfoList.at(0).trimmed(); + } + } + // wayland xrandr --verbose无primary信息 if (qApp->isDXcbPlatform()) { qCDebug(appLog) << "Running on XCB platform, checking for primary display"; @@ -581,3 +606,63 @@ bool DeviceMonitor::caculateScreenSize(const QString &edid) m_ScreenSize = QString("%1 %2(%3mm×%4mm)").arg(QString::number(inch, '0', 1)).arg(translateStr("inch")).arg(width).arg(height); return true; } + +QMap DeviceMonitor::getMonitorResolutionMap(QString rawText, QString key, bool round) +{ + QMap monitorResolutionMap; + + if (!rawText.isEmpty()) { + QStringList rawLines = rawText.split("\n", QT_SKIP_EMPTY_PARTS); + + // get the resolution + for (auto line : rawLines) { + + // handel disconnected monitor + if (line.contains("disconnected", Qt::CaseInsensitive)) + continue; + + // handel connected monitor + if (!line.startsWith(" ") && line.contains("connected")) { + QStringList monitorInfoList = line.split(" ", QT_SKIP_EMPTY_PARTS); + if (monitorInfoList.size() > 0){ + monitorResolutionMap.insert(monitorInfoList.at(0).trimmed(), QStringList()); + } + } + + // handel resolution + if (line.startsWith(" ") && !line.contains("connect") && !line.contains(":")){ + QStringList resolutions = line.trimmed().replace("*", "").replace("+", "").split(" ", QT_SKIP_EMPTY_PARTS); + if (resolutions.size() >= 2 && monitorResolutionMap.size() > 0) { + QString resolution = resolutions.at(0); + resolutions.pop_front(); + + for(auto rate : resolutions) { + QString realResolution; + + if (round) { + bool ok = false; + double realRate = rate.toDouble(&ok); + if (ok) { + realResolution = tr("%1@%2Hz").arg(resolution).arg(QString::number(realRate, 'g', realRate >=100 ? 3 : 2)); + } + } else { + realResolution = tr("%1@%2Hz").arg(resolution).arg(rate); + } + + if (!monitorResolutionMap.value(monitorResolutionMap.lastKey()).contains(realResolution)) { + monitorResolutionMap[monitorResolutionMap.lastKey()].append(realResolution); + } + } + } + } + } + } + + if (monitorResolutionMap.keys().contains(key)) { + return QMap{{key, monitorResolutionMap.value(key)}}; + } else { + monitorResolutionMap.clear(); + } + + return monitorResolutionMap; +} diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h index d53832bc..49409eeb 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h @@ -38,7 +38,7 @@ class DeviceMonitor : public DeviceBaseInfo * @param edid:edid信息 * @return 布尔值,true:信息设置成功;false:信息设置失败 */ - bool setInfoFromXradr(const QString &main, const QString &edid, const QString &rate); + bool setInfoFromXradr(const QString &main, const QString &edid, const QString &rate, const QString &xrandr); // 将年周转化为年月 /** @@ -178,7 +178,14 @@ class DeviceMonitor : public DeviceBaseInfo */ bool caculateScreenSize(const QString &edid); - + /** + * @brief getMonitorResolutionMap:从xrandr字符串获取格式化 + * @param rawText:原始xrandr输出字符串 + * @param key:显示器编号:如 HDMI-0, VGA-1 + * @param round:是否保留整数,如60.00Hz保留后为60Hz + * @return 显示器编号键值对,如{"HDMI-0": ["1920x1080@60Hz, "1920x1080@50Hz",..]} + */ + QMap getMonitorResolutionMap(QString rawText, QString key = "", bool round = true); private: QString m_Model; // #include #include +#include DWIDGET_USE_NAMESPACE using namespace DDLog; @@ -587,6 +588,15 @@ void MainWindow::slotLoadingFinish(const QString &message) if (ret && lst.size() > 0) {//当设备大小为0时,显示概况信息 mp_DeviceWidget->updateDevice(mp_DeviceWidget->currentIndex(), lst); + + // bug-325731 + if (mp_DeviceWidget->currentIndex() == QObject::tr("Monitor")) { + QtConcurrent::run([=](){ + QThread::msleep(700); + emit mp_DeviceWidget->itemClicked(mp_DeviceWidget->currentIndex()); + qWarning() << mp_DeviceWidget->currentIndex(); + }); + } } else { QMap overviewMap = DeviceManager::instance()->getDeviceOverview(); mp_DeviceWidget->updateOverview(overviewMap); diff --git a/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp b/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp index a49ec242..22b465ed 100644 --- a/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp +++ b/deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp @@ -137,6 +137,8 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList> &lstM QString deviceInfo; runCmd(deviceInfo, cmd); + QString xrandInfo; + runCmd(xrandInfo, "xrandr"); QStringList lines = deviceInfo.split("\n"); QStringList::iterator it = lines.begin(); @@ -150,10 +152,11 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList> &lstM qCDebug(appLog) << "Found new display screen:" << (*it).trimmed(); // 新的显示屏 QMap newMap; - newMap.insert("mainInfo", (*it).trimmed()); + newMap.insert("mainInfo", (*it).trimmed()); auto mainInfoList = (*it).trimmed().split(" "); if (mainInfoList.size() > 0) { newMap.insert("port", mainInfoList.at(0)); + newMap.insert("xrandr", xrandInfo); } lstMap.append(newMap); continue; @@ -184,6 +187,7 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList> &lstM // 获取当前频率 if ((*it).contains("*current")) { + // QString ss = *it; if ((it += 2) >= lines.end()) return; QRegularExpression regRate(".*([0-9]{1,5}\\.[0-9]{1,5}Hz).*"); @@ -291,7 +295,7 @@ void ThreadExecXrandr::getMonitorInfoFromXrandrVerbose() if ((*it).size() < 1) continue; - DeviceManager::instance()->setMonitorInfoFromXrandr((*it)["mainInfo"], (*it)["edid"], (*it)["rate"]); + DeviceManager::instance()->setMonitorInfoFromXrandr((*it)["mainInfo"], (*it)["edid"], (*it)["rate"], (*it)["xrandr"]); } }