[Mp3blaster-devel] [patch] mp3blaster doesn't honor terminals transparency

Bernhard Fischer rep.nop at aon.at
Sun Jan 9 14:33:26 CET 2005


Hello,

mp3blaster does ignore the terminals transparency.

Attached patch fixes it for me:

acconfig.h, configure.in
        * add detection of ncurses use_default_colors()
doc/sample.mp3blasterrc, mp3blaster.1
	* document new keyword "default" for colors.
src/config.cc
        * peruse honor_transparent to set transparency if given in
          the config-file and available in ncurses.
        * furthermore, use cached value[0]
src/main.cc
        * declare honor_transparent and peruse ncurses'
          use_default_colors if available and requested.
-------------- next part --------------
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/acconfig.h mp3blaster-3.2.0/acconfig.h
--- mp3blaster-3.2.0.oorig/acconfig.h	2003-09-08 23:48:56.000000000 +0200
+++ mp3blaster-3.2.0/acconfig.h	2004-11-21 19:05:02.000000000 +0100
@@ -41,6 +41,9 @@
 /* use pthreads for threading */
 #undef PTHREADEDMPEG
 
+/* have use_default_colors() for transparency */
+#undef HAVE_USE_DEFAULT_COLORS
+
 #undef SOUNDCARD_HEADERFILE
 @BOTTOM@
 /* Copyright (C) Bram Avontuur (bram at avontuur.org) */
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/configure.in mp3blaster-3.2.0/configure.in
--- mp3blaster-3.2.0.oorig/configure.in	2003-10-26 16:40:37.000000000 +0100
+++ mp3blaster-3.2.0/configure.in	2004-11-21 18:56:11.000000000 +0100
@@ -333,6 +333,11 @@ fi
 
 if test "$INCLUDENCURSES" = 1 ; then
   NCURSES_LIBS="-lncurses"
+  AC_CHECK_LIB(ncurses,use_default_colors,USEDEFCOLORS=1)
+  if test $USEDEFCOLORS -eq 1 ; then
+    AC_DEFINE(HAVE_USE_DEFAULT_COLORS)
+  fi
+  AC_SUBST(HAVE_USE_DEFAULT_COLORS)
 elif test "$INCLUDECURSES" = 1 ; then
   NCURSES_LIBS="-lcurses"
 else
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/doc/sample.mp3blasterrc mp3blaster-3.2.0/doc/sample.mp3blasterrc
--- mp3blaster-3.2.0.oorig/doc/sample.mp3blasterrc	2002-09-20 22:40:14.000000000 +0200
+++ mp3blaster-3.2.0/doc/sample.mp3blasterrc	2005-01-09 13:30:53.000000000 +0100
@@ -46,7 +46,9 @@
 
 #Set a bunch of colours. Try and find out what they do; most should be obvious.
 #Currently, colour support is mostly broken and very inconsistent..
-#Colours: black, red, green, yellow, blue, magenta, cyan, white
+#Colours: black, red, green, yellow, blue, magenta, cyan, white, default
+# The color "default" tells mp3blaster to honor transparent terminals, if
+# supported by your ncurses library.
 #Color.Default.fg = white
 #Color.Default.bg = black
 # Input window color
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/mp3blaster.1 mp3blaster-3.2.0/mp3blaster.1
--- mp3blaster-3.2.0.oorig/mp3blaster.1	2003-09-08 23:25:48.000000000 +0200
+++ mp3blaster-3.2.0/mp3blaster.1	2005-01-09 13:55:02.000000000 +0100
@@ -294,6 +294,10 @@ canonical names: '\fBspc\fR' (space), '\
 .TP
 .B colours
 One of: black, red, green, yellow, blue, magenta, cyan, white
+The special colour "default" tells mp3blaster to use the terminal's background
+colour. E.g. Use "default" for Color.Default.bg, Color.Button.bg, 
+Color.Label.fg, Color.Number.bg on a transparent terminal to get a nice 
+see-through effect.
 .PP
 These keywords are currently supported:
 .TP
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/config.cc mp3blaster-3.2.0/src/config.cc
--- mp3blaster-3.2.0.oorig/src/config.cc	2002-09-20 22:40:15.000000000 +0200
+++ mp3blaster-3.2.0/src/config.cc	2004-11-21 19:58:41.000000000 +0100
@@ -42,6 +42,9 @@ extern short set_pan_size(int);
 #ifdef PTHREADEDMPEG
 extern short set_threads(int);
 #endif
