Skip to content

Commit

Permalink
feat: 增加强制使用OpenGL渲染的设置项
Browse files Browse the repository at this point in the history
  • Loading branch information
mhduiy committed Dec 20, 2024
1 parent e54ab45 commit 830386f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
20 changes: 18 additions & 2 deletions src/cpp/settingPageTools/othersettingshandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ OtherSettingsHandler::OtherSettingsHandler(QObject *parent)
{
m_triggerTimer->setInterval(300);
m_triggerTimer->setSingleShot(true);
connect(m_triggerTimer, &QTimer::timeout, this, &OtherSettingsHandler::syncConfig);

GlobalSetting::instance()->checkConfig("other", "wrapperOpacity", 0.3);
double configWrapperOpacity = GlobalSetting::instance()->readConfig("other", "wrapperOpacity").toDouble();
setWrapperOpacity(configWrapperOpacity);
connect(m_triggerTimer, &QTimer::timeout, this, &OtherSettingsHandler::syncConfig);

GlobalSetting::instance()->checkConfig("other", "useOpenGL", QVariant::fromValue(false));
bool useOpenGL = GlobalSetting::instance()->readConfig("other", "useOpenGL").toBool();

setWrapperOpacity(configWrapperOpacity);
setUseOpenGL(useOpenGL);
}

void OtherSettingsHandler::setWrapperOpacity(double value)
Expand All @@ -23,7 +28,18 @@ void OtherSettingsHandler::setWrapperOpacity(double value)
}
}

void OtherSettingsHandler::setUseOpenGL(bool value)
{
qWarning() << "=========";
if (m_useOpenGL != value) {
m_useOpenGL = value;
Q_EMIT useOpenGLChanged(value);
m_triggerTimer->start();
}
}

void OtherSettingsHandler::syncConfig()
{
GlobalSetting::instance()->writeConfig("other", "wrapperOpacity", m_wrapperOpacity);
GlobalSetting::instance()->writeConfig("other", "useOpenGL", m_useOpenGL);
}
6 changes: 6 additions & 0 deletions src/cpp/settingPageTools/othersettingshandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ class OtherSettingsHandler : public QObject
Q_OBJECT
SINGLETON(OtherSettingsHandler)
Q_PROPERTY(double wrapperOpacity READ wrapperOpacity WRITE setWrapperOpacity NOTIFY wrapperOpacityChanged)
Q_PROPERTY(bool useOpenGL READ useOpenGL WRITE setUseOpenGL NOTIFY useOpenGLChanged)
public:
double wrapperOpacity() const { return m_wrapperOpacity; }
void setWrapperOpacity(double value);

bool useOpenGL() const { return m_useOpenGL; }
void setUseOpenGL(bool value);

signals:
void wrapperOpacityChanged(double value);
void useOpenGLChanged(bool value);

private slots:
void syncConfig();

private:
double m_wrapperOpacity;
bool m_useOpenGL;
QTimer *m_triggerTimer;
};
2 changes: 0 additions & 2 deletions src/cpp/settingPageTools/settingPageTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ void WallPaperModel::setCurrentIndex(int index)
m_currentIndex = index;
emit currentItemChanged(url);
emit currentIndexChanged(index);
qWarning() << "****" << url;
WallpaperHelper::instance()->setWallPaper(url);
GlobalSetting::instance()->writeConfig("wallpaper", "url", url);
GlobalSetting::instance()->writeConfig("wallpaper", "index", QString::number(index));
Expand Down Expand Up @@ -171,7 +170,6 @@ void SettingPageTools::onRequestRefreshWallpaperList()
QJsonObject imageObj = it.toObject();
QString fileNameUrl = imageObj["url"].toString();
QUrl url = QUrl(fileNameUrl);
qWarning() << url << url.toLocalFile();
if (!QFile::exists(url.toLocalFile())) {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/utils/globalsetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ GlobalSetting::GlobalSetting(QObject *parent) : QObject(parent) {
dir.mkpath(cacheDir);
}

qDebug() << "config file:" << cacheDir + "/config.ini";
settings = new QSettings(cacheDir + "/config.ini", QSettings::IniFormat);
}

Expand All @@ -37,8 +38,10 @@ bool GlobalSetting::checkConfig(const QString &title, const QString &key, const
settings->beginGroup(title);
if (!settings->contains(key)) {
settings->setValue(key, defaultValue);
settings->endGroup();
return false;
}
settings->endGroup();
return true;
}

Expand Down
22 changes: 16 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "cpp/settingPageTools/settingPageTools.h"
#include "cpp/utils/notificationcontroller.h"
#include "cpp/components/fpsitem.h"
#include "cpp/utils/globalsetting.h"

bool checkADB() {
QProcess process;
Expand All @@ -41,6 +42,15 @@ bool checkADB() {
return false;
}

bool forceOpenGL()
{
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
QSurfaceFormat format;
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format);
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Expand Down Expand Up @@ -99,12 +109,12 @@ int main(int argc, char *argv[])

qmlRegisterType<FpsItem>( "FpsItem", 1, 0, "FpsItem");

QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

QSurfaceFormat format;
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format);
GlobalSetting::instance()->checkConfig("other", "useOpenGL", QVariant::fromValue(false));
bool useOpenGL = GlobalSetting::instance()->readConfig("other", "useOpenGL").toBool();
if (useOpenGL) {
qInfo() << "force use OpenGL";
forceOpenGL();
}

QQmlApplicationEngine engine;
const QUrl url("qrc:/qml/Main.qml");
Expand Down
25 changes: 11 additions & 14 deletions src/qml/pages/SettingPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,22 @@ ItemPage {
}

SettingItem {
title: "夜间模式"
description: "将所有控件设置为深色主题"
title: "OpenGL渲染模式"
description: "强制使用OpenGL渲染,如果设备镜像功能不可用,可尝试开启此开关,重启应用生效"
controlItem: MSwitchButton {

status: OtherSettingsHandler.useOpenGL
onStatusChanged: {
console.warn("=======", status)
OtherSettingsHandler.useOpenGL = status
}
}
}

Repeater {
model: 16
SettingItem {
title: "夜间模式"
description: "将所有控件设置为深色主题"
controlItem: MLoadIndicator {
id: loadIndicator
Component.onCompleted: {
loadIndicator.start()
}
SettingItem {
title: "夜间模式"
description: "将所有控件设置为深色主题, 此功能开发中..."
controlItem: MSwitchButton {

}
}
}
}
Expand Down

0 comments on commit 830386f

Please sign in to comment.