wmix: moved parsing of Command-Line options to the config handling file
Took opportunity to re-order them alphabetically so they are easier to work with, both for devs and for users. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
parent
4c1bae53c4
commit
eb8be92aa8
|
@ -16,12 +16,14 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <sys/soundcard.h>
|
#include <sys/soundcard.h>
|
||||||
|
|
||||||
|
@ -29,10 +31,75 @@
|
||||||
#include "include/config.h"
|
#include "include/config.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define HELP_TEXT \
|
||||||
|
"WMixer " VERSION " by timecop@japan.co.jp + skunk@mit.edu\n" \
|
||||||
|
"usage:\n" \
|
||||||
|
" -d <dsp> connect to remote X display\n" \
|
||||||
|
" -e <name> exclude channel, can be used many times\n" \
|
||||||
|
" -f <file> parse this config [~/.wmixrc]\n" \
|
||||||
|
" -h print this help\n" \
|
||||||
|
" -m <dev> mixer device [/dev/mixer]\n" \
|
||||||
|
" -v verbose -> id, long name, name\n" \
|
||||||
|
|
||||||
/* The global configuration */
|
/* The global configuration */
|
||||||
struct _Config config;
|
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
|
* Read configuration from a file
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,10 +20,17 @@
|
||||||
#ifndef WMIX_CONFIG_H
|
#ifndef WMIX_CONFIG_H
|
||||||
#define WMIX_CONFIG_H
|
#define WMIX_CONFIG_H
|
||||||
|
|
||||||
|
/* Needed for SOUND_MIXER_NRDEVICES */
|
||||||
|
#include <sys/soundcard.h>
|
||||||
|
|
||||||
|
|
||||||
/* Global Configuration */
|
/* Global Configuration */
|
||||||
extern struct _Config {
|
extern struct _Config {
|
||||||
char *file; /* full path to config file name */
|
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 osd : 1; /* show OSD? */
|
||||||
unsigned int mousewheel : 1; /* mousewheel enabled? */
|
unsigned int mousewheel : 1; /* mousewheel enabled? */
|
||||||
unsigned int scrolltext : 1; /* scroll channel names? */
|
unsigned int scrolltext : 1; /* scroll channel names? */
|
||||||
|
@ -33,8 +40,16 @@ extern struct _Config {
|
||||||
|
|
||||||
float scrollstep; /* scroll mouse step adjustment */
|
float scrollstep; /* scroll mouse step adjustment */
|
||||||
char *osd_color; /* osd color */
|
char *osd_color; /* osd color */
|
||||||
|
|
||||||
|
char *exclude_channel[SOUND_MIXER_NRDEVICES + 1]; /* Devices to exclude from GUI's list */
|
||||||
} config;
|
} 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 */
|
/* Read configuration from file */
|
||||||
void config_read(void);
|
void config_read(void);
|
||||||
|
|
||||||
|
|
71
wmix/wmix.c
71
wmix/wmix.c
|
@ -39,11 +39,8 @@
|
||||||
#include "include/ui_x.h"
|
#include "include/ui_x.h"
|
||||||
#include "include/config.h"
|
#include "include/config.h"
|
||||||
|
|
||||||
#define VERSION "3.0"
|
|
||||||
|
|
||||||
static Display *display;
|
static Display *display;
|
||||||
static char *display_name = NULL;
|
|
||||||
static char *mixer_device = NULL;
|
|
||||||
static bool button_pressed = false;
|
static bool button_pressed = false;
|
||||||
static bool slider_pressed = false;
|
static bool slider_pressed = false;
|
||||||
static double prev_button_press_time = 0.0;
|
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_x;
|
||||||
static int mouse_drag_home_y;
|
static int mouse_drag_home_y;
|
||||||
static int idle_loop;
|
static int idle_loop;
|
||||||
static bool verbose;
|
|
||||||
static char *exclude[SOUND_MIXER_NRDEVICES];
|
|
||||||
|
|
||||||
/* local stuff */
|
/* local stuff */
|
||||||
static void parse_cli_options(int argc, char **argv);
|
|
||||||
static void signal_catch(int sig);
|
static void signal_catch(int sig);
|
||||||
static void button_press_event(XButtonEvent *event);
|
static void button_press_event(XButtonEvent *event);
|
||||||
static void button_release_event(XButtonEvent *event);
|
static void button_release_event(XButtonEvent *event);
|
||||||
static void motion_event(XMotionEvent *event);
|
static void motion_event(XMotionEvent *event);
|
||||||
|
|
||||||
#define HELP_TEXT \
|
|
||||||
"WMixer " VERSION " by timecop@japan.co.jp + skunk@mit.edu\n" \
|
|
||||||
"usage:\n" \
|
|
||||||
" -d <dsp> connect to remote X display\n" \
|
|
||||||
" -f <file> parse this config [~/.wmixrc]\n" \
|
|
||||||
" -m <dev> mixer device [/dev/mixer]\n" \
|
|
||||||
" -h print this help\n" \
|
|
||||||
" -v verbose -> id, long name, name\n" \
|
|
||||||
" -e <name> 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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
@ -143,18 +84,18 @@ int main(int argc, char **argv)
|
||||||
parse_cli_options(argc, argv);
|
parse_cli_options(argc, argv);
|
||||||
config_read();
|
config_read();
|
||||||
|
|
||||||
if (mixer_device == NULL)
|
if (config.mixer_device == NULL)
|
||||||
mixer_device = "/dev/mixer";
|
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);
|
mixer_set_channel(0);
|
||||||
|
|
||||||
display = XOpenDisplay(display_name);
|
display = XOpenDisplay(config.display_name);
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (display_name) {
|
if (config.display_name) {
|
||||||
name = display_name;
|
name = config.display_name;
|
||||||
} else {
|
} else {
|
||||||
name = getenv("DISPLAY");
|
name = getenv("DISPLAY");
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
|
|
Loading…
Reference in a new issue