diff --git a/CMakeLists.txt b/CMakeLists.txt index 015ccf9..8b3fe14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 () diff --git a/README.adoc b/README.adoc index 833987a..2a22b7d 100644 --- a/README.adoc +++ b/README.adoc @@ -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 diff --git a/config.h.in b/config.h.in index 85d85ba..95ecddd 100644 --- a/config.h.in +++ b/config.h.in @@ -8,6 +8,7 @@ #cmakedefine HAVE_LUA #cmakedefine HAVE_X11 +#cmakedefine HAVE_CANBERRA #cmakedefine01 ICONV_ACCEPTS_TRANSLIT diff --git a/xF.c b/xF.c index a517983..2a2005c 100644 --- a/xF.c +++ b/xF.c @@ -26,6 +26,9 @@ #include "xC-proto.c" #include +#ifdef HAVE_CANBERRA +#include +#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); }