3

I've managed to get myself into an argument elsewhere trying to discourage somebody from writing a library that invokes aplay in order to get a GUI program to make a simple noise: the sort of thing that on a text console would be done by \a

My understanding is that ALSA as a subsystem is fairly pervasive, and libasound.so as a client library appears to be installed on any (Linux) host capable of running a GUI-oriented program even if it doesn't have a full desktop environment (i.e. a program relies on X11 tunnelled over SSH etc.).

On the other hand, I notice https://www.gnu.org/software/emacs/manual/html_node/elisp/Desktop-Notifications.html which implies that at least Emacs is able to raise an audible alert via D-Bus, and it looks as though KDE's konsole does something similar although I've not yet looked inside the messages in detail. In those cases I don't know if it's possible to rely on the fact that there's a theme-selected default alert sound.

I've not found anything equivalent using e.g. wmctrl.

Does the community think that best practice would be to interface with ALSA via libasound, or is there in fact a better way using e.g. D-Bus or some other way of interceding with the desktop environment (Window Manager etc.)?

1 Answers1

2

There is nothing more annoying than a program that makes a sound that you cannot control. If you want to give immediate feedback to something typed or clicked, use something visual. At the most basic level, the X11 equivalent to a terminal bell is function XBell(), which works over any X11 connection. xkb added more functionality with XkbBell() and XkbForceBell() etc.

Otherwise, if you want to give notification that some background or long-term operation has changed state, use libnotify and let the user configure a notification daemon.

The gnome specification has hints where, for example, you can specify

  • "sound-file" The path to a sound file to play when the notification pops up, or
  • "sound-name" A themeable named sound from the freedesktop.org sound naming specification to play when the notification pops up.

But implementing hints is optional in a server. To test one out try

notify-send --hint string:sound-name:dialog-ok myheader 'my msg'
meuh
  • 49,672
  • 2
  • 52
  • 114
  • Noted your suggestion of libnotify but I'm afraid that apart from that it's not helpful. This is for a development tool's runtime libraries, which has a Beep() function which works on Windows but has never been implemented for Linux etc. – Mark Morgan Lloyd Oct 23 '20 at 13:04
  • Yes, I'm using xbell myself but it tends to be implemented by a PC's mainboard speaker- which (I'm told) is often not fitted. Also it has quite an overhead in X11 development libraries. – Mark Morgan Lloyd Oct 23 '20 at 13:06
  • Yes, I'm using those and certainly on current Debian they work but aren't exactly strident. I'm revisiting libnotify (I'd read up on it in the past) and it might be the best route, provided that there's some reliable way to work out the "true names" of the various notifications (e.g. as used in the example at https://wiki.archlinux.org/index.php/Desktop_notifications#Pascal) with what can be configured in e.g. KDE's setup app... but I dread trying to talk an inexperienced user through that sort of thing. – Mark Morgan Lloyd Oct 23 '20 at 13:35
  • All the descriptions I can find of this generate sound by having the sender run both notify-send and some sort of media player. I can't find anything about getting the notifier backend to play the sound, or about how to use the same (D-Bus?) notifications as e.g. Konsole. – Mark Morgan Lloyd Oct 23 '20 at 20:00
  • Yes, but so far I've not been able to tie that to anything that notify-send can do and one would expect to simply be able to use dialog-information or whatever and leave the actual choice to a theme setting. Also it's unclear whether notify-send can trigger a sound without displaying a dialog(ue). – Mark Morgan Lloyd Oct 23 '20 at 22:21
  • "`XBell()`, which works over any X11 connection" **`xset b off`**. There was a guy who collected info about how to shut up ringing and blinking widgets in all kind of systems, but lately it got quite out of date. And "modern" apps do not care about user's preferences as a matter of design philosophy, anyways ;-) –  Oct 24 '20 at 17:12
  • @MarkMorganLloyd the mainboard "bell" is usually redirected through the sound-card, and accessible through alsa controls. –  Oct 24 '20 at 17:15
  • @user414777 not in my experience and that of the other users I'm discussing this with. – Mark Morgan Lloyd Oct 24 '20 at 17:27
  • @MarkMorganLloyd Many motherboards have a bios/efi setting for that. It's also been the (unchangeable) default on all the recent laptops I've used. –  Oct 24 '20 at 17:37
  • @user414777 I note what you're saying but it is definitely not my experience, is not the perception of other developers I'm discussing it with, and is tangential to my explicit question in OP. – Mark Morgan Lloyd Oct 24 '20 at 17:57
  • @MarkMorganLloyd When participating in online discussions, please try to keep it to the facts, and not police other contributors. After re-reading your Q, I see that you're trying to collect bogus arguments in order to "correct" people who are using aplay (which is just fine: many Linux systems where aplay *just works* do not have either dbus or xorg). Also your assumptions about the role of a wm are completely off. From all that mess, I've first assumed that you just wanted to know how to reliably produce a beep (a practical problem), and I tried to help. I was wrong. –  Oct 24 '20 at 18:40
  • @user414777 I was not trying to collect arguments- bogus or otherwise. I was trying to sort out a practical problem where somebody had suggested that the runtimes of FPC/Lazarus should on Linux invoke aplay plus an appropriate file, which on Windows can be done by invocation of a standard API: this was considered inappropriate by most people involved and was vetoed by a core developer. I assumed- at one point- that something related to wmctrl might work since it controls several things related to the overall desktop environment, I was wrong with both that and later (it appears) with libnotify. – Mark Morgan Lloyd Oct 24 '20 at 18:55
  • @meuh Unfortunately the example you've added was silent on my system and displayed a warning panel, which is rather the opposite of what I'm trying to do. – Mark Morgan Lloyd Oct 25 '20 at 08:13
  • 1
    It looks as though libnotify, wmctrl etc don't sound a bell reliably, i.e. what was asked in OP; it also looks as though (from discussion elsewhere) a simple \a doesn't work since in general the onboard beeper isn't redirected to ALSA and a GUI-based program might be running without stdout etc. I find I can do it with a drastically cut-down interface to libasound which (unlike the aplay utility) is almost universally installed; it is regrettable that this moves completely outside thematicisation but it looks like the best solution. I am accepting this answer in appreciation of @meuh 's work. – Mark Morgan Lloyd Oct 25 '20 at 08:23