1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

mixer: convert to generic object payload

This commit is contained in:
Phil Sutter 2009-10-06 21:48:26 +02:00
parent c45decda5e
commit dd36fc4caa
6 changed files with 95 additions and 57 deletions

View File

@ -1581,30 +1581,27 @@ void generate_text_internal(char *p, int p_max_size,
#endif /* X11 */ #endif /* X11 */
/* mixer stuff */ /* mixer stuff */
OBJ(mixer) { OBJ(mixer) {
percent_print(p, p_max_size, mixer_get_avg(obj->data.l)); print_mixer(obj, 0, p, p_max_size);
} }
OBJ(mixerl) { OBJ(mixerl) {
percent_print(p, p_max_size, mixer_get_left(obj->data.l)); print_mixer(obj, -1, p, p_max_size);
} }
OBJ(mixerr) { OBJ(mixerr) {
percent_print(p, p_max_size, mixer_get_right(obj->data.l)); print_mixer(obj, 1, p, p_max_size);
} }
#ifdef X11 #ifdef X11
OBJ(mixerbar) { OBJ(mixerbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h, print_mixer_bar(obj, 0, p);
mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
} }
OBJ(mixerlbar) { OBJ(mixerlbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h, print_mixer_bar(obj, -1, p);
mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
} }
OBJ(mixerrbar) { OBJ(mixerrbar) {
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h, print_mixer_bar(obj, 1, p);
mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
} }
#endif /* X11 */ #endif /* X11 */
OBJ(if_mixer_mute) { OBJ(if_mixer_mute) {
if (!mixer_is_mute(obj->data.ifblock.i)) { if (!check_mixer_muted(obj)) {
DO_JUMP; DO_JUMP;
} }
} }

View File

@ -726,27 +726,21 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
if (buf) free(buf); if (buf) free(buf);
#endif /* X11*/ #endif /* X11*/
END OBJ(mixer, 0) END OBJ(mixer, 0)
obj->data.l = mixer_init(arg); parse_mixer_arg(obj, arg);
END OBJ(mixerl, 0) END OBJ(mixerl, 0)
obj->data.l = mixer_init(arg); parse_mixer_arg(obj, arg);
END OBJ(mixerr, 0) END OBJ(mixerr, 0)
obj->data.l = mixer_init(arg); parse_mixer_arg(obj, arg);
#ifdef X11 #ifdef X11
END OBJ(mixerbar, 0) END OBJ(mixerbar, 0)
SIZE_DEFAULTS(bar); scan_mixer_bar(obj, arg);
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
&obj->data.mixerbar.h);
END OBJ(mixerlbar, 0) END OBJ(mixerlbar, 0)
SIZE_DEFAULTS(bar); scan_mixer_bar(obj, arg);
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
&obj->data.mixerbar.h);
END OBJ(mixerrbar, 0) END OBJ(mixerrbar, 0)
SIZE_DEFAULTS(bar); scan_mixer_bar(obj, arg);
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
&obj->data.mixerbar.h);
#endif #endif
END OBJ_IF(if_mixer_mute, 0) END OBJ_IF(if_mixer_mute, 0)
obj->data.ifblock.i = mixer_init(arg); parse_mixer_arg(obj, arg);
#ifdef X11 #ifdef X11
END OBJ(monitor, &update_x11info) END OBJ(monitor, &update_x11info)
END OBJ(monitor_number, &update_x11info) END OBJ(monitor_number, &update_x11info)

View File

@ -42,10 +42,6 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
void free_text_objects(struct text_object *root, int internal); void free_text_objects(struct text_object *root, int internal);
#ifdef X11
void scan_mixer_bar(const char *arg, int *a, int *w, int *h);
#endif /* X11 */
const char *dev_name(const char *); const char *dev_name(const char *);
#endif /* _CONKY_CORE_H_ */ #endif /* _CONKY_CORE_H_ */

View File

