From bbdfdb978d7a1411e4a109c85632092da7aaa2da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 24 Sep 2021 07:31:02 +0530 Subject: [PATCH] Modify canberra wrapper to allow specifying a sound file path --- kitty/data-types.h | 2 +- kitty/desktop.c | 10 ++++++---- kitty/glfw.c | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 2451cafda..d23366a97 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -343,7 +343,7 @@ void scroll_event(double, double, int, int); void on_key_input(GLFWkeyevent *ev); void request_window_attention(id_type, bool); #ifndef __APPLE__ -void play_canberra_sound(const char *which_sound, const char *event_id); +void play_canberra_sound(const char *which_sound, const char *event_id, bool is_path); #endif SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int); SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE); diff --git a/kitty/desktop.c b/kitty/desktop.c index d8335f4bc..3013e918a 100644 --- a/kitty/desktop.c +++ b/kitty/desktop.c @@ -145,12 +145,13 @@ load_libcanberra(void) { } void -play_canberra_sound(const char *which_sound, const char *event_id) { +play_canberra_sound(const char *which_sound, const char *event_id, bool is_path) { load_libcanberra(); if (libcanberra_handle == NULL || canberra_ctx == NULL) return; + const char *which_type = is_path ? "media.filename" : "event.id"; ca_context_play( canberra_ctx, 0, - "event.id", which_sound, + which_type, which_sound, "event.description", event_id, NULL ); @@ -159,8 +160,9 @@ play_canberra_sound(const char *which_sound, const char *event_id) { static PyObject* play_desktop_sound(PyObject *self UNUSED, PyObject *args) { const char *which, *event_id = "test sound"; - if (!PyArg_ParseTuple(args, "s|s", &which, &event_id)) return NULL; - play_canberra_sound(which, event_id); + int is_path = 0; + if (!PyArg_ParseTuple(args, "s|sp", &which, &event_id, &is_path)) return NULL; + play_canberra_sound(which, event_id, is_path); Py_RETURN_NONE; } diff --git a/kitty/glfw.c b/kitty/glfw.c index 6e4386fec..2f61fa400 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1117,7 +1117,7 @@ ring_audio_bell(void) { #ifdef __APPLE__ cocoa_system_beep(); #else - play_canberra_sound("bell", "kitty bell"); + play_canberra_sound("bell", "kitty bell", false); #endif }