/* * Copyright (c) 2021, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Kernel { extern Atomic g_caps_lock_remapped_to_ctrl; class MouseDevice; class KeyboardDevice; class KeyboardClient; class HIDManagement { friend class KeyboardDevice; friend class MouseDevice; public: HIDManagement(); static ErrorOr initialize(); static HIDManagement& the(); ErrorOr enumerate(); struct KeymapData { KeymapData(); NonnullOwnPtr character_map_name; Keyboard::CharacterMapData character_map; }; SpinlockProtected& keymap_data() { return m_keymap_data; } u32 get_char_from_character_map(KeyEvent, u8) const; void set_client(KeyboardClient* client); void set_maps(NonnullOwnPtr character_map_name, Keyboard::CharacterMapData const& character_map); void attach_standalone_hid_device(HIDDevice&); void detach_standalone_hid_device(HIDDevice&); private: size_t generate_minor_device_number_for_mouse(); size_t generate_minor_device_number_for_keyboard(); SpinlockProtected m_keymap_data {}; size_t m_mouse_minor_number { 0 }; size_t m_keyboard_minor_number { 0 }; KeyboardClient* m_client { nullptr }; SpinlockProtected, LockRank::None> m_hid_serial_io_controllers; // NOTE: This list is used for standalone devices, like USB HID devices // (which are not attached via a SerialIO controller in the sense that // there's no specific serial IO controller to coordinate their usage). SpinlockProtected, LockRank::None> m_standalone_hid_devices; Spinlock m_client_lock; }; class KeyboardClient { public: virtual ~KeyboardClient() = default; virtual void on_key_pressed(KeyEvent) = 0; }; }