@ -31,6 +31,7 @@
#include "conky.h" #include "conky.h"
#include "logging.h" #include "logging.h"
#include "specials.h" #include "specials.h"
#include "text_object.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@ -174,7 +175,7 @@ int mixer_init (const char *name)
snd_mixer_selem_get_playback_volume_range(data.elem, &data.vol_min, &data.vol_max); snd_mixer_selem_get_playback_volume_range(data.elem, &data.vol_min, &data.vol_max);
return i; return i;
} }
int mixer_get_avg (int i) static int mixer_get_avg (int i)
{ {
long val; long val;
@ -182,12 +183,12 @@ int mixer_get_avg (int i)
snd_mixer_selem_get_playback_volume (data.elem, 0, &val); snd_mixer_selem_get_playback_volume (data.elem, 0, &val);
return (int) val; return (int) val;
} }
int mixer_get_left (int i) static int mixer_get_left (int i)
{ {
/* stub */ /* stub */
return mixer_get_avg (i); return mixer_get_avg (i);
} }
int mixer_get_right (int i) static int mixer_get_right (int i)
{ {
/* stub */ /* stub */
return mixer_get_avg (i); return mixer_get_avg (i);
@ -254,19 +255,19 @@ static int mixer_get(int i)
return val; return val;
} }
int mixer_get_avg(int i) static int mixer_get_avg(int i)
{ {
int v = mixer_get(i); int v = mixer_get(i);
return ((v >> 8) + (v & 0xFF)) / 2; return ((v >> 8) + (v & 0xFF)) / 2;
} }
int mixer_get_left(int i) static int mixer_get_left(int i)
{ {
return mixer_get(i) >> 8; return mixer_get(i) >> 8;
} }
int mixer_get_right(int i) static int mixer_get_right(int i)
{ {
return mixer_get(i) & 0xFF; return mixer_get(i) & 0xFF;
} }
@ -275,21 +276,81 @@ int mixer_is_mute(int i)
return !mixer_get(i); return !mixer_get(i);
} }
#define mixer_to_255(i, x) x
#endif /* MIXER_IS_ALSA */ #endif /* MIXER_IS_ALSA */
void parse_mixer_arg(struct text_object *obj, const char *arg)
{
obj->data.l = mixer_init(arg);
}
/* chan specifies the channel to print:
* -1 := left channel
* 0 := channel average
* 1 := right channel
*/
void print_mixer(struct text_object *obj, int chan, char *p, int p_max_size)
{
int val;
if (chan < 0)
val = mixer_get_left(obj->data.l);
else if (chan == 0)
val = mixer_get_avg(obj->data.l);
else
val = mixer_get_right(obj->data.l);
percent_print(p, p_max_size, val);
}
int check_mixer_muted(struct text_object *obj)
{
if (!mixer_is_mute(obj->data.l))
return 0;
return 1;
}
#ifdef X11 #ifdef X11
void scan_mixer_bar(const char *arg, int *a, int *w, int *h) struct mixerbar_data {
int l;
int w, h;
};
void scan_mixer_bar(struct text_object *obj, const char *arg)
{ {
char buf1[64]; char buf1[64];
struct mixerbar_data *mbd;
int n; int n;
mbd = malloc(sizeof(struct mixerbar_data));
memset(mbd, 0, sizeof(struct mixerbar_data));
if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) { if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
*a = mixer_init(buf1); mbd->l = mixer_init(buf1);
scan_bar(arg + n, w, h); scan_bar(arg + n, &mbd->w, &mbd->h);
} else { } else {
*a = mixer_init(NULL); mbd->l = mixer_init(NULL);
scan_bar(arg, w, h); scan_bar(arg, &mbd->w, &mbd->h);
} }
obj->data.opaque = mbd;
}
/* see print_mixer() above for a description of 'chan' */
void print_mixer_bar(struct text_object *obj, int chan, char *p)
{
struct mixerbar_data *mdp = obj->data.opaque;
int val;
if (!mdp)
return;
if (chan < 0)
val = mixer_get_left(mdp->l);
else if (chan == 0)
val = mixer_get_avg(mdp->l);
else
val = mixer_get_right(mdp->l);
new_bar(p, mdp->w, mdp->h, mixer_to_255(mdp->l, val));
} }
#endif /* X11 */ #endif /* X11 */

View File

@ -3,17 +3,13 @@
#ifndef MIXER_H_ #ifndef MIXER_H_
#define MIXER_H_ #define MIXER_H_
void parse_mixer_arg(struct text_object *, const char *);
void print_mixer(struct text_object *, int, char *, int);
int check_mixer_muted(struct text_object *);
#ifdef MIXER_IS_ALSA #ifdef X11
int mixer_to_255(int, int); void scan_mixer_bar(struct text_object *, const char *);
#else void print_mixer_bar(struct text_object *, int, char *);
#define mixer_to_255(l,x) x #endif /* X11 */
#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_*/ #endif /*MIXER_H_*/

View File

@ -454,14 +454,8 @@ struct text_object {
char *output; char *output;
} mboxscan; } mboxscan;
#ifdef X11
struct {
int l;
int w, h;
} mixerbar; /* 3 */
#endif
struct { struct {
void *opaque; /* temporary workaround to not blow stuff */
struct text_object *next; struct text_object *next;
char *s; char *s;
int i; int i;