Skip to content

Commit

Permalink
[build] Make Qt5::Feedback optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetersen committed Aug 14, 2020
1 parent f497cc1 commit 2220e3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ set(MALIIT_KEYBOARD_COMMON_SOURCES
src/plugin/units.h)

add_library(maliit-keyboard-common STATIC ${MALIIT_KEYBOARD_COMMON_SOURCES})
target_link_libraries(maliit-keyboard-common Qt5::DBus Maliit::Plugins maliit-keyboard-lib maliit-keyboard-view gsettings-qt Qt5::Multimedia Qt5::Feedback)
target_link_libraries(maliit-keyboard-common Qt5::DBus Maliit::Plugins maliit-keyboard-lib maliit-keyboard-view gsettings-qt Qt5::Multimedia)
if (Qt5Feedback_FOUND)
target_link_libraries(maliit-keyboard-common Qt5::Feedback)
target_compile_definitions(maliit-keyboard-common PUBLIC HAVE_QT5_FEEDBACK)
endif()
target_compile_definitions(maliit-keyboard-common PRIVATE ${maliit-keyboard-definitions})
target_compile_features(maliit-keyboard-common PRIVATE cxx_std_17)

Expand Down
8 changes: 8 additions & 0 deletions src/plugin/feedback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "keyboardsettings.h"

#include <QtMultimedia/QSoundEffect>
#ifdef HAVE_QT5_FEEDBACK
#include <QtFeedback/QFeedbackHapticsEffect>
#endif

#include <memory>

Expand All @@ -29,18 +31,22 @@ Feedback::Feedback(const KeyboardSettings *settings)
: QObject()
, m_settings(settings)
, m_audioEffect(std::make_unique<QSoundEffect>())
#ifdef HAVE_QT5_FEEDBACK
, m_pressEffect(std::make_unique<QFeedbackHapticsEffect>())
#endif
{
connect(settings, &KeyboardSettings::keyPressAudioFeedbackChanged, this, &Feedback::useAudioFeedbackChanged);
connect(settings, &KeyboardSettings::keyPressAudioFeedbackSoundChanged, this, &Feedback::audioFeedbackSoundChanged);
connect(settings, &KeyboardSettings::keyPressHapticFeedbackChanged, this, &Feedback::useHapticFeedbackChanged);
m_audioEffect->setSource(QUrl(audioFeedbackSound()));
#ifdef HAVE_QT5_FEEDBACK
m_pressEffect->setAttackIntensity(0.0);
m_pressEffect->setAttackTime(50);
m_pressEffect->setIntensity(1.0);
m_pressEffect->setDuration(10);
m_pressEffect->setFadeTime(50);
m_pressEffect->setFadeIntensity(0.0);
#endif
}

Feedback::~Feedback() = default;
Expand All @@ -53,8 +59,10 @@ void Feedback::playAudio()

void Feedback::startPressEffect()
{
#ifdef HAVE_QT5_FEEDBACK
if (useHapticFeedback())
m_pressEffect->start();
#endif
}

void Feedback::keyPressed()
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/feedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ Q_OBJECT
private:
const KeyboardSettings *m_settings;
std::unique_ptr<QSoundEffect> m_audioEffect;
#ifdef HAVE_QT5_FEEDBACK
std::unique_ptr<QFeedbackHapticsEffect> m_pressEffect;
#endif
};

}
Expand Down

1 comment on commit 2220e3e

@PureTryOut
Copy link

Choose a reason for hiding this comment

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

Thanks for this one! It seems qt5-qtfeedback isn't developed anymore and doesn't get any more releases, so this is a welcoming change! Hopefully the same functionality can be achieved via some other method in the future.

Please sign in to comment.