changeset 2278:614f7b9838fb

Automated merge with ssh://hg.atheme.org//hg/audacious-plugins
author William Pitcock <nenolod@atheme.org>
date Tue, 01 Jan 2008 16:04:29 -0600
parents 5e54ffc4f46f (current diff) d25cd7e7eddb (diff)
children 90d9e13d2e18
files
diffstat 6 files changed, 551 insertions(+), 352 deletions(-) [+]
line wrap: on
line diff
--- a/src/filewriter/mp3.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/filewriter/mp3.c	Tue Jan 01 16:04:29 2008 -0600
@@ -20,6 +20,8 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+/* #define AUD_DEBUG 1 */
+
 #include "plugins.h"
 
 #ifdef FILEWRITER_MP3
@@ -156,8 +158,6 @@
     (void) vfprintf(stdout, format, ap);
 }
 
-
-
 static void mp3_init(void)
 {
     ConfigDb *db = aud_cfg_db_open();
@@ -206,9 +206,9 @@
 
     if (tuple) {
         /* XXX write UTF-8 even though libmp3lame does id3v2.3. --yaz */
-#ifdef DEBUG
-        g_print("track_name = %s\n", aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
-#endif
+
+        AUDDBG("track_name = %s\n", aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
+
         lameid3.track_name = g_strdup(aud_tuple_get_string(tuple, FIELD_TITLE, NULL));
         id3tag_set_title(gfp, lameid3.track_name);
 
@@ -244,9 +244,7 @@
     lame_set_bWriteVbrTag(gfp, toggle_xing_val);
     lame_set_quality(gfp, algo_quality_val);
     if (audio_mode_val != 4) {
-#ifdef DEBUG
-        printf("set mode to %d\n", audio_mode_val);
-#endif
+        AUDDBG("set mode to %d\n", audio_mode_val);
         lame_set_mode(gfp, audio_mode_val);
     }
     if(auto_ms_val)
@@ -328,10 +326,7 @@
 
 static gint mp3_playing(void)
 {
-#ifdef DEBUG
-    printf("lame: buffer_playing = %d\n", encout ? 1 : 0);
-#endif
-    return encout ? 1 : 0;
+    return 0;
 }
 
 static gint mp3_get_written_time(void)
--- a/src/hotkey/plugin.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/hotkey/plugin.c	Tue Jan 01 16:04:29 2008 -0600
@@ -2,7 +2,7 @@
 /*
  *  This file is part of audacious-hotkey plugin for audacious
  *
- *  Copyright (c) 2007        Sascha Hlusiak <contact@saschahlusiak.de>
+ *  Copyright (c) 2007 - 2008  Sascha Hlusiak <contact@saschahlusiak.de>
  *  Name: plugin.c
  *  Description: plugin.c
  * 
@@ -61,7 +61,7 @@
 static void init (void);
 static void grab_keys ();
 static void ungrab_keys ();
-static gboolean handle_keyevent(int keycode, int state);
+static gboolean handle_keyevent(int keycode, int state, int type);
 static gboolean setup_filter();
 static void release_filter();
 
@@ -75,24 +75,32 @@
 static void about (void);
 static void cleanup (void);
 
+#define TYPE_KEY 0
+#define TYPE_MOUSE 1
+
+
+typedef struct {
+	gint key, mask;
+	gint type;
+} HotkeyConfiguration;
+
 typedef struct {
 	gint vol_increment;
 	gint vol_decrement;
 	
 	/* keyboard */
-	gint mute, mute_mask;
-	gint vol_down, vol_down_mask;
-	gint vol_up, vol_up_mask;
-	gint play, play_mask;
-	gint stop, stop_mask;
-	gint pause, pause_mask;
-	gint prev_track, prev_track_mask;
-	gint next_track, next_track_mask;
-	gint jump_to_file, jump_to_file_mask;
-	gint toggle_win, toggle_win_mask;
-
-	gint forward,  forward_mask;
-	gint backward, backward_mask;
+	HotkeyConfiguration mute;
+	HotkeyConfiguration vol_down;
+	HotkeyConfiguration vol_up;
+	HotkeyConfiguration play;
+	HotkeyConfiguration stop;
+	HotkeyConfiguration pause;
+	HotkeyConfiguration prev_track;
+	HotkeyConfiguration next_track;
+	HotkeyConfiguration jump_to_file;
+	HotkeyConfiguration toggle_win;
+	HotkeyConfiguration forward;
+	HotkeyConfiguration backward;
 } PluginConfig;
 
 PluginConfig plugin_cfg;
@@ -109,17 +117,17 @@
 
 typedef struct {
 	GtkWidget *keytext;
-	gint key, mask;
+	HotkeyConfiguration hotkey;
 } KeyControls;
 
 typedef struct {
 	KeyControls play;
 	KeyControls stop;
 	KeyControls pause;
-	KeyControls prev;
-	KeyControls next;
-	KeyControls up;
-	KeyControls down;
+	KeyControls prev_track;
+	KeyControls next_track;
+	KeyControls vol_up;
+	KeyControls vol_down;
 	KeyControls mute;
 	KeyControls jump_to_file;
 	KeyControls forward;
@@ -201,7 +209,7 @@
 }
 
 /* handle keys */
-static gboolean handle_keyevent (int keycode, int state)
+static gboolean handle_keyevent (int keycode, int state, int type)
 {
 	gint current_volume, old_volume;
 	static gint volume_static = 0;
@@ -225,7 +233,7 @@
 	state &= ~(scrolllock_mask | numlock_mask | capslock_mask);
 	
 	/* mute the playback */
-	if ((keycode == plugin_cfg.mute) && (state == plugin_cfg.mute_mask))
+	if ((keycode == plugin_cfg.mute.key) && (state == plugin_cfg.mute.mask) && (type == plugin_cfg.mute.type))
 	{
 		if (!mute)
 		{
@@ -240,7 +248,7 @@
 	}
 	
 	/* decreace volume */
-	if ((keycode == plugin_cfg.vol_down) && (state == plugin_cfg.vol_down_mask))
+	if ((keycode == plugin_cfg.vol_down.key) && (state == plugin_cfg.vol_down.mask) && (type == plugin_cfg.vol_down.type))
 	{
 		if (mute)
 		{
@@ -264,7 +272,7 @@
 	}
 	
 	/* increase volume */
-	if ((keycode == plugin_cfg.vol_up) && (state == plugin_cfg.vol_up_mask))
+	if ((keycode == plugin_cfg.vol_up.key) && (state == plugin_cfg.vol_up.mask) && (type == plugin_cfg.vol_up.type))
 	{
 		if (mute)
 		{
@@ -288,7 +296,7 @@
 	}
 	
 	/* play */
-	if ((keycode == plugin_cfg.play) && (state == plugin_cfg.play_mask))
+	if ((keycode == plugin_cfg.play.key) && (state == plugin_cfg.play.mask) && (type == plugin_cfg.play.type))
 	{
 		if (!play)
 		{
@@ -300,7 +308,7 @@
 	}
 
 	/* pause */
-	if ((keycode == plugin_cfg.pause) && (state == plugin_cfg.pause_mask))
+	if ((keycode == plugin_cfg.pause.key) && (state == plugin_cfg.pause.mask) && (type == plugin_cfg.pause.type))
 	{
 		if (!play) audacious_drct_play ();
 		else audacious_drct_pause ();
@@ -309,28 +317,28 @@
 	}
 	
 	/* stop */
-	if ((keycode == plugin_cfg.stop) && (state == plugin_cfg.stop_mask))
+	if ((keycode == plugin_cfg.stop.key) && (state == plugin_cfg.stop.mask) && (type == plugin_cfg.stop.type))
 	{
 		audacious_drct_stop ();
 		return TRUE;
 	}
 	
 	/* prev track */	
-	if ((keycode == plugin_cfg.prev_track) && (state == plugin_cfg.prev_track_mask))
+	if ((keycode == plugin_cfg.prev_track.key) && (state == plugin_cfg.prev_track.mask) && (type == plugin_cfg.prev_track.type))
 	{
 		audacious_drct_playlist_prev ();
 		return TRUE;
 	}
 	
 	/* next track */
-	if ((keycode == plugin_cfg.next_track) && (state == plugin_cfg.next_track_mask))
+	if ((keycode == plugin_cfg.next_track.key) && (state == plugin_cfg.next_track.mask) && (type == plugin_cfg.next_track.type))
 	{
 		audacious_drct_playlist_next ();
 		return TRUE;
 	}
 
 	/* forward */
-	if ((keycode == plugin_cfg.forward) && (state == plugin_cfg.forward_mask))
+	if ((keycode == plugin_cfg.forward.key) && (state == plugin_cfg.forward.mask) && (type == plugin_cfg.forward.type))
 	{
 		gint time = audacious_drct_get_output_time();
 		time += 5000; /* Jump 5s into future */
@@ -339,7 +347,7 @@
 	}
 
 	/* backward */
-	if ((keycode == plugin_cfg.backward) && (state == plugin_cfg.backward_mask))
+	if ((keycode == plugin_cfg.backward.key) && (state == plugin_cfg.backward.mask) && (type == plugin_cfg.backward.type))
 	{
 		gint time = audacious_drct_get_output_time();
 		if (time > 5000) time -= 5000; /* Jump 5s back */
@@ -349,14 +357,14 @@
 	}
 
 	/* Open Jump-To-File dialog */
-	if ((keycode == plugin_cfg.jump_to_file) && (state == plugin_cfg.jump_to_file_mask))
+	if ((keycode == plugin_cfg.jump_to_file.key) && (state == plugin_cfg.jump_to_file.mask) && (type == plugin_cfg.jump_to_file.type))
 	{
 		audacious_drct_show_jtf_box();
 		return TRUE;
 	}
 
 	/* Toggle Windows */
-	if ((keycode == plugin_cfg.toggle_win) && (state == plugin_cfg.toggle_win_mask))
+	if ((keycode == plugin_cfg.toggle_win.key) && (state == plugin_cfg.toggle_win.mask) && (type == plugin_cfg.toggle_win.type))
 	{
 		static gboolean is_main, is_eq, is_pl;
 		is_main = audacious_drct_main_win_is_visible();
@@ -382,13 +390,25 @@
 	   GdkEvent *event,
 	   gpointer data)
 {
-	XKeyEvent *keyevent = (XKeyEvent*)xevent;
-	
-	if (((XEvent*)keyevent)->type != KeyPress)
+	switch (((XEvent*)xevent)->type)
+	{
+	case KeyPress:
+		{
+			XKeyEvent *keyevent = (XKeyEvent*)xevent;
+			if (handle_keyevent(keyevent->keycode, keyevent->state, TYPE_KEY))
+				return GDK_FILTER_REMOVE;
+			break;
+		}
+	case ButtonPress:
+		{
+			XButtonEvent *buttonevent = (XButtonEvent*)xevent;
+			if (handle_keyevent(buttonevent->button, buttonevent->state, TYPE_MOUSE))
+				return GDK_FILTER_REMOVE;
+			break;
+		}
+	default:
 		return -1;
-	
-	if (handle_keyevent(keyevent->keycode, keyevent->state))
-		return GDK_FILTER_REMOVE;
+	}
 	
 	return GDK_FILTER_CONTINUE;
 }
@@ -421,58 +441,30 @@
 	plugin_cfg.vol_increment = 4;
 	plugin_cfg.vol_decrement = 4;
 
-	plugin_cfg.mute = XKeysymToKeycode(xdisplay, XF86XK_AudioMute);
-	plugin_cfg.mute_mask = 0;
-	plugin_cfg.vol_down = XKeysymToKeycode(xdisplay, XF86XK_AudioLowerVolume);
-	plugin_cfg.vol_down_mask = 0;
-	plugin_cfg.vol_up = XKeysymToKeycode(xdisplay, XF86XK_AudioRaiseVolume);
-	plugin_cfg.vol_up_mask = 0;
-	plugin_cfg.play = XKeysymToKeycode(xdisplay, XF86XK_AudioPlay);
-	plugin_cfg.play_mask = 0;
-	plugin_cfg.pause = XKeysymToKeycode(xdisplay, XF86XK_AudioPause);
-	plugin_cfg.pause_mask = 0;
-	plugin_cfg.stop = XKeysymToKeycode(xdisplay, XF86XK_AudioStop);
-	plugin_cfg.stop_mask = 0;
-	plugin_cfg.prev_track = XKeysymToKeycode(xdisplay, XF86XK_AudioPrev);
-	plugin_cfg.prev_track_mask = 0;
-	plugin_cfg.next_track = XKeysymToKeycode(xdisplay, XF86XK_AudioNext);
-	plugin_cfg.next_track_mask = 0;
-	plugin_cfg.jump_to_file = XKeysymToKeycode(xdisplay, XF86XK_AudioMedia);
-	plugin_cfg.jump_to_file_mask = 0;
-	plugin_cfg.forward = 0;
-	plugin_cfg.forward_mask = 0;
-	plugin_cfg.backward = XKeysymToKeycode(xdisplay, XF86XK_AudioRewind);
-	plugin_cfg.backward_mask = 0;
-	plugin_cfg.toggle_win = 0;
-	plugin_cfg.toggle_win_mask = 0;
+#define load_key(hotkey,default) \
+	plugin_cfg.hotkey.key = (default)?(XKeysymToKeycode(xdisplay, (default))):0; \
+	plugin_cfg.hotkey.mask = 0; \
+	plugin_cfg.hotkey.type = TYPE_KEY; \
+	aud_cfg_db_get_int (cfdb, "globalHotkey", #hotkey, &plugin_cfg.hotkey.key); \
+	aud_cfg_db_get_int (cfdb, "globalHotkey", #hotkey "_mask", &plugin_cfg.hotkey.mask); \
+	aud_cfg_db_get_int (cfdb, "globalHotkey", #hotkey "_type", &plugin_cfg.hotkey.type);
+
 
 	/* open configuration database */
 	cfdb = aud_cfg_db_open ( );
 
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "mute", &plugin_cfg.mute);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "mute_mask", &plugin_cfg.mute_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "vol_down", &plugin_cfg.vol_down);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "vol_down_mask", &plugin_cfg.vol_down_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "vol_up", &plugin_cfg.vol_up);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "vol_up_mask", &plugin_cfg.vol_up_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "play", &plugin_cfg.play);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "play_mask", &plugin_cfg.play_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "pause", &plugin_cfg.pause);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "pause_mask", &plugin_cfg.pause_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "stop", &plugin_cfg.stop);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "stop_mask", &plugin_cfg.stop_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "prev_track", &plugin_cfg.prev_track);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "prev_track_mask", &plugin_cfg.prev_track_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "next_track", &plugin_cfg.next_track);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "next_track_mask", &plugin_cfg.next_track_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "jump_to_file", &plugin_cfg.jump_to_file);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "jump_to_file_mask", &plugin_cfg.jump_to_file_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "forward", &plugin_cfg.forward);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "forward_mask", &plugin_cfg.forward_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "backward", &plugin_cfg.backward);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "backward_mask", &plugin_cfg.backward_mask);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "toggle_win", &plugin_cfg.toggle_win);
-	aud_cfg_db_get_int (cfdb, "globalHotkey", "toggle_win_mask", &plugin_cfg.toggle_win_mask);
+	load_key(mute, XF86XK_AudioMute);
+	load_key(vol_down, XF86XK_AudioLowerVolume);
+	load_key(vol_up, XF86XK_AudioRaiseVolume);
+	load_key(play, XF86XK_AudioPlay);
+	load_key(pause, XF86XK_AudioPause);
+	load_key(stop, XF86XK_AudioStop);
+	load_key(prev_track, XF86XK_AudioPrev);
+	load_key(next_track, XF86XK_AudioNext);
+	load_key(jump_to_file, XF86XK_AudioMedia);
+	load_key(toggle_win, 0);
+	load_key(forward, 0);
+	load_key(backward, XF86XK_AudioRewind);
 
 	aud_cfg_db_close (cfdb);
 }
