1
0
mirror of https://github.com/gryf/wmamixer.git synced 2025-12-17 11:30:21 +01:00

Added couple of missing icons; fix for the control names, removed config file

This commit is contained in:
2015-01-31 19:03:16 +01:00
parent 4f3c64607e
commit c95074b48d
6 changed files with 253 additions and 429 deletions

7
README
View File

@@ -16,10 +16,9 @@ Changes
Changes with comparison with wmsmixer: Changes with comparison with wmsmixer:
- ALSA instead of OSS. This is real thing, using alsa-lib, not just emulation - ALSA instead of OSS. This is the real thing, using alsa-lib, not just
of OSS. emulation of OSS.
- Placement of configuration file changed to "$XDG_CONFIG_HOME/wmamixer.conf", - Removed config file support, since it doesn't apply anymore
which usually translate to "$HOME/.config/wmamixer.conf"
Limitations Limitations
----------- -----------

Binary file not shown.

View File

@@ -1,35 +1,35 @@
/* XPM */ /* XPM */
static char *icons_xpm[] = { static char *icons_xpm[] = {
/* columns rows colors chars-per-pixel */ /* columns rows colors chars-per-pixel */
"234 24 4 1 ", "416 24 4 1 ",
". c #202020 s back_color", ". c #202020 s back_color",
"+ c #00C9C1 s led_color_high", "+ c #00C9C1 s led_color_high",
"@ c #0C8580 s led_color_med ", "@ c #0C8580 s led_color_med ",
"# c #184A48 s led_color_low", "# c #184A48 s led_color_low",
/* pixels */ /* pixels */
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
"..........................................................................................................................................................................................................................................", ".................................................................................................................................................................................................................................................................................++..................................................................................................@......@...................................",
"....................................+...............................................#..........................#++..............................................#++#.............................##@@..##................#@++++@#.........", "....................................+...............................................#..........................#++..............................................#++#.............................##@@..##................#@++++@#.................#######.......................+..+...................................................................#+++++++++++++#................@....@....................................",
"....................................+........................++...................#+++#.......................#++#+......................#++++++#...............+.#+............................#+@##@@@................#+@#..#@+#........", "....................................+........................++...................#+++#.......................#++#+......................#++++++#...............+.#+............................#+@##@@@................#+@#..#@+#...............#++++++++#....................#+..+#............................................#++++++#............@+++++++++++++++++@...............@..@.................+++++++.............",
".................................+.++....+..+.+.............++#+..................+++++.......................++#+#+....................#++++++++++++#+............+...........................#+......................#+#......#+#.......", ".................................+.++....+..+.+.............++#+..................+++++.......................++#+#+....................#++++++++++++#+............+...........................#+......................#+#......#+#.............#++@#..@+++@...................#+..+#..........................................#++###+++++#.........+++++++++++++++++++++...............@@..................+#####+#............",
".................................+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.......", ".................................+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.............+++.....#+++@..++...............+..+...........................................++####++++++.........+++++@#.......#@+++++........#++++++++++++++#...........+#....+#............",
"............................+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#......", "............................+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#...........#++#......#+++#.++................++................+++++++++++++++............#+++###++++@+#........++++@..++...++..@++++........++++++++++++++++...........+#....+#............",
"...................#+.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@......", "...................#+.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@...........#+++#......+++#..................#+#................+#+#+#+#+#+#+#+#...........+##+###+++@+++.........++#...++...++...#++.........+++####..#...+++...........+#....+#............",
".................#+++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@.....", ".................#+++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@...........++++......+++#.................++++#...............+#+#+#+#+#+#+#+#...........+#####+++@++++..............+++++++++..............++#######.#...++...........+#....+#............",
"...............#+++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@....", "...............#+++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@..........#++#......+++#.++.............#+#.++...............+#+#+#+#+#+#+#+#...........+####+..+####+............++#########++............++##@@####..#.++.......+++++#....+#....+++++...",
".............#+++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+....", ".............#+++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+...................#+++#.++............++#.++++..............+#.#.#.#.#.#.#+#...........+####+..+####+...........+###+@#+@#+@##+...........++##@@@##.#...++........#####....+#....+#####..",
"...........#+++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+....", "...........#+++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+...................++++...............#+#.+.+..+.............+#.#.#.#.#.#.#+#...........++++@+++#####+..........+####@@#@@#@@###+..........++###@#####.#.++.................+#....+#......",
".........#+++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+....", ".........#+++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+..................++++................#+..+..+.+.............+++++++++++++++#...........+++@+++##++##+..........+####+@#+@#+@###+..........++########.#..++.................+#....+#......",
".......#+++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+....", ".......#+++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+................#++++.................#+.....+.+..............###############...........#+@++++###+++#..........+####@@#@@#@@###+..........++########.#.#++.................+#....+#......",
".....#+++++++++++++++.........++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@....", ".....#+++++++++++++++.........++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@..............@++++#...................#+...#+#+.........................................++++++####++...........+####+@#+@#+@###+..........+++#.#.#.#...+++.................+#....+#......",
"....+++++++++++++++++..........+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@.....", "....+++++++++++++++++..........+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@..............++++#......................#++++++..........................................#+++++###++#...........+####@@#@@#@@###+..........++++++++++++++++.................+++++++#......",
"...............................+.+..+.+....+.................++....................................................+...+++#...........++..................................................................................................", "...............................+.+..+.+....+.................++....................................................+...+++#...........++...........................................................................................................@+#.............................+#............................................#++++++#.............+###############+..........#++++++++++++++#..................#######......",
".................................+..+.................................................................................................+...................................................................................................", ".................................+..+.................................................................................................+.........................................................................................................................................+++#...................................................................+++++++++++++++..........................................................",
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
"..........................................................................................................................................................................................................................................", "................................................................................................................................................................................................................................................................................................................................................................................................................................",
".........................................................................................................................................................................................................................................." "................................................................................................................................................................................................................................................................................................................................................................................................................................"
}; };

