diff --git a/Kernel/Devices/HID/HIDManagement.cpp b/Kernel/Devices/HID/HIDManagement.cpp index f110592833d..faa9b6753ce 100644 --- a/Kernel/Devices/HID/HIDManagement.cpp +++ b/Kernel/Devices/HID/HIDManagement.cpp @@ -12,6 +12,7 @@ namespace Kernel { +Atomic g_caps_lock_remapped_to_ctrl; static AK::Singleton s_the; // clang-format off diff --git a/Kernel/Devices/HID/HIDManagement.h b/Kernel/Devices/HID/HIDManagement.h index 6ab96940537..3ca0a8b4580 100644 --- a/Kernel/Devices/HID/HIDManagement.h +++ b/Kernel/Devices/HID/HIDManagement.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -20,6 +21,8 @@ namespace Kernel { +extern Atomic g_caps_lock_remapped_to_ctrl; + class HIDDevice; class I8042Controller; class MouseDevice; diff --git a/Kernel/Devices/HID/KeyboardDevice.cpp b/Kernel/Devices/HID/KeyboardDevice.cpp index 0faa6e995e7..f9e87e4ea72 100644 --- a/Kernel/Devices/HID/KeyboardDevice.cpp +++ b/Kernel/Devices/HID/KeyboardDevice.cpp @@ -234,9 +234,15 @@ void KeyboardDevice::key_state_changed(u8 scan_code, bool pressed) } } - if (key == Key_CapsLock && pressed) + if (!g_caps_lock_remapped_to_ctrl && key == Key_CapsLock && pressed) m_caps_lock_on = !m_caps_lock_on; + if (g_caps_lock_remapped_to_ctrl && key == Key_CapsLock) + m_caps_lock_to_ctrl_pressed = pressed; + + if (g_caps_lock_remapped_to_ctrl) + update_modifier(Mod_Ctrl, m_caps_lock_to_ctrl_pressed); + Event event; event.key = key; event.scancode = m_has_e0_prefix ? 0xe000 + scan_code : scan_code; diff --git a/Kernel/Devices/HID/KeyboardDevice.h b/Kernel/Devices/HID/KeyboardDevice.h index 9d1b9f689d3..35585d6836a 100644 --- a/Kernel/Devices/HID/KeyboardDevice.h +++ b/Kernel/Devices/HID/KeyboardDevice.h @@ -53,6 +53,7 @@ protected: virtual const char* class_name() const override { return "KeyboardDevice"; } u8 m_modifiers { 0 }; + bool m_caps_lock_to_ctrl_pressed { false }; bool m_caps_lock_on { false }; bool m_num_lock_on { false }; bool m_has_e0_prefix { false }; diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 8cbd49e493b..07789b904ad 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2021, Spencer Dixon * * SPDX-License-Identifier: BSD-2-Clause */ @@ -970,6 +971,7 @@ bool ProcFS::initialize() { static Lockable* kmalloc_stack_helper; static Lockable* ubsan_deadly_helper; + static Lockable* caps_lock_to_ctrl_helper; if (kmalloc_stack_helper == nullptr) { kmalloc_stack_helper = new Lockable(); @@ -982,6 +984,10 @@ bool ProcFS::initialize() ProcFS::add_sys_bool("ubsan_is_deadly", *ubsan_deadly_helper, [] { UBSanitizer::g_ubsan_is_deadly = ubsan_deadly_helper->resource(); }); + caps_lock_to_ctrl_helper = new Lockable(); + ProcFS::add_sys_bool("caps_lock_to_ctrl", *caps_lock_to_ctrl_helper, [] { + Kernel::g_caps_lock_remapped_to_ctrl.exchange(caps_lock_to_ctrl_helper->resource()); + }); } return true; }