Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deepin-devicemanager-server/customgpuinfo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include <QFile>
#include <QDebug>

#include <iostream>

Check warning on line 11 in deepin-devicemanager-server/customgpuinfo/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <iostream> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// 名称("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<QString, QString> &mapInfo)
Expand Down
34 changes: 29 additions & 5 deletions deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,25 @@ void DeviceGpu::setGpuInfo(const QMap<QString, QString> &mapInfo)
getOtherMapInfo(mapInfo);
}

// 名称(Name) 厂商(Vendor) 型号(Model) 显存(Graphics Memory)
// 名称(Name) 厂商(Vendor) 型号(Model) 版本(Version) 显存(Graphics Memory)
void DeviceGpu::setGpuInfoByCustom(const QMap<QString, QString> &mapInfo)
{
setAttribute(mapInfo, "Name", m_Name);
setAttribute(mapInfo, "Vendor", m_Vendor);
setAttribute(mapInfo, "Model", m_Model);
setAttribute(mapInfo, "Graphics Memory", m_GraphicsMemory);
QMap<QString, QString>::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
Expand Down Expand Up @@ -426,6 +438,9 @@ void DeviceGpu::loadOtherDeviceInfo()

// 将QMap<QString, QString>内容转存为QList<QPair<QString, QString>>
mapInfoToList();

// 将m_extraInfo追加到m_LstOtherInfo中
appendExtraInfoToOtherInfo();
}

void DeviceGpu::loadTableData()
Expand All @@ -442,3 +457,12 @@ void DeviceGpu::loadTableData()
m_TableData.append(m_Model);
qCDebug(appLog) << "Table data loaded.";
}

void DeviceGpu::appendExtraInfoToOtherInfo()
{
QMap<QString, QString>::const_iterator iter = m_extraInfo.constBegin();
for (; iter != m_extraInfo.constEnd(); ++iter) {
if (isValueValid(iter.value()))
m_LstOtherInfo.append(QPair<QString, QString>(iter.key(), iter.value()));
}
}
4 changes: 4 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class DeviceGpu: public DeviceBaseInfo
*/
void loadTableData() override;

private:
void appendExtraInfoToOtherInfo();

private:
QString m_Model; //<! 【型号】
QString m_GraphicsMemory; //<! 【显存】
Expand All @@ -132,6 +135,7 @@ class DeviceGpu: public DeviceBaseInfo
QString m_IOPort; //<! 【ioport】
QString m_MemAddress; //<! 【内存地址】
// QString m_PhysID; //<! 【物理ID】
QMap<QString, QString> m_extraInfo;
};

#endif // DEVICEGPU_H
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// 判断属性值是否有效
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class DeviceBaseInfo : public QObject
* @param value:属性值
* @return true:属性值有效
*/
bool isValueValid(QString &value);
bool isValueValid(const QString &value);

