Skip to content

Commit 0dc7298

Browse files
committed
Fixed UI lags when resizing the window
1 parent 53a8df6 commit 0dc7298

7 files changed

Lines changed: 41 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
All notable changes to this project will be documented in this file.
44

55
## Unreleased
6+
- Fixed UI lags when resizing the window (issue https://github.com/dmitry-s93/MControlCenter/issues/97)
67
- Updated Norwegian Bokmål (Thanks [msigurdsen](https://github.com/msigurdsen))
78
- Added support for German language (Thanks [EchterAlsFake](https://github.com/EchterAlsFake))
89
- Added support for Hungarian language (Thanks [BiRo96](https://github.com/BiRo96))

src/helper.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "helper/service.h"
2020
#include "helper.h"
21+
#include "mainwindow.h"
2122

2223
#include <QCoreApplication>
2324
#include <QDBusReply>
@@ -60,6 +61,25 @@ bool Helper::updateData() {
6061
return false;
6162
}
6263

64+
void Helper::updateDataAsync() {
65+
QDBusPendingCall async = iface->asyncCall("getData");
66+
QDBusPendingCallWatcher const *watcher = new QDBusPendingCallWatcher(async, this);
67+
68+
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
69+
}
70+
71+
void Helper::callFinishedSlot(QDBusPendingCallWatcher *call) {
72+
QDBusPendingReply<QByteArray> reply = *call;
73+
if (reply.isError()) {
74+
printError(reply.error());
75+
MainWindow::setUpdateDataError(true);
76+
} else {
77+
ecData = reply.value();
78+
MainWindow::setUpdateDataError(false);
79+
}
80+
call->deleteLater();
81+
}
82+
6383
int Helper::getValue(int address) const {
6484
if (!ecData.isEmpty())
6585
return (BYTE) ecData[address];

src/helper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ Q_OBJECT
3232
bool isEcSysModuleLoaded();
3333
bool loadEcSysModule();
3434
bool updateData();
35+
void updateDataAsync();
3536
int getValue(int address) const;
3637
QByteArray getValues(int startAddress, int size) const;
3738
void putValue(int address, int value);
3839
void quit();
3940
QDBusInterface *iface;
4041
private:
4142
void printError(QDBusError const & error) const;
43+
private slots:
44+
void callFinishedSlot(QDBusPendingCallWatcher *call);
4245
};
4346

4447
#endif // HELPER_H

src/mainwindow.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Operate operate;
2727

2828
bool isActive = false;
29+
bool isUpdateDataError = false;
2930

3031
QTimer *realtimeUpdateTimer = new QTimer;
3132

@@ -152,7 +153,8 @@ MainWindow::MainWindow(QWidget *parent)
152153
if (!operate.isEcSysModuleLoaded() && !operate.loadEcSysModule())
153154
QMessageBox::critical(nullptr, this->windowTitle(), tr("Failed to load the ec_sys kernel module"));
154155

155-
updateData();
156+
if(operate.updateEcData())
157+
updateData();
156158

157159
connect(realtimeUpdateTimer, &QTimer::timeout, this, &MainWindow::realtimeUpdate);
158160
setUpdateInterval(1000);
@@ -162,6 +164,10 @@ MainWindow::~MainWindow() {
162164
delete ui;
163165
}
164166

167+
void MainWindow::setUpdateDataError(bool error) {
168+
isUpdateDataError = error;
169+
}
170+
165171
void MainWindow::setTabsEnabled(bool enabled) {
166172
ui->infoTab->setEnabled(enabled);
167173
ui->modeTab->setEnabled(enabled);
@@ -189,11 +195,12 @@ void MainWindow::setUpdateInterval(int msec) const {
189195
}
190196

191197
void MainWindow::realtimeUpdate() {
198+
operate.updateEcDataAsync();
192199
updateData();
193200
}
194201

195202
void MainWindow::updateData() {
196-
if (operate.updateEcData()) {
203+
if (!isUpdateDataError && !operate.getEcVersion().empty()) {
197204
if (!isActive) {
198205
operate.doProbe();
199206
setTabsEnabled(true);

src/mainwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QCloseEvent>
2424
#include <QSystemTrayIcon>
2525
#include <QtWidgets>
26+
#include <QDBusPendingCallWatcher>
2627

2728
QT_BEGIN_NAMESPACE
2829
namespace Ui { class MainWindow; }
@@ -34,6 +35,8 @@ Q_OBJECT
3435
public:
3536
explicit MainWindow(QWidget *parent = nullptr);
3637
~MainWindow();
38+
void updateData();
39+
static void setUpdateDataError(bool error);
3740

3841
private:
3942
Ui::MainWindow *ui;
@@ -43,7 +46,6 @@ Q_OBJECT
4346
void stopRealtimeUpdate() const;
4447
void setUpdateInterval(int msec) const;
4548
void realtimeUpdate();
46-
void updateData();
4749
void loadConfigs();
4850

4951
[[nodiscard]] QString intToQString(int value) const;

src/operate.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ bool Operate::updateEcData() const {
105105
return helper.updateData();
106106
}
107107

108+
void Operate::updateEcDataAsync() const {
109+
helper.updateDataAsync();
110+
}
111+
108112
bool Operate::doProbe() const {
109113
fan1Address = detectFan1Address();
110114
batteryThresholdAddress = detectBatteryThresholdAddress();

src/operate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Operate {
5555
[[nodiscard]] bool isEcSysModuleLoaded() const;
5656
[[nodiscard]] bool loadEcSysModule() const;
5757
[[nodiscard]] bool updateEcData() const;
58+
void updateEcDataAsync() const;
5859
[[nodiscard]] bool doProbe() const;
5960
[[nodiscard]] std::string getEcVersion() const;
6061
[[nodiscard]] std::string getEcBuild() const;

0 commit comments

Comments
 (0)