Skip to content

Commit

Permalink
Activation support for KDE (KF6) notifications (#2586)
Browse files Browse the repository at this point in the history
Use xdg-activation tokens when available. This should work with KF6 and
`xcb` and `wayland` platform backends on Plasma 6.
  • Loading branch information
alebastr authored Dec 26, 2023
1 parent 1d9c0b5 commit 2c59266
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/kvirc/kernel/KviApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
#ifdef COMPILE_KDE_SUPPORT
#include <QStandardPaths>
#include <KNotification>
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <KStartupInfo>
#include <KWindowSystem>
#endif
#endif

#ifdef COMPILE_QX11INFO_SUPPORT
Expand Down Expand Up @@ -811,18 +815,38 @@ void KviApplication::notifierMessage(KviWindow * pWnd, int iIconId, const QStrin
#else
KNotificationAction *action = nullptr;

auto activate = [this, pNotify] () {
if (!g_pMainWindow)
return;

QString szToken = pNotify->xdgActivationToken();
if(szToken.isEmpty())
return showParentFrame();

QWindow * pWindow = g_pMainWindow->windowHandle();
if(KWindowSystem::isPlatformX11())
{
KStartupInfo::setNewStartupId(pWindow, szToken.toUtf8());
}
else if(KWindowSystem::isPlatformWayland())
{
KWindowSystem::setCurrentXdgActivationToken(szToken);
}
KWindowSystem::activateWindow(pWindow);
};

action = pNotify->addDefaultAction(__tr2qs("View"));
connect(action, SIGNAL(activated()), this, SLOT(showParentFrame()));
connect(action, &KNotificationAction::activated, this, activate);

action = pNotify->addAction(__tr2qs("View"));
connect(action, SIGNAL(activated()), this, SLOT(showParentFrame()));
connect(action, &KNotificationAction::activated, this, activate);

action = pNotify->addAction(__tr2qs("Ignore"));
connect(action, SIGNAL(activated()), pNotify, SLOT(close()));

pNotify->setFlags(KNotification::CloseWhenWindowActivated|KNotification::Persistent);
pNotify->setWindow(g_pMainWindow->windowHandle());
#endif
#endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

connect(pNotify, SIGNAL(ignored()), pNotify, SLOT(close()));

Expand Down

0 comments on commit 2c59266

Please sign in to comment.