Skip to content

Commit

Permalink
Linux: Enable native notifications with Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Jan 21, 2024
1 parent dcbf197 commit 04470e1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
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
18 changes: 12 additions & 6 deletions src/notifications.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
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)
install(FILES knotifications5/copyq.notifyrc DESTINATION ${KDE_INSTALL_KNOTIFYRCDIR})

Check failure on line 25 in src/notifications.cmake

View workflow job for this annotation

GitHub Actions / Linux-GCC

install FILES given no DESTINATION!
endif()

0 comments on commit 04470e1

Please sign in to comment.