xF: play highlight sounds through libcanberra
Alpine 3.24 Success
Arch Linux AUR Success
OpenBSD 7.8 Success

This commit is contained in:
2026-08-10 07:30:19 +02:00
parent 36037cb3e5
commit 959fb15828
4 changed files with 49 additions and 3 deletions
+19
View File
@@ -153,9 +153,23 @@ if (WITH_X11 AND NOT x11_FOUND)
message (FATAL_ERROR "Some X11 libraries were not found")
endif ()
pkg_check_modules (canberra libcanberra)
set (canberra_SATISFIED FALSE)
if (WITH_X11 AND canberra_FOUND)
set (canberra_SATISFIED TRUE)
endif ()
option (WITH_CANBERRA "Build xF with libcanberra sound support"
"${canberra_SATISFIED}")
if (WITH_CANBERRA AND NOT WITH_X11)
message (FATAL_ERROR "libcanberra support requires X11 support")
elseif (WITH_CANBERRA AND NOT canberra_FOUND)
message (FATAL_ERROR "libcanberra not found")
endif ()
# Generate a configuration file
set (HAVE_LUA "${WITH_LUA}")
set (HAVE_X11 "${WITH_X11}")
set (HAVE_CANBERRA "${WITH_CANBERRA}")
include (GNUInstallDirs)
set (project_config ${PROJECT_BINARY_DIR}/config.h)
@@ -214,6 +228,11 @@ if (WITH_XF)
target_link_directories (xF PRIVATE ${x11_LIBRARY_DIRS})
target_link_libraries (xF PRIVATE ${x11_LIBRARIES})
endif ()
if (WITH_CANBERRA)
target_include_directories (xF PRIVATE ${canberra_INCLUDE_DIRS})
target_link_directories (xF PRIVATE ${canberra_LIBRARY_DIRS})
target_link_libraries (xF PRIVATE ${canberra_LIBRARIES})
endif ()
add_threads (xF)
endif ()
+1 -1
View File
@@ -99,7 +99,7 @@ Build-only dependencies: CMake, pkg-config, awk, liberty (included),
Common runtime dependencies: openssl +
Additionally for 'xC': any curses, lua >= 5.3 (optional), termo (included) +
Additionally for 'xF': ncursesw, libunistring, termo (included),
x11 + xft + libpng (X11)
x11 + xft + libpng (X11), libcanberra (X11, optional)
$ git clone --recursive https://git.janouch.name/p/xK.git
$ mkdir xK/build
+1
View File
@@ -8,6 +8,7 @@
#cmakedefine HAVE_LUA
#cmakedefine HAVE_X11
#cmakedefine HAVE_CANBERRA
#cmakedefine01 ICONV_ACCEPTS_TRANSLIT
+28 -2
View File
@@ -26,6 +26,9 @@
#include "xC-proto.c"
#include <locale.h>
#ifdef HAVE_CANBERRA
#include <canberra.h>
#endif // HAVE_CANBERRA
#ifdef HAVE_X11
#define LIBERTY_XUI_WANT_X11
@@ -517,6 +520,9 @@ static struct
bool inserting_attribute; ///< M-m awaits an attribute selector
struct app_backend backend;
#ifdef HAVE_CANBERRA
ca_context *canberra; ///< X11 event sound context
#endif // HAVE_CANBERRA
}
g;
@@ -1415,7 +1421,13 @@ relay_process_buffer_line (struct buffer *b,
if (m->is_highlight || (!visible && !m->is_unimportant
&& b->kind == RELAY_BUFFER_KIND_PRIVATE_MESSAGE))
{
g_xui.ui->beep ();
#ifdef HAVE_CANBERRA
if (g_xui.ui != &x11_ui || !g.canberra
|| ca_context_play (g.canberra, 0,
CA_PROP_EVENT_ID, "message-new-instant", NULL))
#endif // HAVE_CANBERRA
g_xui.ui->beep ();
xui_request_attention ();
if (!visible)
b->highlighted = true;
@@ -2275,7 +2287,16 @@ app_select_backend (void)
g.backend.make_editor = tui_make_editor;
#ifdef HAVE_X11
if (g_xui.ui == &x11_ui)
{
g.backend.make_editor = x11_make_editor;
#ifdef HAVE_CANBERRA
if (!ca_context_create (&g.canberra))
ca_context_change_props (g.canberra,
CA_PROP_APPLICATION_NAME, PROGRAM_NAME,
CA_PROP_APPLICATION_ID, PROGRAM_NAME,
CA_PROP_APPLICATION_ICON_NAME, PROGRAM_NAME, NULL);
#endif // HAVE_CANBERRA
}
#endif // HAVE_X11
}
@@ -4458,14 +4479,19 @@ app_free_context (void)
free (g.relay.session_id);
regex_free (g.link_re);
#ifdef HAVE_CANBERRA
if (g.canberra)
(void) ca_context_destroy (g.canberra);
#endif // HAVE_CANBERRA
free (g.keys);
app_editor_free ();
if (g.editor_filename)
(void) unlink (g.editor_filename);
free (g.editor_filename);
free (g.editor_running_for);
poller_free (&g.poller);
poller_free (&g.poller);
str_map_free (&g.config);
}