Linux: Use the system "bell" for the terminal bell

Adds libcanberra as a new dependency to play the system sound.
This commit is contained in:
Kovid Goyal 2019-07-03 22:06:47 +05:30
parent 2e8188e89d
commit 2cfd55f3ce
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 33 additions and 2 deletions

View File

@ -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

View File

@ -38,6 +38,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- 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]
---------------------

View File

@ -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);

View File

@ -7,6 +7,7 @@
#include "data-types.h"
#include <dlfcn.h>
#include <canberra.h>
#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

View File

@ -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*

View File

@ -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: