]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsamixer: Allow setting the default background color in config
authorTakashi Iwai <tiwai@suse.de>
Wed, 20 Oct 2021 15:13:35 +0000 (17:13 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 20 Oct 2021 15:24:35 +0000 (17:24 +0200)
The recent commit c867aa8a84a7 ("alsamixer: use background color
instead of COLOR_BLACK") changed the behavior of alsamixer to take the
system default background color instead of black.  This caused
problems on the terminal setups that have bright background colors,
e.g. yellow is very hard to read.

It could be "fixed" by setting up the color configurations in
~/.config/alsamixer.rc, but this needs to change the all colors in
every element, which is pretty cumbersome.  Instead, this patch
extends the config set command to allow user to specify the default
background color.  A user like me can create their own
~/.config/alsamixer.rc file containing the line

  set background black

and the old good black background is back again.

Note that, for achieving the above, we also had to shuffle the
function call order, to parse the config at first, then initialize
curses.  This shouldn't matter for other behavior.

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

index 19171e12fdcf575465a1dc3ccd71f19f5093dd68..670ab21c902f14faa9fb944c7c02280a581eef32 100644 (file)
@@ -202,6 +202,10 @@ Set the mouse wheel step to \fI<N>\fP
 
 If enabled (\fI1\fP), mixer controls can be changed by hovering over them and scrolling the mouse wheel.
 
+\fBbackground\fP \fIcolor\fP
+
+Set the default background color
+
 .TP
 \fBbind\fP \fIkey_definition\fP \fIcommand\fP
 
index f153f280cd9fec5c31d94192c249fb0d14929074..63c4949bab963399df82a27ce5a2977b6d28129d 100644 (file)
@@ -152,15 +152,15 @@ int main(int argc, char *argv[])
 
        parse_options(argc, argv);
 
-       create_mixer_object(&selem_regopt);
-
-       initialize_curses(use_color, use_mouse);
-
        if (config_file == CONFIG_DEFAULT)
                parse_default_config_file();
        else if (config_file)
                parse_config_file(config_file);
 
+       create_mixer_object(&selem_regopt);
+
+       initialize_curses(use_color, use_mouse);
+
        create_mixer_widget();
 
        mainloop();
index c81ebcf089eead3fde2a7ee1a4d0d1c8abede86a..f76dc26ef3809788c07d60f2167a93c9310a0541 100644 (file)
@@ -23,6 +23,7 @@
 #include "colors.h"
 
 struct attributes attrs;
+short background_color = -1;
 
 int get_color_pair(short fg, short bg)
 {
@@ -50,11 +51,11 @@ void init_colors(int use_color)
                start_color();
                use_default_colors();
 
-               get_color_pair(COLOR_CYAN, -1); // COLOR_PAIR(1)
-               get_color_pair(COLOR_YELLOW, -1);
+               get_color_pair(COLOR_CYAN, background_color); // COLOR_PAIR(1)
+               get_color_pair(COLOR_YELLOW, background_color);
                get_color_pair(COLOR_WHITE, COLOR_GREEN);
-               get_color_pair(COLOR_RED, -1);
-               get_color_pair(COLOR_WHITE, -1);
+               get_color_pair(COLOR_RED, background_color);
+               get_color_pair(COLOR_WHITE, background_color);
                get_color_pair(COLOR_WHITE, COLOR_BLUE);
                get_color_pair(COLOR_RED, COLOR_BLUE);
                get_color_pair(COLOR_GREEN, COLOR_GREEN);
index 7ca6ac58210a618d21707b5aeef8b02a330e8907..1c7bff8e7d32900ec16d929c135ac2de1f605bc9 100644 (file)
@@ -34,6 +34,7 @@ struct attributes {
 };
 
 extern struct attributes attrs;
+extern short background_color;
 
 void init_colors(int use_color);
 int get_color_pair(short fg, short bg);
index 7647987f84d629c670df64b550116cadc2ceb778..4396d4ff302e6a04dc06e0cff3bcba2a615abd19 100644 (file)
@@ -444,6 +444,15 @@ static int cfg_set(char **argv, unsigned int argc)
                                return ERROR_CONFIG;
                        }
                }
+               else if (!strcmp(argv[0], "background")) {
+                       int bg_color = color_by_name(argv[1]);
+                       if (bg_color == -2) {
+                               error_message = _("unknown color");
+                               error_cause = argv[1];
+                               return ERROR_CONFIG;
+                       }
+                       background_color = bg_color;
+               }
                else {
                        error_message = _("unknown option");
                        error_cause = argv[0];