+#ifdef HAVE_USE_DEFAULT_COLORS
+extern short honor_transparent;
+#endif
 
 /* If you want to add a configuration option, you have to add them to the
  * followin three arrays. For each keyword, the index in all three arrays
@@ -228,6 +231,9 @@ cf_type_char(const char *string)
 	return ERR;
 }
 
+/*return curses COLOR_x or -1 for transparency.
+ * else return -2
+ */
 short
 cf_type_colour(const char *string)
 {
@@ -247,8 +253,14 @@ cf_type_colour(const char *string)
 		return COLOR_CYAN;
 	else if (WORDMATCH("white"))
 		return COLOR_WHITE;
+#if defined(HAVE_USE_DEFAULT_COLORS)
+	else if (WORDMATCH("default")) {
+		honor_transparent = 1;
+		return -1;
+	}
+#endif
 	else
-		return -1;	
+		return -2;	
 }
 
 /* returns the (hopefully) correct scancode for a valid key descriptor.
@@ -343,7 +355,7 @@ cf_checktype(const char *value, _kwdtype
 	else if (kwdtype == COLOUR)
 	{
 		short clr = cf_type_colour(value);
-		if (clr < 0)
+		if (clr < -1)
 			return 0;
 	}
 	else //unkown type
@@ -368,7 +380,7 @@ cf_add_keyword(int keyword, const char *
 	{
 	case 0: /* threads */
 #ifdef PTHREADEDMPEG
