godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add a `DisplayServer.beep()` method to produce an OS beep sound #11179

Open markeel opened 3 hours ago

markeel commented 3 hours ago

Describe the project you are working on

Writing an editor plugin as an extension that allows access to a command line terminal from within the Godot Editor. This should look and behave as much like a native terminal application as possible. This includes providing a sound when the terminal would normally issue a "bell" sound.

Describe the problem or limitation you are having in your project

Ideally the bell sound would be the same sound heard as part of any other OS function when a bell alert is presented. But currently there is no access to the underlying X11/Mac/Windows API that would allow the OS native bell or beep.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The enhancement would be to expose on the DisplayServer a beep() method that would provide the OS specific beep sound. This would only apply to Linux/Mac/Windows (not Web/Android etc.). It could be a no-op for other platforms like Android/iOS/Web

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Here is an example implementation of different bell or beep sounds.

void DisplayServerX11::beep() const {
    XBell(x11_display, 0);
}

void DisplayServerMacOS::beep() const {
    NSBeep();
}

void DisplayServerWindows::beep() const {
    MessageBeep(MB_OK);
}

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can sort of be worked around, by creating a AudioStreamPlayer and including a sound file that provides a beep, but it would not really match what the user normally experiences outside the Godot editor.

Is there a reason why this should be core and not an add-on in the asset library?

Since it is exposing a feature behind a core function (the DisplayServer) it would need to be part of the core, but it should also be exposed on the GDExtension interface of DisplayServer so that extensions can use it.

Calinou commented 3 hours ago

This would go well with Window.request_attention() since you can call it and DisplayServer.beep() at the same time.