]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsamixer - Tricolorize volume bars
authorTakashi Iwai <tiwai@suse.de>
Thu, 18 Jun 2009 12:42:28 +0000 (14:42 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 18 Jun 2009 12:42:28 +0000 (14:42 +0200)
A little of bit of Italian taste was missing...

Signed-off-by: Takashi Iwai <tiwai@suse.de>
alsamixer/colors.c
alsamixer/colors.h
alsamixer/mixer_display.c

index f68de54aaf79e918e6749f6fb91d7379b2ebbdba..fcceb16a9ee9a736fa4c96a984b54b21886f5dcc 100644 (file)
@@ -33,7 +33,11 @@ int attr_ctl_nocapture;
 int attr_ctl_label;
 int attr_ctl_label_focus;
 int attr_ctl_mark_focus;
-int attr_ctl_bar;
+int attr_ctl_bar_lo;
+#ifdef TRICOLOR_VOLUME_BAR
+int attr_ctl_bar_mi;
+int attr_ctl_bar_hi;
+#endif
 int attr_ctl_inactive;
 int attr_ctl_label_inactive;
 int attr_errormsg;
@@ -57,6 +61,10 @@ void init_colors(int use_color)
                init_pair(7, COLOR_RED, COLOR_BLUE);
                init_pair(8, COLOR_GREEN, COLOR_GREEN);
                init_pair(9, COLOR_WHITE, COLOR_RED);
+#ifdef TRICOLOR_VOLUME_BAR
+               init_pair(10, COLOR_WHITE, COLOR_WHITE);
+               init_pair(11, COLOR_RED, COLOR_RED);
+#endif
 
                attr_mixer_frame = COLOR_PAIR(1);
                attr_mixer_text = COLOR_PAIR(1);
@@ -69,7 +77,11 @@ void init_colors(int use_color)
                attr_ctl_label = A_BOLD | COLOR_PAIR(6);
                attr_ctl_label_focus = A_BOLD | COLOR_PAIR(7);
                attr_ctl_mark_focus = A_BOLD | COLOR_PAIR(4);
-               attr_ctl_bar = A_BOLD | COLOR_PAIR(8);
+               attr_ctl_bar_lo = A_BOLD | COLOR_PAIR(8);
+#ifdef TRICOLOR_VOLUME_BAR
+               attr_ctl_bar_mi = A_BOLD | COLOR_PAIR(10);
+               attr_ctl_bar_hi = A_BOLD | COLOR_PAIR(11);
+#endif
                attr_ctl_inactive = COLOR_PAIR(5);
                attr_ctl_label_inactive = A_REVERSE | COLOR_PAIR(5);
                attr_errormsg = A_BOLD | COLOR_PAIR(9);
@@ -90,7 +102,11 @@ void init_colors(int use_color)
                attr_ctl_label = A_REVERSE;
                attr_ctl_label_focus = A_REVERSE | A_BOLD;
                attr_ctl_mark_focus = A_BOLD;
-               attr_ctl_bar = A_BOLD;
+               attr_ctl_bar_lo = A_BOLD;
+#ifdef TRICOLOR_VOLUME_BAR
+               attr_ctl_bar_mi = A_BOLD;
+               attr_ctl_bar_hi = A_BOLD;
+#endif
                attr_ctl_inactive = A_NORMAL;
                attr_ctl_label_inactive = A_REVERSE;
                attr_errormsg = A_STANDOUT;
index e1d3b1a96ddd1a7f2d74ece1b30b835e99074fd8..9396004695c03f0d9392b1b6ea66f9f0d4aa0212 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef COLORS_H_INCLUDED
 #define COLORS_H_INCLUDED
 
+#define TRICOLOR_VOLUME_BAR
+
 extern int attr_mixer_frame;
 extern int attr_mixer_text;
 extern int attr_mixer_active;
@@ -12,7 +14,11 @@ extern int attr_ctl_nocapture;
 extern int attr_ctl_label;
 extern int attr_ctl_label_focus;
 extern int attr_ctl_mark_focus;
-extern int attr_ctl_bar;
+extern int attr_ctl_bar_lo;
+#ifdef TRICOLOR_VOLUME_BAR
+extern int attr_ctl_bar_mi;
+extern int attr_ctl_bar_hi;
+#endif
 extern int attr_ctl_inactive;
 extern int attr_ctl_label_inactive;
 extern int attr_errormsg;
index aade71da63115dc57bb93f419809eba4c83838c9..d0a0e56f9a8c05284089a9c9cceb6b7bbc75da1d 100644 (file)
@@ -394,7 +394,7 @@ static void display_control(unsigned int control_index)
 {
        struct control *control;
        int col;
-       int i;
+       int i, c;
        int left, frame_left;
        int bar_height, value;
        long volumes[2];
@@ -465,19 +465,30 @@ static void display_control(unsigned int control_index)
 
                if (control->flags & IS_ACTIVE)
                        wattrset(mixer_widget.window, 0);
-               bar_height = ((volumes[0] - min) * volume_height + max - min - 1) / (max - min);
-               for (i = 0; i < volume_height; ++i)
-                       mvwaddch(mixer_widget.window, base_y - i - 1, frame_left + 1,
-                                i + 1 <= bar_height
-                                ? ACS_CKBOARD | (control->flags & IS_ACTIVE ? attr_ctl_bar : 0)
-                                : ' '         | (control->flags & IS_ACTIVE ? attr_ctl_frame : 0));
-               bar_height = ((volumes[1] - min) * volume_height + max - min - 1) / (max - min);
-               for (i = 0; i < volume_height; ++i)
-                       mvwaddch(mixer_widget.window, base_y - i - 1, frame_left + 2,
-                                i + 1 <= bar_height
-                                ? ACS_CKBOARD | (control->flags & IS_ACTIVE ? attr_ctl_bar : 0)
-                                : ' '         | (control->flags & IS_ACTIVE ? attr_ctl_frame : 0));
-
+               for (c = 0; c < 2; c++) {
+                       bar_height = ((volumes[c] - min) * volume_height +
+                                     max - min - 1) / (max - min);
+                       for (i = 0; i < volume_height; ++i) {
+                               int attr;
+                               if (i + 1 > bar_height)
+                                       attr = ' ' |
+                                               (control->flags & IS_ACTIVE ?
+                                                attr_ctl_frame : 0);
+                               else {
+                                       attr = ACS_CKBOARD;
+#ifdef TRICOLOR_VOLUME_BAR
+                                       if (i > volume_height * 8 / 10)
+                                               attr |= attr_ctl_bar_hi;
+                                       else if (i > volume_height * 4 / 10)
+                                               attr |= attr_ctl_bar_mi;
+                                       else
+#endif
+                                               attr |= attr_ctl_bar_lo;
+                               }
+                               mvwaddch(mixer_widget.window, base_y - i - 1,
+                                        frame_left + c + 1, attr);
+                       }
+               }
                if (control->flags & IS_ACTIVE)
                        wattrset(mixer_widget.window, attr_mixer_active);
                value = ((volumes[0] - min) * 100 + (max - min) / 2) / (max - min);