From 2cfd55f3ce6daa008a81c8074406d62c43191e70 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 3 Jul 2019 22:06:47 +0530 Subject: [PATCH] Linux: Use the system "bell" for the terminal bell Adds libcanberra as a new dependency to play the system sound. --- docs/build.rst | 3 ++- docs/changelog.rst | 3 +++ kitty/data-types.h | 3 +++ kitty/desktop.c | 17 +++++++++++++++++ kitty/glfw.c | 6 +++++- setup.py | 3 +++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/build.rst b/docs/build.rst index c7cd2f2e0..bdc5f1152 100644 --- a/docs/build.rst +++ b/docs/build.rst @@ -20,6 +20,7 @@ Run-time dependencies: * libpng * freetype (not needed on macOS) * fontconfig (not needed on macOS) + * libcanberra (not needed on macOS) * ImageMagick (optional, needed to use the ``kitty icat`` tool to display images in the terminal) * pygments (optional, need for syntax highlighting in ``kitty +kitten diff``) @@ -28,7 +29,7 @@ Build-time dependencies: * gcc or clang * pkg-config * For building on Linux in addition to the above dependencies you might also need to install the ``-dev`` packages for: - ``libdbus-1-dev``, ``libxcursor-dev``, ``libxrandr-dev``, ``libxi-dev``, ``libxinerama-dev``, ``libgl1-mesa-dev``, ``libxkbcommon-x11-dev``, ``libfontconfig-dev`` and ``libpython-dev``. + ``libdbus-1-dev``, ``libxcursor-dev``, ``libxrandr-dev``, ``libxi-dev``, ``libxinerama-dev``, ``libgl1-mesa-dev``, ``libxkbcommon-x11-dev``, ``libfontconfig-dev``, ``libcanberra-dev`` and ``libpython-dev``. if they are not already installed by your distro. Install and run from source diff --git a/docs/changelog.rst b/docs/changelog.rst index 7c296799c..3ee3dee12 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -38,6 +38,9 @@ To update |kitty|, :doc:`follow the instructions `. - Fix an out of bounds read causing a crash when selecting text with the mouse in the alternate screen mode (:iss:`1578`) +- Linux: Use the system "bell" sound for the terminal bell. Adds libcanberra + as a new dependency to play the system sound. + 0.14.2 [2019-06-09] --------------------- diff --git a/kitty/data-types.h b/kitty/data-types.h index d9e9629fe..76a2b91c0 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -307,5 +307,8 @@ void fake_scroll(int, bool); void set_special_key_combo(int glfw_key, int mods, bool is_native); void on_key_input(int key, int scancode, int action, int mods, const char*, int); void request_window_attention(id_type, bool); +#ifndef __APPLE__ +void play_canberra_sound(const char *which_sound, const char *event_id); +#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 5681ae4b4..69fbeeaa3 100644 --- a/kitty/desktop.c +++ b/kitty/desktop.c @@ -7,6 +7,7 @@ #include "data-types.h" #include +#include #define FUNC(name, restype, ...) typedef restype (*name##_func)(__VA_ARGS__); static name##_func name = NULL #define LOAD_FUNC(handle, name) {\ @@ -89,9 +90,25 @@ static PyMethodDef module_methods[] = { {NULL, NULL, 0, NULL} /* Sentinel */ }; +static ca_context *canberra_ctx = NULL; + +void +play_canberra_sound(const char *which_sound, const char *event_id) { + if (canberra_ctx == NULL) ca_context_create(&canberra_ctx); + ca_context_play( + canberra_ctx, 0, + CA_PROP_EVENT_ID, which_sound, + CA_PROP_EVENT_DESCRIPTION, event_id, + NULL + ); +} + static void finalize(void) { if (libsn_handle) dlclose(libsn_handle); + libsn_handle = NULL; + if (canberra_ctx) ca_context_destroy(canberra_ctx); + canberra_ctx = NULL; } bool diff --git a/kitty/glfw.c b/kitty/glfw.c index ed80857cd..997ce3a3f 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -819,14 +819,18 @@ get_clipboard_string(PYNOARG) { } void -ring_audio_bell(OSWindow *w) { +ring_audio_bell(OSWindow *w UNUSED) { static double last_bell_at = -1; double now = monotonic(); if (now - last_bell_at <= 0.1) return; last_bell_at = now; +#ifdef __APPLE__ if (w->handle) { glfwWindowBell(w->handle); } +#else + play_canberra_sound("bell", "kitty bell"); +#endif } static PyObject* diff --git a/setup.py b/setup.py index ad2ea2823..c4b5af938 100755 --- a/setup.py +++ b/setup.py @@ -273,6 +273,9 @@ def kitty_env(): gl_libs = ['-framework', 'OpenGL'] if is_macos else pkg_config('gl', '--libs') libpng = pkg_config('libpng', '--libs') ans.ldpaths += pylib + font_libs + gl_libs + libpng + if not is_macos: + cflags.extend(pkg_config('libcanberra', '--cflags-only-I')) + ans.ldpaths += pkg_config('libcanberra', '--libs') if is_macos: ans.ldpaths.extend('-framework Cocoa'.split()) else: