Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions panels/notification/osd/displaymode/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Repeat presses use stale choices

When the initial output fetch fails and recovers, or outputs or the current mode change after sync while the OSD remains visible, Applet.next() advances the cached plan without calling Applet.sync(), so an empty plan stays empty and changed outputs or modes leave stale choices; the checkmark stays unchanged or points to the wrong choice, and the delayed action targets an unavailable or unintended mode.

Call Applet.sync() before Applet.next() on repeat presses.

Also at panels/notification/osd/displaymode/package/main.qml:24, panels/notification/osd/displaymode/package/main.qml:26, panels/notification/osd/osdpanel.cpp:80.

Prompt for AI agents
In `panels/notification/osd/displaymode/package/main.qml` at line 25:

**Repeat presses use stale choices**

When the initial output fetch fails and recovers, or outputs or the current mode change after sync while the OSD remains visible, `Applet.next()` advances the cached plan without calling `Applet.sync()`, so an empty plan stays empty and changed outputs or modes leave stale choices; the checkmark stays unchanged or points to the wrong choice, and the delayed action targets an unavailable or unintended mode.

Call `Applet.sync()` before `Applet.next()` on repeat presses.

Also at `panels/notification/osd/displaymode/package/main.qml:24`, `panels/notification/osd/displaymode/package/main.qml:26`, `panels/notification/osd/osdpanel.cpp:80`.

return true
}
return false

Applet.sync()
if (osdType === "DirectSwitchLayout" && Applet.state !== 2)
Applet.doAction()

return true
}
function match(osdType)
{
Expand Down
27 changes: 21 additions & 6 deletions panels/notification/osd/osdpanel.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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();
}

Expand All @@ -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;
});
}

Expand All @@ -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()
Expand All @@ -97,6 +111,7 @@ void OsdPanel::hideOsd()

void OsdPanel::showOsd()
{
m_hideTimer->stop();
m_osdTimer->stop();

m_osdTimer->start();
Expand Down
4 changes: 3 additions & 1 deletion panels/notification/osd/osdpanel.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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};
Expand Down
Loading