Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: Enable native notifications with Qt 6 #2600

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
24 changes: 23 additions & 1 deletion docs/build-source-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ On **Ubuntu** you can install all build dependencies with:

Fedora / RHEL / Centos
^^^^^^^^^^^^^^^^^^^^^^
On **Fedora** and derivatives you can install all build dependencies with:
On **Fedora** and derivatives you can install all build dependencies with Qt 5:

::

Expand All @@ -76,6 +76,28 @@ On **Fedora** and derivatives you can install all build dependencies with:
qt5-qtx11extras-devel \
wayland-devel

To build with Qt 6:

::

sudo yum install \
cmake \
extra-cmake-modules \
gcc-c++ \
git \
kf6-knotifications-devel \
kf6-kstatusnotifieritem-devel \
libSM-devel \
libXfixes-devel \
libXtst-devel \
qt6-qtbase-devel \
qt6-qtbase-private-devel \
qt6-qtdeclarative-devel \
qt6-qtsvg-devel \
qt6-qttools-devel \
qt6-qtwayland-devel \
wayland-devel

Build and Install
-----------------

Expand Down
1 change: 0 additions & 1 deletion src/copyq.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<file alias="images/tab_remove">images/tab_remove.svg</file>
<file alias="images/logo.png">images/icon_512x512.png</file>
<file>images/fontawesome.ttf</file>
<file>knotifications5/copyq.notifyrc</file>
</qresource>
</RCC>
29 changes: 21 additions & 8 deletions src/gui/notificationnative/notificationnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,33 @@ void NotificationNative::show()

if (m_notification) {
update();
#if KNOTIFICATIONS_VERSION < QT_VERSION_CHECK(5,110,0)
if (m_notification)
m_notification->update();
#endif
notificationLog("Updated");
return;
}

m_notification = new KNotification("generic");
m_notification = new KNotification(QStringLiteral("generic"));
notificationLog("Create");
m_notification->setComponentName(componentName);

#if KNOTIFICATIONS_VERSION < QT_VERSION_CHECK(5,245,0)
connect( m_notification.data(), static_cast<void (KNotification::*)(unsigned int)>(&KNotification::activated),
this, &NotificationNative::onButtonClicked );
connect( m_notification.data(), &KNotification::closed,
this, &NotificationNative::onClosed );
connect( m_notification.data(), &KNotification::ignored,
this, &NotificationNative::onIgnored );
#if KNOTIFICATIONS_VERSION < QT_VERSION_CHECK(5,67,0)
# if KNOTIFICATIONS_VERSION < QT_VERSION_CHECK(5,67,0)
connect( m_notification.data(), static_cast<void (KNotification::*)()>(&KNotification::activated),
this, &NotificationNative::onActivated );
#else
# else
connect( m_notification.data(), &KNotification::defaultActivated,
this, &NotificationNative::onActivated );
# endif
#endif
connect( m_notification.data(), &KNotification::closed,
this, &NotificationNative::onClosed );
connect( m_notification.data(), &KNotification::ignored,
this, &NotificationNative::onIgnored );
connect( m_notification.data(), &QObject::destroyed,
this, &NotificationNative::onDestroyed );

Expand All @@ -220,7 +224,7 @@ void NotificationNative::close()

void NotificationNative::onButtonClicked(unsigned int id)
{
notificationLog("onButtonClicked");
notificationLog(QByteArray("onButtonClicked ") + QByteArray::number(id));

if ( id - 1 < static_cast<unsigned int>(m_buttons.size()) ) {
emit buttonClicked(m_buttons[id - 1]);
Expand Down Expand Up @@ -288,10 +292,19 @@ void NotificationNative::update()
m_notification->setPixmap(defaultIcon());
}

#if KNOTIFICATIONS_VERSION >= QT_VERSION_CHECK(5,245,0)
m_notification->clearActions();
for (int i = 0; i < m_buttons.size(); ++i) {
KNotificationAction* act = m_notification->addAction(m_buttons[i].name);
connect( act, &KNotificationAction::activated,
this, [=](){ onButtonClicked(i + 1); } );
}
#else
QStringList actions;
for (const auto &button : m_buttons)
actions.append(button.name);
m_notification->setActions(actions);
#endif

if (m_intervalMsec < 0) {
m_timer.stop();
Expand Down
23 changes: 17 additions & 6 deletions src/notifications.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
OPTION(WITH_NATIVE_NOTIFICATIONS "Build with native notification support" ON)

if (WITH_NATIVE_NOTIFICATIONS AND WITH_QT6)
message(WARNING "Native notifications are not supported with Qt 6")
elseif (WITH_NATIVE_NOTIFICATIONS)
if (WITH_NATIVE_NOTIFICATIONS)
set(KF5_MIN_VERSION "5.18.0")

find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})

find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Notifications)

list(APPEND copyq_LIBRARIES KF5::Notifications)
if (WITH_QT6)
set(KF6_MIN_VERSION "5.248.0")
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS Notifications StatusNotifierItem)
list(APPEND copyq_LIBRARIES KF6::Notifications KF6::StatusNotifierItem)
else()
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Notifications)
list(APPEND copyq_LIBRARIES KF5::Notifications)
endif()

list(APPEND copyq_SOURCES
gui/notificationnative/notificationnative.cpp
gui/notificationnative/notificationdaemonnative.cpp)

list(APPEND copyq_DEFINITIONS WITH_NATIVE_NOTIFICATIONS)

include(KDEInstallDirs)
if (KDE_INSTALL_KNOTIFYRCDIR)
install(FILES knotifications5/copyq.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR})
else()
install(FILES knotifications5/copyq.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFY5RCDIR})
endif()

endif()