/**
* @brief setForcedDisplay:设置强制显示
Expand Down
4 changes: 2 additions & 2 deletions deepin-devicemanager/src/DeviceManager/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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中添加显示设备信息
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 获取的显示设备信息
Expand Down
109 changes: 97 additions & 12 deletions deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
#include <QLoggingCategory>
#include <QDate>
#include <QSize>
#include <QRegularExpression>

Check warning on line 18 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QRegularExpression> not found. Please note: Cppcheck does not need standard library headers to get proper results.
// 其它头文件
#include <math.h>

Check warning on line 20 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <math.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 21 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DWIDGET_USE_NAMESPACE
using namespace DDLog;
Expand Down Expand Up @@ -136,7 +137,7 @@
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;
Expand All @@ -146,22 +147,22 @@
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;

Expand Down Expand Up @@ -239,7 +240,7 @@
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) {
Expand Down Expand Up @@ -281,6 +282,23 @@
}
}
}

QMap<QString, QStringList> 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;
}
Expand Down Expand Up @@ -425,6 +443,13 @@
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";
Expand Down Expand Up @@ -581,3 +606,63 @@
m_ScreenSize = QString("%1 %2(%3mm×%4mm)").arg(QString::number(inch, '0', 1)).arg(translateStr("inch")).arg(width).arg(height);
return true;
}

QMap<QString, QStringList> DeviceMonitor::getMonitorResolutionMap(QString rawText, QString key, bool round)

Check warning on line 610 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'rawText' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
QMap<QString, QStringList> monitorResolutionMap;

if (!rawText.isEmpty()) {
QStringList rawLines = rawText.split("\n", QT_SKIP_EMPTY_PARTS);

// get the resolution
for (auto line : rawLines) {

Check warning on line 618 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'line' is used to iterate by value. It could be declared as a const reference which is usually faster and recommended in C++.

// 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<QString, QStringList>{{key, monitorResolutionMap.value(key)}};
} else {
monitorResolutionMap.clear();
}

return monitorResolutionMap;
}
14 changes: 11 additions & 3 deletions deepin-devicemanager/src/DeviceManager/DeviceMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 将年周转化为年月
/**
Expand Down Expand Up @@ -178,15 +178,22 @@ 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<QString, QStringList> getMonitorResolutionMap(QString rawText, QString key = "", bool round = true);

private:
QString m_Model; //<! 【型号】
QString m_DisplayInput; //<! 【显示输入】
QString m_VGA; //<! 【VGA】
QString m_HDMI; //<! 【HDMI】
QString m_DVI; //<! 【DVI】
QString m_Interface; //<! 【显示屏借口类型
QString m_Interface; //<! 【显示屏接口类型
QString m_ScreenSize; //<! 【屏幕尺寸】
QString m_AspectRatio; //<! 【显示比例】
QString m_MainScreen; //<! 【主显示器】
Expand All @@ -199,6 +206,7 @@ class DeviceMonitor : public DeviceBaseInfo
int m_Width; //<! 屏幕的宽度
int m_Height; //<! 屏幕的高度
bool m_IsTomlSet;
QString m_RawInterface; //<! 【原始显示屏接口类型】
};

#endif // DEVICEMONITOR_H
10 changes: 10 additions & 0 deletions deepin-devicemanager/src/Page/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
#include <QJsonDocument>
#include <QProcess>
#include <QDir>
#include <QVBoxLayout>

Check warning on line 44 in deepin-devicemanager/src/Page/MainWindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QVBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 45 in deepin-devicemanager/src/Page/MainWindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QRegularExpression>

Check warning on line 46 in deepin-devicemanager/src/Page/MainWindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QRegularExpression> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QtConcurrent/QtConcurrent>

Check warning on line 47 in deepin-devicemanager/src/Page/MainWindow.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtConcurrent/QtConcurrent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DWIDGET_USE_NAMESPACE
using namespace DDLog;
Expand Down Expand Up @@ -587,6 +588,15 @@

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<QString, QString> overviewMap = DeviceManager::instance()->getDeviceOverview();
mp_DeviceWidget->updateOverview(overviewMap);
Expand Down
8 changes: 6 additions & 2 deletions deepin-devicemanager/src/Tool/ThreadExecXrandr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList<QMap<QString, QString>> &lstM

QString deviceInfo;
runCmd(deviceInfo, cmd);
QString xrandInfo;
runCmd(xrandInfo, "xrandr");

QStringList lines = deviceInfo.split("\n");
QStringList::iterator it = lines.begin();
Expand All @@ -150,10 +152,11 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList<QMap<QString, QString>> &lstM
qCDebug(appLog) << "Found new display screen:" << (*it).trimmed();
// 新的显示屏
QMap<QString, QString> 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;
Expand Down Expand Up @@ -184,6 +187,7 @@ void ThreadExecXrandr::loadXrandrVerboseInfo(QList<QMap<QString, QString>> &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).*");
Expand Down Expand Up @@ -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"]);
}
}

Expand Down