diff --git a/wmix/config.c b/wmix/config.c index 9823949..8a0419c 100644 --- a/wmix/config.c +++ b/wmix/config.c @@ -16,12 +16,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* - * config.c: functions related to loading the configuration from file + * config.c: functions related to loading the configuration, both from + * command line options and from file */ #include #include #include +#include #include @@ -29,10 +31,75 @@ #include "include/config.h" +#define HELP_TEXT \ + "WMixer " VERSION " by timecop@japan.co.jp + skunk@mit.edu\n" \ + "usage:\n" \ + " -d connect to remote X display\n" \ + " -e exclude channel, can be used many times\n" \ + " -f parse this config [~/.wmixrc]\n" \ + " -h print this help\n" \ + " -m mixer device [/dev/mixer]\n" \ + " -v verbose -> id, long name, name\n" \ + /* The global configuration */ struct _Config config; +/* + * Parse Command-Line options + * + * Supposed to be called before reading config file, as there's an + * option to change its name + */ +void parse_cli_options(int argc, char **argv) +{ + int opt; + int count_exclude = 0; + + config.verbose = false; + while ((opt = getopt(argc, argv, "d:e:f:hm:v")) != EOF) { + switch (opt) { + case 'd': + if (optarg != NULL) + config.display_name = strdup(optarg); + break; + + case 'e': + if (count_exclude < SOUND_MIXER_NRDEVICES) { + config.exclude_channel[count_exclude] = strdup(optarg); + count_exclude++; + } else + fprintf(stderr, "Warning: You can't exclude this many channels\n"); + break; + + case 'f': + if (optarg != NULL) + if (config.file != NULL) + free(config.file); + config.file = strdup(optarg); + break; + + case 'h': + fputs(HELP_TEXT, stdout); + exit(0); + break; + + case 'm': + if (optarg != NULL) + config.mixer_device = strdup(optarg); + break; + + case 'v': + config.verbose = true; + break; + + default: + break; + } + } + config.exclude_channel[count_exclude] = NULL; +} + /* * Read configuration from a file * diff --git a/wmix/include/config.h b/wmix/include/config.h index 5d84ae9..71a79d4 100644 --- a/wmix/include/config.h +++ b/wmix/include/config.h @@ -20,10 +20,17 @@ #ifndef WMIX_CONFIG_H #define WMIX_CONFIG_H +/* Needed for SOUND_MIXER_NRDEVICES */ +#include + + /* Global Configuration */ extern struct _Config { char *file; /* full path to config file name */ + char *display_name; /* X Display to connect to */ + char *mixer_device; /* device file to use for controlling Mixer volumes */ + unsigned int verbose : 1; /* be Verbose when starting */ unsigned int osd : 1; /* show OSD? */ unsigned int mousewheel : 1; /* mousewheel enabled? */ unsigned int scrolltext : 1; /* scroll channel names? */ @@ -33,8 +40,16 @@ extern struct _Config { float scrollstep; /* scroll mouse step adjustment */ char *osd_color; /* osd color */ + + char *exclude_channel[SOUND_MIXER_NRDEVICES + 1]; /* Devices to exclude from GUI's list */ } config; +/* Current version of WMixer */ +#define VERSION "3.0" + +/* Sets configuration from command line */ +void parse_cli_options(int argc, char **argv); + /* Read configuration from file */ void config_read(void); diff --git a/wmix/wmix.c b/wmix/wmix.c index 331c3b9..94b3422 100644 --- a/wmix/wmix.c +++ b/wmix/wmix.c @@ -39,11 +39,8 @@ #include "include/ui_x.h" #include "include/config.h" -#define VERSION "3.0" static Display *display; -static char *display_name = NULL; -static char *mixer_device = NULL; static bool button_pressed = false; static bool slider_pressed = false; static double prev_button_press_time = 0.0; @@ -53,69 +50,13 @@ static float display_width; static int mouse_drag_home_x; static int mouse_drag_home_y; static int idle_loop; -static bool verbose; -static char *exclude[SOUND_MIXER_NRDEVICES]; /* local stuff */ -static void parse_cli_options(int argc, char **argv); static void signal_catch(int sig); static void button_press_event(XButtonEvent *event); static void button_release_event(XButtonEvent *event); static void motion_event(XMotionEvent *event); -#define HELP_TEXT \ - "WMixer " VERSION " by timecop@japan.co.jp + skunk@mit.edu\n" \ - "usage:\n" \ - " -d connect to remote X display\n" \ - " -f parse this config [~/.wmixrc]\n" \ - " -m mixer device [/dev/mixer]\n" \ - " -h print this help\n" \ - " -v verbose -> id, long name, name\n" \ - " -e exclude channel, can be used many times\n" \ - -static void parse_cli_options(int argc, char **argv) -{ - int opt; - int count_exclude = 0 ; - verbose = false ; - - while ((opt = getopt(argc, argv, "d:f:hm:ve:")) != EOF) { - switch (opt) { - case 'd': - if (optarg != NULL) - display_name = strdup(optarg); - break; - case 'm': - if (optarg != NULL) - mixer_device = strdup(optarg); - break; - case 'f': - if (optarg != NULL) - if (config.file != NULL) - free(config.file); - config.file = strdup(optarg); - break; - case 'h': - fputs(HELP_TEXT, stdout); - exit(0); - break; - case 'v': - verbose = true; - break; - case 'e': - if (count_exclude < SOUND_MIXER_NRDEVICES) { - exclude[count_exclude] = strdup(optarg); - /* printf("exclude : %s\n", exclude[count_exclude]); */ - count_exclude++; - } else - fprintf(stderr, "Warning: You can't exclude this many channels\n"); - break; - default: - break; - } - } - exclude[count_exclude] = NULL ; -} int main(int argc, char **argv) { @@ -143,18 +84,18 @@ int main(int argc, char **argv) parse_cli_options(argc, argv); config_read(); - if (mixer_device == NULL) - mixer_device = "/dev/mixer"; + if (config.mixer_device == NULL) + config.mixer_device = "/dev/mixer"; - mixer_init(mixer_device, verbose, (const char **)exclude); + mixer_init(config.mixer_device, config.verbose, (const char **)config.exclude_channel); mixer_set_channel(0); - display = XOpenDisplay(display_name); + display = XOpenDisplay(config.display_name); if (display == NULL) { const char *name; - if (display_name) { - name = display_name; + if (config.display_name) { + name = config.display_name; } else { name = getenv("DISPLAY"); if (name == NULL) {