View File

@@ -1,4 +1,4 @@
// wmamixer - An alsa mixer designed for WindowMaker with scrollwheel support // wmamixer - An ALSA mixer designed for WindowMaker with scrollwheel support
// Copyright (C) 2015 Roman Dobosz <gryf@vimja.com> // Copyright (C) 2015 Roman Dobosz <gryf@vimja.com>
// Copyright (C) 2003 Damian Kramer <psiren@hibernaculum.net> // Copyright (C) 2003 Damian Kramer <psiren@hibernaculum.net>
// Copyright (C) 1998 Sam Hawker <shawkie@geocities.com> // Copyright (C) 1998 Sam Hawker <shawkie@geocities.com>
@@ -10,9 +10,6 @@
#include "wmamixer.h" #include "wmamixer.h"
// global mixer struct
struct Mixer *mix;
int main(int argc, char **argv) { int main(int argc, char **argv) {
XGCValues gcv; XGCValues gcv;
unsigned long gcm; unsigned long gcm;
@@ -69,8 +66,6 @@ int main(int argc, char **argv) {
mix = Mixer_create(); mix = Mixer_create();
readFile();
if (mix->devices_no == 0) if (mix->devices_no == 0)
fprintf(stderr,"%s: Sorry, no supported channels found.\n", NAME); fprintf(stderr,"%s: Sorry, no supported channels found.\n", NAME);
else { else {
@@ -146,6 +141,7 @@ int main(int argc, char **argv) {
XFreePixmap(d_display, pm_digits); XFreePixmap(d_display, pm_digits);
XFreePixmap(d_display, pm_chars); XFreePixmap(d_display, pm_chars);
freeXWin(); freeXWin();
Selem_destroy();
Mixer_destroy(mix); Mixer_destroy(mix);
return 0; return 0;
} }
@@ -220,87 +216,113 @@ struct Mixer *Mixer_create() {
return mixer; return mixer;
} }
/* Guess and return short name for the mixer simple element */
void Mixer_set_selem_props(struct Selem *selem, const char *name) { void Mixer_set_selem_props(struct Selem *selem, const char *name) {
const char *pcm = "PCM", const char *pcm = "PCM",
*mic = "Mic", *mic = "Mic",
*cap = "Capture", *cap = "Capture",
*boost = "Boost", *boost = "Boost",
*line = "Line"; *line = "Line",
char variable[5]; *aux = "Aux";
// Get the name. Simple match.
if (strcmp("Master", name) == 0) { if (strcmp("Master", name) == 0) {
selem->name = "mstr"; selem->name = "mstr";
selem->iconIndex = 0; selem->iconIndex = 0;
} else if (strstr(pcm, name)) { } else if (strstr(pcm, name)) {
selem->iconIndex = 1; selem->iconIndex = 1;
if (strcmp(pcm, name) == 0) { if (strcmp(pcm, name) == 0)
selem->name = "pcm "; selem->name = "pcm ";
} else { else
sprintf(variable, "pcm%d", namesCount.pcm); Selem_set_name(selem, "pcm", &namesCount.pcm);
selem->name = variable;
namesCount.pcm++;
}
} else if (strstr("Headphone", name)) { } else if (strstr("Headphone", name)) {
selem->name = "hdph"; selem->name = "hdph";
selem->iconIndex = 8; selem->iconIndex = 8;
} else if (strstr("Beep", name)) { } else if (strstr("Beep", name) || strstr("PC Speaker", name)) {
selem->name = "beep"; selem->name = "beep";
selem->iconIndex = 7; selem->iconIndex = 7;
} else if (strstr("Digital", name)) { } else if (strstr("Digital", name)) {
selem->iconIndex = selem->capture ? 3 : 6; selem->iconIndex = selem->capture ? 3 : 15;
selem->name = "digt"; selem->name = "digt";
} else if (strstr("Bass", name)) {
selem->name = "bass";
selem->iconIndex = 9;
} else if (strstr("Treble", name)) {
selem->name = "trbl";
selem->iconIndex = 10;
} else if (strstr("Synth", name)) {
selem->name = "synt";
selem->iconIndex = 11;
} else if (strstr("CD", name)) {
selem->name = " cd ";
selem->iconIndex = 12;
} else if (strstr("Phone", name)) {
selem->name = "phne";
selem->iconIndex = 13;
} else if (strstr("Video", name)) {
selem->name = "vdeo";
selem->iconIndex = 14;
} else if (strstr(mic, name)) { } else if (strstr(mic, name)) {
if (strcmp(mic, name) == 0) { if (strcmp(mic, name) == 0) {
selem->name = "mic "; selem->name = "mic ";
} else { } else {
if (strstr(boost, name)) { if (strstr(boost, name))
sprintf(variable, "mib%d", namesCount.micb); Selem_set_name(selem, "mib", &namesCount.micb);
namesCount.micb++; else
} else { Selem_set_name(selem, "mic", &namesCount.mic);
sprintf(variable, "mib%d", namesCount.mic);
namesCount.mic++;
}
selem->name = variable;
} }
selem->iconIndex = 4; selem->iconIndex = 4;
} else if (strstr(aux, name)) {
if (strcmp(aux, name) == 0) {
selem->name = "aux ";
} else {
Selem_set_name(selem, "aux", &namesCount.aux);
}
selem->iconIndex = 5;
} else if (strstr(line, name)) { } else if (strstr(line, name)) {
if (strcmp(line, name) == 0) { if (strcmp(line, name) == 0) {
selem->name = "line"; selem->name = "line";
} else { } else {
if (strstr(boost, name)) { if (strstr(boost, name))
sprintf(variable, "lnb%d", namesCount.lineb); Selem_set_name(selem, "lnb", &namesCount.lineb);
namesCount.lineb++; else
} else { Selem_set_name(selem, "lin", &namesCount.line);
sprintf(variable, "lin%d", namesCount.line);
namesCount.line++;
}
selem->name = variable;
} }
selem->iconIndex = 5; selem->iconIndex = 5;
} else if (strstr(cap, name)) { } else if (strstr(cap, name)) {
if (strcmp(cap, name) == 0) { if (strcmp(cap, name) == 0) {
selem->name = "cap "; selem->name = "cap ";
} else { } else {
sprintf(variable, "cap%d", namesCount.capt); Selem_set_name(selem, "cap", &namesCount.capt);
selem->name = variable;
namesCount.capt++;
} }
selem->iconIndex = 3; selem->iconIndex = 3;
} else { } else {
/* defaults */
printf("defaults\n");
sprintf(variable, "vol%d", namesCount.vol);
namesCount.vol++; namesCount.vol++;
selem->iconIndex = 6; selem->iconIndex = 6;
Selem_set_name(selem, name, &namesCount.vol);
} }
} }
void Selem_set_name(struct Selem *selem, const char *name, short int *count) {
char new_name[5], buf[5];
if (*count > 10)
snprintf(new_name, 5, "%s", name);
else {
snprintf(buf, 4, "%s", name);
printf("%s: %s\n", name, buf);
snprintf(new_name, 5, "%s%d", buf, *count);
}
selem->name = new_name;
*count = *count + 1;
}
void Mixer_set_channels(struct Selem *selem) { void Mixer_set_channels(struct Selem *selem) {
int idx; int idx;
snd_mixer_selem_channel_id_t chn; snd_mixer_selem_channel_id_t chn;
selem->stereo = true;
if (snd_mixer_selem_has_playback_volume(selem->elem)) { if (snd_mixer_selem_has_playback_volume(selem->elem)) {
if (snd_mixer_selem_is_playback_mono(selem->elem)) { if (snd_mixer_selem_is_playback_mono(selem->elem)) {
selem->stereo = false; selem->stereo = false;
@@ -452,90 +474,101 @@ void Mixer_destroy(struct Mixer *mixer) {
free(mixer); free(mixer);
} }
void initXWin(int argc, char **argv) void Selem_destroy() {
{ int i;
winsize=astep ? ASTEPSIZE : NORMSIZE;
if ((d_display=XOpenDisplay(display))==NULL ) { for (i = 0; i < mix->devices_no; i++) {
fprintf(stderr,"%s: Unable to open X display '%s'.\n", NAME, XDisplayName(display)); free(selems[i]);
exit(1); }
}
_XA_GNUSTEP_WM_FUNC=XInternAtom(d_display, "_GNUSTEP_WM_FUNCTION", false);
deleteWin=XInternAtom(d_display, "WM_DELETE_WINDOW", false);
w_root=DefaultRootWindow(d_display);
XWMHints wmhints;
XSizeHints shints;
shints.x=0;
shints.y=0;
shints.flags=0;
bool pos=(XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0, &shints, &shints.x, &shints.y,
&shints.width, &shints.height, &shints.win_gravity) & (XValue | YValue));
shints.min_width=winsize;
shints.min_height=winsize;
shints.max_width=winsize;
shints.max_height=winsize;
shints.base_width=winsize;
shints.base_height=winsize;
shints.flags=PMinSize | PMaxSize | PBaseSize;
createWin(&w_main, shints.x, shints.y);
if (wmaker || astep || pos)
shints.flags |= USPosition;
if (wmaker ) {
wmhints.initial_state=WithdrawnState;
wmhints.flags=WindowGroupHint | StateHint | IconWindowHint;
createWin(&w_icon, shints.x, shints.y);
w_activewin=w_icon;
wmhints.icon_window=w_icon;
}
else{
wmhints.initial_state=NormalState;
wmhints.flags=WindowGroupHint | StateHint;
w_activewin=w_main;
}
wmhints.window_group=w_main;
XSetWMHints(d_display, w_main, &wmhints);
XSetWMNormalHints(d_display, w_main, &shints);
XSetCommand(d_display, w_main, argv, argc);
XStoreName(d_display, w_main, NAME);
XSetIconName(d_display, w_main, NAME);
XSetWMProtocols(d_display, w_activewin, &deleteWin, 1);
} }
void freeXWin()
{ void initXWin(int argc, char **argv) {
XDestroyWindow(d_display, w_main); bool pos;
if (wmaker) winsize = astep ? ASTEPSIZE : NORMSIZE;
XDestroyWindow(d_display, w_icon); XWMHints wmhints;
XCloseDisplay(d_display); XSizeHints shints;
if ((d_display = XOpenDisplay(display)) == NULL) {
fprintf(stderr, "%s: Unable to open X display '%s'.\n", NAME,
XDisplayName(display));
exit(1);
}
_XA_GNUSTEP_WM_FUNC = XInternAtom(d_display, "_GNUSTEP_WM_FUNCTION",
false);
deleteWin = XInternAtom(d_display, "WM_DELETE_WINDOW", false);
w_root=DefaultRootWindow(d_display);
shints.x = 0;
shints.y = 0;
shints.flags = 0;
pos = (XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0,
&shints, &shints.x, &shints.y, &shints.width, &shints.height,
&shints.win_gravity) & (XValue | YValue)) == 1;
shints.min_width = winsize;
shints.min_height = winsize;
shints.max_width = winsize;
shints.max_height = winsize;
shints.base_width = winsize;
shints.base_height = winsize;
shints.flags = PMinSize | PMaxSize | PBaseSize;
createWin(&w_main, shints.x, shints.y);
if (wmaker || astep || pos)
shints.flags |= USPosition;
if (wmaker) {
wmhints.initial_state = WithdrawnState;
wmhints.flags = WindowGroupHint | StateHint | IconWindowHint;
createWin(&w_icon, shints.x, shints.y);
w_activewin = w_icon;
wmhints.icon_window = w_icon;
} else {
wmhints.initial_state = NormalState;
wmhints.flags = WindowGroupHint | StateHint;
w_activewin = w_main;
}
wmhints.window_group = w_main;
XSetWMHints(d_display, w_main, &wmhints);
XSetWMNormalHints(d_display, w_main, &shints);
XSetCommand(d_display, w_main, argv, argc);
XStoreName(d_display, w_main, NAME);
XSetIconName(d_display, w_main, NAME);
XSetWMProtocols(d_display, w_activewin, &deleteWin, 1);
} }
void createWin(Window *win, int x, int y) void freeXWin() {
{ XDestroyWindow(d_display, w_main);
XClassHint classHint; if (wmaker)
*win=XCreateSimpleWindow(d_display, w_root, x, y, winsize, winsize, 0, 0, 0); XDestroyWindow(d_display, w_icon);
classHint.res_name=NAME; XCloseDisplay(d_display);
classHint.res_class=CLASS;
XSetClassHint(d_display, *win, &classHint);
} }
unsigned long mixColor(char *colorname1, int prop1, char *colorname2, int prop2) void createWin(Window *win, int x, int y) {
{ XClassHint classHint;
XColor color, color1, color2; *win = XCreateSimpleWindow(d_display, w_root, x, y, winsize, winsize, 0,
XWindowAttributes winattr; 0, 0);
XGetWindowAttributes(d_display, w_root, &winattr); classHint.res_name = NAME;
XParseColor(d_display, winattr.colormap, colorname1, &color1); classHint.res_class = CLASS;
XParseColor(d_display, winattr.colormap, colorname2, &color2); XSetClassHint(d_display, *win, &classHint);
color.pixel=0; }
color.red=(color1.red*prop1+color2.red*prop2)/(prop1+prop2);
color.green=(color1.green*prop1+color2.green*prop2)/(prop1+prop2); unsigned long mixColor(char *colorname1, int prop1, char *colorname2,
color.blue=(color1.blue*prop1+color2.blue*prop2)/(prop1+prop2); int prop2) {
color.flags=DoRed | DoGreen | DoBlue; XColor color, color1, color2;
XAllocColor(d_display, winattr.colormap, &color); XWindowAttributes winattr;
return color.pixel; XGetWindowAttributes(d_display, w_root, &winattr);
XParseColor(d_display, winattr.colormap, colorname1, &color1);
XParseColor(d_display, winattr.colormap, colorname2, &color2);
color.pixel = 0;
color.red = (color1.red * prop1 + color2.red * prop2) / (prop1 + prop2);
color.green = (color1.green * prop1 + color2.green * prop2) /
(prop1 + prop2);
color.blue = (color1.blue * prop1 + color2.blue * prop2) / (prop1 + prop2);
color.flags = DoRed | DoGreen | DoBlue;
XAllocColor(d_display, winattr.colormap, &color);
return color.pixel;
} }
void scanArgs(int argc, char **argv) { void scanArgs(int argc, char **argv) {
@@ -627,87 +660,6 @@ void scanArgs(int argc, char **argv) {
} }
} }
void readFile() {
FILE *rcfile;
int done, current = -1;
char *confpath, buf[256];
if (getenv("XDG_CONFIG_HOME")) {
confpath = malloc(snprintf(NULL, 0, "%s%s", getenv("XDG_CONFIG_HOME"),
"/wmamixer.conf") + 1);
sprintf(confpath, "%s%s", getenv("XDG_CONFIG_HOME"), "/wmamixer.conf");
} else {
confpath = malloc(snprintf(NULL, 0, "%s%s", getenv("HOME"),
"/.config/wmamixer.conf") + 1);
sprintf(confpath, "%s%s", getenv("HOME"), "/.config/wmamixer.conf");
}
if(access(confpath, 0) != 0) {
fprintf(stderr, "%s: No config file found.\n", NAME);
free(confpath);
return;
}
if ((rcfile = fopen(confpath, "r")) == NULL) {
fprintf(stderr, "%s: Cannot open config file. Using defaults.\n",
NAME);
free(confpath);
return;
}
do {
fgets(buf, 250, rcfile);
if ((done=feof(rcfile)) == 0) {
buf[strlen(buf) - 1] = 0;
if (strncmp(buf, "setchannel ", strlen("setchannel ")) == 0) {
sscanf(buf, "setchannel %i", &current);
if (current >= mix->devices_no ) {
fprintf(stderr,"%s: Sorry, this channel (%i) is "
"not supported.\n", NAME, current);
current = -1;
}
}
if (strncmp(buf, "setmono ", strlen("setmono ")) == 0) {
if (current == -1) {
fprintf(stderr,"%s: Sorry, no current channel.\n",
NAME);
} else {
int value;
sscanf(buf, "setmono %i", &value);
Mixer_set_left(current, value);
Mixer_set_right(current, value);
}
}
if (strncmp(buf, "setleft ", strlen("setleft ")) == 0 ) {
if (current == -1) {
fprintf(stderr, "%s: Sorry, no current channel.\n",
NAME);
} else {
int value;
sscanf(buf, "setleft %i", &value);
Mixer_set_left(current, value);
}
}
if (strncmp(buf, "setright ", strlen("setright ")) == 0 ) {
if (current == -1) {
fprintf(stderr, "%s: Sorry, no current channel.\n",
NAME);
} else{
int value;
sscanf(buf, "setleft %i", &value);
Mixer_set_right(current, value);
}
}
}
} while (done == 0);
fclose(rcfile);
free(confpath);
}
void checkVol(bool forced) { void checkVol(bool forced) {
int nl = Mixer_read_left(curchannel); int nl = Mixer_read_left(curchannel);
int nr = Mixer_read_right(curchannel); int nr = Mixer_read_right(curchannel);
@@ -721,14 +673,14 @@ void checkVol(bool forced) {
if (nl != curleft) { if (nl != curleft) {
curleft = nl; curleft = nl;
if (selems[curchannel]->stereo) if (selems[curchannel]->stereo)
drawLeft(); drawStereo(true);
else else
drawMono(); drawMono();
} }
if (nr != curright) { if (nr != curright) {
curright = nr; curright = nr;
if (selems[curchannel]->stereo) if (selems[curchannel]->stereo)
drawRight(); drawStereo(false);
else else
drawMono(); drawMono();
} }
@@ -801,27 +753,26 @@ void releaseEvent() {
repaint(); repaint();
} }
void motionEvent(XMotionEvent *xev) void motionEvent(XMotionEvent *xev) {
{ int x = xev->x - (winsize / 2 - 32);
int x=xev->x-(winsize/2-32); int y = xev->y - (winsize / 2 - 32);
int y=xev->y-(winsize/2-32); if (x >= 37 && x <= 56 && y >= 8 && dragging) {
if (x>=37 && x<=56 && y>=8 && dragging ) { int v = ((60 - y) * 100) / (2 * 25);
int v=((60-y)*100)/(2*25); if (v < 0)
if (v<0) v = 0;
v=0; if (x <= 50)
if (x<=50) Mixer_set_left(curchannel, v);
Mixer_set_left(curchannel, v); if (x >= 45)
if (x>=45) Mixer_set_right(curchannel, v);
Mixer_set_right(curchannel, v); checkVol(false);
checkVol(false); }
}
} }
void repaint() void repaint() {
{ XCopyArea(d_display, pm_disp, w_activewin, gc_gc, 0, 0, 64, 64,
XCopyArea(d_display, pm_disp, w_activewin, gc_gc, 0, 0, 64, 64, winsize/2-32, winsize/2-32); winsize / 2 - 32, winsize / 2 - 32);
XEvent xev; XEvent xev;
while(XCheckTypedEvent(d_display, Expose, &xev)); while(XCheckTypedEvent(d_display, Expose, &xev));
} }
void update() { void update() {
@@ -830,8 +781,8 @@ void update() {
XCopyArea(d_display, pm_icon, pm_disp, gc_gc, XCopyArea(d_display, pm_icon, pm_disp, gc_gc,
selems[curchannel]->iconIndex * 26, 0, 26, 24, 5, 19); selems[curchannel]->iconIndex * 26, 0, 26, 24, 5, 19);
if (selems[curchannel]->stereo) { if (selems[curchannel]->stereo) {
drawLeft(); drawStereo(true);
drawRight(); drawStereo(false);
} else { } else {
drawMono(); drawMono();
} }
@@ -878,63 +829,51 @@ void drawVolLevel() {
} }
} }
void drawLeft() { void drawStereo(bool left) {
int i; int i;
XSetForeground(d_display, gc_gc, color[0]); short pos = left? 37 : 48;
XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49);
XSetForeground(d_display, gc_gc, color[1]); XSetForeground(d_display, gc_gc, color[0]);
for (i = 0; i < 25; i++) { XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49);
if (i==(curleft*25)/100)
XSetForeground(d_display, gc_gc, color[3]); XSetForeground(d_display, gc_gc, color[1]);
XFillRectangle(d_display, pm_disp, gc_gc, 37, 55-2*i, 9, 1); for (i = 0; i < 25; i++) {
} if (i == ((left ? curleft : curright) * 25) / 100)
XSetForeground(d_display, gc_gc, color[3]);
XFillRectangle(d_display, pm_disp, gc_gc, pos, 55 - 2 * i, 9, 1);
}
} }
void drawRight() void drawMono() {
{
int i; int i;
XSetForeground(d_display, gc_gc, color[0]); XSetForeground(d_display, gc_gc, color[1]);
XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49); for (i = 0; i < 25; i++) {
if (i == (curright * 25) / 100)
XSetForeground(d_display, gc_gc, color[1]); XSetForeground(d_display, gc_gc, color[3]);
for (i=0;i<25;i++) { XFillRectangle(d_display, pm_disp, gc_gc, 37, 55 - 2 * i, 20, 1);
if (i==(curright*25)/100) }
XSetForeground(d_display, gc_gc, color[3]);
XFillRectangle(d_display, pm_disp, gc_gc, 48, 55-2*i, 9, 1);
}
} }
void drawMono() void drawBtns(int btns) {
{ if (btns & BTNPREV)
int i; drawBtn(5, 47, 13, 11, (btnstate & BTNPREV));
XSetForeground(d_display, gc_gc, color[1]); if (btns & BTNNEXT)
for (i=0;i<25;i++ ) { drawBtn(18, 47, 13, 11, (btnstate & BTNNEXT));
if (i==(curright*25)/100)
XSetForeground(d_display, gc_gc, color[3]);
XFillRectangle(d_display, pm_disp, gc_gc, 37, 55-2*i, 20, 1);
}
} }
void drawBtn(int x, int y, int w, int h, bool down) {
void drawBtns(int btns) if (!down) {
{ XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w, h, x, y);
if (btns & BTNPREV) } else {
drawBtn(5, 47, 13, 11, (btnstate & BTNPREV)); XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, 1, h - 1,
if (btns & BTNNEXT) x + w - 1, y + 1);
drawBtn(18, 47, 13, 11, (btnstate & BTNNEXT)); XCopyArea(d_display, pm_main, pm_disp, gc_gc, x + w - 1, y + 1, 1,
} h - 1, x, y);
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w - 1, 1, x + 1,
void drawBtn(int x, int y, int w, int h, bool down) y + h - 1);
{ XCopyArea(d_display, pm_main, pm_disp, gc_gc, x + 1, y + h - 1, w - 1,
if (!down) 1, x, y);
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w, h, x, y); }
else {
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, 1, h-1, x+w-1, y+1);
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x+w-1, y+1, 1, h-1, x, y);
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x, y, w-1, 1, x+1, y+h-1);
XCopyArea(d_display, pm_main, pm_disp, gc_gc, x+1, y+h-1, w-1, 1, x, y);
}
} }
void usage() { void usage() {

View File

@@ -1,116 +0,0 @@
# User config file
# Should be saved as $XDG_CONFIG_HOME/wmamixer.conf (XDG_CONFIG_HOME is
# usually accessible under ~/.config direcotry)
# Comments and blank lines mostly allowed
# The format of this file is a series of commands:
# addchannel %i
# Adds a channel to the sequence. %i specifies a channel.
# These are the values from my <linux/soundcard.h>:
#
# SOUND_MIXER_VOLUME 0
# SOUND_MIXER_BASS 1
# SOUND_MIXER_TREBLE 2
# SOUND_MIXER_SYNTH 3
# SOUND_MIXER_PCM 4
# SOUND_MIXER_SPEAKER 5
# SOUND_MIXER_LINE 6
# SOUND_MIXER_MIC 7
# SOUND_MIXER_CD 8
# SOUND_MIXER_IMIX 9 /* Recording monitor */
# SOUND_MIXER_ALTPCM 10
# SOUND_MIXER_RECLEV 11 /* Recording level */
# SOUND_MIXER_IGAIN 12 /* Input gain */
# SOUND_MIXER_OGAIN 13 /* Output gain */
# SOUND_MIXER_LINE1 14 /* Input source 1 (aux1) */
# SOUND_MIXER_LINE2 15 /* Input source 2 (aux2) */
# SOUND_MIXER_LINE3 16 /* Input source 3 (line) */
# SOUND_MIXER_DIGITAL1 17 /* Digital (input) 1 */
# SOUND_MIXER_DIGITAL2 18 /* Digital (input) 2 */
# SOUND_MIXER_DIGITAL3 19 /* Digital (input) 3 */
# SOUND_MIXER_PHONEIN 20 /* Phone input */
# SOUND_MIXER_PHONEOUT 21 /* Phone output */
# SOUND_MIXER_VIDEO 22 /* Video/TV (audio) in */
# SOUND_MIXER_RADIO 23 /* Radio in */
# SOUND_MIXER_MONITOR 24 /* Monitor (usually mic) volume */
#
# Ths channel added becomes the current channel for subsequent
# setmono, setleft, setright and setname commands.
# setchannel %i
# Similar to addchannel, except the channel is not actually added
# to the sequence, merely made the current channel for subsequent
# setmono, setleft, setright and setname commands.
# setmono %i
# Sets both left and right volumes for the current channel.
# The channel may be mono or stereo.
# The value specified must be an integer in the range 0 to 100.
# setleft %i
# Sets left volume for the current channel.
# Do not use on a mono channel.
# The value specified must be an integer in the range 0 to 100.
# setright %i
# Sets right volume for the current channel.
# Do not use on a mono channel.
# The value specified must be an integer in the range 0 to 100.
# setname <text>
# Set the name for this channel. This will be displayed briefly
# when you switch to this channel, or when you click on the
# icon. The program will only use the first 4 characters of this
# text.
# At least one channel must be added!
# VOLUME
addchannel 0
setmono 90
setname main
# PCM
addchannel 4
setmono 64
# SPEAKER
addchannel 5
setmono 0
# LINE
addchannel 6
setmono 0
# MIC
addchannel 7
setmono 0
# CD
addchannel 8
setmono 90
# RECLEVEL
addchannel 11
setmono 0
# OGAIN
addchannel 13
setmono 0
# LINE1
addchannel 14
setmono 0
# LINE2
addchannel 15
setmono 100
# DIGITAL1
addchannel 17
setmono 0
# PHONEIN
addchannel 20
setmono 0

View File

@@ -1,4 +1,4 @@
// wmamixer - An alsa mixer designed for WindowMaker with scrollwheel support // wmamixer - An ALSA mixer designed for WindowMaker with scrollwheel support
// Copyright (C) 2015 Roman Dobosz <gryf@vimja.com> // Copyright (C) 2015 Roman Dobosz <gryf@vimja.com>
// Copyright (C) 2003 Damian Kramer <psiren@hibernaculum.net> // Copyright (C) 2003 Damian Kramer <psiren@hibernaculum.net>
// Copyright (C) 1998 Sam Hawker <shawkie@geocities.com> // Copyright (C) 1998 Sam Hawker <shawkie@geocities.com>
@@ -121,7 +121,6 @@ int rpttimer = 0;
bool dragging = false; bool dragging = false;
int channel[32]; int channel[32];
int icon[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
struct Selem { struct Selem {
char *name; char *name;
@@ -134,7 +133,6 @@ struct Selem {
long max; long max;
bool capture; bool capture;
snd_mixer_selem_channel_id_t channels[2]; snd_mixer_selem_channel_id_t channels[2];
}; };
typedef struct { typedef struct {
@@ -144,17 +142,20 @@ typedef struct {
} slideCaptureMono; } slideCaptureMono;
struct NamesCount { struct NamesCount {
short int pcm, line, lineb, mic, micb, capt, vol; short int pcm, line, lineb, mic, micb, capt, vol, aux;
} namesCount = {1, 1, 1, 1, 1, 1, 1}; } namesCount = {1, 1, 1, 1, 1, 1, 1, 1};
struct Selem *selems[32]; struct Selem *selems[32] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL};
struct Mixer { struct Mixer {
int devices_no; int devices_no;
snd_mixer_t * handle; snd_mixer_t * handle;
void *elems[32];
}; };
struct Mixer *mix;
static int smixer_level = 0; static int smixer_level = 0;
static struct snd_mixer_selem_regopt smixer_options; static struct snd_mixer_selem_regopt smixer_options;
@@ -168,14 +169,12 @@ unsigned long mixColor(char *color1, int prop1, char *color2, int prop2);
void checkVol(bool forced); void checkVol(bool forced);
void drawBtn(int x, int y, int w, int h, bool down); void drawBtn(int x, int y, int w, int h, bool down);
void drawBtns(int btns); void drawBtns(int btns);
void drawLeft(); void drawStereo(bool left);
void drawMono(); void drawMono();
void drawRight();
void drawText(char *text); void drawText(char *text);
void drawVolLevel(); void drawVolLevel();
void motionEvent(XMotionEvent *xev); void motionEvent(XMotionEvent *xev);
void pressEvent(XButtonEvent *xev); void pressEvent(XButtonEvent *xev);
void readFile();
void releaseEvent(); void releaseEvent();
void repaint(); void repaint();
void scanArgs(int argc, char **argv); void scanArgs(int argc, char **argv);
@@ -195,4 +194,7 @@ void Mixer_set_right(int current, int value);
void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem); void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem);
void Mixer_set_volume(int current, int channelIndex, int value); void Mixer_set_volume(int current, int channelIndex, int value);
void Selem_set_name(struct Selem *selem, const char *name, short int *count);
void Selem_destroy();
#endif /* WMAMIXER_H */ #endif /* WMAMIXER_H */