-		if (!set_threads(cf_type_number(values[0])))
+		if (!set_threads(cf_type_number(v)))
 		{
 			error = BADVALUE;
 			return 0;
@@ -376,10 +388,10 @@ cf_add_keyword(int keyword, const char *
 #endif
 		break;
 	case 1: /* DownFrequency */
-		globalopts.downsample = cf_type_yesno(values[0]);
+		globalopts.downsample = cf_type_yesno(v);
 		break;
 	case 2: /* SoundDevice */
-		set_sound_device(values[0]);
+		set_sound_device(v);
 		break;
 	case 3: /* AudiofileMatching */
 		if (!set_audiofile_matching(values, nrvals))
@@ -389,21 +401,21 @@ cf_add_keyword(int keyword, const char *
 		}
 		break;
 	case 4: //WarnDelay
-		if (!set_warn_delay((unsigned int)cf_type_number(values[0])))
+		if (!set_warn_delay((unsigned int)cf_type_number(v)))
 		{
 			error = BADVALUE;
 			return 0;
 		}
 		break;
 	case 5: //SkipFrames
-		if (!set_skip_frames((unsigned int)cf_type_number(values[0])))
+		if (!set_skip_frames((unsigned int)cf_type_number(v)))
 		{
 			error = BADVALUE;
 			return 0;
 		}
 		break;
 	case 6: //WrapAround
-		globalopts.wraplist = (cf_type_yesno(values[0]) != 0);
+		globalopts.wraplist = (cf_type_yesno(v) != 0);
 		break;
 	case 7: //PlaylistMatching
 		if (!set_playlist_matching(values, nrvals))
@@ -413,29 +425,29 @@ cf_add_keyword(int keyword, const char *
 		}
 		break;
 	//now the lot of colour settings.
-	case 8: globalopts.colours.default_fg = cf_type_colour(values[0]); break;
-	case 9: globalopts.colours.default_bg = cf_type_colour(values[0]); break;
-	case 10: globalopts.colours.popup_fg = cf_type_colour(values[0]); break;
-	case 11: globalopts.colours.popup_bg = cf_type_colour(values[0]); break;
-	case 12: globalopts.colours.popup_input_fg = cf_type_colour(values[0]); break;
-	case 13: globalopts.colours.popup_input_bg = cf_type_colour(values[0]); break;
-	case 14: globalopts.colours.error_fg = cf_type_colour(values[0]); break;
-	case 15: globalopts.colours.error_bg = cf_type_colour(values[0]); break;
-	case 16: globalopts.colours.button_fg = cf_type_colour(values[0]); break;
-	case 17: globalopts.colours.button_bg = cf_type_colour(values[0]); break;
-	case 18: globalopts.colours.progbar_bg = cf_type_colour(values[0]); break;
-	case 19: globalopts.colours.bartoken_fg = cf_type_colour(values[0]); break;
-	case 20: globalopts.colours.bartoken_bg = cf_type_colour(values[0]); break;
-	case 21: globalopts.colours.shortcut_fg = cf_type_colour(values[0]); break;
-	case 22: globalopts.colours.shortcut_bg = cf_type_colour(values[0]); break;
-	case 23: globalopts.colours.label_fg = cf_type_colour(values[0]); break;
-	case 24: globalopts.colours.label_bg = cf_type_colour(values[0]); break;
-	case 25: globalopts.colours.number_fg = cf_type_colour(values[0]); break;
-	case 26: globalopts.colours.number_bg = cf_type_colour(values[0]); break;
-	case 27: globalopts.colours.file_mp3_fg = cf_type_colour(values[0]); break;
-	case 28: globalopts.colours.file_dir_fg = cf_type_colour(values[0]); break;
-	case 29: globalopts.colours.file_lst_fg = cf_type_colour(values[0]); break;
-	case 30: globalopts.colours.file_win_fg = cf_type_colour(values[0]); break;
+	case 8: globalopts.colours.default_fg = cf_type_colour(v); break;
+	case 9: globalopts.colours.default_bg = cf_type_colour(v); break;
+	case 10: globalopts.colours.popup_fg = cf_type_colour(v); break;
+	case 11: globalopts.colours.popup_bg = cf_type_colour(v); break;
+	case 12: globalopts.colours.popup_input_fg = cf_type_colour(v); break;
+	case 13: globalopts.colours.popup_input_bg = cf_type_colour(v); break;
+	case 14: globalopts.colours.error_fg = cf_type_colour(v); break;
+	case 15: globalopts.colours.error_bg = cf_type_colour(v); break;
+	case 16: globalopts.colours.button_fg = cf_type_colour(v); break;
+	case 17: globalopts.colours.button_bg = cf_type_colour(v); break;
+	case 18: globalopts.colours.progbar_bg = cf_type_colour(v); break;
+	case 19: globalopts.colours.bartoken_fg = cf_type_colour(v); break;
+	case 20: globalopts.colours.bartoken_bg = cf_type_colour(v); break;
+	case 21: globalopts.colours.shortcut_fg = cf_type_colour(v); break;
+	case 22: globalopts.colours.shortcut_bg = cf_type_colour(v); break;
+	case 23: globalopts.colours.label_fg = cf_type_colour(v); break;
+	case 24: globalopts.colours.label_bg = cf_type_colour(v); break;
+	case 25: globalopts.colours.number_fg = cf_type_colour(v); break;
+	case 26: globalopts.colours.number_bg = cf_type_colour(v); break;
+	case 27: globalopts.colours.file_mp3_fg = cf_type_colour(v); break;
+	case 28: globalopts.colours.file_dir_fg = cf_type_colour(v); break;
+	case 29: globalopts.colours.file_lst_fg = cf_type_colour(v); break;
+	case 30: globalopts.colours.file_win_fg = cf_type_colour(v); break;
 	//keybindings
 	case 31: bindkey(CMD_SELECT_FILES, cf_type_key(v)); break;
 	case 32: bindkey(CMD_ADD_GROUP, cf_type_key(v)); break;
@@ -491,7 +503,7 @@ cf_add_keyword(int keyword, const char *
 	case 78: bindkey(CMD_HELP_NEXT, cf_type_key(v)); break;
 	case 79: bindkey(CMD_FILE_MARK_BAD, cf_type_key(v)); break;
 	case 80: //PlaylistDir
-		if (!set_playlist_dir(values[0]))
+		if (!set_playlist_dir(v))
 		{
 			error = BADVALUE;
 			return 0;
@@ -499,27 +511,27 @@ cf_add_keyword(int keyword, const char *
 		break;
 	case 81: bindkey(CMD_CLEAR_PLAYLIST, cf_type_key(v)); break;
 	case 82: bindkey(CMD_DEL_MARK, cf_type_key(v)); break;
-	case 83: globalopts.fw_hideothers = cf_type_yesno(values[0]); break;
+	case 83: globalopts.fw_hideothers = cf_type_yesno(v); break;
 	case 84:
-		if (set_sort_mode(values[0]) < 0) { error = BADVALUE; return 0; }
+		if (set_sort_mode(v) < 0) { error = BADVALUE; return 0; }
 		break;
-	case 85: globalopts.want_id3names = cf_type_yesno(values[0]); break;
+	case 85: globalopts.want_id3names = cf_type_yesno(v); break;
 	case 86: bindkey(CMD_FILE_DELETE, cf_type_key(v)); break;
 	case 87: bindkey(CMD_PLAY_SKIPEND, cf_type_key(v)); break;
 	case 88: bindkey(CMD_PLAY_NEXTGROUP, cf_type_key(v)); break;
 	case 89: bindkey(CMD_PLAY_PREVGROUP, cf_type_key(v)); break;
-	case 90: globalopts.selectitems_unselectfirst = cf_type_yesno(values[0]);
+	case 90: globalopts.selectitems_unselectfirst = cf_type_yesno(v);
 		break;
-	case 91: globalopts.selectitems_searchusingregexp = cf_type_yesno(values[0]);
+	case 91: globalopts.selectitems_searchusingregexp = cf_type_yesno(v);
 		break;
-	case 92: globalopts.selectitems_caseinsensitive = cf_type_yesno(values[0]);
+	case 92: globalopts.selectitems_caseinsensitive = cf_type_yesno(v);
 		break;
-	case 93: globalopts.scan_mp3s = cf_type_yesno(values[0]);
+	case 93: globalopts.scan_mp3s = cf_type_yesno(v);
 		break;
 	case 94: bindkey(CMD_FILE_RENAME, cf_type_key(v)); break;
-	case 95: set_mixer_device(values[0]); break;
+	case 95: set_mixer_device(v); break;
 	case 96: //CharsetTable
-		if (!set_charset_table(values[0])) { error = BADVALUE; return 0; }
+		if (!set_charset_table(v)) { error = BADVALUE; return 0; }
 		break;
 	case 97: bindkey(CMD_FILE_TOGGLE_SORT, cf_type_key(v)); break;
 	case 98: bindkey(CMD_TOGGLE_DISPLAY, cf_type_key(v)); break;
diff -X /usr/src/excl -rup mp3blaster-3.2.0.oorig/src/main.cc mp3blaster-3.2.0/src/main.cc
--- mp3blaster-3.2.0.oorig/src/main.cc	2003-09-09 23:22:55.000000000 +0200
+++ mp3blaster-3.2.0/src/main.cc	2004-12-12 14:44:59.000000000 +0100
@@ -211,6 +211,9 @@ void *lirc_loop(void *);
 #define UPDATE_CURSES
 #define UNLOCK_NCURSES pth_mutex_release(&ncurses_mutex)
 #endif
+#ifdef HAVE_USE_DEFAULT_COLORS
+short honor_transparent = 0;
+#endif
 
 #define OPT_LOADLIST 1
 #define OPT_DEBUG 2
@@ -387,6 +390,7 @@ main(int argc, char *argv[], char *envp[
 	init_globalopts();
 	init_playopts();
 	set_default_colours(); // fill globalopts.colours with default values.
+
 	/* parse arguments */
 	while (1)
 	{
@@ -559,6 +563,12 @@ main(int argc, char *argv[], char *envp[
 	//Initialize NCURSES
 	initscr();
  	start_color();
+#if defined(HAVE_USE_DEFAULT_COLORS)
+	if (honor_transparent)
+		if (use_default_colors())
+			debug("Error getting default colors from term.\n");
+#endif
+
 	set_inout_opts();
 
 	startup_path = get_current_working_path();



More information about the Mp3blaster-devel mailing list