Skip to content

Commit aac5725

Browse files
committed
Windows 下, 歌词窗口将会一直保持置顶.
1 parent 476d51c commit aac5725

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/mainwindow.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ MainWindow::MainWindow(QApplication* app, QWidget *parent)
2424
#ifdef LINUX
2525
setAttribute(Qt::WA_TransparentForMouseEvents);
2626
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::WindowTransparentForInput);
27+
#else
28+
connect(this->stayOnTopTimer, &QTimer::timeout, this, &MainWindow::handleRefreshStayOnTopFlag);
2729
#endif
2830

2931
connect(this, &MainWindow::needReloadSetting, this, &MainWindow::reloadSetting);
@@ -94,6 +96,17 @@ void MainWindow::reloadSetting()
9496
setWindowFlag(Qt::WindowTransparentForInput, setting.getBool(KEY_FRAME_LESS));
9597
setAttribute(Qt::WA_TransparentForMouseEvents, setting.getBool(KEY_FRAME_LESS));
9698

99+
# ifndef LINUX
100+
this->stayOnTop = setting.getBool(KEY_FLAGS_STAY_ON_TOP);
101+
if (this->stayOnTop)
102+
{
103+
this->stayOnTopTimer->start(1000);
104+
} else
105+
{
106+
this->stayOnTopTimer->stop();
107+
}
108+
# endif
109+
97110
// 自动tick
98111
int autoTick = QString::fromStdString(setting.get(KEY_LYRIC_AUTO_TICK, "0")).toInt();
99112
quint16 port = setting.has(KEY_RECEIVE_PORT) ? QString::fromStdString(setting.get(KEY_RECEIVE_PORT)).toInt() : PORT;
@@ -187,7 +200,7 @@ void MainWindow::handleCommand(QString command)
187200
}
188201
else if (commands[0] == "LYRIC_CONFIG_STAY_ON_TOP" && commands.size() == 2)
189202
{
190-
setWindowFlag(Qt::WindowStaysOnBottomHint, commands[1] == "1");
203+
setWindowFlag(Qt::WindowStaysOnTopHint, commands[1] == "1");
191204
setVisible(true);
192205
return;
193206
}
@@ -197,6 +210,16 @@ void MainWindow::handleCommand(QString command)
197210
}
198211
}
199212

213+
void MainWindow::handleRefreshStayOnTopFlag()
214+
{
215+
# ifndef LINUX
216+
setWindowFlag(Qt::WindowStaysOnTopHint, !this->stayOnTop);
217+
setWindowFlag(Qt::WindowStaysOnTopHint, this->stayOnTop);
218+
setWindowFlag(Qt::Tool, true);
219+
setVisible(true);
220+
# endif
221+
}
222+
200223
void MainWindow::receiveLyric()
201224
{
202225
QByteArray buffer;

src/mainwindow.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class MainWindow : public QMainWindow
3232
qint64 index;
3333
LyricNetworkController* mprisLyricController = nullptr;
3434

35+
# ifndef LINUX
36+
bool stayOnTop = false;
37+
QTimer* stayOnTopTimer = new QTimer();
38+
# endif
39+
3540
private:
3641
void closeEvent(QCloseEvent* event) override;
3742

@@ -43,5 +48,6 @@ private slots:
4348
void receiveLyric();
4449
void reloadSetting();
4550
void handleCommand(QString command);
51+
void handleRefreshStayOnTopFlag();
4652
};
4753
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)