mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-05 21:07:52 +00:00
mixer: convert to generic object payload
This commit is contained in:
parent
c45decda5e
commit
dd36fc4caa
17
src/conky.c
17
src/conky.c
@ -1581,30 +1581,27 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
#endif /* X11 */
|
||||
/* mixer stuff */
|
||||
OBJ(mixer) {
|
||||
percent_print(p, p_max_size, mixer_get_avg(obj->data.l));
|
||||
print_mixer(obj, 0, p, p_max_size);
|
||||
}
|
||||
OBJ(mixerl) {
|
||||
percent_print(p, p_max_size, mixer_get_left(obj->data.l));
|
||||
print_mixer(obj, -1, p, p_max_size);
|
||||
}
|
||||
OBJ(mixerr) {
|
||||
percent_print(p, p_max_size, mixer_get_right(obj->data.l));
|
||||
print_mixer(obj, 1, p, p_max_size);
|
||||
}
|
||||
#ifdef X11
|
||||
OBJ(mixerbar) {
|
||||
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
||||
mixer_to_255(obj->data.mixerbar.l,mixer_get_avg(obj->data.mixerbar.l)));
|
||||
print_mixer_bar(obj, 0, p);
|
||||
}
|
||||
OBJ(mixerlbar) {
|
||||
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
||||
mixer_to_255(obj->data.mixerbar.l,mixer_get_left(obj->data.mixerbar.l)));
|
||||
print_mixer_bar(obj, -1, p);
|
||||
}
|
||||
OBJ(mixerrbar) {
|
||||
new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
|
||||
mixer_to_255(obj->data.mixerbar.l,mixer_get_right(obj->data.mixerbar.l)));
|
||||
print_mixer_bar(obj, 1, p);
|
||||
}
|
||||
#endif /* X11 */
|
||||
OBJ(if_mixer_mute) {
|
||||
if (!mixer_is_mute(obj->data.ifblock.i)) {
|
||||
if (!check_mixer_muted(obj)) {
|
||||
DO_JUMP;
|
||||
}
|
||||
}
|
||||
|
20
src/core.c
20
src/core.c
@ -726,27 +726,21 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
if (buf) free(buf);
|
||||
#endif /* X11*/
|
||||
END OBJ(mixer, 0)
|
||||
obj->data.l = mixer_init(arg);
|
||||
parse_mixer_arg(obj, arg);
|
||||
END OBJ(mixerl, 0)
|
||||
obj->data.l = mixer_init(arg);
|
||||
parse_mixer_arg(obj, arg);
|
||||
END OBJ(mixerr, 0)
|
||||
obj->data.l = mixer_init(arg);
|
||||
parse_mixer_arg(obj, arg);
|
||||
#ifdef X11
|
||||
END OBJ(mixerbar, 0)
|
||||
SIZE_DEFAULTS(bar);
|
||||
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
||||
&obj->data.mixerbar.h);
|
||||
scan_mixer_bar(obj, arg);
|
||||
END OBJ(mixerlbar, 0)
|
||||
SIZE_DEFAULTS(bar);
|
||||
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
||||
&obj->data.mixerbar.h);
|
||||
scan_mixer_bar(obj, arg);
|
||||
END OBJ(mixerrbar, 0)
|
||||
SIZE_DEFAULTS(bar);
|
||||
scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
|
||||
&obj->data.mixerbar.h);
|
||||
scan_mixer_bar(obj, arg);
|
||||
#endif
|
||||
END OBJ_IF(if_mixer_mute, 0)
|
||||
obj->data.ifblock.i = mixer_init(arg);
|
||||
parse_mixer_arg(obj, arg);
|
||||
#ifdef X11
|
||||
END OBJ(monitor, &update_x11info)
|
||||
END OBJ(monitor_number, &update_x11info)
|
||||
|
@ -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);
|
||||
|
||||
#ifdef X11
|
||||
void scan_mixer_bar(const char *arg, int *a, int *w, int *h);
|
||||
#endif /* X11 */
|
||||
|
||||
const char *dev_name(const char *);
|
||||
|
||||
#endif /* _CONKY_CORE_H_ */
|
||||
|
85
src/mixer.c
85
src/mixer.c
@ -31,6 +31,7 @@
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "specials.h"
|
||||
#include "text_object.h"
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.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);
|
||||
return i;
|
||||
}
|
||||
int mixer_get_avg (int i)
|
||||
static int mixer_get_avg (int i)
|
||||
{
|
||||
long val;
|
||||
|
||||
@ -182,12 +183,12 @@ int mixer_get_avg (int i)
|
||||
snd_mixer_selem_get_playback_volume (data.elem, 0, &val);
|
||||
return (int) val;
|
||||
}
|
||||
int mixer_get_left (int i)
|
||||
static int mixer_get_left (int i)
|
||||
{
|
||||
/* stub */
|
||||
return mixer_get_avg (i);
|
||||
}
|
||||
int mixer_get_right (int i)
|
||||
static int mixer_get_right (int i)
|
||||
{
|
||||
/* stub */
|
||||
return mixer_get_avg (i);
|
||||
@ -254,19 +255,19 @@ static int mixer_get(int i)
|
||||
return val;
|
||||
}
|
||||
|
||||
int mixer_get_avg(int i)
|
||||
static int mixer_get_avg(int i)
|
||||
{
|
||||
int v = mixer_get(i);
|
||||
|
||||
return ((v >> 8) + (v & 0xFF)) / 2;
|
||||
}
|
||||
|
||||
int mixer_get_left(int i)
|
||||
static int mixer_get_left(int i)
|
||||
{
|
||||
return mixer_get(i) >> 8;
|
||||
}
|
||||
|
||||
int mixer_get_right(int i)
|
||||
static int mixer_get_right(int i)
|
||||
{
|
||||
return mixer_get(i) & 0xFF;
|
||||
}
|
||||
@ -275,21 +276,81 @@ int mixer_is_mute(int i)
|
||||
return !mixer_get(i);
|
||||
}
|
||||
|
||||
#define mixer_to_255(i, x) x
|
||||
#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
|
||||
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];
|
||||
struct mixerbar_data *mbd;
|
||||
int n;
|
||||
|
||||
mbd = malloc(sizeof(struct mixerbar_data));
|
||||
memset(mbd, 0, sizeof(struct mixerbar_data));
|
||||
|
||||
if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
|
||||
*a = mixer_init(buf1);
|
||||
scan_bar(arg + n, w, h);
|
||||
mbd->l = mixer_init(buf1);
|
||||
scan_bar(arg + n, &mbd->w, &mbd->h);
|
||||
} else {
|
||||
*a = mixer_init(NULL);
|
||||
scan_bar(arg, w, h);
|
||||
mbd->l = mixer_init(NULL);
|
||||
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 */
|
||||
|
||||
|
18
src/mixer.h
18
src/mixer.h
@ -3,17 +3,13 @@
|
||||
#ifndef 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
|
||||
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);
|
||||
#ifdef X11
|
||||
void scan_mixer_bar(struct text_object *, const char *);
|
||||
void print_mixer_bar(struct text_object *, int, char *);
|
||||
#endif /* X11 */
|
||||
|
||||
#endif /*MIXER_H_*/
|
||||
|
@ -454,14 +454,8 @@ struct text_object {
|
||||
char *output;
|
||||
} mboxscan;
|
||||
|
||||
#ifdef X11
|
||||
struct {
|
||||
int l;
|
||||
int w, h;
|
||||
} mixerbar; /* 3 */
|
||||
#endif
|
||||
|
||||
struct {
|
||||
void *opaque; /* temporary workaround to not blow stuff */
|
||||
struct text_object *next;
|
||||
char *s;
|
||||
int i;
|
||||
|
Loading…
Reference in New Issue
Block a user