1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 10:35:10 +00:00

Make ALSA mixers available on Linux, and added $if_mixer_mute.

This commit is contained in:
Jérôme Plût 2009-04-28 10:56:49 -06:00 committed by Brenden Matthews
parent 2dfc0ee6b4
commit ff9154216b
9 changed files with 326 additions and 100 deletions

View File

@ -1,5 +1,7 @@
2009-04-28
* Various XMMS2 updates (thanks Lassi)
* Make ALSA mixers available on Linux, and added $if_mixer_mute (thanks
Jérôme)
2009-04-19
* Make it possible to place spaces in front of RSS-items as a workaround

198
README
View File

@ -1072,9 +1072,14 @@ conky(1) conky(1)
Valid operands are: '>', '<', '>=', '<=', '==', '!='.
if_mixer_mute (mixer)
If mixer exists, display everything between $if_mixer_mute and
the matching $endif. If no mixer is specified, "Master" is used.
if_running (process)
if PROCESS is running, display everything $if_running and the
matching $endif. This uses the ``pidof'' command, so the -x
if PROCESS is running, display everything $if_running and the
matching $endif. This uses the ``pidof'' command, so the -x
switch is also supported.
@ -1084,8 +1089,8 @@ conky(1) conky(1)
if_smapi_bat_installed (INDEX)
when using smapi, if the battery with index INDEX is installed,
display everything between $if_smapi_bat_installed and the
when using smapi, if the battery with index INDEX is installed,
display everything between $if_smapi_bat_installed and the
matching $endif
@ -1095,17 +1100,17 @@ conky(1) conky(1)
if_updatenr (updatenr)
If it's the UPDATENR-th time that conky updates, display every
If it's the UPDATENR-th time that conky updates, display every
thing between $if_updatenr and the matching $endif. The counter
resets when the highest UPDATENR is reached. Example :
resets when the highest UPDATENR is reached. Example :
"{$if_updatenr 1}foo$endif{$if_updatenr 2}bar$endif{$if_updatenr
4}$endif" shows foo 25% of the time followed by bar 25% of the
4}$endif" shows foo 25% of the time followed by bar 25% of the
time followed by nothing the other half of the time.
imap_messages (args)
Displays the number of messages in your global IMAP inbox by de
fault. You can define individual IMAP inboxes seperately by
fault. You can define individual IMAP inboxes seperately by
passing arguments to this object. Arguments are: "host user pass
[-i interval] [-p port] [-e command] [-r retries]". Default port
is 143, default interval is 5 minutes, and default number of re
@ -1124,7 +1129,7 @@ conky(1) conky(1)
ioscheduler disk
Prints the current ioscheduler used for the given disk name
Prints the current ioscheduler used for the given disk name
(i.e. e.g. "hda" or "sdb")
@ -1142,8 +1147,8 @@ conky(1) conky(1)
loadgraph ("normal"|"log") (height),(width) (gradient colour 1) (gradi
ent colour 2) (scale)
Load1 average graph, similar to xload, with optional colours in
hex, minus the #. Uses a logarithmic scale (to see small num
Load1 average graph, similar to xload, with optional colours in
hex, minus the #. Uses a logarithmic scale (to see small num
bers) when you use "log" instead of "normal".
@ -1156,9 +1161,9 @@ conky(1) conky(1)
mails (mailbox) (interval)
Mail count in the specified mailbox or your mail spool if not.
Both mbox and maildir type mailboxes are supported. You can use
a program like fetchmail to get mails from some server using
Mail count in the specified mailbox or your mail spool if not.
Both mbox and maildir type mailboxes are supported. You can use
a program like fetchmail to get mails from some server using
your favourite protocol. See also new_mails.
@ -1168,32 +1173,32 @@ conky(1) conky(1)
seen_mails (maildir) (interval)
Number of mails marked as seen in the specified mailbox or mail
spool if not. Only maildir type mailboxes are supported, mbox
Number of mails marked as seen in the specified mailbox or mail
spool if not. Only maildir type mailboxes are supported, mbox
type will return -1.
unseen_mails (maildir) (interval)
Number of new or unseen mails in the specified mailbox or mail
spool if not. Only maildir type mailboxes are supported, mbox
Number of new or unseen mails in the specified mailbox or mail
spool if not. Only maildir type mailboxes are supported, mbox
type will return -1.
flagged_mails (maildir) (interval)
Number of mails marked as flagged in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
Number of mails marked as flagged in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
unflagged_mails (maildir) (interval)
Number of mails not marked as flagged in the specified mailbox
Number of mails not marked as flagged in the specified mailbox
or mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
forwarded_mails (maildir) (interval)
Number of mails marked as forwarded in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
Number of mails marked as forwarded in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
@ -1204,33 +1209,33 @@ conky(1) conky(1)
replied_mails (maildir) (interval)
Number of mails marked as replied in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
Number of mails marked as replied in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
unreplied_mails (maildir) (interval)
Number of mails not marked as replied in the specified mailbox
Number of mails not marked as replied in the specified mailbox
or mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
draft_mails (maildir) (interval)
Number of mails marked as draft in the specified mailbox or mail
spool if not. Only maildir type mailboxes are supported, mbox
spool if not. Only maildir type mailboxes are supported, mbox
type will return -1.
trashed_mails (maildir) (interval)
Number of mails marked as trashed in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
Number of mails marked as trashed in the specified mailbox or
mail spool if not. Only maildir type mailboxes are supported,
mbox type will return -1.
mboxscan (-n number of messages to print) (-fw from width) (-sw subject
width) mbox
Print a summary of recent messages in an mbox format mailbox.
mbox parameter is the filename of the mailbox (can be encapsu
Print a summary of recent messages in an mbox format mailbox.
mbox parameter is the filename of the mailbox (can be encapsu
lated using '"', ie. ${mboxscan -n 10 "/home/brenden/some box"}
@ -1245,14 +1250,14 @@ conky(1) conky(1)
Gauge that shows amount of memory in use (see cpugauge)
memgraph ("normal"|"log") (height),(width) (gradient colour 1) (gradi
memgraph ("normal"|"log") (height),(width) (gradient colour 1) (gradi
ent colour 2) (scale)
Memory usage graph. Uses a logarithmic scale (to see small num
Memory usage graph. Uses a logarithmic scale (to see small num
bers) when you use "log" instead of "normal".
memeasyfree
Amount of free memory including the memory that is very easily
Amount of free memory including the memory that is very easily
freed (buffers/cache)
@ -1268,39 +1273,39 @@ conky(1) conky(1)
mixer (device)
Prints the mixer value as reported by the OS. Default mixer is
"vol", but you can specify one of the following optional argu
Prints the mixer value as reported by the OS. Default mixer is
"vol", but you can specify one of the following optional argu
ments: "vol", "bass", "treble", "synth", "pcm", "speaker",
"line", "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain",
"line", "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain",
"line1", "line2", "line3", "dig1", "dig2", "dig3", "phin",
"phout", "video", "radio", "monitor". Refer to the definition of
SOUND_DEVICE_NAMES in <linux/soundcard.h> (on Linux), <sound
SOUND_DEVICE_NAMES in <linux/soundcard.h> (on Linux), <sound
card.h> (on OpenBSD), or <sys/soundcard.h> to find the exact op
tions available on your system.
mixerbar (device)
Displays mixer value in a bar as reported by the OS. See docs
Displays mixer value in a bar as reported by the OS. See docs
for $mixer for details on arguments.
mixerr (device)
Prints the right channel mixer value as reported by the OS. See
Prints the right channel mixer value as reported by the OS. See
docs for $mixer for details on arguments.
mixerrbar (device)
Displays the right channel mixer value in a bar as reported by
Displays the right channel mixer value in a bar as reported by
the OS. See docs for $mixer for details on arguments.
mixerl (device)
Prints the left channel mixer value as reported by the OS. See
Prints the left channel mixer value as reported by the OS. See
docs for $mixer for details on arguments.
mixerlbar (device)
Displays the left channel mixer value in a bar as reported by
Displays the left channel mixer value in a bar as reported by
the OS. See docs for $mixer for details on arguments.
@ -1422,12 +1427,12 @@ conky(1) conky(1)
if_mpd_playing
if mpd is playing or paused, display everything between
if mpd is playing or paused, display everything between
$if_mpd_playing and the matching $endif
nameserver (index)
Print a nameserver from /etc/resolv.conf. Index starts at and
Print a nameserver from /etc/resolv.conf. Index starts at and
defaults to 0.
@ -1436,8 +1441,8 @@ conky(1) conky(1)
nvidia threshold temp ambient gpufreq memfreq imagequality
Nvidia graficcard support for the XNVCtrl library. Each option
can be shortened to the least significant part. Temperatures
Nvidia graficcard support for the XNVCtrl library. Each option
can be shortened to the least significant part. Temperatures
are printed as float, all other values as integer.
threshold: the thresholdtemperature at which the gpu slows down
@ -1455,25 +1460,25 @@ conky(1) conky(1)
pb_battery item
If running on Apple powerbook/ibook, display information on bat
tery status. The item parameter specifies, what information to
tery status. The item parameter specifies, what information to
display. Exactly one item must be specified. Valid items are:
status: Display if battery is fully charged, charging, discharg
ing or absent (running on AC)
percent: Display charge of battery in percent, if charging or
discharging. Nothing will be displayed, if battery is fully
percent: Display charge of battery in percent, if charging or
discharging. Nothing will be displayed, if battery is fully
charged or absent.
time: Display the time remaining until the battery will be fully
charged or discharged at current rate. Nothing is displayed, if
battery is absent or if it's present but fully charged and not
charged or discharged at current rate. Nothing is displayed, if
battery is absent or if it's present but fully charged and not
discharging.
platform (dev) type n
Platform sensor from sysfs (Linux 2.6). Parameter dev may be
omitted if you have only one platform device. Platform type is
either 'in' or 'vol' meaning voltage; 'fan' meaning fan; 'temp'
meaning temperature. Parameter n is number of the sensor. See
Platform sensor from sysfs (Linux 2.6). Parameter dev may be
omitted if you have only one platform device. Platform type is
either 'in' or 'vol' meaning voltage; 'fan' meaning fan; 'temp'
meaning temperature. Parameter n is number of the sensor. See
/sys/bus/platform/devices/ on your local computer.
@ -1488,13 +1493,13 @@ conky(1) conky(1)
pop3_used (args)
Displays the amount of space (in MiB, 2^20) used in your global
POP3 inbox by default. You can define individual POP3 inboxes
seperately by passing arguments to this object. Arguments are:
"host user pass [-i interval] [-p port] [-e command] [-r re
Displays the amount of space (in MiB, 2^20) used in your global
POP3 inbox by default. You can define individual POP3 inboxes
seperately by passing arguments to this object. Arguments are:
"host user pass [-i interval] [-p port] [-e command] [-r re
tries]". Default port is 110, default interval is 5 minutes, and
default number of retries before giving up is 5. If the password
is supplied as '*', you will be prompted to enter the password
is supplied as '*', you will be prompted to enter the password
when Conky starts.
@ -1512,14 +1517,14 @@ conky(1) conky(1)
scroll length (step) text
Scroll 'text' by 'step' characters showing 'length' number of
characters at the same time. The text may also contain vari
Scroll 'text' by 'step' characters showing 'length' number of
characters at the same time. The text may also contain vari
ables. 'step' is optional and defaults to 1 if not set. If a var
creates output on multiple lines then the lines are placed be
hind each other separated with a '|'-sign. Do NOT use vars that
change colors or otherwise affect the design inside a scrolling
text. If you want spaces between the start and the end of
'text', place them at the end of 'text' not at the front ("foo
creates output on multiple lines then the lines are placed be
hind each other separated with a '|'-sign. Do NOT use vars that
change colors or otherwise affect the design inside a scrolling
text. If you want spaces between the start and the end of
'text', place them at the end of 'text' not at the front ("foo
bar" and " foobar" can both generate "barfoo" but "foobar " will
keep the spaces like this "bar foo").
@ -1529,35 +1534,35 @@ conky(1) conky(1)
smapi (ARGS)
when using smapi, display contents of the /sys/devices/plat
form/smapi directory. ARGS are either '(FILENAME)' or 'bat (IN
DEX) (FILENAME)' to display the corresponding files' content.
This is a very raw method of accessing the smapi values. When
when using smapi, display contents of the /sys/devices/plat
form/smapi directory. ARGS are either '(FILENAME)' or 'bat (IN
DEX) (FILENAME)' to display the corresponding files' content.
This is a very raw method of accessing the smapi values. When
available, better use one of the smapi_* variables instead.
smapi_bat_bar (INDEX),(height),(width)
when using smapi, display the remaining capacity of the battery
when using smapi, display the remaining capacity of the battery
with index INDEX as a bar.
smapi_bat_perc (INDEX)
when using smapi, display the remaining capacity in percent of
the battery with index INDEX. This is a separate variable be
when using smapi, display the remaining capacity in percent of
the battery with index INDEX. This is a separate variable be
cause it supports the 'use_spacer' configuration option.
smapi_bat_power INDEX
when using smapi, display the current power of the battery with
index INDEX in watt. This is a separate variable because the
original read out value is being converted from mW. The sign of
the output reflects charging (positive) or discharging (nega
when using smapi, display the current power of the battery with
index INDEX in watt. This is a separate variable because the
original read out value is being converted from mW. The sign of
the output reflects charging (positive) or discharging (nega
tive) state.
smapi_bat_temp INDEX
when using smapi, display the current temperature of the battery
with index INDEX in degree Celsius. This is a separate variable
with index INDEX in degree Celsius. This is a separate variable
because the original read out value is being converted from mil
li degree Celsius.
@ -1602,36 +1607,36 @@ conky(1) conky(1)
The connection index provides you with access to each connection
in the port monitor. The monitor will return information for in
dex values from 0 to n-1 connections. Values higher than n-1 are
simply ignored. For the "count" item, the connection index must
simply ignored. For the "count" item, the connection index must
be omitted. It is required for all other items.
Examples:
${tcp_portmon 6881 6999 count} - displays the number of connec
${tcp_portmon 6881 6999 count} - displays the number of connec
tions in the bittorrent port range
${tcp_portmon 22 22 rip 0} - displays the remote host ip of the
${tcp_portmon 22 22 rip 0} - displays the remote host ip of the
first sshd connection
${tcp_portmon 22 22 rip 9} - displays the remote host ip of the
${tcp_portmon 22 22 rip 9} - displays the remote host ip of the
tenth sshd connection
${tcp_portmon 1 1024 rhost 0} - displays the remote host name of
the first connection on a privileged port
${tcp_portmon 1 1024 rport 4} - displays the remote host port of
the fifth connection on a privileged port
${tcp_portmon 1 65535 lservice 14} - displays the local service
${tcp_portmon 1 65535 lservice 14} - displays the local service
name of the fifteenth connection in the range of all ports
Note that port monitor variables which share the same port range
actually refer to the same monitor, so many references to a sin
gle port range for different items and different indexes all use
the same monitor internally. In other words, the program avoids
the same monitor internally. In other words, the program avoids
creating redundant monitors.
texeci interval command
Runs a command at an interval inside a thread and displays the
output. Same as $execi, except the command is run inside a
thread. Use this if you have a slow script to keep Conky updat
ing. You should make the interval slightly longer then the time
it takes your script to execute. For example, if you have a
script that take 5 seconds to execute, you should make the in
Runs a command at an interval inside a thread and displays the
output. Same as $execi, except the command is run inside a
thread. Use this if you have a slow script to keep Conky updat
ing. You should make the interval slightly longer then the time
it takes your script to execute. For example, if you have a
script that take 5 seconds to execute, you should make the in
terval at least 6 seconds. See also $execi.
@ -1639,10 +1644,11 @@ conky(1) conky(1)
Move text over by N pixels. See also $voffset.
rss url delay_in_minutes action item_num
Download and parse RSS feeds. Action may be one of the follow
ing: feed_title, item_title (with num par), item_desc (with num
par) and item_titles.
rss url delay_in_minutes action (num_par (spaces_in_front))
Download and parse RSS feeds. Action may be one of the follow
ing: feed_title, item_title (with num par), item_desc (with num
par) and item_titles (when using this action and spaces_in_front
is given conky places that many spaces in front of each item).
tab (width, (start))

View File

@ -546,11 +546,28 @@ if test x$WANT_OSSLIB = xyes; then
)
fi
dnl
dnl ALSA for Linux
dnl
AC_ARG_ENABLE([alsa],
AC_HELP_STRING([--disable-alsa], [disable if you do not
want ALSA support @<:@default=yes@:>@]),
[want_alsa="$enableval"], [want_alsa=yes])
if test x$want_alsa = xyes; then
AC_CHECK_HEADER(alsa/asoundlib.h,, want_alsa=no)
fi
if test x$want_alsa = xyes; then
AC_CHECK_LIB(asound, snd_pcm_open,LIBS="$LIBS -lasound", want_alsa=no)
fi
if test x$want_alsa = xyes; then
AC_DEFINE(MIXER_IS_ALSA, 1, [Define if the mixers use ALSA])
fi
dnl
dnl Some headers
dnl
AC_CHECK_HEADERS([signal.h unistd.h sys/utsname.h sys/stat.h linux/soundcard.h dirent.h mcheck.h \
AC_CHECK_HEADERS([signal.h unistd.h sys/utsname.h sys/stat.h linux/soundcard.h alsa/asoundlib.h dirent.h mcheck.h \
sys/statfs.h sys/param.h pthread.h assert.h errno.h time.h])
AC_CHECK_HEADERS([sys/mount.h], [], [],
[#ifdef HAVE_SYS_PARAM_H
@ -733,4 +750,5 @@ $PACKAGE $VERSION configured successfully:
nvidia: $want_nvidia
eve-online: $want_eve
config-output: $want_config_output
ALSA mixer: $want_alsa
EOF

View File

@ -919,6 +919,11 @@ before.
Valid operands are:
\&'>', '<', '>=', '<=', '==', '!='.
.TP
\fB\*(T<\fBif_mixer_mute\fR\*(T>\fR \*(T<\fB(mixer)\fR\*(T>
If mixer exists, display everything between $if_mixer_mute and the
matching $endif. If no mixer is specified, "Master" is used.
.TP
\fB\*(T<\fBif_running\fR\*(T>\fR \*(T<\fB(process)\fR\*(T>
if PROCESS is running, display everything $if_running

View File

@ -1112,6 +1112,17 @@
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>if_mixer_mute</option></command>
<option>(mixer)</option>
</term>
<listitem>
If mixer exists, display everything between $if_mixer_mute and the
matching $endif. If no mixer is specified, "Master" is used.
<para></para></listitem>
</varlistentry>
<varlistentry>
<term>
<command><option>if_running</option></command>

View File

@ -210,6 +210,9 @@ static void print_version(void)
#ifdef CONFIG_OUTPUT
" * config-output\n"
#endif /* CONFIG_OUTPUT */
#ifdef MIXER_IS_ALSA
" * ALSA mixer support\n"
#endif /* MIXER_IS_ALSA */
);
exit(0);
@ -2099,6 +2102,8 @@ static struct text_object *construct_text_object(const char *s,
END OBJ(mixerrbar, INFO_MIXER)
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
&obj->data.mixerbar.h);
END OBJ_IF(if_mixer_mute, INFO_MIXER)
obj->data.ifblock.i = mixer_init(arg);
#ifdef X11
END OBJ(monitor, INFO_X11)
END OBJ(monitor_number, INFO_X11)
@ -4128,15 +4133,20 @@ static void generate_text_internal(char *p, int p_max_size,
}
OBJ(mixerbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
}
OBJ(mixerlbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
}
OBJ(mixerrbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
}
OBJ(if_mixer_mute) {
if (!mixer_is_mute(obj->data.ifblock.i)) {
DO_JUMP;
}
}
#ifdef X11
OBJ(monitor) {

View File

@ -30,8 +30,12 @@
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#ifdef MIXER_IS_ALSA
#include <alsa/asoundlib.h>
#else
#ifdef HAVE_LINUX_SOUNDCARD_H
#include <linux/soundcard.h>
#else
@ -41,12 +45,168 @@
#include <sys/soundcard.h>
#endif /* __OpenBSD__ */
#endif /* HAVE_LINUX_SOUNDCARD_H */
#endif /* MIXER_IS_ALSA */
#define MIXER_DEV "/dev/mixer"
#ifdef MIXER_IS_ALSA
#define MAX_MIXERS 8
struct mixer_control {
char name[64];
snd_mixer_t *mixer;
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t *elem;
long vol_min, vol_max;
};
static struct mixer_control mixer_data[MAX_MIXERS];
int num_mixers = 0;
static char soundcard[64] = "default";
#else
static int mixer_fd;
static const char *devs[] = SOUND_DEVICE_NAMES;
#endif
#ifdef MIXER_IS_ALSA
static int parse_simple_id(const char *str, snd_mixer_selem_id_t *sid)
{
int c, size;
char buf[128];
char *ptr = buf;
while (*str == ' ' || *str == '\t')
str++;
if (!(*str))
return -EINVAL;
size = 1; /* for '\0' */
if (*str != '"' && *str != '\'') {
while (*str && *str != ',') {
if (size < (int)sizeof(buf)) {
*ptr++ = *str;
size++;
}
str++;
}
} else {
c = *str++;
while (*str && *str != c) {
if (size < (int)sizeof(buf)) {
*ptr++ = *str;
size++;
}
str++;
}
if (*str == c)
str++;
}
if (*str == '\0') {
snd_mixer_selem_id_set_index(sid, 0);
*ptr = 0;
goto _set;
}
if (*str != ',')
return -EINVAL;
*ptr = 0; /* terminate the string */
str++;
if (!isdigit(*str))
return -EINVAL;
snd_mixer_selem_id_set_index(sid, atoi(str));
_set:
snd_mixer_selem_id_set_name(sid, buf);
return 0;
}
int mixer_init (const char *name)
{
/* from amixer.c, replaced -EINVAL with -1 */
int i, err;
if (!name)
name = "Master";
for (i = 0; i < num_mixers; i++) {
if (!strcasecmp (mixer_data[i].name, name)) {
return i;
}
}
if (i == MAX_MIXERS) {
fprintf (stderr, "max mixers (%d) reached\n", MAX_MIXERS);
return -1;
};
num_mixers++;
#define data mixer_data[i]
strncpy (mixer_data[i].name, name, 63);
mixer_data[i].name[63] = '\0';
snd_mixer_selem_id_alloca (&data.sid);
data.mixer = NULL;
if (parse_simple_id (name, data.sid) < 0) {
fprintf (stderr, "Wrong mixer identifier: %s\n", name);
return -1;
}
if ((err = snd_mixer_open (&data.mixer, 0)) < 0) {
fprintf (stderr, "snd_mixer_open: %s\n", snd_strerror (err));
return -1;
}
if ((err = snd_mixer_attach (data.mixer, soundcard)) < 0) {
fprintf (stderr, "snd_mixer_attach: %s\n", snd_strerror (err));
return -1;
}
if ((err = snd_mixer_selem_register (data.mixer, NULL, NULL)) < 0) {
fprintf (stderr, "snd_mixer_selem_register: %s\n",
snd_strerror (err));
return -1;
}
if ((err = snd_mixer_load (data.mixer)) < 0) {
fprintf (stderr, "snd_mixer_load: %s\n", snd_strerror (err));
return -1;
}
if (!(data.elem = snd_mixer_find_selem (data.mixer, data.sid))) {
fprintf (stderr, "snd_mixer_find_selem (\"%s\", %i)\n",
snd_mixer_selem_id_get_name (data.sid),
snd_mixer_selem_id_get_index (data.sid));
return -1;
}
snd_mixer_selem_get_playback_volume_range(data.elem, &data.vol_min, &data.vol_max);
return i;
}
int mixer_get_avg (int i)
{
long val;
snd_mixer_handle_events (data.mixer);
snd_mixer_selem_get_playback_volume (data.elem, 0, &val);
return (int) val;
}
int mixer_get_left (int i)
{
/* stub */
return mixer_get_avg (i);
}
int mixer_get_right (int i)
{
/* stub */
return mixer_get_avg (i);
}
int mixer_to_255(int i, int x)
{
return (x-data.vol_min)*255/(data.vol_max-data.vol_min);
}
int mixer_is_mute(int i)
{
snd_mixer_handle_events (data.mixer);
if (snd_mixer_selem_has_playback_switch (data.elem)) {
int val, err;
if ((err = snd_mixer_selem_get_playback_switch(data.elem, 0, &val)) < 0)
fprintf (stderr, "playback_switch: %s\n", snd_strerror (err));
return !val;
} else {
return !mixer_get_avg(i);
}
}
#undef data
#else
int mixer_init(const char *name)
{
unsigned int i;
@ -106,3 +266,8 @@ int mixer_get_right(int i)
{
return mixer_get(i) & 0xFF;
}
int mixer_is_mute(int i)
{
return !mixer_get(i);
}
#endif

View File

@ -1,9 +1,17 @@
#ifndef MIXER_H_
#define MIXER_H_
#ifdef MIXER_IS_ALSA
int mixer_to_255(int, int);
#else
#define mixer_to_255(l,x) x
#endif
int mixer_init(const char *);
int mixer_get_avg(int);
int mixer_get_left(int);
int mixer_get_right(int);
int mixer_is_mute(int);
#endif /*MIXER_H_*/

View File

@ -213,6 +213,7 @@ enum text_object_type {
OBJ_mixerbar,
OBJ_mixerlbar,
OBJ_mixerrbar,
OBJ_if_mixer_mute,
#ifdef X11
OBJ_monitor,
OBJ_monitor_number,