From af2622b68e660abbf6bfa9c4bd9fd92b58feb1b1 Mon Sep 17 00:00:00 2001 From: Fabian Moor Pucar <107020057+fabianmoor@users.noreply.github.com> Date: Tue, 31 Mar 2026 05:39:37 +0200 Subject: [PATCH] feat(linux): add librepods-ctl CLI tool for IPC control (#494) * feat(linux): expanded IPC socket handler with CLI command support * feat(linux): added librepods-ctl CLI tool for IPC control * build(linux): added librepods-ctl as a seperate binary * docs(linux): added CLI control usage to README --- linux/CMakeLists.txt | 10 ++++++++++ linux/README.md | 29 +++++++++++++++++++++++++++++ linux/librepods-ctl.cpp | 31 +++++++++++++++++++++++++++++++ linux/main.cpp | 12 ++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 linux/librepods-ctl.cpp diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 629abd8..2870a19 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -78,6 +78,16 @@ target_link_libraries(librepods PRIVATE Qt6::Quick Qt6::Widgets Qt6::Bluetooth Qt6::DBus OpenSSL::SSL OpenSSL::Crypto ${PULSEAUDIO_LIBRARIES} ) +qt_add_executable(librepods-ctl + librepods-ctl.cpp +) +target_link_libraries(librepods-ctl + PRIVATE Qt6::Core Qt6::Network +) +install(TARGETS librepods-ctl + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + target_include_directories(librepods PRIVATE ${PULSEAUDIO_INCLUDE_DIRS}) include(GNUInstallDirs) diff --git a/linux/README.md b/linux/README.md index e405b90..b86c22a 100644 --- a/linux/README.md +++ b/linux/README.md @@ -129,6 +129,35 @@ systemctl --user enable --now mpris-proxy - View battery levels - Control playback + +## CLI Control + +`librepods-ctl` is a small command-line tool that lets you access LibrePods from the terminal or via scripts, as long as the main application is running. + +### Usage +```bash +librepods-ctl +``` + +### Commands + +| Command | Description | +|---|---| +| `noise:off` | Disable noise control | +| `noise:anc` | Enable Active Noise Cancellation | +| `noise:transparency` | Enable Transparency mode | +| `noise:adaptive` | Enable Adaptive mode | + +### Example +```bash +# Enable ANC +librepods-ctl noise:anc + +# Enable Transparency mode +librepods-ctl noise:transparency +``` + + ## Hearing Aid To use hearing aid features, you need to have an audiogram. To enable/disable hearing aid, you can use the toggle in the main app. But, to adjust the settings and set the audiogram, you need to use a different script which is located in this folder as `hearing_aid.py`. You can run it with: diff --git a/linux/librepods-ctl.cpp b/linux/librepods-ctl.cpp new file mode 100644 index 0000000..71c32ce --- /dev/null +++ b/linux/librepods-ctl.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + QCoreApplication app(argc, argv); + + if (argc < 2) { + QTextStream(stderr) << "Usage: librepods-ctl \n" + << "Commands:\n" + << " noise:off Disable noise control\n" + << " noise:anc Enable Active Noise Cancellation\n" + << " noise:transparency Enable Transparency mode\n" + << " noise:adaptive Enable Adaptive mode\n"; + return 1; + } + + QLocalSocket socket; + socket.connectToServer("app_server"); + + if (!socket.waitForConnected(500)) { + QTextStream(stderr) << "Could not connect to librepods (is it running?)\n"; + return 1; + } + + socket.write(QByteArray(argv[1])); + socket.flush(); + socket.waitForBytesWritten(200); + socket.disconnectFromServer(); + return 0; +} diff --git a/linux/main.cpp b/linux/main.cpp index 94d341e..7b1826b 100644 --- a/linux/main.cpp +++ b/linux/main.cpp @@ -1089,6 +1089,18 @@ int main(int argc, char *argv[]) { trayApp->loadMainModule(); } } + else if (msg == "noise:off") { + trayApp->setNoiseControlModeInt(0); + } + else if (msg == "noise:anc") { + trayApp->setNoiseControlModeInt(1); + } + else if (msg == "noise:transparency") { + trayApp->setNoiseControlModeInt(2); + } + else if (msg == "noise:adaptive") { + trayApp->setNoiseControlModeInt(3); + } else { LOG_ERROR("Unknown message received: " << msg);