diff --git a/CMakeLists.txt b/CMakeLists.txt index d19888263c..ae89d560e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ add_subdirectory(bootloader) add_subdirectory(BAN) add_subdirectory(libc) add_subdirectory(LibELF) +add_subdirectory(LibInput) add_subdirectory(userspace) add_custom_target(sysroot @@ -33,6 +34,7 @@ add_custom_target(headers DEPENDS ban-headers DEPENDS libc-headers DEPENDS libelf-headers + DEPENDS libinput-headers ) add_custom_target(install-sysroot @@ -41,6 +43,7 @@ add_custom_target(install-sysroot DEPENDS libc-install DEPENDS userspace-install DEPENDS libelf-install + DEPENDS libinput-install ) add_custom_target(package-sysroot diff --git a/LibInput/CMakeLists.txt b/LibInput/CMakeLists.txt new file mode 100644 index 0000000000..e357bcfd81 --- /dev/null +++ b/LibInput/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.26) + +project(libinput CXX) + +set(LIBINPUT_SOURCES + KeyEvent.cpp + KeyboardLayout.cpp +) + +add_custom_target(libinput-headers + COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/ + DEPENDS sysroot +) + +add_library(libinput ${LIBINPUT_SOURCES}) +target_link_libraries(libinput PUBLIC libc ban) + +add_custom_target(libinput-install + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libinput.a ${BANAN_LIB}/ + DEPENDS libinput + BYPRODUCTS ${BANAN_LIB}/libinput.a +) + +set(CMAKE_STATIC_LIBRARY_PREFIX "") diff --git a/kernel/kernel/Input/KeyEvent.cpp b/LibInput/KeyEvent.cpp similarity index 90% rename from kernel/kernel/Input/KeyEvent.cpp rename to LibInput/KeyEvent.cpp index 2806af1bd7..99a7e59edd 100644 --- a/kernel/kernel/Input/KeyEvent.cpp +++ b/LibInput/KeyEvent.cpp @@ -1,15 +1,9 @@ #include -#include -#include +#include -namespace Kernel::Input +namespace LibInput { - Key key_event_to_key(KeyEvent event) - { - return KeyboardLayout::get().get_key_from_event(event); - } - const char* key_to_utf8(Key key, uint16_t modifier) { static constexpr const char* utf8_lower[] = { @@ -50,7 +44,7 @@ namespace Kernel::Input }; static_assert((size_t)Key::Count == sizeof(utf8_upper) / sizeof(*utf8_lower)); - KeyEvent event { .modifier = modifier, .keycode = 0x00 }; + KeyEvent event { .modifier = modifier, .key = key }; return (event.shift() ^ event.caps_lock()) ? utf8_upper[static_cast(key)] : utf8_lower[static_cast(key)]; } diff --git a/kernel/kernel/Input/KeyboardLayout.cpp b/LibInput/KeyboardLayout.cpp similarity index 91% rename from kernel/kernel/Input/KeyboardLayout.cpp rename to LibInput/KeyboardLayout.cpp index 052d67e651..724791e0d4 100644 --- a/kernel/kernel/Input/KeyboardLayout.cpp +++ b/LibInput/KeyboardLayout.cpp @@ -1,10 +1,20 @@ +#include #include +#include +#include +#include + +#if __is_kernel #include -#include +#else +#include +#include +#include +#endif #include -namespace Kernel::Input +namespace LibInput { struct StringViewLower @@ -71,14 +81,17 @@ namespace Kernel::Input key = Key::None; } - Key KeyboardLayout::get_key_from_event(KeyEvent event) + KeyEvent KeyboardLayout::key_event_from_raw(RawKeyEvent event) { - SpinLockGuard _(m_lock); - if (event.shift()) - return m_keycode_to_key_shift[event.keycode]; - if (event.ralt()) - return m_keycode_to_key_altgr[event.keycode]; - return m_keycode_to_key_normal[event.keycode]; + KeyEvent result; + result.modifier = event.modifier; + if (result.shift()) + result.key = m_keycode_to_key_shift[event.keycode]; + else if (result.ralt()) + result.key = m_keycode_to_key_altgr[event.keycode]; + else + result.key = m_keycode_to_key_normal[event.keycode]; + return result; } static BAN::Optional parse_keycode(BAN::StringView str) @@ -109,11 +122,36 @@ namespace Kernel::Input static BAN::ErrorOr> load_keymap_lines_and_parse_includes(BAN::StringView path) { - auto file = TRY(VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, path, 0)); - BAN::String file_data; - TRY(file_data.resize(file.inode->size())); - TRY(file.inode->read(0, BAN::ByteSpan { reinterpret_cast(file_data.data()), file_data.size() })); + BAN::String canonical_path; + +#if __is_kernel + { + auto file = TRY(Kernel::VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, path, 0)); + TRY(file_data.resize(file.inode->size())); + TRY(file.inode->read(0, BAN::ByteSpan { reinterpret_cast(file_data.data()), file_data.size() })); + canonical_path = file.canonical_path; + } +#else + { + char null_path[PATH_MAX]; + strncpy(null_path, path.data(), path.size()); + null_path[path.size()] = '\0'; + + struct stat st; + if (stat(null_path, &st) == -1) + return BAN::Error::from_errno(errno); + TRY(file_data.resize(st.st_size)); + int fd = open(null_path, O_RDONLY); + if (fd == -1) + return BAN::Error::from_errno(errno); + ssize_t nread = read(fd, file_data.data(), st.st_size); + close(fd); + if (nread != st.st_size) + return BAN::Error::from_errno(errno); + MUST(canonical_path.append(path)); + } +#endif BAN::Vector result; @@ -142,7 +180,7 @@ namespace Kernel::Input parts[1] = parts[1].substring(1, parts[1].size() - 2); BAN::String include_path; - TRY(include_path.append(file.canonical_path)); + TRY(include_path.append(canonical_path)); ASSERT(include_path.sv().contains('/')); while (include_path.back() != '/') include_path.pop_back(); @@ -256,8 +294,6 @@ namespace Kernel::Input } } - SpinLockGuard _(m_lock); - for (size_t i = 0; i < new_layout->m_keycode_to_key_normal.size(); i++) if (new_layout->m_keycode_to_key_normal[i] != Key::None) m_keycode_to_key_normal[i] = new_layout->m_keycode_to_key_normal[i]; diff --git a/kernel/include/kernel/Input/KeyEvent.h b/LibInput/include/LibInput/KeyEvent.h similarity index 95% rename from kernel/include/kernel/Input/KeyEvent.h rename to LibInput/include/LibInput/KeyEvent.h index f6661373b1..722e49feb2 100644 --- a/kernel/include/kernel/Input/KeyEvent.h +++ b/LibInput/include/LibInput/KeyEvent.h @@ -2,7 +2,7 @@ #include -namespace Kernel::Input +namespace LibInput { /* @@ -53,6 +53,14 @@ namespace Kernel::Input Count, }; + // KeyEvent with general keycode + struct RawKeyEvent + { + uint16_t modifier; + uint8_t keycode; + }; + + // KeyEvent with key parsed from keycode struct KeyEvent { enum Modifier : uint16_t @@ -89,10 +97,9 @@ namespace Kernel::Input bool released() const { return !pressed(); } uint16_t modifier; - uint8_t keycode; + Key key; }; - Key key_event_to_key(KeyEvent); const char* key_to_utf8(Key key, uint16_t modifier); } diff --git a/kernel/include/kernel/Input/KeyboardLayout.h b/LibInput/include/LibInput/KeyboardLayout.h similarity index 76% rename from kernel/include/kernel/Input/KeyboardLayout.h rename to LibInput/include/LibInput/KeyboardLayout.h index 9eea41313c..8c0a8dd20e 100644 --- a/kernel/include/kernel/Input/KeyboardLayout.h +++ b/LibInput/include/LibInput/KeyboardLayout.h @@ -1,11 +1,11 @@ #pragma once #include +#include #include -#include -#include +#include -namespace Kernel::Input +namespace LibInput { class KeyboardLayout @@ -14,7 +14,7 @@ namespace Kernel::Input static BAN::ErrorOr initialize(); static KeyboardLayout& get(); - Key get_key_from_event(KeyEvent); + KeyEvent key_event_from_raw(RawKeyEvent); BAN::ErrorOr load_from_file(BAN::StringView path); private: @@ -24,8 +24,6 @@ namespace Kernel::Input BAN::Array m_keycode_to_key_normal; BAN::Array m_keycode_to_key_shift; BAN::Array m_keycode_to_key_altgr; - SpinLock m_lock; - friend class BAN::UniqPtr; }; diff --git a/kernel/include/kernel/Input/MouseEvent.h b/LibInput/include/LibInput/MouseEvent.h similarity index 95% rename from kernel/include/kernel/Input/MouseEvent.h rename to LibInput/include/LibInput/MouseEvent.h index 5567c4a7f9..ac39c4f65e 100644 --- a/kernel/include/kernel/Input/MouseEvent.h +++ b/LibInput/include/LibInput/MouseEvent.h @@ -2,7 +2,7 @@ #include -namespace Kernel::Input +namespace LibInput { enum class MouseButton diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 6da790f221..61d1fe24c9 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -42,8 +42,6 @@ set(KERNEL_SOURCES kernel/FS/VirtualFileSystem.cpp kernel/GDT.cpp kernel/IDT.cpp - kernel/Input/KeyboardLayout.cpp - kernel/Input/KeyEvent.cpp kernel/Input/PS2/Controller.cpp kernel/Input/PS2/Device.cpp kernel/Input/PS2/Keyboard.cpp @@ -150,12 +148,18 @@ set(LIBELF_SOURCES ../LibELF/LibELF/LoadableELF.cpp ) +set(LIBINPUT_SOURCE + ../LibInput/KeyboardLayout.cpp + ../LibInput/KeyEvent.cpp +) + set(KERNEL_SOURCES ${KERNEL_SOURCES} ${LAI_SOURCES} ${BAN_SOURCES} ${KLIBC_SOURCES} ${LIBELF_SOURCES} + ${LIBINPUT_SOURCE} ) add_executable(kernel ${KERNEL_SOURCES}) diff --git a/kernel/include/kernel/Input/PS2/Keyboard.h b/kernel/include/kernel/Input/PS2/Keyboard.h index 5b97e522d7..93b8dc5342 100644 --- a/kernel/include/kernel/Input/PS2/Keyboard.h +++ b/kernel/include/kernel/Input/PS2/Keyboard.h @@ -2,10 +2,10 @@ #include #include -#include #include #include #include +#include namespace Kernel::Input { @@ -40,7 +40,7 @@ namespace Kernel::Input uint16_t m_modifiers { 0 }; - BAN::CircularQueue m_event_queue; + BAN::CircularQueue m_event_queue; SpinLock m_event_lock; PS2Keymap m_keymap; diff --git a/kernel/include/kernel/Input/PS2/Mouse.h b/kernel/include/kernel/Input/PS2/Mouse.h index cc66d582e7..fb5eee460f 100644 --- a/kernel/include/kernel/Input/PS2/Mouse.h +++ b/kernel/include/kernel/Input/PS2/Mouse.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include namespace Kernel::Input { @@ -36,7 +36,7 @@ namespace Kernel::Input uint8_t m_mouse_id { 0x00 }; uint8_t m_button_mask { 0x00 }; - BAN::CircularQueue m_event_queue; + BAN::CircularQueue m_event_queue; SpinLock m_event_lock; Semaphore m_semaphore; diff --git a/kernel/include/kernel/Terminal/TTY.h b/kernel/include/kernel/Terminal/TTY.h index f4499bc4aa..1fbbe0f624 100644 --- a/kernel/include/kernel/Terminal/TTY.h +++ b/kernel/include/kernel/Terminal/TTY.h @@ -2,11 +2,11 @@ #include #include -#include #include #include #include #include +#include namespace Kernel { @@ -30,7 +30,7 @@ namespace Kernel void set_as_current(); static void initialize_devices(); - void on_key_event(Input::KeyEvent); + void on_key_event(LibInput::KeyEvent); void handle_input_byte(uint8_t); virtual bool is_tty() const override { return true; } diff --git a/kernel/include/kernel/Terminal/VirtualTTY.h b/kernel/include/kernel/Terminal/VirtualTTY.h index 70ba61adfd..a85cb4900d 100644 --- a/kernel/include/kernel/Terminal/VirtualTTY.h +++ b/kernel/include/kernel/Terminal/VirtualTTY.h @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/kernel/kernel/Input/PS2/Keyboard.cpp b/kernel/kernel/Input/PS2/Keyboard.cpp index 1e66261104..adeef1dc3b 100644 --- a/kernel/kernel/Input/PS2/Keyboard.cpp +++ b/kernel/kernel/Input/PS2/Keyboard.cpp @@ -1,9 +1,9 @@ #include #include -#include #include #include #include +#include namespace Kernel::Input { @@ -44,6 +44,10 @@ namespace Kernel::Input void PS2Keyboard::handle_byte(uint8_t byte) { + using LibInput::Key; + using LibInput::RawKeyEvent; + using KeyModifier = LibInput::KeyEvent::Modifier; + if (byte == PS2::KBResponse::KEY_ERROR_OR_BUFFER_OVERRUN1 || byte == PS2::KBResponse::KEY_ERROR_OR_BUFFER_OVERRUN2) { dwarnln("Key detection error or internal buffer overrun"); @@ -123,25 +127,24 @@ namespace Kernel::Input if (!keycode.has_value()) return; - auto key = KeyboardLayout::get().get_key_from_event(KeyEvent { .modifier = 0, .keycode = keycode.value() }); - - if (key == Key::F1) + auto dummy_event = LibInput::KeyboardLayout::get().key_event_from_raw(RawKeyEvent { .modifier = 0, .keycode = keycode.value() }); + if (dummy_event.key == Key::F1) panic("OOF"); uint16_t modifier_mask = 0; uint16_t toggle_mask = 0; - switch (key) + switch (dummy_event.key) { - case Key::LeftShift: modifier_mask = KeyEvent::Modifier::LShift; break; - case Key::RightShift: modifier_mask = KeyEvent::Modifier::RShift; break; - case Key::LeftCtrl: modifier_mask = KeyEvent::Modifier::LCtrl; break; - case Key::RightCtrl: modifier_mask = KeyEvent::Modifier::RCtrl; break; - case Key::LeftAlt: modifier_mask = KeyEvent::Modifier::LAlt; break; - case Key::RightAlt: modifier_mask = KeyEvent::Modifier::RAlt; break; + case Key::LeftShift: modifier_mask = KeyModifier::LShift; break; + case Key::RightShift: modifier_mask = KeyModifier::RShift; break; + case Key::LeftCtrl: modifier_mask = KeyModifier::LCtrl; break; + case Key::RightCtrl: modifier_mask = KeyModifier::RCtrl; break; + case Key::LeftAlt: modifier_mask = KeyModifier::LAlt; break; + case Key::RightAlt: modifier_mask = KeyModifier::RAlt; break; - case Key::ScrollLock: toggle_mask = KeyEvent::Modifier::ScrollLock; break; - case Key::NumLock: toggle_mask = KeyEvent::Modifier::NumLock; break; - case Key::CapsLock: toggle_mask = KeyEvent::Modifier::CapsLock; break; + case Key::ScrollLock: toggle_mask = KeyModifier::ScrollLock; break; + case Key::NumLock: toggle_mask = KeyModifier::NumLock; break; + case Key::CapsLock: toggle_mask = KeyModifier::CapsLock; break; default: break; } @@ -160,8 +163,8 @@ namespace Kernel::Input update_leds(); } - KeyEvent event; - event.modifier = m_modifiers | (released ? 0 : KeyEvent::Modifier::Pressed); + RawKeyEvent event; + event.modifier = m_modifiers | (released ? 0 : KeyModifier::Pressed); event.keycode = keycode.value(); SpinLockGuard _(m_event_lock); @@ -178,19 +181,23 @@ namespace Kernel::Input void PS2Keyboard::update_leds() { + using KeyModifier = LibInput::KeyEvent::Modifier; + uint8_t new_leds = 0; - if (m_modifiers & +KeyEvent::Modifier::ScrollLock) + if (m_modifiers & +KeyModifier::ScrollLock) new_leds |= PS2::KBLeds::SCROLL_LOCK; - if (m_modifiers & +KeyEvent::Modifier::NumLock) + if (m_modifiers & +KeyModifier::NumLock) new_leds |= PS2::KBLeds::NUM_LOCK; - if (m_modifiers & +KeyEvent::Modifier::CapsLock) + if (m_modifiers & +KeyModifier::CapsLock) new_leds |= PS2::KBLeds::CAPS_LOCK; append_command_queue(Command::SET_LEDS, new_leds, 0); } BAN::ErrorOr PS2Keyboard::read_impl(off_t, BAN::ByteSpan buffer) { - if (buffer.size() < sizeof(KeyEvent)) + using LibInput::RawKeyEvent; + + if (buffer.size() < sizeof(RawKeyEvent)) return BAN::Error::from_errno(ENOBUFS); auto state = m_event_lock.lock(); @@ -201,12 +208,12 @@ namespace Kernel::Input state = m_event_lock.lock(); } - buffer.as() = m_event_queue.front(); + buffer.as() = m_event_queue.front(); m_event_queue.pop(); m_event_lock.unlock(state); - return sizeof(KeyEvent); + return sizeof(RawKeyEvent); } } diff --git a/kernel/kernel/Input/PS2/Keymap.cpp b/kernel/kernel/Input/PS2/Keymap.cpp index 4024a6e6d8..6f77b3e885 100644 --- a/kernel/kernel/Input/PS2/Keymap.cpp +++ b/kernel/kernel/Input/PS2/Keymap.cpp @@ -1,11 +1,14 @@ #include -#include #include +#include #include namespace Kernel::Input { + using LibInput::keycode_function; + using LibInput::keycode_normal; + using LibInput::keycode_numpad; void PS2Keymap::initialize(uint8_t scancode_set) { diff --git a/kernel/kernel/Input/PS2/Mouse.cpp b/kernel/kernel/Input/PS2/Mouse.cpp index decaea2991..5861d23ef6 100644 --- a/kernel/kernel/Input/PS2/Mouse.cpp +++ b/kernel/kernel/Input/PS2/Mouse.cpp @@ -71,6 +71,10 @@ namespace Kernel::Input void PS2Mouse::handle_byte(uint8_t byte) { + using LibInput::MouseButton; + using LibInput::MouseEvent; + using LibInput::MouseEventType; + if (!m_enabled) return initialize_extensions(byte); @@ -174,6 +178,8 @@ namespace Kernel::Input BAN::ErrorOr PS2Mouse::read_impl(off_t, BAN::ByteSpan buffer) { + using LibInput::MouseEvent; + if (buffer.size() < sizeof(MouseEvent)) return BAN::Error::from_errno(ENOBUFS); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 1f328cb4ec..ac965e2933 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -17,6 +16,7 @@ #include #include +#include #include #include @@ -1460,7 +1460,7 @@ namespace Kernel return BAN::Error::from_errno(EPERM); auto absolute_path = TRY(absolute_path_of(path)); - TRY(Input::KeyboardLayout::get().load_from_file(absolute_path)); + TRY(LibInput::KeyboardLayout::get().load_from_file(absolute_path)); return 0; } diff --git a/kernel/kernel/Terminal/TTY.cpp b/kernel/kernel/Terminal/TTY.cpp index 3a621cee16..c91e068925 100644 --- a/kernel/kernel/Terminal/TTY.cpp +++ b/kernel/kernel/Terminal/TTY.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -94,10 +95,11 @@ namespace Kernel while (!TTY::current()->m_tty_ctrl.receive_input) TTY::current()->m_tty_ctrl.semaphore.block_indefinite(); - Input::KeyEvent event; + LibInput::RawKeyEvent event; size_t read = MUST(inode->read(0, BAN::ByteSpan::from(event))); ASSERT(read == sizeof(event)); - TTY::current()->on_key_event(event); + + TTY::current()->on_key_event(LibInput::KeyboardLayout::get().key_event_from_raw(event)); } }, nullptr ); @@ -120,71 +122,70 @@ namespace Kernel return {}; } - void TTY::on_key_event(Input::KeyEvent event) + void TTY::on_key_event(LibInput::KeyEvent event) { LockGuard _(m_mutex); if (event.released()) return; - Input::Key key = Input::key_event_to_key(event); - const char* ansi_c_str = Input::key_to_utf8(key, event.modifier); + const char* ansi_c_str = LibInput::key_to_utf8(event.key, event.modifier); if (event.ctrl()) { ansi_c_str = nullptr; - switch (key) + switch (event.key) { - case Input::Key::A: ansi_c_str = "\x01"; break; - case Input::Key::B: ansi_c_str = "\x02"; break; - case Input::Key::C: ansi_c_str = "\x03"; break; - case Input::Key::D: ansi_c_str = "\x04"; break; - case Input::Key::E: ansi_c_str = "\x05"; break; - case Input::Key::F: ansi_c_str = "\x06"; break; - case Input::Key::G: ansi_c_str = "\x07"; break; - case Input::Key::H: ansi_c_str = "\x08"; break; - case Input::Key::I: ansi_c_str = "\x09"; break; - case Input::Key::J: ansi_c_str = "\x0A"; break; - case Input::Key::K: ansi_c_str = "\x0B"; break; - case Input::Key::L: ansi_c_str = "\x0C"; break; - case Input::Key::M: ansi_c_str = "\x0D"; break; - case Input::Key::N: ansi_c_str = "\x0E"; break; - case Input::Key::O: ansi_c_str = "\x0F"; break; - case Input::Key::P: ansi_c_str = "\x10"; break; - case Input::Key::Q: ansi_c_str = "\x11"; break; - case Input::Key::R: ansi_c_str = "\x12"; break; - case Input::Key::S: ansi_c_str = "\x13"; break; - case Input::Key::T: ansi_c_str = "\x14"; break; - case Input::Key::U: ansi_c_str = "\x15"; break; - case Input::Key::V: ansi_c_str = "\x16"; break; - case Input::Key::W: ansi_c_str = "\x17"; break; - case Input::Key::X: ansi_c_str = "\x18"; break; - case Input::Key::Y: ansi_c_str = "\x19"; break; - case Input::Key::Z: ansi_c_str = "\x1A"; break; + case LibInput::Key::A: ansi_c_str = "\x01"; break; + case LibInput::Key::B: ansi_c_str = "\x02"; break; + case LibInput::Key::C: ansi_c_str = "\x03"; break; + case LibInput::Key::D: ansi_c_str = "\x04"; break; + case LibInput::Key::E: ansi_c_str = "\x05"; break; + case LibInput::Key::F: ansi_c_str = "\x06"; break; + case LibInput::Key::G: ansi_c_str = "\x07"; break; + case LibInput::Key::H: ansi_c_str = "\x08"; break; + case LibInput::Key::I: ansi_c_str = "\x09"; break; + case LibInput::Key::J: ansi_c_str = "\x0A"; break; + case LibInput::Key::K: ansi_c_str = "\x0B"; break; + case LibInput::Key::L: ansi_c_str = "\x0C"; break; + case LibInput::Key::M: ansi_c_str = "\x0D"; break; + case LibInput::Key::N: ansi_c_str = "\x0E"; break; + case LibInput::Key::O: ansi_c_str = "\x0F"; break; + case LibInput::Key::P: ansi_c_str = "\x10"; break; + case LibInput::Key::Q: ansi_c_str = "\x11"; break; + case LibInput::Key::R: ansi_c_str = "\x12"; break; + case LibInput::Key::S: ansi_c_str = "\x13"; break; + case LibInput::Key::T: ansi_c_str = "\x14"; break; + case LibInput::Key::U: ansi_c_str = "\x15"; break; + case LibInput::Key::V: ansi_c_str = "\x16"; break; + case LibInput::Key::W: ansi_c_str = "\x17"; break; + case LibInput::Key::X: ansi_c_str = "\x18"; break; + case LibInput::Key::Y: ansi_c_str = "\x19"; break; + case LibInput::Key::Z: ansi_c_str = "\x1A"; break; default: break; } } else { - switch (key) + switch (event.key) { - case Input::Key::Enter: - case Input::Key::NumpadEnter: + case LibInput::Key::Enter: + case LibInput::Key::NumpadEnter: ansi_c_str = "\n"; break; - case Input::Key::Backspace: + case LibInput::Key::Backspace: ansi_c_str = "\b"; break; - case Input::Key::ArrowUp: + case LibInput::Key::ArrowUp: ansi_c_str = "\e[A"; break; - case Input::Key::ArrowDown: + case LibInput::Key::ArrowDown: ansi_c_str = "\e[B"; break; - case Input::Key::ArrowRight: + case LibInput::Key::ArrowRight: ansi_c_str = "\e[C"; break; - case Input::Key::ArrowLeft: + case LibInput::Key::ArrowLeft: ansi_c_str = "\e[D"; break; default: diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index d0c68de876..a717094a8e 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -28,6 +27,8 @@ #include #include +#include + struct ParsedCommandLine { bool force_pic = false; @@ -194,7 +195,7 @@ static void init2(void*) #endif // Initialize empty keymap - MUST(Input::KeyboardLayout::initialize()); + MUST(LibInput::KeyboardLayout::initialize()); if (auto res = PS2Controller::initialize(); res.is_error()) dprintln("{}", res.error()); diff --git a/userspace/test-mouse/main.cpp b/userspace/test-mouse/main.cpp index 46ecc0d540..399f726bf8 100644 --- a/userspace/test-mouse/main.cpp +++ b/userspace/test-mouse/main.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include framebuffer_info_t fb_info; void* fb_mmap = nullptr; @@ -137,7 +137,7 @@ int main(int argc, char** argv) while (true) { - using namespace Kernel::Input; + using namespace LibInput; MouseEvent event; if (read(mouse_fd, &event, sizeof(event)) == -1)