From f70e13dd70dd7a29851ea9e80951be56dfbe7b04 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sun, 22 Feb 2026 02:08:46 +0545 Subject: [PATCH] feat(include): add system volume following support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement configurable system volume following and replace JSON IPC with binary struct. - New Feature: Introduce `system_volume_following` CLI and runtime option. - Enhancement: Extend CLI options, reload, and user‑config APIs to propagate the new flag. - Enhancement: Add `VbxEvent` binary IPC struct and logging macros for better performance. - Enhancement: Add helper to persist system volume following state. - Bug Fix: Remove stale `parse_keyboard_event` prototype. --- include/app/cli.h | 1 + include/app/process.h | 3 ++- include/app/reload.h | 5 +++-- include/audio/playback.h | 1 - include/audio/types.h | 2 ++ include/common/ipc.h | 13 +++++++++++++ include/common/log.h | 29 +++++++++++++++++++++++++++++ include/common/utils.h | 3 +++ include/user_config.h | 6 ++++-- 9 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 include/common/ipc.h create mode 100644 include/common/log.h diff --git a/include/app/cli.h b/include/app/cli.h index 69a1e91..a29b58c 100644 --- a/include/app/cli.h +++ b/include/app/cli.h @@ -15,6 +15,7 @@ typedef struct { int mouse_mute; // -1 unchanged, 0 unmute, 1 mute int keyboard_enabled; // -1 unchanged, 0 disabled, 1 enabled int mouse_enabled; // -1 unchanged, 0 disabled, 1 enabled + int system_volume_following; // -1 unchanged, 0 disabled, 1 enabled } CliOptions; void print_usage(const char *program_name); diff --git a/include/app/process.h b/include/app/process.h index 3696b2a..2a83812 100644 --- a/include/app/process.h +++ b/include/app/process.h @@ -17,7 +17,8 @@ void stop_children(void); int start_children(const char *sound_dir, const char *config_path, int volume, int verbose, int mute, const char *mouse_sound_dir, const char *mouse_config_path, int mouse_volume, - int keyboard_mute, int mouse_mute, int keyboard_enabled, int mouse_enabled); + int keyboard_mute, int mouse_mute, int keyboard_enabled, + int mouse_enabled, int system_volume_following); void handle_sighup(int sig); #endif // VBX_PROCESS_H diff --git a/include/app/reload.h b/include/app/reload.h index a213bcd..c291dea 100644 --- a/include/app/reload.h +++ b/include/app/reload.h @@ -7,8 +7,9 @@ int handle_reload(const char *user_cfg_path, char *current_config_path, char *current_sound_dir, char *current_mouse_config_path, char *current_mouse_sound_dir, int current_mute, int current_verbose, - int current_mouse_volume_arg, int current_keyboard_mute, - int current_mouse_mute, int *current_keyboard_enabled, int *current_mouse_enabled); + int current_keyboard_mute, int current_mouse_mute, + int *current_keyboard_enabled, int *current_mouse_enabled, + int *current_system_volume_following); #endif // VBX_RELOAD_H diff --git a/include/audio/playback.h b/include/audio/playback.h index 325a7a2..1223c9b 100644 --- a/include/audio/playback.h +++ b/include/audio/playback.h @@ -2,7 +2,6 @@ #define VBX_AUDIO_PLAYBACK_H int init_audio(void); -int parse_keyboard_event(const char *json_line, int *key_code, int *is_pressed); void play_sound_segment(int key_code, int is_pressed); #endif // VBX_AUDIO_PLAYBACK_H diff --git a/include/audio/types.h b/include/audio/types.h index 11f4861..743a725 100644 --- a/include/audio/types.h +++ b/include/audio/types.h @@ -41,5 +41,7 @@ extern int g_keyboard_mute; extern int g_mouse_mute; extern int g_keyboard_enabled; extern int g_mouse_enabled; +extern int g_system_volume_following; +extern float g_system_volume_multiplier; #endif // VBX_AUDIO_TYPES_H diff --git a/include/common/ipc.h b/include/common/ipc.h new file mode 100644 index 0000000..0c88a02 --- /dev/null +++ b/include/common/ipc.h @@ -0,0 +1,13 @@ +#ifndef VBX_IPC_H +#define VBX_IPC_H + +#include + +// Lightweight binary structure for IPC between vbx-input and vbx-audio +// Replaces the heavy JSON parsing +typedef struct { + uint32_t key_code; + uint8_t is_pressed; +} VbxEvent; + +#endif // VBX_IPC_H diff --git a/include/common/log.h b/include/common/log.h new file mode 100644 index 0000000..e358e8d --- /dev/null +++ b/include/common/log.h @@ -0,0 +1,29 @@ +#ifndef VBX_LOG_H +#define VBX_LOG_H + +#include +#include + +// Assuming g_verbose is defined globally or we pass it +extern int g_verbose; +extern int is_daemon; + +#define LOG_LEVEL_DEBUG 0 +#define LOG_LEVEL_INFO 1 +#define LOG_LEVEL_WARN 2 +#define LOG_LEVEL_ERROR 3 + +#define LOG_MACRO(level, prefix, out_stream, ...) do { \ + if (level == LOG_LEVEL_DEBUG && !g_verbose) break; \ + fprintf(out_stream, "[VBX-%s] ", prefix); \ + fprintf(out_stream, __VA_ARGS__); \ + fprintf(out_stream, "\n"); \ + fflush(out_stream); \ +} while(0) + +#define LOG_DEBUG(...) LOG_MACRO(LOG_LEVEL_DEBUG, "DEBUG", stdout, __VA_ARGS__) +#define LOG_INFO(...) LOG_MACRO(LOG_LEVEL_INFO, "INFO", stdout, __VA_ARGS__) +#define LOG_WARN(...) LOG_MACRO(LOG_LEVEL_WARN, "WARN", stderr, __VA_ARGS__) +#define LOG_ERROR(...) LOG_MACRO(LOG_LEVEL_ERROR, "ERROR", stderr, __VA_ARGS__) + +#endif // VBX_LOG_H diff --git a/include/common/utils.h b/include/common/utils.h index eb808d7..b0fa16a 100644 --- a/include/common/utils.h +++ b/include/common/utils.h @@ -29,6 +29,9 @@ void write_runtime_mouse_mute_file(int mute); int write_runtime_keyboard_enabled_file(int enabled); int write_runtime_mouse_enabled_file(int enabled); +// System volume following helper +int write_runtime_system_volume_following_file(int enabled); + // Helper functions void int_to_str(char *buffer, size_t size, int value); char *xstrdup(const char *s); diff --git a/include/user_config.h b/include/user_config.h index f063805..0362fe3 100644 --- a/include/user_config.h +++ b/include/user_config.h @@ -8,11 +8,13 @@ char *get_user_config_path(char *buffer, size_t buflen); // Write ~/.vbx.json in new format int write_user_config(const char *path, const char *keyboard_sound, const char *mouse_sound, int keyboard_volume, - int mouse_volume, int keyboard_enabled, int mouse_enabled); + int mouse_volume, int keyboard_enabled, int mouse_enabled, + int system_volume_following); // Read ~/.vbx.json supporting new and legacy formats int read_user_config(const char *path, char **out_keyboard_sound, char **out_mouse_sound, int *out_keyboard_volume, - int *out_mouse_volume, int *out_keyboard_enabled, int *out_mouse_enabled); + int *out_mouse_volume, int *out_keyboard_enabled, int *out_mouse_enabled, + int *out_system_volume_following); #endif // VBX_CONFIG_IO_H