mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel+Userland: Add support for using the PCSpeaker with various tones
This commit is contained in:
parent
2d27c98659
commit
11a7e21c2a
Notes:
sideshowbarker
2024-07-17 07:35:03 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/11a7e21c2a Pull-request: https://github.com/SerenityOS/serenity/pull/17687 Reviewed-by: https://github.com/AtkinsSJ
9 changed files with 26 additions and 12 deletions
|
@ -12,6 +12,10 @@ $ beep
|
|||
|
||||
beep allows the user to beep the PC speaker.
|
||||
|
||||
## Options
|
||||
|
||||
* `-f|--beep-tone`: Beep tone (frequency in Hz)
|
||||
|
||||
## Notes
|
||||
|
||||
If the user disabled the usage of PC speaker in the kernel commandline, the program
|
||||
|
@ -20,7 +24,10 @@ will fail to use the PC speaker.
|
|||
## Examples
|
||||
|
||||
```sh
|
||||
# Use beep with default tone
|
||||
$ beep
|
||||
# Use beep with tone of 1000Hz
|
||||
$ beep -f 1000
|
||||
```
|
||||
|
||||
## See also
|
||||
|
|
|
@ -291,7 +291,7 @@ public:
|
|||
ErrorOr<FlatPtr> sys$emuctl();
|
||||
ErrorOr<FlatPtr> sys$yield();
|
||||
ErrorOr<FlatPtr> sys$sync();
|
||||
ErrorOr<FlatPtr> sys$beep();
|
||||
ErrorOr<FlatPtr> sys$beep(int tone);
|
||||
ErrorOr<FlatPtr> sys$get_process_name(Userspace<char*> buffer, size_t buffer_size);
|
||||
ErrorOr<FlatPtr> sys$set_process_name(Userspace<char const*> user_name, size_t user_name_length);
|
||||
ErrorOr<FlatPtr> sys$create_inode_watcher(u32 flags);
|
||||
|
|
|
@ -12,13 +12,15 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
ErrorOr<FlatPtr> Process::sys$beep()
|
||||
ErrorOr<FlatPtr> Process::sys$beep(int tone)
|
||||
{
|
||||
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
||||
if (!kernel_command_line().is_pc_speaker_enabled())
|
||||
return ENODEV;
|
||||
if (tone < 20 || tone > 20000)
|
||||
return EINVAL;
|
||||
#if ARCH(X86_64)
|
||||
PCSpeaker::tone_on(440);
|
||||
PCSpeaker::tone_on(tone);
|
||||
auto result = Thread::current()->sleep(Time::from_nanoseconds(200'000'000));
|
||||
PCSpeaker::tone_off();
|
||||
if (result.was_interrupted())
|
||||
|
|
|
@ -924,9 +924,9 @@ int gettid()
|
|||
return cached_tid;
|
||||
}
|
||||
|
||||
int sysbeep()
|
||||
int sysbeep(int tone)
|
||||
{
|
||||
int rc = syscall(SC_beep);
|
||||
int rc = syscall(SC_beep, tone);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ int get_process_name(char* buffer, int buffer_size);
|
|||
int set_process_name(char const* name, size_t name_length);
|
||||
void dump_backtrace(void);
|
||||
int fsync(int fd);
|
||||
int sysbeep(void);
|
||||
int sysbeep(int tone);
|
||||
int gettid(void);
|
||||
int getpagesize(void);
|
||||
pid_t fork(void);
|
||||
|
|
|
@ -132,9 +132,9 @@ namespace Core::System {
|
|||
|
||||
#ifdef AK_OS_SERENITY
|
||||
|
||||
ErrorOr<void> beep()
|
||||
ErrorOr<void> beep(Optional<size_t> tone)
|
||||
{
|
||||
auto rc = ::sysbeep();
|
||||
auto rc = ::sysbeep(tone.value_or(440));
|
||||
if (rc < 0)
|
||||
return Error::from_syscall("beep"sv, -errno);
|
||||
return {};
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
namespace Core::System {
|
||||
|
||||
#ifdef AK_OS_SERENITY
|
||||
ErrorOr<void> beep();
|
||||
ErrorOr<void> beep(Optional<size_t> tone);
|
||||
ErrorOr<void> pledge(StringView promises, StringView execpromises = {});
|
||||
ErrorOr<void> unveil(StringView path, StringView permissions);
|
||||
ErrorOr<void> unveil_after_exec(StringView path, StringView permissions);
|
||||
|
|
|
@ -1067,7 +1067,7 @@ void TerminalWidget::beep()
|
|||
return;
|
||||
}
|
||||
if (m_bell_mode == BellMode::AudibleBeep) {
|
||||
sysbeep();
|
||||
sysbeep(440);
|
||||
return;
|
||||
}
|
||||
m_visual_beep_timer->restart(200);
|
||||
|
|
|
@ -4,11 +4,16 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
TRY(Core::System::beep());
|
||||
Optional<size_t> tone;
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(tone, "Beep tone", "beep-tone", 'f', "Beep tone (frequency in Hz)");
|
||||
args_parser.parse(arguments);
|
||||
TRY(Core::System::beep(tone));
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue