diff --git a/panels/notification/osd/displaymode/package/main.qml b/panels/notification/osd/displaymode/package/main.qml index df1d933f9..1f1e6a20a 100644 --- a/panels/notification/osd/displaymode/package/main.qml +++ b/panels/notification/osd/displaymode/package/main.qml @@ -18,22 +18,19 @@ AppletItem { function update(osdType) { - Applet.sync() - if (match(osdType)) { - - if (osdType === "DirectSwitchLayout") { - if (Applet.state !== 2) { - Applet.doAction() - } - } else if (osdType === "SwitchMonitors") { - if (Panel.lastOsdType() === osdType) { - Applet.next() - } - } + if (!match(osdType)) + return false + if (osdType === "SwitchMonitors" && Panel.lastOsdType() === osdType) { + Applet.next() return true } - return false + + Applet.sync() + if (osdType === "DirectSwitchLayout" && Applet.state !== 2) + Applet.doAction() + + return true } function match(osdType) { diff --git a/panels/notification/osd/osdpanel.cpp b/panels/notification/osd/osdpanel.cpp index 6d47be03d..8dc5d8a58 100644 --- a/panels/notification/osd/osdpanel.cpp +++ b/panels/notification/osd/osdpanel.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -48,6 +48,9 @@ bool OsdPanel::init() m_osdTimer->setInterval(m_interval); m_osdTimer->setSingleShot(true); QObject::connect(m_osdTimer, &QTimer::timeout, this, &OsdPanel::doneSetting); + m_hideTimer = new QTimer(this); + m_hideTimer->setSingleShot(true); + connect(m_hideTimer, &QTimer::timeout, this, &OsdPanel::hideOsd); return DPanel::init(); } @@ -65,12 +68,25 @@ bool OsdPanel::visible() const void OsdPanel::ShowOSD(const QString &text) { + m_hideTimer->stop(); qCInfo(osdLog()) << "show text" << text; m_osdTimer->setInterval(text == "SwitchWM3D" ? 2000 : 1000); - - QTimer::singleShot(100, this, [this, text]() { + const auto dispatch = [this, text] { setOsdType(text); showOsd(); + }; + + // Keep repeat presses behind any OSD requests already scheduled for delivery. + if (m_visible && m_pendingDispatches == 0 && text == QLatin1String("SwitchMonitors") + && m_lastOsdType == text) { + dispatch(); + return; + } + + ++m_pendingDispatches; + QTimer::singleShot(100, this, [this, dispatch] { + dispatch(); + --m_pendingDispatches; }); } @@ -83,9 +99,7 @@ void OsdPanel::doneSetting() int delay = m_osdTimer->interval() - m_osdTimer->remainingTime(); if (delay < 0) delay = 0; - QTimer::singleShot(delay,this, [this](){ - hideOsd(); - }); + m_hideTimer->start(delay); } void OsdPanel::hideOsd() @@ -97,6 +111,7 @@ void OsdPanel::hideOsd() void OsdPanel::showOsd() { + m_hideTimer->stop(); m_osdTimer->stop(); m_osdTimer->start(); diff --git a/panels/notification/osd/osdpanel.h b/panels/notification/osd/osdpanel.h index d01334189..cccffc734 100644 --- a/panels/notification/osd/osdpanel.h +++ b/panels/notification/osd/osdpanel.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -46,6 +46,8 @@ private Q_SLOTS: private: bool m_visible = false; QTimer *m_osdTimer = nullptr; + QTimer *m_hideTimer = nullptr; + int m_pendingDispatches = 0; QString m_osdType; QString m_lastOsdType; int m_interval {2000};