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:
7
README
7
README
@@ -16,10 +16,9 @@ Changes
|
||||
|
||||
Changes with comparison with wmsmixer:
|
||||
|
||||
- ALSA instead of OSS. This is real thing, using alsa-lib, not just emulation
|
||||
of OSS.
|
||||
- Placement of configuration file changed to "$XDG_CONFIG_HOME/wmamixer.conf",
|
||||
which usually translate to "$HOME/.config/wmamixer.conf"
|
||||
- ALSA instead of OSS. This is the real thing, using alsa-lib, not just
|
||||
emulation of OSS.
|
||||
- Removed config file support, since it doesn't apply anymore
|
||||
|
||||
Limitations
|
||||
-----------
|
||||
|
||||
BIN
XPM/icons.xcf
BIN
XPM/icons.xcf
Binary file not shown.
@@ -1,35 +1,35 @@
|
||||
/* XPM */
|
||||
static char *icons_xpm[] = {
|
||||
/* columns rows colors chars-per-pixel */
|
||||
"234 24 4 1 ",
|
||||
"416 24 4 1 ",
|
||||
". c #202020 s back_color",
|
||||
"+ c #00C9C1 s led_color_high",
|
||||
"@ c #0C8580 s led_color_med ",
|
||||
"# c #184A48 s led_color_low",
|
||||
|
||||
/* pixels */
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"....................................+...............................................#..........................#++..............................................#++#.............................##@@..##................#@++++@#.........",
|
||||
"....................................+........................++...................#+++#.......................#++#+......................#++++++#...............+.#+............................#+@##@@@................#+@#..#@+#........",
|
||||
".................................+.++....+..+.+.............++#+..................+++++.......................++#+#+....................#++++++++++++#+............+...........................#+......................#+#......#+#.......",
|
||||
".................................+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.......",
|
||||
"............................+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#......",
|
||||
"...................#+.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@......",
|
||||
".................#+++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@.....",
|
||||
"...............#+++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@....",
|
||||
".............#+++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+....",
|
||||
"...........#+++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+....",
|
||||
".........#+++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+....",
|
||||
".......#+++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+....",
|
||||
".....#+++++++++++++++.........++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@....",
|
||||
"....+++++++++++++++++..........+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@.....",
|
||||
"...............................+.+..+.+....+.................++....................................................+...+++#...........++..................................................................................................",
|
||||
".................................+..+.................................................................................................+...................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
"..........................................................................................................................................................................................................................................",
|
||||
".........................................................................................................................................................................................................................................."
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
".................................................................................................................................................................................................................................................................................++..................................................................................................@......@...................................",
|
||||
"....................................+...............................................#..........................#++..............................................#++#.............................##@@..##................#@++++@#.................#######.......................+..+...................................................................#+++++++++++++#................@....@....................................",
|
||||
"....................................+........................++...................#+++#.......................#++#+......................#++++++#...............+.#+............................#+@##@@@................#+@#..#@+#...............#++++++++#....................#+..+#............................................#++++++#............@+++++++++++++++++@...............@..@.................+++++++.............",
|
||||
".................................+.++....+..+.+.............++#+..................+++++.......................++#+#+....................#++++++++++++#+............+...........................#+......................#+#......#+#.............#++@#..@+++@...................#+..+#..........................................#++###+++++#.........+++++++++++++++++++++...............@@..................+#####+#............",
|
||||
".................................+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.............+++.....#+++@..++...............+..+...........................................++####++++++.........+++++@#.......#@+++++........#++++++++++++++#...........+#....+#............",
|
||||
"............................+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#...........#++#......#+++#.++................++................+++++++++++++++............#+++###++++@+#........++++@..++...++..@++++........++++++++++++++++...........+#....+#............",
|
||||
"...................#+.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@...........#+++#......+++#..................#+#................+#+#+#+#+#+#+#+#...........+##+###+++@+++.........++#...++...++...#++.........+++####..#...+++...........+#....+#............",
|
||||
".................#+++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@...........++++......+++#.................++++#...............+#+#+#+#+#+#+#+#...........+#####+++@++++..............+++++++++..............++#######.#...++...........+#....+#............",
|
||||
"...............#+++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@..........#++#......+++#.++.............#+#.++...............+#+#+#+#+#+#+#+#...........+####+..+####+............++#########++............++##@@####..#.++.......+++++#....+#....+++++...",
|
||||
".............#+++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+...................#+++#.++............++#.++++..............+#.#.#.#.#.#.#+#...........+####+..+####+...........+###+@#+@#+@##+...........++##@@@##.#...++........#####....+#....+#####..",
|
||||
"...........#+++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+...................++++...............#+#.+.+..+.............+#.#.#.#.#.#.#+#...........++++@+++#####+..........+####@@#@@#@@###+..........++###@#####.#.++.................+#....+#......",
|
||||
".........#+++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+..................++++................#+..+..+.+.............+++++++++++++++#...........+++@+++##++##+..........+####+@#+@#+@###+..........++########.#..++.................+#....+#......",
|
||||
".......#+++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+................#++++.................#+.....+.+..............###############...........#+@++++###+++#..........+####@@#@@#@@###+..........++########.#.#++.................+#....+#......",
|
||||
".....#+++++++++++++++.........++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@..............@++++#...................#+...#+#+.........................................++++++####++...........+####+@#+@#+@###+..........+++#.#.#.#...+++.................+#....+#......",
|
||||
"....+++++++++++++++++..........+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@..............++++#......................#++++++..........................................#+++++###++#...........+####@@#@@#@@###+..........++++++++++++++++.................+++++++#......",
|
||||
"...............................+.+..+.+....+.................++....................................................+...+++#...........++...........................................................................................................@+#.............................+#............................................#++++++#.............+###############+..........#++++++++++++++#..................#######......",
|
||||
".................................+..+.................................................................................................+.........................................................................................................................................+++#...................................................................+++++++++++++++..........................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................",
|
||||
"................................................................................................................................................................................................................................................................................................................................................................................................................................"
|
||||
};
|
||||
|
||||
487
wmamixer.c
487
wmamixer.c
@@ -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) 2003 Damian Kramer <psiren@hibernaculum.net>
|
||||
// Copyright (C) 1998 Sam Hawker <shawkie@geocities.com>
|
||||
@@ -10,9 +10,6 @@
|
||||
|
||||
#include "wmamixer.h"
|
||||
|
||||
// global mixer struct
|
||||
struct Mixer *mix;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
XGCValues gcv;
|
||||
unsigned long gcm;
|
||||
@@ -69,8 +66,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
mix = Mixer_create();
|
||||
|
||||
readFile();
|
||||
|
||||
if (mix->devices_no == 0)
|
||||
fprintf(stderr,"%s: Sorry, no supported channels found.\n", NAME);
|
||||
else {
|
||||
@@ -146,6 +141,7 @@ int main(int argc, char **argv) {
|
||||
XFreePixmap(d_display, pm_digits);
|
||||
XFreePixmap(d_display, pm_chars);
|
||||
freeXWin();
|
||||
Selem_destroy();
|
||||
Mixer_destroy(mix);
|
||||
return 0;
|
||||
}
|
||||
@@ -220,87 +216,113 @@ struct Mixer *Mixer_create() {
|
||||
return mixer;
|
||||
}
|
||||
|
||||
/* Guess and return short name for the mixer simple element */
|
||||
void Mixer_set_selem_props(struct Selem *selem, const char *name) {
|
||||
const char *pcm = "PCM",
|
||||
*mic = "Mic",
|
||||
*cap = "Capture",
|
||||
*boost = "Boost",
|
||||
*line = "Line";
|
||||
char variable[5];
|
||||
*line = "Line",
|
||||
*aux = "Aux";
|
||||
|
||||
// Get the name. Simple match.
|
||||
if (strcmp("Master", name) == 0) {
|
||||
selem->name = "mstr";
|
||||
selem->iconIndex = 0;
|
||||
} else if (strstr(pcm, name)) {
|
||||
selem->iconIndex = 1;
|
||||
if (strcmp(pcm, name) == 0) {
|
||||
if (strcmp(pcm, name) == 0)
|
||||
selem->name = "pcm ";
|
||||
} else {
|
||||
sprintf(variable, "pcm%d", namesCount.pcm);
|
||||
selem->name = variable;
|
||||
namesCount.pcm++;
|
||||
}
|
||||
else
|
||||
Selem_set_name(selem, "pcm", &namesCount.pcm);
|
||||
|
||||
} else if (strstr("Headphone", name)) {
|
||||
selem->name = "hdph";
|
||||
selem->iconIndex = 8;
|
||||
} else if (strstr("Beep", name)) {
|
||||
} else if (strstr("Beep", name) || strstr("PC Speaker", name)) {
|
||||
selem->name = "beep";
|
||||
selem->iconIndex = 7;
|
||||
} else if (strstr("Digital", name)) {
|
||||
selem->iconIndex = selem->capture ? 3 : 6;
|
||||
selem->iconIndex = selem->capture ? 3 : 15;
|
||||
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)) {
|
||||
if (strcmp(mic, name) == 0) {
|
||||
selem->name = "mic ";
|
||||
} else {
|
||||
if (strstr(boost, name)) {
|
||||
sprintf(variable, "mib%d", namesCount.micb);
|
||||
namesCount.micb++;
|
||||
} else {
|
||||
sprintf(variable, "mib%d", namesCount.mic);
|
||||
namesCount.mic++;
|
||||
}
|
||||
selem->name = variable;
|
||||
if (strstr(boost, name))
|
||||
Selem_set_name(selem, "mib", &namesCount.micb);
|
||||
else
|
||||
Selem_set_name(selem, "mic", &namesCount.mic);
|
||||
}
|
||||
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)) {
|
||||
if (strcmp(line, name) == 0) {
|
||||
selem->name = "line";
|
||||
} else {
|
||||
if (strstr(boost, name)) {
|
||||
sprintf(variable, "lnb%d", namesCount.lineb);
|
||||
namesCount.lineb++;
|
||||
} else {
|
||||
sprintf(variable, "lin%d", namesCount.line);
|
||||
namesCount.line++;
|
||||
}
|
||||
selem->name = variable;
|
||||
if (strstr(boost, name))
|
||||
Selem_set_name(selem, "lnb", &namesCount.lineb);
|
||||
else
|
||||
Selem_set_name(selem, "lin", &namesCount.line);
|
||||
}
|
||||
selem->iconIndex = 5;
|
||||
} else if (strstr(cap, name)) {
|
||||
if (strcmp(cap, name) == 0) {
|
||||
selem->name = "cap ";
|
||||
} else {
|
||||
sprintf(variable, "cap%d", namesCount.capt);
|
||||
selem->name = variable;
|
||||
namesCount.capt++;
|
||||
Selem_set_name(selem, "cap", &namesCount.capt);
|
||||
}
|
||||
selem->iconIndex = 3;
|
||||
} else {
|
||||
/* defaults */
|
||||
printf("defaults\n");
|
||||
sprintf(variable, "vol%d", namesCount.vol);
|
||||
namesCount.vol++;
|
||||
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) {
|
||||
int idx;
|
||||
snd_mixer_selem_channel_id_t chn;
|
||||
|
||||
selem->stereo = true;
|
||||
|
||||
if (snd_mixer_selem_has_playback_volume(selem->elem)) {
|
||||
if (snd_mixer_selem_is_playback_mono(selem->elem)) {
|
||||
selem->stereo = false;
|
||||
@@ -422,10 +444,10 @@ void Mixer_set_volume(int current, int channelIndex, int value) {
|
||||
raw = (long)convert_prange1(value, selem->min, selem->max);
|
||||
|
||||
if (!selem->capture) {
|
||||
snd_mixer_selem_set_playback_volume(selem->elem,
|
||||
snd_mixer_selem_set_playback_volume(selem->elem,
|
||||
selem->channels[channelIndex], raw);
|
||||
} else {
|
||||
snd_mixer_selem_set_capture_volume(selem->elem,
|
||||
snd_mixer_selem_set_capture_volume(selem->elem,
|
||||
selem->channels[channelIndex], raw);
|
||||
}
|
||||
}
|
||||
@@ -452,90 +474,101 @@ void Mixer_destroy(struct Mixer *mixer) {
|
||||
free(mixer);
|
||||
}
|
||||
|
||||
void initXWin(int argc, char **argv)
|
||||
{
|
||||
winsize=astep ? ASTEPSIZE : NORMSIZE;
|
||||
void Selem_destroy() {
|
||||
int i;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
for (i = 0; i < mix->devices_no; i++) {
|
||||
free(selems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void freeXWin()
|
||||
{
|
||||
XDestroyWindow(d_display, w_main);
|
||||
if (wmaker)
|
||||
XDestroyWindow(d_display, w_icon);
|
||||
XCloseDisplay(d_display);
|
||||
|
||||
void initXWin(int argc, char **argv) {
|
||||
bool pos;
|
||||
winsize = astep ? ASTEPSIZE : NORMSIZE;
|
||||
XWMHints wmhints;
|
||||
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)
|
||||
{
|
||||
XClassHint classHint;
|
||||
*win=XCreateSimpleWindow(d_display, w_root, x, y, winsize, winsize, 0, 0, 0);
|
||||
classHint.res_name=NAME;
|
||||
classHint.res_class=CLASS;
|
||||
XSetClassHint(d_display, *win, &classHint);
|
||||
void freeXWin() {
|
||||
XDestroyWindow(d_display, w_main);
|
||||
if (wmaker)
|
||||
XDestroyWindow(d_display, w_icon);
|
||||
XCloseDisplay(d_display);
|
||||
}
|
||||
|
||||
unsigned long mixColor(char *colorname1, int prop1, char *colorname2, int prop2)
|
||||
{
|
||||
XColor color, color1, color2;
|
||||
XWindowAttributes winattr;
|
||||
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 createWin(Window *win, int x, int y) {
|
||||
XClassHint classHint;
|
||||
*win = XCreateSimpleWindow(d_display, w_root, x, y, winsize, winsize, 0,
|
||||
0, 0);
|
||||
classHint.res_name = NAME;
|
||||
classHint.res_class = CLASS;
|
||||
XSetClassHint(d_display, *win, &classHint);
|
||||
}
|
||||
|
||||
unsigned long mixColor(char *colorname1, int prop1, char *colorname2,
|
||||
int prop2) {
|
||||
XColor color, color1, color2;
|
||||
XWindowAttributes winattr;
|
||||
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) {
|
||||
@@ -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", ¤t);
|
||||
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) {
|
||||
int nl = Mixer_read_left(curchannel);
|
||||
int nr = Mixer_read_right(curchannel);
|
||||
@@ -721,14 +673,14 @@ void checkVol(bool forced) {
|
||||
if (nl != curleft) {
|
||||
curleft = nl;
|
||||
if (selems[curchannel]->stereo)
|
||||
drawLeft();
|
||||
drawStereo(true);
|
||||
else
|
||||
drawMono();
|
||||
}
|
||||
if (nr != curright) {
|
||||
curright = nr;
|
||||
if (selems[curchannel]->stereo)
|
||||
drawRight();
|
||||
drawStereo(false);
|
||||
else
|
||||
drawMono();
|
||||
}
|
||||
@@ -745,12 +697,12 @@ void pressEvent(XButtonEvent *xev) {
|
||||
if (xev->button == Button4 || xev->button == Button5) {
|
||||
if (xev->button == Button4)
|
||||
inc = 4;
|
||||
else
|
||||
else
|
||||
inc = -4;
|
||||
|
||||
Mixer_set_left(curchannel,
|
||||
Mixer_set_left(curchannel,
|
||||
CLAMP(Mixer_read_left(curchannel) + inc, 0, 100));
|
||||
Mixer_set_right(curchannel,
|
||||
Mixer_set_right(curchannel,
|
||||
CLAMP(Mixer_read_right(curchannel) + inc, 0, 100));
|
||||
checkVol(false);
|
||||
return;
|
||||
@@ -801,27 +753,26 @@ void releaseEvent() {
|
||||
repaint();
|
||||
}
|
||||
|
||||
void motionEvent(XMotionEvent *xev)
|
||||
{
|
||||
int x=xev->x-(winsize/2-32);
|
||||
int y=xev->y-(winsize/2-32);
|
||||
if (x>=37 && x<=56 && y>=8 && dragging ) {
|
||||
int v=((60-y)*100)/(2*25);
|
||||
if (v<0)
|
||||
v=0;
|
||||
if (x<=50)
|
||||
Mixer_set_left(curchannel, v);
|
||||
if (x>=45)
|
||||
Mixer_set_right(curchannel, v);
|
||||
checkVol(false);
|
||||
}
|
||||
void motionEvent(XMotionEvent *xev) {
|
||||
int x = xev->x - (winsize / 2 - 32);
|
||||
int y = xev->y - (winsize / 2 - 32);
|
||||
if (x >= 37 && x <= 56 && y >= 8 && dragging) {
|
||||
int v = ((60 - y) * 100) / (2 * 25);
|
||||
if (v < 0)
|
||||
v = 0;
|
||||
if (x <= 50)
|
||||
Mixer_set_left(curchannel, v);
|
||||
if (x >= 45)
|
||||
Mixer_set_right(curchannel, v);
|
||||
checkVol(false);
|
||||
}
|
||||
}
|
||||
|
||||
void repaint()
|
||||
{
|
||||
XCopyArea(d_display, pm_disp, w_activewin, gc_gc, 0, 0, 64, 64, winsize/2-32, winsize/2-32);
|
||||
XEvent xev;
|
||||
while(XCheckTypedEvent(d_display, Expose, &xev));
|
||||
void repaint() {
|
||||
XCopyArea(d_display, pm_disp, w_activewin, gc_gc, 0, 0, 64, 64,
|
||||
winsize / 2 - 32, winsize / 2 - 32);
|
||||
XEvent xev;
|
||||
while(XCheckTypedEvent(d_display, Expose, &xev));
|
||||
}
|
||||
|
||||
void update() {
|
||||
@@ -830,8 +781,8 @@ void update() {
|
||||
XCopyArea(d_display, pm_icon, pm_disp, gc_gc,
|
||||
selems[curchannel]->iconIndex * 26, 0, 26, 24, 5, 19);
|
||||
if (selems[curchannel]->stereo) {
|
||||
drawLeft();
|
||||
drawRight();
|
||||
drawStereo(true);
|
||||
drawStereo(false);
|
||||
} else {
|
||||
drawMono();
|
||||
}
|
||||
@@ -878,63 +829,51 @@ void drawVolLevel() {
|
||||
}
|
||||
}
|
||||
|
||||
void drawLeft() {
|
||||
void drawStereo(bool left) {
|
||||
int i;
|
||||
XSetForeground(d_display, gc_gc, color[0]);
|
||||
XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49);
|
||||
short pos = left? 37 : 48;
|
||||
|
||||
XSetForeground(d_display, gc_gc, color[1]);
|
||||
for (i = 0; i < 25; i++) {
|
||||
if (i==(curleft*25)/100)
|
||||
XSetForeground(d_display, gc_gc, color[3]);
|
||||
XFillRectangle(d_display, pm_disp, gc_gc, 37, 55-2*i, 9, 1);
|
||||
}
|
||||
XSetForeground(d_display, gc_gc, color[0]);
|
||||
XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49);
|
||||
|
||||
XSetForeground(d_display, gc_gc, color[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;
|
||||
XSetForeground(d_display, gc_gc, color[0]);
|
||||
XFillRectangle(d_display, pm_disp, gc_gc, 46, 7, 2, 49);
|
||||
|
||||
XSetForeground(d_display, gc_gc, color[1]);
|
||||
for (i=0;i<25;i++) {
|
||||
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);
|
||||
}
|
||||
XSetForeground(d_display, gc_gc, color[1]);
|
||||
for (i = 0; i < 25; i++) {
|
||||
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 drawMono()
|
||||
{
|
||||
int i;
|
||||
XSetForeground(d_display, gc_gc, color[1]);
|
||||
for (i=0;i<25;i++ ) {
|
||||
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 drawBtns(int btns) {
|
||||
if (btns & BTNPREV)
|
||||
drawBtn(5, 47, 13, 11, (btnstate & BTNPREV));
|
||||
if (btns & BTNNEXT)
|
||||
drawBtn(18, 47, 13, 11, (btnstate & BTNNEXT));
|
||||
}
|
||||
|
||||
|
||||
void drawBtns(int btns)
|
||||
{
|
||||
if (btns & BTNPREV)
|
||||
drawBtn(5, 47, 13, 11, (btnstate & BTNPREV));
|
||||
if (btns & BTNNEXT)
|
||||
drawBtn(18, 47, 13, 11, (btnstate & BTNNEXT));
|
||||
}
|
||||
|
||||
void drawBtn(int x, int y, int w, int h, bool down)
|
||||
{
|
||||
if (!down)
|
||||
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 drawBtn(int x, int y, int w, int h, bool down) {
|
||||
if (!down) {
|
||||
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() {
|
||||
|
||||
@@ -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
|
||||
22
wmamixer.h
22
wmamixer.h
@@ -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) 2003 Damian Kramer <psiren@hibernaculum.net>
|
||||
// Copyright (C) 1998 Sam Hawker <shawkie@geocities.com>
|
||||
@@ -121,7 +121,6 @@ int rpttimer = 0;
|
||||
bool dragging = false;
|
||||
|
||||
int channel[32];
|
||||
int icon[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
struct Selem {
|
||||
char *name;
|
||||
@@ -134,7 +133,6 @@ struct Selem {
|
||||
long max;
|
||||
bool capture;
|
||||
snd_mixer_selem_channel_id_t channels[2];
|
||||
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -144,17 +142,20 @@ typedef struct {
|
||||
} slideCaptureMono;
|
||||
|
||||
struct NamesCount {
|
||||
short int pcm, line, lineb, mic, micb, capt, vol;
|
||||
} namesCount = {1, 1, 1, 1, 1, 1, 1};
|
||||
short int pcm, line, lineb, mic, micb, capt, vol, aux;
|
||||
} 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 {
|
||||
int devices_no;
|
||||
snd_mixer_t * handle;
|
||||
void *elems[32];
|
||||
};
|
||||
|
||||
struct Mixer *mix;
|
||||
|
||||
static int smixer_level = 0;
|
||||
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 drawBtn(int x, int y, int w, int h, bool down);
|
||||
void drawBtns(int btns);
|
||||
void drawLeft();
|
||||
void drawStereo(bool left);
|
||||
void drawMono();
|
||||
void drawRight();
|
||||
void drawText(char *text);
|
||||
void drawVolLevel();
|
||||
void motionEvent(XMotionEvent *xev);
|
||||
void pressEvent(XButtonEvent *xev);
|
||||
void readFile();
|
||||
void releaseEvent();
|
||||
void repaint();
|
||||
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_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 */
|
||||
|
||||
Reference in New Issue
Block a user