Don't open libcanberra connection for every event

Closes #645
This commit is contained in:
TingPing 2013-06-12 10:41:52 -04:00
parent 8ce1a9476d
commit 8be56d7003
2 changed files with 26 additions and 11 deletions

View File

@ -58,6 +58,9 @@ struct pevt_stage1
struct pevt_stage1 *next; struct pevt_stage1 *next;
}; };
#ifdef USE_LIBCANBERRA
static ca_context *ca_con;
#endif
static void mkdir_p (char *filename); static void mkdir_p (char *filename);
static char *log_create_filename (char *channame); static char *log_create_filename (char *channame);
@ -2209,9 +2212,6 @@ sound_play (const char *file, gboolean quiet)
char *wavfile; char *wavfile;
#ifndef WIN32 #ifndef WIN32
char *cmd; char *cmd;
#ifdef USE_LIBCANBERRA
ca_context *con;
#endif
#endif #endif
/* the pevents GUI editor triggers this after removing a soundfile */ /* the pevents GUI editor triggers this after removing a soundfile */
@ -2240,9 +2240,16 @@ sound_play (const char *file, gboolean quiet)
PlaySound (wavfile, NULL, SND_NODEFAULT|SND_FILENAME|SND_ASYNC); PlaySound (wavfile, NULL, SND_NODEFAULT|SND_FILENAME|SND_ASYNC);
#else #else
#ifdef USE_LIBCANBERRA #ifdef USE_LIBCANBERRA
ca_context_create (&con); if (ca_con == NULL)
/* TODO: Volume setting? */ {
if (ca_context_play (con, 0, CA_PROP_MEDIA_FILENAME, wavfile, NULL) != 0) ca_context_create (&ca_con);
ca_context_change_props (ca_con,
CA_PROP_APPLICATION_ID, "hexchat",
CA_PROP_APPLICATION_NAME, "HexChat",
CA_PROP_APPLICATION_ICON_NAME, "hexchat", NULL);
}
if (ca_context_play (ca_con, 0, CA_PROP_MEDIA_FILENAME, wavfile, NULL) != 0)
#endif #endif
{ {
cmd = g_find_program_in_path ("play"); cmd = g_find_program_in_path ("play");

View File

@ -62,6 +62,9 @@
GdkPixmap *channelwin_pix; GdkPixmap *channelwin_pix;
#ifdef USE_LIBCANBERRA
static ca_context *ca_con;
#endif
#ifdef USE_XLIB #ifdef USE_XLIB
@ -674,11 +677,16 @@ fe_beep (session *sess)
} }
#else #else
#ifdef USE_LIBCANBERRA #ifdef USE_LIBCANBERRA
ca_context *con; if (ca_con == NULL)
ca_context_create (&con); {
if (ca_context_play (con, 0, ca_context_create (&ca_con);
ca_context_change_props (ca_con,
CA_PROP_APPLICATION_ID, "hexchat",
CA_PROP_APPLICATION_NAME, DISPLAY_NAME, CA_PROP_APPLICATION_NAME, DISPLAY_NAME,
CA_PROP_EVENT_ID, "message-new-instant", NULL) != 0) CA_PROP_APPLICATION_ICON_NAME, "hexchat", NULL);
}
if (ca_context_play (ca_con, 0, CA_PROP_EVENT_ID, "message-new-instant", NULL) != 0)
#endif #endif
gdk_beep (); gdk_beep ();
#endif #endif