@@ -481,34 +473,28 @@
 static void save_config (void)
 {
 	ConfigDb *cfdb;
+
+#define save_key(hotkey) \
+	aud_cfg_db_set_int (cfdb, "globalHotkey", #hotkey, plugin_cfg.hotkey.key); \
+	aud_cfg_db_set_int (cfdb, "globalHotkey", #hotkey "_mask", plugin_cfg.hotkey.mask); \
+	aud_cfg_db_set_int (cfdb, "globalHotkey", #hotkey "_type", plugin_cfg.hotkey.type);
 	
 	/* open configuration database */
 	cfdb = aud_cfg_db_open ( );
 	
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "mute", plugin_cfg.mute);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "mute_mask", plugin_cfg.mute_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "vol_up", plugin_cfg.vol_up);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "vol_up_mask", plugin_cfg.vol_up_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "vol_down", plugin_cfg.vol_down);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "vol_down_mask", plugin_cfg.vol_down_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "play", plugin_cfg.play);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "play_mask", plugin_cfg.play_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "pause", plugin_cfg.pause);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "pause_mask", plugin_cfg.pause_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "stop", plugin_cfg.stop);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "stop_mask", plugin_cfg.stop_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "prev_track", plugin_cfg.prev_track);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "prev_track_mask", plugin_cfg.prev_track_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "next_track", plugin_cfg.next_track);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "next_track_mask", plugin_cfg.next_track_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "jump_to_file", plugin_cfg.jump_to_file);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "jump_to_file_mask", plugin_cfg.jump_to_file_mask);	
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "forward", plugin_cfg.forward);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "forward_mask", plugin_cfg.forward_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "backward", plugin_cfg.backward);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "backward_mask", plugin_cfg.backward_mask);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "toggle_win", plugin_cfg.toggle_win);
-	aud_cfg_db_set_int (cfdb, "globalHotkey", "toggle_win_mask", plugin_cfg.toggle_win_mask);
+	save_key(mute);
+	save_key(vol_up);
+	save_key(vol_down);
+	save_key(play);
+	save_key(pause);
+	save_key(stop);
+	save_key(prev_track);
+	save_key(next_track);
+	save_key(jump_to_file);
+	save_key(forward);
+	save_key(backward);
+	save_key(toggle_win);
+
 	aud_cfg_db_close (cfdb);
 }
 
