From 720d8889ad3a74c9b4776ebf5a7b435a30fd1c5d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 3 Jul 2023 11:13:38 -0400 Subject: [PATCH] LibWeb: Allow changing media volume with keyboard controls This allows increasing and decreasing the media volume by 10% with the up and down arrow keys, respectively. This also allows toggling the mute state with the M key. --- .../Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index d1a7432ea2..216f7bd88f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -1885,6 +1885,24 @@ WebIDL::ExceptionOr HTMLMediaElement::handle_keydown(Badgevolume(); + + if (key == KeyCode::Key_Up) + volume = min(1.0, volume + volume_change_per_key_press); + else + volume = max(0.0, volume - volume_change_per_key_press); + + TRY(set_volume(volume)); + break; + } + + case KeyCode::Key_M: + set_muted(!muted()); + break; + default: break; }