All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH alsa-utils 1/2] alsamixer: Check the availability of mouse
@ 2021-10-20 15:26 Takashi Iwai
  2021-10-20 15:26 ` [PATCH alsa-utils 2/2] alsamixer: Allow setting the default background color in config Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2021-10-20 15:26 UTC (permalink / raw)
  To: alsa-devel

Let's check the availiabiy via has_mouse().  Otherwise the program
aborts unexpectedly just focusing on my rxvt terminal :-(

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 alsamixer/mainloop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/alsamixer/mainloop.c b/alsamixer/mainloop.c
index e67c0f821e8a..cdbe28e390fd 100644
--- a/alsamixer/mainloop.c
+++ b/alsamixer/mainloop.c
@@ -50,7 +50,7 @@ void initialize_curses(bool use_color, bool use_mouse)
 #endif
 	window_size_changed(); /* update screen_lines/cols */
 	init_colors(use_color);
-	if (use_mouse)
+	if (use_mouse && has_mouse())
 		mousemask(ALL_MOUSE_EVENTS, NULL);
 	snd_lib_error_set_handler(black_hole_error_handler);
 }
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH alsa-utils 2/2] alsamixer: Allow setting the default background color in config
  2021-10-20 15:26 [PATCH alsa-utils 1/2] alsamixer: Check the availability of mouse Takashi Iwai
@ 2021-10-20 15:26 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2021-10-20 15:26 UTC (permalink / raw)
  To: alsa-devel

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    | 4 ++++
 alsamixer/cli.c          | 8 ++++----
 alsamixer/colors.c       | 9 +++++----
 alsamixer/colors.h       | 1 +
 alsamixer/configparser.c | 9 +++++++++
 5 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/alsamixer/alsamixer.1 b/alsamixer/alsamixer.1
index 19171e12fdcf..670ab21c902f 100644
--- a/alsamixer/alsamixer.1
+++ b/alsamixer/alsamixer.1
@@ -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
 
diff --git a/alsamixer/cli.c b/alsamixer/cli.c
index f153f280cd9f..63c4949bab96 100644
--- a/alsamixer/cli.c
+++ b/alsamixer/cli.c
@@ -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();
diff --git a/alsamixer/colors.c b/alsamixer/colors.c
index c81ebcf089ee..f76dc26ef380 100644
--- a/alsamixer/colors.c
+++ b/alsamixer/colors.c
@@ -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);
diff --git a/alsamixer/colors.h b/alsamixer/colors.h
index 7ca6ac58210a..1c7bff8e7d32 100644
--- a/alsamixer/colors.h
+++ b/alsamixer/colors.h
@@ -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);
diff --git a/alsamixer/configparser.c b/alsamixer/configparser.c
index 7647987f84d6..4396d4ff302e 100644
--- a/alsamixer/configparser.c
+++ b/alsamixer/configparser.c
@@ -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];
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-20 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-20 15:26 [PATCH alsa-utils 1/2] alsamixer: Check the availability of mouse Takashi Iwai
2021-10-20 15:26 ` [PATCH alsa-utils 2/2] alsamixer: Allow setting the default background color in config Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.