feat(include): add system volume following support

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.
This commit is contained in:
sankalp committed 2026-02-22 02:08:46 +05:45
1 parent c44ae01226
commit f70e13dd70
9 files changed
+57 -6

No files matched your search

+1
View File
@@ -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);
+2 -1
View File
@@ -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
+3 -2
View File
@@ -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
-1
View File
@@ -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
+2
View File
@@ -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
+13
View File
@@ -0,0 +1,13 @@
#ifndef VBX_IPC_H
#define VBX_IPC_H
#include <stdint.h>
// 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
+29
View File
@@ -0,0 +1,29 @@
#ifndef VBX_LOG_H
#define VBX_LOG_H
#include <stdio.h>
#include <time.h>
// 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
+3
View File
@@ -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);
+4 -2
View File
@@ -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