Skip to content

Commit b8b76aa

Browse files
committed
fix: prevent duplicate OSD actions for same type
1. Added lastOsdType tracking in OsdPanel to store the most recent OSD type 2. Modified displaymode, kblayout and windoweffect OSD handlers to only perform actions if the current OSD type matches the last one 3. This prevents duplicate actions when multiple OSD events of same type are triggered in quick succession 4. Added updateLastOsdType method to track and clear the last OSD type when hiding fix: 防止相同类型OSD的重复操作 1. 在OsdPanel中添加lastOsdType跟踪最近显示的OSD类型 2. 修改了displaymode、kblayout和windoweffect的OSD处理逻辑,仅在当前OSD类 型与最后一次相同时才执行操作 3. 防止在快速连续触发相同类型OSD事件时重复执行操作 4. 添加updateLastOsdType方法来跟踪并在隐藏时清除最后OSD类型
1 parent c8de151 commit b8b76aa

5 files changed

Lines changed: 29 additions & 5 deletions

File tree

panels/notification/osd/displaymode/package/main.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ AppletItem {
2626
Applet.doAction()
2727
}
2828
} else if (osdType === "SwitchMonitors") {
29-
Applet.next()
29+
if (Panel.lastOsdType() === osdType) {
30+
Applet.next()
31+
}
3032
}
3133

3234
return true

panels/notification/osd/kblayout/package/main.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ AppletItem {
2020
{
2121
if (match(osdType)) {
2222
Applet.sync()
23-
Applet.next()
23+
if (Panel.lastOsdType() === osdType) {
24+
Applet.next()
25+
}
2426
return true
2527
}
2628
return false

panels/notification/osd/osdpanel.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ void OsdPanel::hideOsd()
7878
{
7979
m_osdTimer->stop();
8080
setVisible(false);
81+
updateLastOsdType({});
8182
}
8283

8384
void OsdPanel::showOsd()
@@ -86,6 +87,7 @@ void OsdPanel::showOsd()
8687

8788
m_osdTimer->start();
8889
setVisible(true);
90+
updateLastOsdType(m_osdType);
8991
}
9092

9193
void OsdPanel::setVisible(const bool visible)
@@ -102,6 +104,18 @@ void OsdPanel::setOsdType(const QString &osdType)
102104
emit osdTypeChanged(m_osdType);
103105
}
104106

107+
void OsdPanel::updateLastOsdType(const QString &osdType)
108+
{
109+
if (m_lastOsdType != osdType) {
110+
m_lastOsdType = osdType;
111+
}
112+
}
113+
114+
QString OsdPanel::lastOsdType() const
115+
{
116+
return m_lastOsdType;
117+
}
118+
105119
D_APPLET_CLASS(OsdPanel)
106120

107121
}

panels/notification/osd/osdpanel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class OsdPanel : public DS_NAMESPACE::DPanel
2424
bool visible() const;
2525
QString osdType() const;
2626

27+
Q_INVOKABLE QString lastOsdType() const;
28+
2729
public Q_SLOTS:
2830
void ShowOSD(const QString &text);
2931

@@ -37,11 +39,13 @@ private Q_SLOTS:
3739
void showOsd();
3840
void setVisible(const bool visible);
3941
void setOsdType(const QString &osdType);
42+
void updateLastOsdType(const QString &osdType);
4043

4144
private:
4245
bool m_visible = false;
4346
QTimer *m_osdTimer = nullptr;
4447
QString m_osdType;
48+
QString m_lastOsdType;
4549
int m_interval {2000};
4650
};
4751

panels/notification/osd/windoweffect/package/main.qml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ AppletItem {
4949
function update(osdType)
5050
{
5151
if (match(osdType)) {
52-
Qt.callLater(function() {
53-
control.selectIndex = (control.selectIndex + 1) % effectModel.count
54-
})
52+
if (Panel.lastOsdType() === osdType) {
53+
Qt.callLater(function() {
54+
control.selectIndex = (control.selectIndex + 1) % effectModel.count
55+
})
56+
}
5557
return true
5658
}
5759
return false

0 commit comments

Comments
 (0)