Fix wayland activation
Adds support for xdg_activation_v1 when calling the application from the system tray by using KStatusNotifier which supports it. Listens to XDG_ACTIVATION_TOKEN as it's passed when we are started from dbus.
This commit is contained in:
committed by
Aleix Pol Gonzalez
parent
5c86692fb5
commit
265fcbfead
@@ -158,6 +158,7 @@ Kirigami.ApplicationWindow {
|
|||||||
root.show()
|
root.show()
|
||||||
root.raise()
|
root.raise()
|
||||||
root.requestActivate()
|
root.requestActivate()
|
||||||
|
Controller.raiseWindow(root)
|
||||||
}
|
}
|
||||||
|
|
||||||
contextDrawer: RoomDrawer {
|
contextDrawer: RoomDrawer {
|
||||||
|
|||||||
@@ -48,7 +48,12 @@ ecm_add_app_icon(NEOCHAT_ICON ICONS ${CMAKE_SOURCE_DIR}/128-logo.png)
|
|||||||
target_sources(neochat PRIVATE ${NEOCHAT_ICON})
|
target_sources(neochat PRIVATE ${NEOCHAT_ICON})
|
||||||
|
|
||||||
if(NOT ANDROID)
|
if(NOT ANDROID)
|
||||||
target_sources(neochat PRIVATE trayicon.cpp colorschemer.cpp)
|
target_sources(neochat PRIVATE colorschemer.cpp)
|
||||||
|
if (NOT WIN32 AND NOT APPLE)
|
||||||
|
target_sources(neochat PRIVATE trayicon_sni.cpp)
|
||||||
|
else()
|
||||||
|
target_sources(neochat PRIVATE trayicon.cpp)
|
||||||
|
endif()
|
||||||
target_link_libraries(neochat PRIVATE KF5::ConfigWidgets KF5::WindowSystem KF5::SonnetCore)
|
target_link_libraries(neochat PRIVATE KF5::ConfigWidgets KF5::WindowSystem KF5::SonnetCore)
|
||||||
target_compile_definitions(neochat PRIVATE -DHAVE_COLORSCHEME)
|
target_compile_definitions(neochat PRIVATE -DHAVE_COLORSCHEME)
|
||||||
target_compile_definitions(neochat PRIVATE -DHAVE_WINDOWSYSTEM)
|
target_compile_definitions(neochat PRIVATE -DHAVE_WINDOWSYSTEM)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <KWindowConfig>
|
#include <KWindowConfig>
|
||||||
#ifdef HAVE_WINDOWSYSTEM
|
#ifdef HAVE_WINDOWSYSTEM
|
||||||
#include <KWindowEffects>
|
#include <KWindowEffects>
|
||||||
|
#include <KWindowSystem>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <QAuthenticator>
|
#include <QAuthenticator>
|
||||||
@@ -55,8 +56,10 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <KStandardShortcut>
|
#include <KStandardShortcut>
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||||
#include "trayicon.h"
|
#include "trayicon.h"
|
||||||
|
#elif !defined(Q_OS_ANDROID)
|
||||||
|
#include "trayicon_sni.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
@@ -634,6 +637,13 @@ void Controller::setBlur(QQuickItem *item, bool blur)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::raiseWindow(QWindow *window)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_WINDOWSYSTEM
|
||||||
|
KWindowSystem::activateWindow(window->winId());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool Controller::hasWindowSystem() const
|
bool Controller::hasWindowSystem() const
|
||||||
{
|
{
|
||||||
#ifdef HAVE_WINDOWSYSTEM
|
#ifdef HAVE_WINDOWSYSTEM
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ public:
|
|||||||
Q_INVOKABLE void openOrCreateDirectChat(NeoChatUser *user);
|
Q_INVOKABLE void openOrCreateDirectChat(NeoChatUser *user);
|
||||||
|
|
||||||
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
|
Q_INVOKABLE void setBlur(QQuickItem *item, bool blur);
|
||||||
|
Q_INVOKABLE void raiseWindow(QWindow *window);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Controller(QObject *parent = nullptr);
|
explicit Controller(QObject *parent = nullptr);
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -22,6 +22,7 @@
|
|||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#ifdef HAVE_KDBUSADDONS
|
#ifdef HAVE_KDBUSADDONS
|
||||||
#include <KDBusService>
|
#include <KDBusService>
|
||||||
|
#include <KWindowSystem>
|
||||||
#endif
|
#endif
|
||||||
#include <KLocalizedContext>
|
#include <KLocalizedContext>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
@@ -66,6 +67,18 @@
|
|||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
|
#ifdef HAVE_KDBUSADDONS
|
||||||
|
static void raiseWindow(QWindow *window)
|
||||||
|
{
|
||||||
|
if (KWindowSystem::isPlatformWayland()) {
|
||||||
|
KWindowSystem::setCurrentXdgActivationToken(qEnvironmentVariable("XDG_ACTIVATION_TOKEN"));
|
||||||
|
KWindowSystem::activateWindow(window->winId());
|
||||||
|
} else {
|
||||||
|
window->raise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
Q_DECL_EXPORT
|
Q_DECL_EXPORT
|
||||||
#endif
|
#endif
|
||||||
@@ -232,7 +245,7 @@ int main(int argc, char *argv[])
|
|||||||
auto view = qobject_cast<QQuickWindow *>(obj);
|
auto view = qobject_cast<QQuickWindow *>(obj);
|
||||||
if (view) {
|
if (view) {
|
||||||
view->show();
|
view->show();
|
||||||
view->raise();
|
raiseWindow(view);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
src/trayicon_sni.cpp
Normal file
25
src/trayicon_sni.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
#include "trayicon_sni.h"
|
||||||
|
#include <KWindowSystem>
|
||||||
|
|
||||||
|
TrayIcon::TrayIcon(QObject *parent)
|
||||||
|
: KStatusNotifierItem(parent)
|
||||||
|
{
|
||||||
|
setIconByName("org.kde.neochat");
|
||||||
|
connect(this, &KStatusNotifierItem::activateRequested, this, [this] {
|
||||||
|
KWindowSystem::setCurrentXdgActivationToken(providedToken());
|
||||||
|
Q_EMIT showWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::show()
|
||||||
|
{
|
||||||
|
setStatus(Active);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrayIcon::hide()
|
||||||
|
{
|
||||||
|
setStatus(Passive);
|
||||||
|
}
|
||||||
19
src/trayicon_sni.h
Normal file
19
src/trayicon_sni.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <KStatusNotifierItem>
|
||||||
|
|
||||||
|
class TrayIcon : public KStatusNotifierItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TrayIcon(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
void show();
|
||||||
|
void hide();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void showWindow();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user