@@ -517,55 +503,103 @@
 	return 0;
 }
 
-/* grab requied keys */
-static void grab_key(KeyCode keycode, unsigned int modifier)
+/* grab required keys */
+static void grab_key(HotkeyConfiguration hotkey)
 {
-	modifier &= ~(numlock_mask | capslock_mask | scrolllock_mask);
-	
-	XGrabKey (xdisplay, keycode, modifier, x_root_window,
-		False, GrabModeAsync, GrabModeAsync);
-	
-	if (modifier == AnyModifier)
-		return;
-	
-	if (numlock_mask)
-		XGrabKey (xdisplay, keycode, modifier | numlock_mask,
-			x_root_window,
-			False, GrabModeAsync, GrabModeAsync);
-	
-	if (capslock_mask)
-		XGrabKey (xdisplay, keycode, modifier | capslock_mask,
-			x_root_window,
-			False, GrabModeAsync, GrabModeAsync);
+	unsigned int modifier = hotkey.mask & ~(numlock_mask | capslock_mask | scrolllock_mask);
 	
-	if (scrolllock_mask)
-		XGrabKey (xdisplay, keycode, modifier | scrolllock_mask,
-			x_root_window,
-			False, GrabModeAsync, GrabModeAsync);
-	
-	if (numlock_mask && capslock_mask)
-		XGrabKey (xdisplay, keycode, modifier | numlock_mask | capslock_mask,
-			x_root_window,
-			False, GrabModeAsync, GrabModeAsync);
-	
-	if (numlock_mask && scrolllock_mask)
-		XGrabKey (xdisplay, keycode, modifier | numlock_mask | scrolllock_mask,
-			x_root_window,
+	if (hotkey.key == 0) return;
+
+	if (hotkey.type == TYPE_KEY)
+	{
+		XGrabKey (xdisplay, hotkey.key, modifier, x_root_window,
 			False, GrabModeAsync, GrabModeAsync);
-	
-	if (capslock_mask && scrolllock_mask)
-		XGrabKey (xdisplay, keycode, modifier | capslock_mask | scrolllock_mask,
-			x_root_window,
-			False, GrabModeAsync, GrabModeAsync);
-	
-	if (numlock_mask && capslock_mask && scrolllock_mask)
-		XGrabKey (xdisplay, keycode,
-			modifier | numlock_mask | capslock_mask | scrolllock_mask,
-			x_root_window, False, GrabModeAsync,
-			GrabModeAsync);
+		
+		if (modifier == AnyModifier)
+			return;
+		
+		if (numlock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | numlock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (capslock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | capslock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (scrolllock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | scrolllock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (numlock_mask && capslock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (numlock_mask && scrolllock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | numlock_mask | scrolllock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (capslock_mask && scrolllock_mask)
+			XGrabKey (xdisplay, hotkey.key, modifier | capslock_mask | scrolllock_mask,
+				x_root_window,
+				False, GrabModeAsync, GrabModeAsync);
+		
+		if (numlock_mask && capslock_mask && scrolllock_mask)
+			XGrabKey (xdisplay, hotkey.key,
+				modifier | numlock_mask | capslock_mask | scrolllock_mask,
+				x_root_window, False, GrabModeAsync,
+				GrabModeAsync);
+	}
+	if (hotkey.type == TYPE_MOUSE)
+	{
+		XGrabButton (xdisplay, hotkey.key, modifier, x_root_window,
+			False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (modifier == AnyModifier)
+			return;
+		
+		if (numlock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | numlock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (capslock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | capslock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (scrolllock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | scrolllock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (numlock_mask && capslock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (numlock_mask && scrolllock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | numlock_mask | scrolllock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (capslock_mask && scrolllock_mask)
+			XGrabButton (xdisplay, hotkey.key, modifier | capslock_mask | scrolllock_mask,
+				x_root_window,
+				False, ButtonPressMask, GrabModeAsync, GrabModeAsync, None, None);
+		
+		if (numlock_mask && capslock_mask && scrolllock_mask)
+			XGrabButton (xdisplay, hotkey.key,
+				modifier | numlock_mask | capslock_mask | scrolllock_mask,
+				x_root_window, False, ButtonPressMask, GrabModeAsync,
+				GrabModeAsync, None, None);
+	}
 }
 
-
 static void grab_keys ()
 {
 	if (grabbed) return;
@@ -575,20 +609,20 @@
 
 	XSync(xdisplay, False);
 	old_handler = XSetErrorHandler (x11_error_handler);
+
+	grab_key(plugin_cfg.mute);
+	grab_key(plugin_cfg.vol_up);
+	grab_key(plugin_cfg.vol_down);
+	grab_key(plugin_cfg.play);
+	grab_key(plugin_cfg.pause);
+	grab_key(plugin_cfg.stop);
+	grab_key(plugin_cfg.prev_track);
+	grab_key(plugin_cfg.next_track);
+	grab_key(plugin_cfg.jump_to_file);
+	grab_key(plugin_cfg.forward);
+	grab_key(plugin_cfg.backward);
+	grab_key(plugin_cfg.toggle_win);
 	
-	if (plugin_cfg.mute) grab_key(plugin_cfg.mute, plugin_cfg.mute_mask);
-	if (plugin_cfg.vol_up) grab_key(plugin_cfg.vol_up, plugin_cfg.vol_up_mask);
-	if (plugin_cfg.vol_down) grab_key(plugin_cfg.vol_down, plugin_cfg.vol_down_mask);
-	if (plugin_cfg.play) grab_key(plugin_cfg.play, plugin_cfg.play_mask);
-	if (plugin_cfg.pause) grab_key(plugin_cfg.pause, plugin_cfg.pause_mask);
-	if (plugin_cfg.stop) grab_key(plugin_cfg.stop, plugin_cfg.stop_mask);
-	if (plugin_cfg.prev_track) grab_key(plugin_cfg.prev_track, plugin_cfg.prev_track_mask);
-	if (plugin_cfg.next_track) grab_key(plugin_cfg.next_track, plugin_cfg.next_track_mask);
-	if (plugin_cfg.jump_to_file) grab_key(plugin_cfg.jump_to_file, plugin_cfg.jump_to_file_mask);
-	if (plugin_cfg.forward) grab_key(plugin_cfg.forward, plugin_cfg.forward_mask);
-	if (plugin_cfg.backward) grab_key(plugin_cfg.backward, plugin_cfg.backward_mask);
-	if (plugin_cfg.toggle_win) grab_key(plugin_cfg.toggle_win, plugin_cfg.toggle_win_mask);
-
 	XSync(xdisplay, False);
 	XSetErrorHandler (old_handler);
 
@@ -598,7 +632,7 @@
  * plugin init end
  */
 
-static void set_keytext (GtkWidget *entry, gint key, gint mask)
+static void set_keytext (GtkWidget *entry, gint key, gint mask, gint type)
 {
 	gchar *text = NULL;
 
@@ -611,14 +645,20 @@
 		gchar *strings[9];
 		gchar *keytext = NULL;
 		int i, j;
-		KeySym keysym;
-
-		keysym = XKeycodeToKeysym(xdisplay, key, 0);
-		if (keysym == 0 || keysym == NoSymbol)
+		if (type == TYPE_KEY)
 		{
-			keytext = g_strdup_printf("#%3d", key);
-		} else {
-			keytext = g_strdup(XKeysymToString(keysym));
+			KeySym keysym;
+			keysym = XKeycodeToKeysym(xdisplay, key, 0);
+			if (keysym == 0 || keysym == NoSymbol)
+			{
+				keytext = g_strdup_printf("#%d", key);
+			} else {
+				keytext = g_strdup(XKeysymToString(keysym));
+			}
+		}
+		if (type == TYPE_MOUSE)
+		{
+			keytext = g_strdup_printf("Button%d", key);
 		}
 
 		for (i = 0, j=0; j<7; j++)
@@ -648,6 +688,7 @@
 	int mod;
 
 	if (event->keyval == GDK_Tab) return FALSE;
+
 	mod = 0;
 	is_mod = 0;
 
@@ -667,12 +708,13 @@
         	mod |= Mod4Mask;
 
 	if (!is_mod) {
-		controls->key = event->hardware_keycode;
-		controls->mask = mod;
-	} else controls->key = 0;
+		controls->hotkey.key = event->hardware_keycode;
+		controls->hotkey.mask = mod;
+		controls->hotkey.type = TYPE_KEY;
+	} else controls->hotkey.key = 0;
 
-	set_keytext(controls->keytext, is_mod ? 0 : event->hardware_keycode, mod);
-	return FALSE;
+	set_keytext(controls->keytext, is_mod ? 0 : event->hardware_keycode, mod, TYPE_KEY);
+	return TRUE;
 }
 
 static gboolean
@@ -681,21 +723,119 @@
                            gpointer user_data)
 {
 	KeyControls *controls = (KeyControls*) user_data;
-	if (controls->key == 0) {
-		controls->mask = 0;
+	if (controls->hotkey.key == 0) {
+		controls->hotkey.mask = 0;
+		return TRUE;
 	}
-	set_keytext(controls->keytext, controls->key, controls->mask);
-	return FALSE;
+	set_keytext(controls->keytext, controls->hotkey.key, controls->hotkey.mask, controls->hotkey.type);
+	return TRUE;
 }
 
+static gboolean
+on_entry_button_press_event(GtkWidget * widget,
+                            GdkEventButton * event,
+                            gpointer user_data)
+{
+	KeyControls *controls = (KeyControls*) user_data;
+	int mod;
+	
+	if (!gtk_widget_is_focus(widget)) return FALSE;
 
-static void add_event_controls(GtkWidget *table, KeyControls *controls, int row, char* descr, gint key, gint mask)
+	mod = 0;
+	if (event->state & GDK_CONTROL_MASK)
+        	mod |= ControlMask;
+
+	if (event->state & GDK_MOD1_MASK)
+        	mod |= Mod1Mask;
+
+	if (event->state & GDK_SHIFT_MASK)
+        	mod |= ShiftMask;
+
+	if (event->state & GDK_MOD5_MASK)
+        	mod |= Mod5Mask;
+
+	if (event->state & GDK_MOD4_MASK)
+        	mod |= Mod4Mask;
+
+	if ((event->button <= 3) && (mod == 0))
+	{
+		GtkWidget* dialog;
+		GtkResponseType response;
+		dialog = gtk_message_dialog_new (GTK_WINDOW(gtk_widget_get_toplevel(widget)),
+			GTK_DIALOG_MODAL,
+			GTK_MESSAGE_WARNING,
+			GTK_BUTTONS_YES_NO,
+			_("It is not recommended to bind the primary mouse buttons without modificators.\n\n"
+			  "Do you want to continue?"));
+		gtk_window_set_title(GTK_WINDOW(dialog), _("Binding mouse buttons"));
+		response = gtk_dialog_run(GTK_DIALOG(dialog));
+		gtk_widget_destroy (dialog);
+		if (response != GTK_RESPONSE_YES) return TRUE;
+	}
+
+	controls->hotkey.key = event->button;
+	controls->hotkey.mask = mod;
+        controls->hotkey.type = TYPE_MOUSE;
+	set_keytext(controls->keytext, controls->hotkey.key, controls->hotkey.mask, controls->hotkey.type);
+	return TRUE;
+}
+
+static gboolean
+on_entry_scroll_event(GtkWidget * widget,
+                            GdkEventScroll * event,
+                            gpointer user_data)
+{
+	KeyControls *controls = (KeyControls*) user_data;
+	int mod;
+	
+	if (!gtk_widget_is_focus(widget)) return FALSE;
+
+	mod = 0;
+	if (event->state & GDK_CONTROL_MASK)
+        	mod |= ControlMask;
+
+	if (event->state & GDK_MOD1_MASK)
+        	mod |= Mod1Mask;
+
+	if (event->state & GDK_SHIFT_MASK)
+        	mod |= ShiftMask;
+
+	if (event->state & GDK_MOD5_MASK)
+        	mod |= Mod5Mask;
+
+	if (event->state & GDK_MOD4_MASK)
+        	mod |= Mod4Mask;
+
+	if (event->direction == GDK_SCROLL_UP)
+		controls->hotkey.key = 4;
+	else if (event->direction == GDK_SCROLL_DOWN)
+		controls->hotkey.key = 5;
+	else if (event->direction == GDK_SCROLL_LEFT)
+		controls->hotkey.key = 6;
+	else if (event->direction == GDK_SCROLL_RIGHT)
+		controls->hotkey.key = 7;
+	else return FALSE;
+
+	controls->hotkey.mask = mod;
+        controls->hotkey.type = TYPE_MOUSE;
+	set_keytext(controls->keytext, controls->hotkey.key, controls->hotkey.mask, controls->hotkey.type);
+	return TRUE;
+}
+
+static void add_event_controls(GtkWidget *table, 
+				KeyControls *controls, 
+				int row, 
+				char* descr, 
+				HotkeyConfiguration hotkey)
 {
 	GtkWidget *label;
 	GtkWidget *button;
 
-	controls->key = key;
-	controls->mask = mask;	
+	controls->hotkey.key = hotkey.key;
+	controls->hotkey.mask = hotkey.mask;
+	controls->hotkey.type = hotkey.type;
+	if (controls->hotkey.key == 0)
+		controls->hotkey.mask = 0;
 
 	label = gtk_label_new (_(descr));
 	gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, 
@@ -708,11 +848,15 @@
 			(GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (GTK_EXPAND), 0, 0);
 	gtk_entry_set_editable (GTK_ENTRY (controls->keytext), FALSE);
 
-	set_keytext(controls->keytext, key, mask);
+	set_keytext(controls->keytext, hotkey.key, hotkey.mask, hotkey.type);
 	g_signal_connect((gpointer)controls->keytext, "key_press_event",
                          G_CALLBACK(on_entry_key_press_event), controls);
 	g_signal_connect((gpointer)controls->keytext, "key_release_event",
                          G_CALLBACK(on_entry_key_release_event), controls);
+	g_signal_connect((gpointer)controls->keytext, "button_press_event",
+                         G_CALLBACK(on_entry_button_press_event), controls);
+	g_signal_connect((gpointer)controls->keytext, "scroll_event",
+                         G_CALLBACK(on_entry_scroll_event), controls);
 
 	button = gtk_button_new_with_label (_("None"));
 	gtk_table_attach (GTK_TABLE (table), button, 2, 3, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
@@ -792,26 +936,26 @@
 	gtk_table_set_row_spacings (GTK_TABLE (table), 2);
 
 	/* prev track */
-	add_event_controls(table, &controls->prev, 0, _("Previous Track:"), 
-			plugin_cfg.prev_track, plugin_cfg.prev_track_mask);
+	add_event_controls(table, &controls->prev_track, 0, _("Previous Track:"), 
+			plugin_cfg.prev_track);
 
 	add_event_controls(table, &controls->play, 1, _("Play/Pause:"), 
-			plugin_cfg.play, plugin_cfg.play_mask);
+			plugin_cfg.play);
 
 	add_event_controls(table, &controls->pause, 2, _("Pause:"), 
-			plugin_cfg.pause, plugin_cfg.pause_mask);
+			plugin_cfg.pause);
 
 	add_event_controls(table, &controls->stop, 3, _("Stop:"), 
-			plugin_cfg.stop, plugin_cfg.stop_mask);
+			plugin_cfg.stop);
 
-	add_event_controls(table, &controls->next, 4, _("Next Track:"), 
-			plugin_cfg.next_track, plugin_cfg.next_track_mask);
+	add_event_controls(table, &controls->next_track, 4, _("Next Track:"), 
+			plugin_cfg.next_track);
 
 	add_event_controls(table, &controls->forward, 5, _("Forward 5 sec.:"), 
-			plugin_cfg.forward, plugin_cfg.forward_mask);
+			plugin_cfg.forward);
 
 	add_event_controls(table, &controls->backward, 6, _("Rewind 5 sec.:"), 
-			plugin_cfg.backward, plugin_cfg.backward_mask);
+			plugin_cfg.backward);
 
 
 	label = gtk_label_new (NULL);
@@ -835,17 +979,15 @@
 	gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
 	gtk_table_set_col_spacings (GTK_TABLE (table), 2);
 	gtk_table_set_row_spacings (GTK_TABLE (table), 2);
-	
-
 
 	add_event_controls(table, &controls->mute, 0, _("Mute:"),
-			plugin_cfg.mute, plugin_cfg.mute_mask);
+			plugin_cfg.mute);
 
-	add_event_controls(table, &controls->up, 1, _("Volume Up:"), 
-			plugin_cfg.vol_up, plugin_cfg.vol_up_mask);
+	add_event_controls(table, &controls->vol_up, 1, _("Volume Up:"), 
+			plugin_cfg.vol_up);
 
-	add_event_controls(table, &controls->down, 2, _("Volume Down:"), 
-			plugin_cfg.vol_down, plugin_cfg.vol_down_mask);
+	add_event_controls(table, &controls->vol_down, 2, _("Volume Down:"), 
+			plugin_cfg.vol_down);
 
 
 	label = gtk_label_new (NULL);
@@ -871,10 +1013,10 @@
 	gtk_table_set_row_spacings (GTK_TABLE (table), 2);
 
 	add_event_controls(table, &controls->jump_to_file, 0, _("Jump to File:"), 
-			plugin_cfg.jump_to_file, plugin_cfg.jump_to_file_mask);
+			plugin_cfg.jump_to_file);
 
 	add_event_controls(table, &controls->toggle_win, 1, _("Toggle Player Windows:"), 
-			plugin_cfg.toggle_win, plugin_cfg.toggle_win_mask);
+			plugin_cfg.toggle_win);
 
 
 	button_box = gtk_hbutton_box_new ( );
@@ -903,9 +1045,9 @@
 	dialog = audacious_info_dialog (_("About Global Hotkey Plugin"),
 				_("Global Hotkey Plugin\n"
 				"Control the player with global key combinations or multimedia keys.\n\n"
-				"Copyright (C) 2007 Sascha Hlusiak <contact@saschahlusiak.de>\n\n"
+				"Copyright (C) 2007-2008 Sascha Hlusiak <contact@saschahlusiak.de>\n\n"
 				"Contributers include:\n"
-				"Copyright (C) 2006 - 2007 Vladimir Paskov <vlado.paskov@gmail.com>\n"
+				"Copyright (C) 2006-2007 Vladimir Paskov <vlado.paskov@gmail.com>\n"
 				"Copyright (C) 2000-2002 Ville Syrjälä <syrjala@sci.fi>\n"
                          	"			Bryn Davies <curious@ihug.com.au>\n"
                         	"			Jonathan A. Davis <davis@jdhouse.org>\n"
@@ -921,9 +1063,10 @@
 static void clear_keyboard (GtkWidget *widget, gpointer data)
 {
 	KeyControls *spins = (KeyControls*)data;
-	spins->key = 0;
-	spins->mask = 0;
-	set_keytext(spins->keytext, 0, 0);
+	spins->hotkey.key = 0;
+	spins->hotkey.mask = 0;
+	spins->hotkey.type = TYPE_KEY;
+	set_keytext(spins->keytext, 0, 0, TYPE_KEY);
 }
 
 void cancel_callback (GtkWidget *widget, gpointer data)
@@ -941,42 +1084,19 @@
 {
 	ConfigurationControls *controls= (ConfigurationControls*)data;
 	
-	plugin_cfg.play = controls->play.key;
-	plugin_cfg.play_mask = controls->play.mask;
-	
-	plugin_cfg.pause = controls->pause.key;
-	plugin_cfg.pause_mask = controls->pause.mask;
-
-	plugin_cfg.stop = controls->stop.key;
-	plugin_cfg.stop_mask = controls->stop.mask;
-	
-	plugin_cfg.prev_track = controls->prev.key;
-	plugin_cfg.prev_track_mask = controls->prev.mask;
+	plugin_cfg.play = controls->play.hotkey;
+	plugin_cfg.pause = controls->pause.hotkey;
+	plugin_cfg.stop= controls->stop.hotkey;
+	plugin_cfg.prev_track= controls->prev_track.hotkey;
+	plugin_cfg.next_track = controls->next_track.hotkey;
+	plugin_cfg.forward = controls->forward.hotkey;
+	plugin_cfg.backward = controls->backward.hotkey;
+	plugin_cfg.vol_up= controls->vol_up.hotkey;
+	plugin_cfg.vol_down = controls->vol_down.hotkey;
+	plugin_cfg.mute = controls->mute.hotkey;
+	plugin_cfg.jump_to_file= controls->jump_to_file.hotkey;
+	plugin_cfg.toggle_win = controls->toggle_win.hotkey;
 	
-	plugin_cfg.next_track = controls->next.key;
-	plugin_cfg.next_track_mask = controls->next.mask;
-
-	plugin_cfg.forward = controls->forward.key;
-	plugin_cfg.forward_mask = controls->forward.mask;
-
-	plugin_cfg.backward = controls->backward.key;
-	plugin_cfg.backward_mask = controls->backward.mask;
-	
-	plugin_cfg.vol_up = controls->up.key;
-	plugin_cfg.vol_up_mask = controls->up.mask;
-	
-	plugin_cfg.vol_down = controls->down.key;
-	plugin_cfg.vol_down_mask = controls->down.mask;
-	
-	plugin_cfg.mute = controls->mute.key;
-	plugin_cfg.mute_mask = controls->mute.mask;
-	
-	plugin_cfg.jump_to_file = controls->jump_to_file.key;
-	plugin_cfg.jump_to_file_mask = controls->jump_to_file.mask;
-
-	plugin_cfg.toggle_win= controls->toggle_win.key;
-	plugin_cfg.toggle_win_mask = controls->toggle_win.mask;
-
 	save_config ( );
 	
 	if (loaded)
@@ -999,13 +1119,97 @@
 	release_filter();
 	loaded = FALSE;
 }
- 
+
+/* grab required keys */
+static void ungrab_key(HotkeyConfiguration hotkey)
+{
+	unsigned int modifier = hotkey.mask & ~(numlock_mask | capslock_mask | scrolllock_mask);
+	
+	if (hotkey.key == 0) return;
+	
+	if (hotkey.type == TYPE_KEY)
+	{
+		XUngrabKey (xdisplay, hotkey.key, modifier, x_root_window);
+		
+		if (modifier == AnyModifier)
+			return;
+		
+		if (numlock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | numlock_mask, x_root_window);
+	
+		if (capslock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | capslock_mask, x_root_window);
+	
+		if (scrolllock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | scrolllock_mask, x_root_window);
+	
+		if (numlock_mask && capslock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask, x_root_window);
+	
+		if (numlock_mask && scrolllock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | numlock_mask | scrolllock_mask, x_root_window);
+	
+		if (capslock_mask && scrolllock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | capslock_mask | scrolllock_mask, x_root_window);
+	
+		if (numlock_mask && capslock_mask && scrolllock_mask)
+			XUngrabKey (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask | scrolllock_mask, x_root_window);
+	}
+	if (hotkey.type == TYPE_MOUSE)
+	{
+		XUngrabButton (xdisplay, hotkey.key, modifier, x_root_window);
+		
+		if (modifier == AnyModifier)
+			return;
+		
+		if (numlock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | numlock_mask, x_root_window);
+	
+		if (capslock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | capslock_mask, x_root_window);
+	
+		if (scrolllock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | scrolllock_mask, x_root_window);
+	
+		if (numlock_mask && capslock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask, x_root_window);
+	
+		if (numlock_mask && scrolllock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | numlock_mask | scrolllock_mask, x_root_window);
+	
+		if (capslock_mask && scrolllock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | capslock_mask | scrolllock_mask, x_root_window);
+	
+		if (numlock_mask && capslock_mask && scrolllock_mask)
+			XUngrabButton (xdisplay, hotkey.key, modifier | numlock_mask | capslock_mask | scrolllock_mask, x_root_window);
+	}
+}
+
 static void ungrab_keys ()
 {
+	XErrorHandler old_handler = 0;
+
 	if (!grabbed) return;
 	if (!xdisplay) return;
+
+	XSync(xdisplay, False);
+	old_handler = XSetErrorHandler (x11_error_handler);
+
+	ungrab_key(plugin_cfg.mute);
+	ungrab_key(plugin_cfg.vol_up);
+	ungrab_key(plugin_cfg.vol_down);
+	ungrab_key(plugin_cfg.play);
+	ungrab_key(plugin_cfg.pause);
+	ungrab_key(plugin_cfg.stop);
+	ungrab_key(plugin_cfg.prev_track);
+	ungrab_key(plugin_cfg.next_track);
+	ungrab_key(plugin_cfg.jump_to_file);
+	ungrab_key(plugin_cfg.forward);
+	ungrab_key(plugin_cfg.backward);
+	ungrab_key(plugin_cfg.toggle_win);
 	
-	XUngrabKey (xdisplay, AnyKey, AnyModifier, x_root_window);
-	
+	XSync(xdisplay, False);
+	XSetErrorHandler (old_handler);
+
 	grabbed = 0;
 }
--- a/src/madplug/decoder.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/madplug/decoder.c	Tue Jan 01 16:04:29 2008 -0600
@@ -196,8 +196,8 @@
         info->fileinfo_request = FALSE;
     }
 
-    AUDDBG("f: scan_file");
-    AUDDBG("scan_file frames = %d", info->frames);
+    AUDDBG("f: scan_file\n");
+    AUDDBG("scan_file frames = %d\n", info->frames);
 
     while (1) {
         remainder = stream.bufend - stream.next_frame;
@@ -214,7 +214,7 @@
                              BUFFER_SIZE - remainder);
 
         if (len <= 0) {
-            AUDDBG("scan_file: len <= 0 len = %d", len);
+            AUDDBG("scan_file: len <= 0 len = %d\n", len);
             break;
         }
 
@@ -226,10 +226,10 @@
                     break;
                 }
                 if (!MAD_RECOVERABLE(stream.error)) {
-                    AUDDBG("(fatal) error decoding header %d: %s",
+                    AUDDBG("(fatal) error decoding header %d: %s\n",
                               info->frames, mad_stream_errorstr(&stream));
-                    AUDDBG("remainder = %d", remainder);
-                    AUDDBG("len = %d", len);
+                    AUDDBG("remainder = %d\n", remainder);
+                    AUDDBG("len = %d\n", len);
                     break;
                 }
                 if (stream.error == MAD_ERROR_LOSTSYNC) {
@@ -238,27 +238,27 @@
                                             stream.bufend -
                                             stream.this_frame);
                     if (tagsize > 0) {
-                        AUDDBG("skipping id3_tag: %d", tagsize);
+                        AUDDBG("skipping id3_tag: %d\n", tagsize);
                         mad_stream_skip(&stream, tagsize);
                         continue;
                     }
                 }
 
-                AUDDBG("(recovered) error decoding header %d: %s",
+                AUDDBG("(recovered) error decoding header %d: %s\n",
                           info->frames, mad_stream_errorstr(&stream));
-                AUDDBG("remainder = %d", remainder);
-                AUDDBG("len = %d", len);
+                AUDDBG("remainder = %d\n", remainder);
+                AUDDBG("len = %d\n", len);
 
                 continue;
             }
             info->frames++;
 
 #ifdef DEBUG_INTENSIVELY
-            AUDDBG("header bitrate = %ld", header.bitrate);
-            AUDDBG("duration = %ul",
+            AUDDBG("header bitrate = %ld\n", header.bitrate);
+            AUDDBG("duration = %ul\n",
                       mad_timer_count(header.duration,
                                       MAD_UNITS_MILLISECONDS));
-            AUDDBG("size = %d", stream.next_frame - stream.this_frame);
+            AUDDBG("size = %d\n", stream.next_frame - stream.this_frame);
 #endif
             if(aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1)
                 mad_timer_add(&info->duration, header.duration);
@@ -280,15 +280,15 @@
                 if (audmad_config.use_xing) {
                     frame.header = header;
                     if (mad_frame_decode(&frame, &stream) == -1) {
-                        AUDDBG("xing frame decode failed");
+                        AUDDBG("xing frame decode failed\n");
                         goto no_xing;
                     }
                     if (xing_parse(&info->xing, stream.anc_ptr, stream.anc_bitlen) == 0) {
-                        AUDDBG("xing header found ");
+                        AUDDBG("xing header found\n");
                         has_xing = TRUE;
                         info->vbr = TRUE;   /* otherwise xing header would have been 'Info' */
 
-                        AUDDBG("xing: bytes = %ld frames = %ld", info->xing.bytes, info->xing.frames);
+                        AUDDBG("xing: bytes = %ld frames = %ld\n", info->xing.bytes, info->xing.frames);
 
                         /* we have enough info to calculate bitrate and duration */
                         if(info->xing.bytes && info->xing.frames) {
@@ -296,8 +296,8 @@
 #ifdef AUD_DEBUG
                             {
                                 gint tmp = (gint)(info->xing.bytes * 8 / xing_bitrate);
-                                AUDDBG("xing: bitrate = %4.1f kbps", xing_bitrate / 1000);
-                                AUDDBG("xing: duration = %d:%02d", tmp / 60, tmp % 60);
+                                AUDDBG("xing: bitrate = %4.1f kbps\n", xing_bitrate / 1000);
+                                AUDDBG("xing: duration = %d:%02d\n", tmp / 60, tmp % 60);
                             }
 #endif
                         }
@@ -305,7 +305,7 @@
                     }
 #ifdef AUD_DEBUG
                     else {
-                        AUDDBG("no usable xing header");
+                        AUDDBG("no usable xing header\n");
                         continue;
                     }
 #endif
@@ -332,14 +332,14 @@
             if (fast && info->frames >= N_AVERAGE_FRAMES) {
                 float frame_size = ((double) data_used) / N_AVERAGE_FRAMES;
 
-                AUDDBG("bitrate = %ld samplerate = %d", header.bitrate, header.samplerate);
-                AUDDBG("data_used = %d info->frames = %d info->size = %d tagsize = %d frame_size = %lf",
+                AUDDBG("bitrate = %ld samplerate = %d\n", header.bitrate, header.samplerate);
+                AUDDBG("data_used = %d info->frames = %d info->size = %d tagsize = %d frame_size = %lf\n",
                           data_used, info->frames, info->size, tagsize, frame_size);
 
                 if(info->size != 0)
                     info->frames = (info->size - tagsize) / frame_size;
 
-                AUDDBG("info->frames = %d", info->frames);
+                AUDDBG("info->frames = %d\n", info->frames);
 
                 if(aud_tuple_get_int(info->tuple, FIELD_LENGTH, NULL) == -1) {
                     if(xing_bitrate > 0.0) {
@@ -361,14 +361,14 @@
                     info->duration.fraction = length % 1000;
                 }
 #ifdef AUD_DEBUG
-                AUDDBG("using fast playtime calculation");
-                AUDDBG("data used = %d [tagsize=%d framesize=%f]",
+                AUDDBG("using fast playtime calculation\n");
+                AUDDBG("data used = %d [tagsize=%d framesize=%f]\n",
                           data_used, tagsize, frame_size);
-                AUDDBG("frames = %d, frequency = %d, channels = %d",
+                AUDDBG("frames = %d, frequency = %d, channels = %d\n",
                           info->frames, info->freq, info->channels);
                 long millis = mad_timer_count(info->duration,
                                               MAD_UNITS_MILLISECONDS);
-                AUDDBG("duration = %ld:%02ld", millis / 1000 / 60, (millis / 1000) % 60);
+                AUDDBG("duration = %ld:%02ld\n", millis / 1000 / 60, (millis / 1000) % 60);
 #endif                          /* DEBUG */
                 break;
             }
@@ -392,8 +392,8 @@
     mad_stream_finish(&stream);
     xing_finish(&info->xing);
 
-    AUDDBG("scan_file: info->frames = %d", info->frames);
-    AUDDBG("e: scan_file");
+    AUDDBG("scan_file: info->frames = %d\n", info->frames);
+    AUDDBG("e: scan_file\n");
 
     return (info->frames != 0 || info->remote == TRUE);
 }
@@ -428,7 +428,7 @@
     /* track info is passed in as thread argument */
     struct mad_info_t *info = (struct mad_info_t *) arg;
 
-    AUDDBG("f: decode");
+    AUDDBG("f: decode\n");
 
     /* init mad stuff */
     mad_frame_init(&frame);
@@ -437,11 +437,11 @@
     mad_synth_init(&synth);
 
     if(!info->playback){
-        AUDDBG("decode: playback == NULL");
+        AUDDBG("decode: playback == NULL\n");
         return NULL;
     }
 
-    AUDDBG("decode: fmt = %d freq = %d channels = %d", info->fmt, info->freq, info->channels);
+    AUDDBG("decode: fmt = %d freq = %d channels = %d\n", info->fmt, info->freq, info->channels);
 
     if(check_audio_param(info) == FALSE)
         return NULL;
@@ -467,12 +467,12 @@
                              (tlen == 0 || info->size <= 0) ? -1 : tlen,
                              info->bitrate, info->freq, info->channels);
 
-    AUDDBG("decode: tlen = %d", tlen);
+    AUDDBG("decode: tlen = %d\n", tlen);
 
     /* main loop */
     do {
         if (!info->playback->playing) {
-            AUDDBG("decode: stop signaled");
+            AUDDBG("decode: stop signaled\n");
             break;
         }
         if (seek_skip)
@@ -487,7 +487,7 @@
         input_process_remote_metadata(info);
 
         if (len <= 0) {
-            AUDDBG("finished decoding");
+            AUDDBG("finished decoding\n");
             break;
         }
         len += remainder;
@@ -502,7 +502,7 @@
 
         if (seek_skip) {
 
-            AUDDBG("skipping: %d", seek_skip);
+            AUDDBG("skipping: %d\n", seek_skip);
 
             int skip = 2;
             do {
@@ -526,7 +526,7 @@
         while (info->playback->playing) {
             if (info->seek != -1 && info->size > 0) {
 
-                AUDDBG("seeking: %ld", info->seek);
+                AUDDBG("seeking: %ld\n", info->seek);
 
                 int new_position;
                 gulong milliseconds =
@@ -541,7 +541,7 @@
                 if(new_position < 0)
                     new_position = 0;
 
-                AUDDBG("seeking to: %d bytes", new_position);
+                AUDDBG("seeking to: %d bytes\n", new_position);
 
                 if (aud_vfs_fseek(info->infile, new_position, SEEK_SET) == -1)
                     audmad_error("failed to seek to: %d", new_position);
@@ -570,7 +570,7 @@
                     }
                 }
 
-                AUDDBG("(recovered) error decoding header %d: %s",
+                AUDDBG("(recovered) error decoding header %d: %s\n",
                           info->current_frame,
                           mad_stream_errorstr(&stream));
 
@@ -582,7 +582,7 @@
             if (!audmad_config.show_avg_vbr_bitrate && info->vbr && (iteration % 40 == 0)) {
 
 #ifdef DEBUG_INTENSIVELY
-                AUDDBG("decode vbr tlen = %d", tlen);
+                AUDDBG("decode vbr tlen = %d\n", tlen);
 #endif
                 info->playback->set_params(info->playback, info->title,
                                      (tlen == 0 || info->size <= 0) ? -1 : tlen,
@@ -594,7 +594,7 @@
                 if (!MAD_RECOVERABLE(stream.error))
                     break;
 
-                AUDDBG("(recovered) error decoding frame %d: %s",
+                AUDDBG("(recovered) error decoding frame %d: %s\n",
                           info->current_frame,
                           mad_stream_errorstr(&stream));
 
@@ -606,10 +606,10 @@
                 || info->channels !=
                 (guint) MAD_NCHANNELS(&frame.header)) {
 
-                AUDDBG("change in audio type detected");
-                AUDDBG("old: frequency = %d, channels = %d", info->freq,
+                AUDDBG("change in audio type detected\n");
+                AUDDBG("old: frequency = %d, channels = %d\n", info->freq,
                           info->channels);
-                AUDDBG("new: frequency = %d, channels = %d",
+                AUDDBG("new: frequency = %d, channels = %d\n",
                           frame.header.samplerate,
                           (guint) MAD_NCHANNELS(&frame.header));
 
@@ -619,7 +619,7 @@
                 if(audmad_config.force_reopen_audio && check_audio_param(info)) {
                     gint current_time = info->playback->output->output_time();
 
-                    AUDDBG("re-opening audio due to change in audio type");
+                    AUDDBG("re-opening audio due to change in audio type\n");
 
                     info->playback->output->close_audio();
                     if (!info->playback->output->open_audio(info->fmt, info->freq,
@@ -660,7 +660,7 @@
         info->playback->output->buffer_free();
         while (info->playback->output->buffer_playing()) {
 
-            AUDDBG("f: buffer_playing=%d", info->playback->output->buffer_playing());
+            AUDDBG("f: buffer_playing=%d\n", info->playback->output->buffer_playing());
 
             g_get_current_time(&sleeptime);
             g_time_val_add(&sleeptime, 500000);
@@ -675,7 +675,7 @@
         }
     }
 
-    AUDDBG("e: decode");
+    AUDDBG("e: decode\n");
 
     aud_tuple_free(info->tuple);
     info->tuple = NULL;
--- a/src/madplug/input.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/madplug/input.c	Tue Jan 01 16:04:29 2008 -0600
@@ -71,7 +71,7 @@
  */
 gboolean input_init(struct mad_info_t * info, const char *url, VFSFile *fd)
 {
-    AUDDBG("f: input_init");
+    AUDDBG("f: input_init\n");
 
     memset(info, 0, sizeof(struct mad_info_t)); // all fields are cleared to 0 --yaz
 
@@ -112,8 +112,8 @@
 
     info->fileinfo_request = FALSE;
 
-    AUDDBG("i: info->size = %lu", (long unsigned int)info->size);
-    AUDDBG("e: input_init");
+    AUDDBG("i: info->size = %lu\n", (long unsigned int)info->size);
+    AUDDBG("e: input_init\n");
 
     return TRUE;
 }
@@ -345,7 +345,7 @@
     Tuple *tuple;
     glong curpos = 0;
 
-    AUDDBG("f: input_read_tag");
+    AUDDBG("f: input_read_tag\n");
 
     if (info->tuple != NULL)
         aud_tuple_free(info->tuple);
@@ -362,13 +362,13 @@
     }
 
     if (!info->id3file) {
-        AUDDBG("read_tag: no id3file");
+        AUDDBG("read_tag: no id3file\n");
         return;
     }
 
     info->tag = id3_file_tag(info->id3file);
     if (!info->tag) {
-        AUDDBG("read_tag: no tag");
+        AUDDBG("read_tag: no tag\n");
         return;
     }
 
@@ -401,7 +401,7 @@
     string = input_id3_get_string(info->tag, "TLEN");
     if (string) {
         aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, atoi(string));
-        AUDDBG("input_read_tag: TLEN = %d", atoi(string));
+        AUDDBG("input_read_tag: TLEN = %d\n", atoi(string));
         g_free(string);
         string = NULL;
     } else
@@ -419,7 +419,7 @@
         aud_vfs_fseek(info->infile, curpos, SEEK_SET);
     }
     
-    AUDDBG("e: input_read_tag");
+    AUDDBG("e: input_read_tag\n");
 }
 
 void input_process_remote_metadata(struct mad_info_t *info)
@@ -430,7 +430,7 @@
         gchar *tmp = NULL;
 
 #ifdef DEBUG_INTENSIVELY
-        AUDDBG("process_remote_meta");
+        AUDDBG("process_remote_meta\n");
 #endif
         g_free(info->title);
         info->title = NULL;
@@ -500,7 +500,7 @@
 {
 #ifdef AUD_DEBUG
     gchar *tmp = g_filename_to_utf8(info->filename, -1, NULL, NULL, NULL);    
-    AUDDBG("f: input_get_info: %s, fast_scan = %s", tmp, fast_scan ? "TRUE" : "FALSE");
+    AUDDBG("f: input_get_info: %s, fast_scan = %s\n", tmp, fast_scan ? "TRUE" : "FALSE");
     g_free(tmp);
 #endif                          /* DEBUG */
 
@@ -513,7 +513,7 @@
 
     /* scan mp3 file, decoding headers */
     if (scan_file(info, fast_scan) == FALSE) {
-        AUDDBG("input_get_info: scan_file failed");
+        AUDDBG("input_get_info: scan_file failed\n");
         return FALSE;
     }
 
@@ -530,7 +530,7 @@
             info->title = g_strdup(info->filename); //XXX info->filename is uri. --yaz
     }
 
-    AUDDBG("e: input_get_info");
+    AUDDBG("e: input_get_info\n");
     return TRUE;
 }
 
@@ -549,7 +549,7 @@
 {
     int len = 0;
 #ifdef DEBUG_INTENSIVELY
-  AUDDBG ("f: input_get_data: %d", buffer_size);
+  AUDDBG ("f: input_get_data: %d\n", buffer_size);
 #endif
     /* simply read to data from the file */
     len = aud_vfs_fread(buffer, 1, buffer_size, info->infile); //aud_vfs_fread returns num of elements.
@@ -559,7 +559,7 @@
     }
 
 #ifdef DEBUG_INTENSIVELY
-    AUDDBG ("e: input_get_data: size=%d offset=%d", len, info->offset);
+    AUDDBG ("e: input_get_data: size=%d offset=%d\n", len, info->offset);
 #endif
 
     info->offset += len;
@@ -571,7 +571,7 @@
  */
 gboolean input_term(struct mad_info_t * info)
 {
-    AUDDBG("f: input_term");
+    AUDDBG("f: input_term\n");
 
     if (info->title)
         g_free(info->title);
@@ -608,7 +608,7 @@
     /* set everything to zero in case it gets used again. */
     memset(info, 0, sizeof(struct mad_info_t));
 
-    AUDDBG("e: input_term");
+    AUDDBG("e: input_term\n");
 
     return TRUE;
 }
--- a/src/madplug/plugin.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/madplug/plugin.c	Tue Jan 01 16:04:29 2008 -0600
@@ -104,14 +104,14 @@
     else
       x = 0;
     config->pregain_scale = (x != 0) ? pow(10.0, x / 20) : 1;
-    AUDDBG("pregain=[%s] -> %g  -> %g", text, x, config->pregain_scale);
+    AUDDBG("pregain=[%s] -> %g  -> %g\n", text, x, config->pregain_scale);
     text = config->replaygain.default_db;
     if ( text != NULL )
       x = g_strtod(text, NULL);
     else
       x = 0;
     config->replaygain.default_scale = (x != 0) ? pow(10.0, x / 20) : 1;
-    AUDDBG("RG.default=[%s] -> %g  -> %g", text, x,
+    AUDDBG("RG.default=[%s] -> %g  -> %g\n", text, x,
               config->replaygain.default_scale);
 }
 
@@ -403,7 +403,7 @@
 
 static void audmad_stop(InputPlayback *playback)
 {
-    AUDDBG("f: audmad_stop");
+    AUDDBG("f: audmad_stop\n");
     g_mutex_lock(mad_mutex);
     info.playback = playback;
     g_mutex_unlock(mad_mutex);
@@ -415,15 +415,15 @@
         g_mutex_unlock(mad_mutex);
         g_cond_signal(mad_cond);
 
-        AUDDBG("waiting for thread");
+        AUDDBG("waiting for thread\n");
         g_thread_join(decode_thread);
-        AUDDBG("thread done");
+        AUDDBG("thread done\n");
 
         input_term(&info);
         decode_thread = NULL;
 
     }
-    AUDDBG("e: audmad_stop");
+    AUDDBG("e: audmad_stop\n");
 }
 
 static void audmad_play_file(InputPlayback *playback)
@@ -434,7 +434,7 @@
 #ifdef AUD_DEBUG
     {
         gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL);
-        AUDDBG("playing %s", tmp);
+        AUDDBG("playing %s\n", tmp);
         g_free(tmp);
     }
 #endif                          /* DEBUG */
@@ -496,12 +496,12 @@
     struct mad_info_t myinfo;
 #ifdef AUD_DEBUG
     gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL);
-    AUDDBG("f: audmad_get_song_info: %s", tmp);
+    AUDDBG("f: audmad_get_song_info: %s\n", tmp);
     g_free(tmp);
 #endif                          /* DEBUG */
 
     if (input_init(&myinfo, url, NULL) == FALSE) {
-        AUDDBG("error initialising input");
+        AUDDBG("error initialising input\n");
         return;
     }
 
@@ -520,17 +520,17 @@
         *length = -1;
     }
     input_term(&myinfo);
-    AUDDBG("e: audmad_get_song_info");
+    AUDDBG("e: audmad_get_song_info\n");
 }
 
 static gboolean
 audmad_fill_info(struct mad_info_t *info, VFSFile *fd)
 {
     if (fd == NULL || info == NULL) return FALSE;
-    AUDDBG("f: audmad_fill_info(): %s", fd->uri);
+    AUDDBG("f: audmad_fill_info(): %s\n", fd->uri);
 
     if (input_init(info, fd->uri, fd) == FALSE) {
-        AUDDBG("audmad_fill_info(): error initialising input");
+        AUDDBG("audmad_fill_info(): error initialising input\n");
         return FALSE;
     }
     
@@ -621,7 +621,7 @@
 
 #ifdef AUD_DEBUG
     string = aud_str_to_utf8(filename);
-    AUDDBG("f: mad: audmad_get_song_tuple: %s", string);
+    AUDDBG("f: mad: audmad_get_song_tuple: %s\n", string);
     g_free(string);
     string = NULL;
 #endif
@@ -635,7 +635,7 @@
 
 #ifdef AUD_DEBUG
             if(info.playback)
-                AUDDBG("info.playback->playing = %d",info.playback->playing);
+                AUDDBG("info.playback->playing = %d\n",info.playback->playing);
 #endif
             tmp = aud_vfs_get_metadata(info.infile ? info.infile : fd, "track-name");
             if(tmp){
@@ -660,14 +660,14 @@
                 tmp = NULL;
             }
 
-            AUDDBG("audmad_get_song_tuple: track_name = %s", aud_tuple_get_string(tuple, -1, "track-name"));
-            AUDDBG("audmad_get_song_tuple: stream_name = %s", aud_tuple_get_string(tuple, -1, "stream-name"));
+            AUDDBG("audmad_get_song_tuple: track_name = %s\n", aud_tuple_get_string(tuple, -1, "track-name"));
+            AUDDBG("audmad_get_song_tuple: stream_name = %s\n", aud_tuple_get_string(tuple, -1, "stream-name"));
             aud_tuple_associate_int(tuple, FIELD_LENGTH, NULL, -1);
             aud_tuple_associate_int(tuple, FIELD_MTIME, NULL, 0); // this indicates streaming
-            AUDDBG("get_song_tuple: remote: tuple");
+            AUDDBG("get_song_tuple: remote: tuple\n");
             return tuple;
         }
-        AUDDBG("get_song_tuple: remote: NULL");
+        AUDDBG("get_song_tuple: remote: NULL\n");
     } /* info.remote  */
 
     // if !fd, pre-open the file with aud_vfs_fopen() and reuse fd.
@@ -727,7 +727,7 @@
             // genre
             __set_and_free(tuple, FIELD_GENRE, NULL, input_id3_get_string(tag, ID3_FRAME_GENRE));
             __set_and_free(tuple, FIELD_COMMENT, NULL, input_id3_get_string(tag, ID3_FRAME_COMMENT));
-            AUDDBG("genre = %s", aud_tuple_get_string(tuple, FIELD_GENRE, NULL));
+            AUDDBG("genre = %s\n", aud_tuple_get_string(tuple, FIELD_GENRE, NULL));
         }
         id3_file_close(id3file);
     } // id3file
@@ -755,7 +755,7 @@
     if(local_fd)
         aud_vfs_fclose(fd);
 
-    AUDDBG("e: mad: audmad_get_song_tuple");
+    AUDDBG("e: mad: audmad_get_song_tuple\n");
     return tuple;
 }
 
--- a/src/madplug/replaygain.c	Tue Jan 01 16:03:44 2008 -0600
+++ b/src/madplug/replaygain.c	Tue Jan 01 16:04:29 2008 -0600
@@ -203,11 +203,11 @@
 	char *value;
 	struct id3_frame *frame;
 
-	AUDDBG("f: ReadId3v2TXXX");
+	AUDDBG("f: ReadId3v2TXXX\n");
 
 	/* tag must be read before! */
 	if (! file_info->tag ) {
-		AUDDBG("id3v2 not found");
+		AUDDBG("id3v2 not found\n");
 		return 0;
 	}
 
@@ -255,7 +255,7 @@
     VFSFile *fp;
     glong curpos = 0;
 
-    AUDDBG("f: read_replaygain");
+    AUDDBG("f: read_replaygain\n");
 
     file_info->has_replaygain = FALSE;
     file_info->replaygain_album_scale = -1;
@@ -265,10 +265,10 @@
 
     if (ReadId3v2TXXX(file_info)) {
 #ifdef AUD_DEBUG
-        AUDDBG("found ReplayGain info in id3v2 tag");
+        AUDDBG("found ReplayGain info in id3v2 tag\n");
 
 	gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL);
-        AUDDBG("RG album scale= %g, RG track scale = %g, in %s",
+        AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n",
 		  file_info->replaygain_album_scale,
 		  file_info->replaygain_track_scale, tmp);
         g_free(tmp);
@@ -318,13 +318,13 @@
         }
 #ifdef AUD_DEBUG
         else 
-            AUDDBG("replaygain: not found");
+            AUDDBG("replaygain: not found\n");
 #endif
     }
 #ifdef AUD_DEBUG
     if (res == 0) {             // got APE tags, show the result
         gchar *tmp = g_filename_to_utf8(file_info->filename, -1, NULL, NULL, NULL);        
-        AUDDBG("RG album scale= %g, RG track scale = %g, in %s",
+        AUDDBG("RG album scale= %g, RG track scale = %g, in %s\n",
 		  file_info->replaygain_album_scale,
 		  file_info->replaygain_track_scale, tmp);
         g_free(tmp);
@@ -340,5 +340,5 @@
 
     aud_vfs_fclose(fp);
 
-    AUDDBG("e: read_replaygain");
+    AUDDBG("e: read_replaygain\n");
 }