From eeabf0d57893f1c2bc9d071642d727174b75e1c1 Mon Sep 17 00:00:00 2001 From: Jahn Date: Sun, 15 Oct 2023 16:00:50 +0200 Subject: [PATCH] feat: add command line vibrate command --- CMakeLists.txt | 53 ++++++++++++++++++------------------ src/device-command-helper.cc | 52 +++++++++++++++++++++++++++++++++++ src/device-command-helper.h | 24 ++++++++++++++++ src/projecteurapp.cc | 7 +++++ src/projecteurapp.h | 7 +++-- 5 files changed, 115 insertions(+), 28 deletions(-) create mode 100644 src/device-command-helper.cc create mode 100644 src/device-command-helper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f6350b30..2eb00177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,32 +108,33 @@ else() endif() add_executable(projecteur - src/main.cc src/enum-helper.h - src/aboutdlg.cc src/aboutdlg.h - src/actiondelegate.cc src/actiondelegate.h - src/colorselector.cc src/colorselector.h - src/device.cc src/device.h - src/device-hidpp.cc src/device-hidpp.h - src/device-key-lookup.cc src/device-key-lookup.h - src/device-vibration.cc src/device-vibration.h - src/deviceinput.cc src/deviceinput.h - src/devicescan.cc src/devicescan.h - src/deviceswidget.cc src/deviceswidget.h - src/hidpp.cc src/hidpp.h - src/linuxdesktop.cc src/linuxdesktop.h - src/iconwidgets.cc src/iconwidgets.h - src/imageitem.cc src/imageitem.h - src/inputmapconfig.cc src/inputmapconfig.h - src/inputseqedit.cc src/inputseqedit.h - src/logging.cc src/logging.h - src/nativekeyseqedit.cc src/nativekeyseqedit.h - src/preferencesdlg.cc src/preferencesdlg.h - src/projecteurapp.cc src/projecteurapp.h - src/runguard.cc src/runguard.h - src/settings.cc src/settings.h - src/spotlight.cc src/spotlight.h - src/spotshapes.cc src/spotshapes.h - src/virtualdevice.h src/virtualdevice.cc + src/main.cc src/enum-helper.h + src/aboutdlg.cc src/aboutdlg.h + src/actiondelegate.cc src/actiondelegate.h + src/colorselector.cc src/colorselector.h + src/device.cc src/device.h + src/device-command-helper.cc src/device-command-helper.h + src/device-hidpp.cc src/device-hidpp.h + src/device-key-lookup.cc src/device-key-lookup.h + src/device-vibration.cc src/device-vibration.h + src/deviceinput.cc src/deviceinput.h + src/devicescan.cc src/devicescan.h + src/deviceswidget.cc src/deviceswidget.h + src/hidpp.cc src/hidpp.h + src/linuxdesktop.cc src/linuxdesktop.h + src/iconwidgets.cc src/iconwidgets.h + src/imageitem.cc src/imageitem.h + src/inputmapconfig.cc src/inputmapconfig.h + src/inputseqedit.cc src/inputseqedit.h + src/logging.cc src/logging.h + src/nativekeyseqedit.cc src/nativekeyseqedit.h + src/preferencesdlg.cc src/preferencesdlg.h + src/projecteurapp.cc src/projecteurapp.h + src/runguard.cc src/runguard.h + src/settings.cc src/settings.h + src/spotlight.cc src/spotlight.h + src/spotshapes.cc src/spotshapes.h + src/virtualdevice.cc src/virtualdevice.h ${RESOURCES}) target_include_directories(projecteur PRIVATE src) diff --git a/src/device-command-helper.cc b/src/device-command-helper.cc new file mode 100644 index 00000000..85ad73df --- /dev/null +++ b/src/device-command-helper.cc @@ -0,0 +1,52 @@ +// This file is part of Projecteur - https://github.com/jahnf/projecteur +// - See LICENSE.md and README.md + +#include "device-command-helper.h" + +#include "device-hidpp.h" +#include "spotlight.h" + +// ------------------------------------------------------------------------------------------------- +DeviceCommandHelper::DeviceCommandHelper(QObject* parent, Spotlight* spotlight) + : QObject(parent), m_spotlight(spotlight) +{ + +} + +// ------------------------------------------------------------------------------------------------- +DeviceCommandHelper::~DeviceCommandHelper() = default; + + +// ------------------------------------------------------------------------------------------------- +bool DeviceCommandHelper::sendVibrateCommand(uint8_t intensity, uint8_t length) +{ + if (m_spotlight.isNull()) { + return false; + } + + for ( auto const& dev : m_spotlight->connectedDevices()) { + if (auto connection = m_spotlight->deviceConnection(dev.id)) { + if (!connection->hasHidppSupport()) { + continue; + } + + for (auto const& subInfo : connection->subDevices()) { + auto const& subConn = subInfo.second; + if (!subConn || !subConn->hasFlags(DeviceFlag::Vibrate)) { + continue; + } + + if (auto hidppConn = std::dynamic_pointer_cast(subConn)) + { + hidppConn->sendVibrateCommand(intensity, length, + [](HidppConnectionInterface::MsgResult, HIDPP::Message&&) { + // logDebug(hid) << tr("Vibrate command returned: %1 (%2)") + // .arg(toString(result)).arg(msg.hex()); + }); + } + } + } + } + + return true; +} diff --git a/src/device-command-helper.h b/src/device-command-helper.h new file mode 100644 index 00000000..00fb34ed --- /dev/null +++ b/src/device-command-helper.h @@ -0,0 +1,24 @@ +// This file is part of Projecteur - https://github.com/jahnf/projecteur +// - See LICENSE.md and README.md +#pragma once + +#include +#include + +class Spotlight; + +/// Class that offers easy access to device commands with a given Spotlight +/// instance. +class DeviceCommandHelper : public QObject +{ + Q_OBJECT + +public: + explicit DeviceCommandHelper(QObject* parent, Spotlight* spotlight); + virtual ~DeviceCommandHelper(); + + bool sendVibrateCommand(uint8_t intensity, uint8_t length); + +private: + QPointer m_spotlight; +}; diff --git a/src/projecteurapp.cc b/src/projecteurapp.cc index cc73981d..3bef3296 100644 --- a/src/projecteurapp.cc +++ b/src/projecteurapp.cc @@ -4,6 +4,7 @@ #include "projecteurapp.h" #include "aboutdlg.h" +#include "device-command-helper.h" #include "imageitem.h" #include "linuxdesktop.h" #include "logging.h" @@ -68,6 +69,8 @@ ProjecteurApplication::ProjecteurApplication(int &argc, char **argv, const Optio m_spotlight = new Spotlight(this, Spotlight::Options{options.enableUInput, options.additionalDevices}, m_settings); + m_deviceCommandHelper = new DeviceCommandHelper(this, m_spotlight); + m_settings->setOverlayDisabled(options.disableOverlay); m_dialog = std::make_unique(m_settings, m_spotlight, options.dialogMinimizeOnly @@ -586,6 +589,10 @@ void ProjecteurApplication::readCommand(QLocalSocket* clientConnection) logDebug(cmdserver) << tr("Received quit command."); this->quit(); } + else if (cmdKey == "vibrate") + { + m_deviceCommandHelper->sendVibrateCommand(128, 0); + } else if (cmdKey == "spot.size.adjust") { bool ok = false; diff --git a/src/projecteurapp.h b/src/projecteurapp.h index 6a394c83..e3ab04ae 100644 --- a/src/projecteurapp.h +++ b/src/projecteurapp.h @@ -2,7 +2,7 @@ // - See LICENSE.md and README.md #pragma once -#include "spotlight.h" +#include "devicescan.h" #include #include @@ -11,6 +11,7 @@ #include class AboutDialog; +class DeviceCommandHelper; class LinuxDesktop; class PreferencesDialog; class QLocalServer; @@ -20,6 +21,7 @@ class QQmlApplicationEngine; class QQmlComponent; class QSystemTrayIcon; class Settings; +class Spotlight; class ProjecteurApplication : public QApplication { @@ -78,8 +80,9 @@ private slots: std::unique_ptr m_dialog; QPointer m_aboutDialog; QLocalServer* const m_localServer = nullptr; - Spotlight* m_spotlight = nullptr; Settings* m_settings = nullptr; + Spotlight* m_spotlight = nullptr; + DeviceCommandHelper* m_deviceCommandHelper = nullptr; LinuxDesktop* m_linuxDesktop = nullptr; QQmlApplicationEngine* m_qmlEngine = nullptr; QQmlComponent* m_windowQmlComponent = nullptr;