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

Several style issues fixes

This commit is contained in:
2015-03-21 15:31:54 +01:00
parent f7548d5b37
commit 8d9ae094f9
2 changed files with 40 additions and 39 deletions

View File

@@ -66,9 +66,9 @@ int main(int argc, char **argv) {
mix = Mixer_create(); mix = Mixer_create();
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 {
checkVol(true); checkVol(true);
XEvent xev; XEvent xev;
@@ -78,9 +78,9 @@ int main(int argc, char **argv) {
bool done = false; bool done = false;
while (!done) { while (!done) {
while(XPending(d_display) ) { while (XPending(d_display)) {
XNextEvent(d_display, &xev); XNextEvent(d_display, &xev);
switch(xev.type ) { switch (xev.type) {
case Expose: case Expose:
repaint(); repaint();
break; break;
@@ -95,7 +95,7 @@ int main(int argc, char **argv) {
break; break;
case ClientMessage: case ClientMessage:
if (xev.xclient.data.l[0] == (int) deleteWin) if (xev.xclient.data.l[0] == (int) deleteWin)
done=true; done = true;
break; break;
} }
} }
@@ -231,7 +231,7 @@ void Mixer_set_selem_props(struct Selem *selem, const char *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
Selem_set_name(selem, "pcm", &namesCount.pcm); Selem_set_name(selem, "pcm", &namesCount.pcm);
} else if (strstr("Headphone", name)) { } else if (strstr("Headphone", name)) {
@@ -305,11 +305,11 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) {
void Selem_set_name(struct Selem *selem, const char *name, short int *count) { void Selem_set_name(struct Selem *selem, const char *name, short int *count) {
char new_name[5], buf[5]; char new_name[5], buf[5];
if (*count > 10) if (*count > 10) {
snprintf(new_name, 5, "%s", name); snprintf(new_name, sizeof(new_name), "%s", name);
else { } else {
snprintf(buf, 4, "%s", name); snprintf(buf, sizeof(buf) - 1, "%s", name);
snprintf(new_name, 5, "%s%d", buf, *count); snprintf(new_name, sizeof(new_name), "%s%d", buf, *count);
} }
selem->name = new_name; selem->name = new_name;
@@ -329,7 +329,7 @@ void Mixer_set_channels(struct Selem *selem) {
selem->channels[1] = SND_MIXER_SCHN_MONO; selem->channels[1] = SND_MIXER_SCHN_MONO;
} else { } else {
idx = 0; idx = 0;
for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++){ for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {
if (!snd_mixer_selem_has_playback_channel(selem->elem, chn)) if (!snd_mixer_selem_has_playback_channel(selem->elem, chn))
continue; continue;
selem->channels[idx] = chn; selem->channels[idx] = chn;
@@ -347,7 +347,7 @@ void Mixer_set_channels(struct Selem *selem) {
selem->channels[1] = SND_MIXER_SCHN_MONO; selem->channels[1] = SND_MIXER_SCHN_MONO;
} else { } else {
idx = 0; idx = 0;
for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++){ for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++) {
if (!snd_mixer_selem_has_capture_channel(selem->elem, chn)) if (!snd_mixer_selem_has_capture_channel(selem->elem, chn))
continue; continue;
selem->channels[idx] = chn; selem->channels[idx] = chn;
@@ -372,7 +372,6 @@ slideCaptureMono Mixer_get_capabilities(snd_mixer_elem_t *elem) {
snd_mixer_selem_is_playback_mono(elem) ) snd_mixer_selem_is_playback_mono(elem) )
retval.mono = true; retval.mono = true;
} else { } else {
if (snd_mixer_selem_has_playback_volume(elem)) { if (snd_mixer_selem_has_playback_volume(elem)) {
retval.isvolume = true; retval.isvolume = true;
if (snd_mixer_selem_has_playback_volume_joined(elem) || if (snd_mixer_selem_has_playback_volume_joined(elem) ||
@@ -408,15 +407,15 @@ void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem) {
} }
static int convert_prange(long val, long min, long max) { static int convert_prange(long val, long min, long max) {
long range = max - min; long range = max - min;
int tmp; int tmp;
if (range == 0) if (range == 0)
return 0; return 0;
val -= min; val -= min;
tmp = rint((double)val/(double)range * 100); tmp = rint((double)val/(double)range * 100);
return tmp; return tmp;
} }
int Mixer_get_volume(int current, int channelIndex) { int Mixer_get_volume(int current, int channelIndex) {
@@ -497,13 +496,13 @@ void initXWin(int argc, char **argv) {
false); false);
deleteWin = XInternAtom(d_display, "WM_DELETE_WINDOW", false); deleteWin = XInternAtom(d_display, "WM_DELETE_WINDOW", false);
w_root=DefaultRootWindow(d_display); w_root = DefaultRootWindow(d_display);
shints.x = 0; shints.x = 0;
shints.y = 0; shints.y = 0;
shints.flags = 0; shints.flags = 0;
pos = (XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0, pos = (XWMGeometry(d_display, DefaultScreen(d_display), position, NULL, 0,
&shints, &shints.x, &shints.y, &shints.width, &shints.height, &shints, &shints.x, &shints.y, &shints.width, &shints.height,
&shints.win_gravity) & (XValue | YValue)) == 1; &shints.win_gravity) & (XValue | YValue)) == 1;
shints.min_width = winsize; shints.min_width = winsize;
shints.min_height = winsize; shints.min_height = winsize;
@@ -562,7 +561,7 @@ unsigned long mixColor(char *colorname1, int prop1, char *colorname2,
XParseColor(d_display, winattr.colormap, colorname2, &color2); XParseColor(d_display, winattr.colormap, colorname2, &color2);
color.pixel = 0; color.pixel = 0;
color.red = (color1.red * prop1 + color2.red * prop2) / (prop1 + prop2); color.red = (color1.red * prop1 + color2.red * prop2) / (prop1 + prop2);
color.green = (color1.green * prop1 + color2.green * prop2) / color.green = (color1.green * prop1 + color2.green * prop2) /
(prop1 + prop2); (prop1 + prop2);
color.blue = (color1.blue * prop1 + color2.blue * prop2) / (prop1 + prop2); color.blue = (color1.blue * prop1 + color2.blue * prop2) / (prop1 + prop2);
color.flags = DoRed | DoGreen | DoBlue; color.flags = DoRed | DoGreen | DoBlue;
@@ -603,20 +602,20 @@ void scanArgs(int argc, char **argv) {
fprintf(stderr, "%s: Illegal device name.\n", NAME); fprintf(stderr, "%s: Illegal device name.\n", NAME);
exit(1); exit(1);
} }
sprintf(card, "%s", argv[i]); snprintf(card, sizeof(card), "%s", argv[i]);
smixer_options.device = card; smixer_options.device = card;
} }
continue; continue;
} }
if (strcmp(argv[i], "-l") == 0) { if (strcmp(argv[i], "-l") == 0) {
if ( i < argc - 1) { if (i < argc - 1) {
i++; i++;
if (strlen(argv[i]) > 255) { if (strlen(argv[i]) > 255) {
fprintf(stderr, "%s: Illegal color name.\n", NAME); fprintf(stderr, "%s: Illegal color name.\n", NAME);
exit(1); exit(1);
} }
sprintf(ledcolor, "%s", argv[i]); snprintf(ledcolor, sizeof(ledcolor), "%s", argv[i]);
} }
continue; continue;
} }
@@ -628,7 +627,7 @@ void scanArgs(int argc, char **argv) {
fprintf(stderr, "%s: Illegal color name.\n", NAME); fprintf(stderr, "%s: Illegal color name.\n", NAME);
exit(1); exit(1);
} }
sprintf(backcolor, "%s", argv[i]); snprintf(backcolor, sizeof(backcolor), "%s", argv[i]);
} }
continue; continue;
} }
@@ -640,7 +639,7 @@ void scanArgs(int argc, char **argv) {
fprintf(stderr, "%s: Illegal position.\n", NAME); fprintf(stderr, "%s: Illegal position.\n", NAME);
exit(1); exit(1);
} }
sprintf(position, "%s", argv[i]); snprintf(position, sizeof(position), "%s", argv[i]);
} }
continue; continue;
} }
@@ -652,7 +651,7 @@ void scanArgs(int argc, char **argv) {
fprintf(stderr, "%s: Illegal display name.\n", NAME); fprintf(stderr, "%s: Illegal display name.\n", NAME);
exit(1); exit(1);
} }
sprintf(display, "%s", argv[i]); snprintf(display, sizeof(display), "%s", argv[i]);
} }
continue; continue;
} }
@@ -771,7 +770,9 @@ 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)) {
continue;
}
} }
void update() { void update() {

View File

@@ -8,8 +8,8 @@
// under certain conditions // under certain conditions
// See the README file for a more complete notice. // See the README file for a more complete notice.
#ifndef WMAMIXER_H #ifndef WMAMIXER_H_
#define WMAMIXER_H #define WMAMIXER_H_
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -49,7 +49,7 @@
/* Function to convert from percentage to volume. val = percentage */ /* Function to convert from percentage to volume. val = percentage */
#define convert_prange1(val, min, max) \ #define convert_prange1(val, min, max) \
ceil((val) * ((max) - (min)) * 0.01 + (min)) ceil((val) * ((max) - (min)) * 0.01 + (min))
// Pixmaps - standard // Pixmaps - standard
Pixmap pm_main; Pixmap pm_main;
@@ -128,7 +128,7 @@ struct Selem {
int currentVolRight; int currentVolRight;
int currentVolLeft; int currentVolLeft;
short int iconIndex; short int iconIndex;
snd_mixer_elem_t *elem; snd_mixer_elem_t *elem;
long min; long min;
long max; long max;
bool capture; bool capture;
@@ -147,7 +147,7 @@ struct NamesCount {
struct Selem *selems[32] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 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, NULL, NULL, 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;
@@ -197,4 +197,4 @@ 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_set_name(struct Selem *selem, const char *name, short int *count);
void Selem_destroy(); void Selem_destroy();
#endif /* WMAMIXER_H */ #endif // WMAMIXER_H_