Skip to content

Commit 41c8a9d

Browse files
committed
fix: prevent duplicate OSD actions for same type
1. Added lastOsdType tracking in OsdPanel to store previous OSD type 2. Modified displaymode, kblayout, and windoweffect OSD handlers to only trigger actions when current type matches last type 3. This prevents duplicate actions when receiving multiple OSD notifications of same type in quick succession 4. Added Q_PROPERTY for lastOsdType to make it accessible from QML 5. Updated hideOsd and showOsd methods to properly manage lastOsdType state fix: 防止相同类型OSD的重复操作 1. 在OsdPanel中添加lastOsdType跟踪以存储先前的OSD类型 2. 修改了displaymode、kblayout和windoweffect的OSD处理程序,仅在当前类型 与上次类型匹配时才触发操作 3. 防止在快速连续收到相同类型的多个OSD通知时出现重复操作 4. 添加了lastOsdType的Q_PROPERTY使其可从QML访问 5. 更新了hideOsd和showOsd方法以正确管理lastOsdType状态 pms: BUG-304139
1 parent c8de151 commit 41c8a9d

5 files changed

Lines changed: 30 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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class OsdPanel : public DS_NAMESPACE::DPanel
1414
Q_OBJECT
1515
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged FINAL)
1616
Q_PROPERTY(QString osdType READ osdType NOTIFY osdTypeChanged FINAL)
17+
Q_PROPERTY(QString lastOsdType READ lastOsdType)
1718
Q_CLASSINFO("D-Bus Interface", "org.deepin.dde.shell.osd")
1819
public:
1920
explicit OsdPanel(QObject *parent = nullptr);
@@ -24,6 +25,8 @@ class OsdPanel : public DS_NAMESPACE::DPanel
2425
bool visible() const;
2526
QString osdType() const;
2627

28+
QString lastOsdType() const;
29+
2730
public Q_SLOTS:
2831
void ShowOSD(const QString &text);
2932

@@ -37,11 +40,13 @@ private Q_SLOTS:
3740
void showOsd();
3841
void setVisible(const bool visible);
3942
void setOsdType(const QString &osdType);
43+
void updateLastOsdType(const QString &osdType);
4044

4145
private:
4246
bool m_visible = false;
4347
QTimer *m_osdTimer = nullptr;
4448
QString m_osdType;
49+
QString m_lastOsdType;
4550
int m_interval {2000};
4651
};
4752

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)