wmix: created new file config.c to contain configuration related stuff
Management of the configuration is split in many places, the goal is to regroup stuff together, starting with the loading from file stuff. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
parent
e2dc01bdc0
commit
4c1bae53c4
|
@ -2,7 +2,7 @@ CC = gcc
|
||||||
CFLAGS = -O3 -W -Wall
|
CFLAGS = -O3 -W -Wall
|
||||||
LDFLAGS = -L/usr/X11R6/lib
|
LDFLAGS = -L/usr/X11R6/lib
|
||||||
LIBS = -lXpm -lXext -lX11 -lm
|
LIBS = -lXpm -lXext -lX11 -lm
|
||||||
OBJECTS = misc.o mixer-oss.o ui_x.o wmix.o
|
OBJECTS = misc.o config.o mixer-oss.o ui_x.o wmix.o
|
||||||
|
|
||||||
# where to install this program (also for packaging stuff)
|
# where to install this program (also for packaging stuff)
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
|
|
95
wmix/config.c
Normal file
95
wmix/config.c
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/* WMix -- a mixer using the OSS mixer API.
|
||||||
|
* Copyright (C) 2014 Christophe CURIS for the WindowMaker Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* config.c: functions related to loading the configuration from file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/soundcard.h>
|
||||||
|
|
||||||
|
#include "include/common.h"
|
||||||
|
#include "include/config.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* The global configuration */
|
||||||
|
struct _Config config;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read configuration from a file
|
||||||
|
*
|
||||||
|
* The file name is taken from CLI if available, of falls back to
|
||||||
|
* a default name.
|
||||||
|
*/
|
||||||
|
void config_read(void)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
char buf[512];
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
if (config.file == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fp = fopen(config.file, "r");
|
||||||
|
if (!fp)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (fgets(buf, 512, fp)) {
|
||||||
|
if ((ptr = strstr(buf, "mousewheel="))) {
|
||||||
|
ptr += 11;
|
||||||
|
config.mousewheel = atoi(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "scrolltext="))) {
|
||||||
|
ptr += 11;
|
||||||
|
config.scrolltext = atoi(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "osd="))) {
|
||||||
|
ptr += 4;
|
||||||
|
config.osd = atoi(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "osdcolor="))) {
|
||||||
|
char *end;
|
||||||
|
ptr += 9;
|
||||||
|
end = strchr(ptr, '\n');
|
||||||
|
ptr[end - ptr] = '\0';
|
||||||
|
if (config.osd_color)
|
||||||
|
free(config.osd_color);
|
||||||
|
config.osd_color = strdup(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "wheelstep="))) {
|
||||||
|
ptr += 10;
|
||||||
|
/* detect old style config */
|
||||||
|
if (atoi(ptr) > 1)
|
||||||
|
config.scrollstep = (float)atoi(ptr) / 100.0;
|
||||||
|
else
|
||||||
|
config.scrollstep = atof(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "wheelbtn1="))) {
|
||||||
|
ptr += 10;
|
||||||
|
config.wheel_button_up = atoi(ptr);
|
||||||
|
}
|
||||||
|
if ((ptr = strstr(buf, "wheelbtn2="))) {
|
||||||
|
ptr += 10;
|
||||||
|
config.wheel_button_down = atoi(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
|
@ -35,16 +35,3 @@ typedef unsigned int bool;
|
||||||
#define MAX_DOUBLE_CLICK_TIME 0.5
|
#define MAX_DOUBLE_CLICK_TIME 0.5
|
||||||
#define BUTTON_WHEEL_UP 4
|
#define BUTTON_WHEEL_UP 4
|
||||||
#define BUTTON_WHEEL_DOWN 5
|
#define BUTTON_WHEEL_DOWN 5
|
||||||
|
|
||||||
typedef struct _Config Config;
|
|
||||||
|
|
||||||
struct _Config {
|
|
||||||
char *file; /* full path to config file name */
|
|
||||||
unsigned int osd : 1; /* show OSD? */
|
|
||||||
unsigned int mousewheel : 1; /* mousewheel enabled? */
|
|
||||||
unsigned int scrolltext : 1; /* scroll channel names? */
|
|
||||||
unsigned int wheel_button_up; /* up button */
|
|
||||||
unsigned int wheel_button_down; /* down button */
|
|
||||||
float scrollstep; /* scroll mouse step adjustment */
|
|
||||||
char *osd_color; /* osd color */
|
|
||||||
};
|
|
||||||
|
|
41
wmix/include/config.h
Normal file
41
wmix/include/config.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* WMix -- a mixer using the OSS mixer API
|
||||||
|
* Copyright (C)2014 Christophe CURIS for the WindowMaker Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
/* include/config.h: functions related to setting the configuration */
|
||||||
|
|
||||||
|
#ifndef WMIX_CONFIG_H
|
||||||
|
#define WMIX_CONFIG_H
|
||||||
|
|
||||||
|
/* Global Configuration */
|
||||||
|
extern struct _Config {
|
||||||
|
char *file; /* full path to config file name */
|
||||||
|
|
||||||
|
unsigned int osd : 1; /* show OSD? */
|
||||||
|
unsigned int mousewheel : 1; /* mousewheel enabled? */
|
||||||
|
unsigned int scrolltext : 1; /* scroll channel names? */
|
||||||
|
|
||||||
|
unsigned int wheel_button_up; /* up button */
|
||||||
|
unsigned int wheel_button_down; /* down button */
|
||||||
|
|
||||||
|
float scrollstep; /* scroll mouse step adjustment */
|
||||||
|
char *osd_color; /* osd color */
|
||||||
|
} config;
|
||||||
|
|
||||||
|
/* Read configuration from file */
|
||||||
|
void config_read(void);
|
||||||
|
|
||||||
|
#endif /* WMIX_CONFIG_H */
|
|
@ -23,5 +23,4 @@ void vb_to_lr (float volume, float balance, float *left, float *right);
|
||||||
double get_current_time(void);
|
double get_current_time(void);
|
||||||
void add_region (int index, int x, int y, int width, int height);
|
void add_region (int index, int x, int y, int width, int height);
|
||||||
int check_region (int x, int y);
|
int check_region (int x, int y);
|
||||||
void config_read (void);
|
|
||||||
void create_pid_file (void);
|
void create_pid_file (void);
|
||||||
|
|
56
wmix/misc.c
56
wmix/misc.c
|
@ -42,7 +42,6 @@ typedef struct {
|
||||||
} MRegion;
|
} MRegion;
|
||||||
MRegion mr[16];
|
MRegion mr[16];
|
||||||
|
|
||||||
extern Config config;
|
|
||||||
|
|
||||||
/* Converts separate left and right channel volumes (each in [0, 1]) to
|
/* Converts separate left and right channel volumes (each in [0, 1]) to
|
||||||
* volume and balance values. (Volume is in [0, 1], balance is in [-1, 1])
|
* volume and balance values. (Volume is in [0, 1], balance is in [-1, 1])
|
||||||
|
@ -109,61 +108,6 @@ int check_region(int x, int y)
|
||||||
return (i - 1);
|
return (i - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void config_read(void)
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char buf[512];
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
if (config.file == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fp = fopen(config.file, "r");
|
|
||||||
if (!fp)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (fgets(buf, 512, fp)) {
|
|
||||||
if ((ptr = strstr(buf, "mousewheel="))) {
|
|
||||||
ptr += 11;
|
|
||||||
config.mousewheel = atoi(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "scrolltext="))) {
|
|
||||||
ptr += 11;
|
|
||||||
config.scrolltext = atoi(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "osd="))) {
|
|
||||||
ptr += 4;
|
|
||||||
config.osd = atoi(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "osdcolor="))) {
|
|
||||||
char *end;
|
|
||||||
ptr += 9;
|
|
||||||
end = strchr(ptr, '\n');
|
|
||||||
ptr[end - ptr] = '\0';
|
|
||||||
if (config.osd_color)
|
|
||||||
free(config.osd_color);
|
|
||||||
config.osd_color = strdup(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "wheelstep="))) {
|
|
||||||
ptr += 10;
|
|
||||||
/* detect old style config */
|
|
||||||
if (atoi(ptr) > 1)
|
|
||||||
config.scrollstep = (float)atoi(ptr) / 100.0;
|
|
||||||
else
|
|
||||||
config.scrollstep = atof(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "wheelbtn1="))) {
|
|
||||||
ptr += 10;
|
|
||||||
config.wheel_button_up = atoi(ptr);
|
|
||||||
}
|
|
||||||
if ((ptr = strstr(buf, "wheelbtn2="))) {
|
|
||||||
ptr += 10;
|
|
||||||
config.wheel_button_down = atoi(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* handle writing PID file, silently ignore if we can't do it */
|
/* handle writing PID file, silently ignore if we can't do it */
|
||||||
void create_pid_file(void)
|
void create_pid_file(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,8 @@
|
||||||
#include "include/misc.h"
|
#include "include/misc.h"
|
||||||
#include "include/mixer.h"
|
#include "include/mixer.h"
|
||||||
#include "include/ui_x.h"
|
#include "include/ui_x.h"
|
||||||
|
#include "include/config.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef PI
|
#ifndef PI
|
||||||
#define PI M_PI
|
#define PI M_PI
|
||||||
|
@ -72,8 +74,6 @@ struct _Dockapp {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Config config;
|
|
||||||
|
|
||||||
static Pixmap led_on_pixmap;
|
static Pixmap led_on_pixmap;
|
||||||
static Pixmap led_on_mask;
|
static Pixmap led_on_mask;
|
||||||
static Pixmap led_off_pixmap;
|
static Pixmap led_off_pixmap;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "include/mixer.h"
|
#include "include/mixer.h"
|
||||||
#include "include/misc.h"
|
#include "include/misc.h"
|
||||||
#include "include/ui_x.h"
|
#include "include/ui_x.h"
|
||||||
|
#include "include/config.h"
|
||||||
|
|
||||||
#define VERSION "3.0"
|
#define VERSION "3.0"
|
||||||
|
|
||||||
|
@ -49,7 +50,6 @@ static double prev_button_press_time = 0.0;
|
||||||
|
|
||||||
static float display_height;
|
static float display_height;
|
||||||
static float display_width;
|
static float display_width;
|
||||||
Config config;
|
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue