From f556ee99749d2b72256f37b882d4ac74d920f1c9 Mon Sep 17 00:00:00 2001 From: nattensleplubo Date: Mon, 15 Jun 2026 16:16:10 +0200 Subject: [PATCH 1/3] feat(keyboard): added french keyboard layout support --- Cargo.toml | 2 + Makefile | 9 +- src/driver/keyboard/keymaps/fr_azerty.rs | 696 +++++++++++++++++++++++ src/driver/keyboard/keymaps/mod.rs | 3 + src/driver/keyboard/ps2.rs | 9 +- 5 files changed, 716 insertions(+), 3 deletions(-) create mode 100644 src/driver/keyboard/keymaps/fr_azerty.rs diff --git a/Cargo.toml b/Cargo.toml index e74d080..1bb6e65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,5 @@ unwrap_used = "deny" default = [] multiboot = [] multiboot2 = [] +# To use the french "azerty" keyboard layout instead of the default us qwerty +azerty = [] diff --git a/Makefile b/Makefile index 7c9ef5f..9d509a1 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ BOOTLOADER := grub # BOOTLOADER := limine BOOTPROTOCOL := multiboot # BOOTPROTOCOL := multiboot2 +KEYMAP := qwerty +# KEYMAP := azerty # utlis CARGO := cargo @@ -17,8 +19,11 @@ GRUBCFG := boot/grub-${BOOTPROTOCOL}.cfg LIMINECONF := boot/limine-${BOOTPROTOCOL}.conf # flags -CARGOFLAGS.debug := --features=${BOOTPROTOCOL} -CARGOFLAGS.release := --features=${BOOTPROTOCOL} --release +ifeq (${KEYMAP},azerty) +KEYMAPFEATURE := ,azerty +endif +CARGOFLAGS.debug := --features=${BOOTPROTOCOL}${KEYMAPFEATURE} +CARGOFLAGS.release := --features=${BOOTPROTOCOL}${KEYMAPFEATURE} --release # dirs BUILDDIR := build/${BUILD} diff --git a/src/driver/keyboard/keymaps/fr_azerty.rs b/src/driver/keyboard/keymaps/fr_azerty.rs new file mode 100644 index 0000000..1441008 --- /dev/null +++ b/src/driver/keyboard/keymaps/fr_azerty.rs @@ -0,0 +1,696 @@ +use super::{Keymap, KeymapSet, KeymapValue}; +use crate::driver::keyboard::ScanCodeValue; + +pub const FR_AZERTY_KEYMAP: Keymap = { + let mut keymap = [None; 0x80]; + // Letters -------------------------------------------------------------- + keymap[ScanCodeValue::Q as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('a'), + shift: KeymapValue::Ascii('A'), + alt1: KeymapValue::Alt('a'), + alt2: KeymapValue::Alt('a'), + alt_shift: KeymapValue::Alt('A'), + ctrl: KeymapValue::Control('A'), + }); + keymap[ScanCodeValue::B as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('b'), + shift: KeymapValue::Ascii('B'), + alt1: KeymapValue::Alt('b'), + alt2: KeymapValue::Alt('b'), + alt_shift: KeymapValue::Alt('B'), + ctrl: KeymapValue::Control('B'), + }); + keymap[ScanCodeValue::C as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('c'), + shift: KeymapValue::Ascii('C'), + alt1: KeymapValue::Alt('c'), + alt2: KeymapValue::Alt('c'), + alt_shift: KeymapValue::Alt('C'), + ctrl: KeymapValue::Control('C'), + }); + keymap[ScanCodeValue::D as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('d'), + shift: KeymapValue::Ascii('D'), + alt1: KeymapValue::Alt('d'), + alt2: KeymapValue::Alt('d'), + alt_shift: KeymapValue::Alt('D'), + ctrl: KeymapValue::Control('D'), + }); + keymap[ScanCodeValue::E as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('e'), + shift: KeymapValue::Ascii('E'), + alt1: KeymapValue::Alt('e'), + alt2: KeymapValue::Alt('e'), + alt_shift: KeymapValue::Alt('E'), + ctrl: KeymapValue::Control('E'), + }); + keymap[ScanCodeValue::F as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('f'), + shift: KeymapValue::Ascii('F'), + alt1: KeymapValue::Alt('f'), + alt2: KeymapValue::Alt('f'), + alt_shift: KeymapValue::Alt('F'), + ctrl: KeymapValue::Control('F'), + }); + keymap[ScanCodeValue::G as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('g'), + shift: KeymapValue::Ascii('G'), + alt1: KeymapValue::Alt('g'), + alt2: KeymapValue::Alt('g'), + alt_shift: KeymapValue::Alt('G'), + ctrl: KeymapValue::Control('G'), + }); + keymap[ScanCodeValue::H as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('h'), + shift: KeymapValue::Ascii('H'), + alt1: KeymapValue::Alt('h'), + alt2: KeymapValue::Alt('h'), + alt_shift: KeymapValue::Alt('H'), + ctrl: KeymapValue::Control('H'), + }); + keymap[ScanCodeValue::I as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('i'), + shift: KeymapValue::Ascii('I'), + alt1: KeymapValue::Alt('i'), + alt2: KeymapValue::Alt('i'), + alt_shift: KeymapValue::Alt('I'), + ctrl: KeymapValue::Control('I'), + }); + keymap[ScanCodeValue::J as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('j'), + shift: KeymapValue::Ascii('J'), + alt1: KeymapValue::Alt('j'), + alt2: KeymapValue::Alt('j'), + alt_shift: KeymapValue::Alt('J'), + ctrl: KeymapValue::Control('J'), + }); + keymap[ScanCodeValue::K as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('k'), + shift: KeymapValue::Ascii('K'), + alt1: KeymapValue::Alt('k'), + alt2: KeymapValue::Alt('k'), + alt_shift: KeymapValue::Alt('K'), + ctrl: KeymapValue::Control('K'), + }); + keymap[ScanCodeValue::L as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('l'), + shift: KeymapValue::Ascii('L'), + alt1: KeymapValue::Alt('l'), + alt2: KeymapValue::Alt('l'), + alt_shift: KeymapValue::Alt('L'), + ctrl: KeymapValue::Control('L'), + }); + keymap[ScanCodeValue::Semicolon as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('m'), + shift: KeymapValue::Ascii('M'), + alt1: KeymapValue::Alt('m'), + alt2: KeymapValue::Alt('m'), + alt_shift: KeymapValue::Alt('M'), + ctrl: KeymapValue::Control('M'), + }); + keymap[ScanCodeValue::N as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('n'), + shift: KeymapValue::Ascii('N'), + alt1: KeymapValue::Alt('n'), + alt2: KeymapValue::Alt('n'), + alt_shift: KeymapValue::Alt('N'), + ctrl: KeymapValue::Control('N'), + }); + keymap[ScanCodeValue::O as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('o'), + shift: KeymapValue::Ascii('O'), + alt1: KeymapValue::Alt('o'), + alt2: KeymapValue::Alt('o'), + alt_shift: KeymapValue::Alt('O'), + ctrl: KeymapValue::Control('O'), + }); + keymap[ScanCodeValue::P as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('p'), + shift: KeymapValue::Ascii('P'), + alt1: KeymapValue::Alt('p'), + alt2: KeymapValue::Alt('p'), + alt_shift: KeymapValue::Alt('P'), + ctrl: KeymapValue::Control('P'), + }); + keymap[ScanCodeValue::A as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('q'), + shift: KeymapValue::Ascii('Q'), + alt1: KeymapValue::Alt('q'), + alt2: KeymapValue::Alt('q'), + alt_shift: KeymapValue::Alt('Q'), + ctrl: KeymapValue::Control('Q'), + }); + keymap[ScanCodeValue::R as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('r'), + shift: KeymapValue::Ascii('R'), + alt1: KeymapValue::Alt('r'), + alt2: KeymapValue::Alt('r'), + alt_shift: KeymapValue::Alt('R'), + ctrl: KeymapValue::Control('R'), + }); + keymap[ScanCodeValue::S as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('s'), + shift: KeymapValue::Ascii('S'), + alt1: KeymapValue::Alt('s'), + alt2: KeymapValue::Alt('s'), + alt_shift: KeymapValue::Alt('S'), + ctrl: KeymapValue::Control('S'), + }); + keymap[ScanCodeValue::T as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('t'), + shift: KeymapValue::Ascii('T'), + alt1: KeymapValue::Alt('t'), + alt2: KeymapValue::Alt('t'), + alt_shift: KeymapValue::Alt('T'), + ctrl: KeymapValue::Control('T'), + }); + keymap[ScanCodeValue::U as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('u'), + shift: KeymapValue::Ascii('U'), + alt1: KeymapValue::Alt('u'), + alt2: KeymapValue::Alt('u'), + alt_shift: KeymapValue::Alt('U'), + ctrl: KeymapValue::Control('U'), + }); + keymap[ScanCodeValue::V as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('v'), + shift: KeymapValue::Ascii('V'), + alt1: KeymapValue::Alt('v'), + alt2: KeymapValue::Alt('v'), + alt_shift: KeymapValue::Alt('V'), + ctrl: KeymapValue::Control('V'), + }); + keymap[ScanCodeValue::W as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('z'), + shift: KeymapValue::Ascii('Z'), + alt1: KeymapValue::Alt('z'), + alt2: KeymapValue::Alt('z'), + alt_shift: KeymapValue::Alt('Z'), + ctrl: KeymapValue::Control('Z'), + }); + keymap[ScanCodeValue::X as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('x'), + shift: KeymapValue::Ascii('X'), + alt1: KeymapValue::Alt('x'), + alt2: KeymapValue::Alt('x'), + alt_shift: KeymapValue::Alt('X'), + ctrl: KeymapValue::Control('X'), + }); + keymap[ScanCodeValue::Y as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('y'), + shift: KeymapValue::Ascii('Y'), + alt1: KeymapValue::Alt('y'), + alt2: KeymapValue::Alt('y'), + alt_shift: KeymapValue::Alt('Y'), + ctrl: KeymapValue::Control('Y'), + }); + keymap[ScanCodeValue::Z as usize] = Some(KeymapSet { + not_shift: KeymapValue::Lowercase('w'), + shift: KeymapValue::Ascii('W'), + alt1: KeymapValue::Alt('w'), + alt2: KeymapValue::Alt('w'), + alt_shift: KeymapValue::Alt('W'), + ctrl: KeymapValue::Control('W'), + }); + // Number row (digits require Shift; accents fall back to ASCII) --------- + keymap[ScanCodeValue::One as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('&'), + shift: KeymapValue::Ascii('1'), + alt1: KeymapValue::Alt('&'), + alt2: KeymapValue::Alt('&'), + alt_shift: KeymapValue::Alt('1'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Two as usize] = Some(KeymapSet { + // é + not_shift: KeymapValue::Ascii('e'), + shift: KeymapValue::Ascii('2'), + alt1: KeymapValue::Alt('e'), + alt2: KeymapValue::Alt('~'), + alt_shift: KeymapValue::Alt('2'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Three as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('"'), + shift: KeymapValue::Ascii('3'), + alt1: KeymapValue::Alt('"'), + alt2: KeymapValue::Alt('#'), + alt_shift: KeymapValue::Alt('3'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Four as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('\''), + shift: KeymapValue::Ascii('4'), + alt1: KeymapValue::Alt('\''), + alt2: KeymapValue::Alt('{'), + alt_shift: KeymapValue::Alt('4'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Five as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('('), + shift: KeymapValue::Ascii('5'), + alt1: KeymapValue::Alt('('), + alt2: KeymapValue::Alt('['), + alt_shift: KeymapValue::Alt('5'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Six as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('-'), + shift: KeymapValue::Ascii('6'), + alt1: KeymapValue::Alt('-'), + alt2: KeymapValue::Alt('|'), + alt_shift: KeymapValue::Alt('6'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Seven as usize] = Some(KeymapSet { + // è + not_shift: KeymapValue::Ascii('e'), + shift: KeymapValue::Ascii('7'), + alt1: KeymapValue::Alt('e'), + alt2: KeymapValue::Alt('`'), + alt_shift: KeymapValue::Alt('7'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Eight as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('_'), + shift: KeymapValue::Ascii('8'), + alt1: KeymapValue::Alt('_'), + alt2: KeymapValue::Alt('\\'), + alt_shift: KeymapValue::Alt('8'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Nine as usize] = Some(KeymapSet { + // ç + not_shift: KeymapValue::Ascii('c'), + shift: KeymapValue::Ascii('9'), + alt1: KeymapValue::Alt('c'), + alt2: KeymapValue::Alt('^'), + alt_shift: KeymapValue::Alt('9'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Zero as usize] = Some(KeymapSet { + // à + not_shift: KeymapValue::Ascii('a'), + shift: KeymapValue::Ascii('0'), + alt1: KeymapValue::Alt('a'), + alt2: KeymapValue::Alt('@'), + alt_shift: KeymapValue::Alt('0'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Min as usize] = Some(KeymapSet { + // shift is ° on a real keyboard -> ASCII fallback ')' + not_shift: KeymapValue::Ascii(')'), + shift: KeymapValue::Ascii(')'), + alt1: KeymapValue::Alt(')'), + alt2: KeymapValue::Alt(']'), + alt_shift: KeymapValue::Alt(')'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Equal as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('='), + shift: KeymapValue::Ascii('+'), + alt1: KeymapValue::Alt('='), + alt2: KeymapValue::Alt('}'), + alt_shift: KeymapValue::Alt('+'), + ctrl: KeymapValue::Control('@'), + }); + // Ponctuation + keymap[ScanCodeValue::LeftSquareBracket as usize] = Some(KeymapSet { + // ^ dead key (¨ shifted) ASCII fallback '^' + not_shift: KeymapValue::Ascii('^'), + shift: KeymapValue::Ascii('^'), + alt1: KeymapValue::Alt('^'), + alt2: KeymapValue::Alt('['), + alt_shift: KeymapValue::Alt('^'), + ctrl: KeymapValue::Control('['), + }); + keymap[ScanCodeValue::RightSquareBracket as usize] = Some(KeymapSet { + // £ shifted / ¤ AltGr -> ASCII fallback '$' + not_shift: KeymapValue::Ascii('$'), + shift: KeymapValue::Ascii('$'), + alt1: KeymapValue::Alt('$'), + alt2: KeymapValue::Alt('$'), + alt_shift: KeymapValue::Alt('$'), + ctrl: KeymapValue::Control(']'), + }); + keymap[ScanCodeValue::BackSlash as usize] = Some(KeymapSet { + // µ shifted -> ASCII fallback '*' + not_shift: KeymapValue::Ascii('*'), + shift: KeymapValue::Ascii('*'), + alt1: KeymapValue::Alt('*'), + alt2: KeymapValue::Alt('*'), + alt_shift: KeymapValue::Alt('*'), + ctrl: KeymapValue::Control('\\'), + }); + keymap[ScanCodeValue::SingleQuote as usize] = Some(KeymapSet { + // ù -> ASCII fallback 'u' + not_shift: KeymapValue::Ascii('u'), + shift: KeymapValue::Ascii('%'), + alt1: KeymapValue::Alt('u'), + alt2: KeymapValue::Alt('u'), + alt_shift: KeymapValue::Alt('%'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Comma as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii(';'), + shift: KeymapValue::Ascii('.'), + alt1: KeymapValue::Alt(';'), + alt2: KeymapValue::Alt(';'), + alt_shift: KeymapValue::Alt('.'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Dot as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii(':'), + shift: KeymapValue::Ascii('/'), + alt1: KeymapValue::Alt(':'), + alt2: KeymapValue::Alt(':'), + alt_shift: KeymapValue::Alt('/'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::Slash as usize] = Some(KeymapSet { + // § shifted -> ASCII fallback '!' + not_shift: KeymapValue::Ascii('!'), + shift: KeymapValue::Ascii('!'), + alt1: KeymapValue::Alt('!'), + alt2: KeymapValue::Alt('!'), + alt_shift: KeymapValue::Alt('!'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::M as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii(','), + shift: KeymapValue::Ascii('?'), + alt1: KeymapValue::Alt(','), + alt2: KeymapValue::Alt(','), + alt_shift: KeymapValue::Alt('?'), + ctrl: KeymapValue::Control('@'), + }); + // ² key had no ASCII equivalent so its disabled for now. + keymap[ScanCodeValue::BackTick as usize] = None; + keymap[ScanCodeValue::Enter as usize] = Some(KeymapSet { + not_shift: KeymapValue::Control('M'), + shift: KeymapValue::Control('M'), + alt1: KeymapValue::ControlAlt('M'), + alt2: KeymapValue::ControlAlt('M'), + alt_shift: KeymapValue::ControlAlt('M'), + ctrl: KeymapValue::Control('J'), + }); + keymap[ScanCodeValue::Escape as usize] = Some(KeymapSet { + not_shift: KeymapValue::Control('['), + shift: KeymapValue::Control('['), + alt1: KeymapValue::ControlAlt('['), + alt2: KeymapValue::ControlAlt('['), + alt_shift: KeymapValue::ControlAlt('['), + ctrl: KeymapValue::Control('['), + }); + keymap[ScanCodeValue::Backspace as usize] = Some(KeymapSet { + not_shift: KeymapValue::Control('H'), + shift: KeymapValue::Control('H'), + alt1: KeymapValue::ControlAlt('H'), + alt2: KeymapValue::ControlAlt('H'), + alt_shift: KeymapValue::ControlAlt('H'), + ctrl: KeymapValue::Delete, + }); + keymap[ScanCodeValue::Tab as usize] = Some(KeymapSet { + not_shift: KeymapValue::Control('I'), + shift: KeymapValue::Control('I'), + alt1: KeymapValue::ControlAlt('I'), + alt2: KeymapValue::ControlAlt('I'), + alt_shift: KeymapValue::ControlAlt('I'), + ctrl: KeymapValue::Control('I'), + }); + keymap[ScanCodeValue::Space as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii(' '), + shift: KeymapValue::Ascii(' '), + alt1: KeymapValue::Alt(' '), + alt2: KeymapValue::Alt(' '), + alt_shift: KeymapValue::Alt(' '), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::CapsLock as usize] = Some(KeymapSet { + not_shift: KeymapValue::CapsLock, + shift: KeymapValue::CapsLock, + alt1: KeymapValue::CapsLock, + alt2: KeymapValue::CapsLock, + alt_shift: KeymapValue::CapsLock, + ctrl: KeymapValue::CapsLock, + }); + keymap[ScanCodeValue::F1 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F1, + shift: KeymapValue::SF1, + alt1: KeymapValue::AF1, + alt2: KeymapValue::AF1, + alt_shift: KeymapValue::ASF1, + ctrl: KeymapValue::CF1, + }); + keymap[ScanCodeValue::F2 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F2, + shift: KeymapValue::SF2, + alt1: KeymapValue::AF2, + alt2: KeymapValue::AF2, + alt_shift: KeymapValue::ASF2, + ctrl: KeymapValue::CF2, + }); + keymap[ScanCodeValue::F3 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F3, + shift: KeymapValue::SF3, + alt1: KeymapValue::AF3, + alt2: KeymapValue::AF3, + alt_shift: KeymapValue::ASF3, + ctrl: KeymapValue::CF3, + }); + keymap[ScanCodeValue::F4 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F4, + shift: KeymapValue::SF4, + alt1: KeymapValue::AF4, + alt2: KeymapValue::AF4, + alt_shift: KeymapValue::ASF4, + ctrl: KeymapValue::CF4, + }); + keymap[ScanCodeValue::F5 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F5, + shift: KeymapValue::SF5, + alt1: KeymapValue::AF5, + alt2: KeymapValue::AF5, + alt_shift: KeymapValue::ASF5, + ctrl: KeymapValue::CF5, + }); + keymap[ScanCodeValue::F6 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F6, + shift: KeymapValue::SF6, + alt1: KeymapValue::AF6, + alt2: KeymapValue::AF6, + alt_shift: KeymapValue::ASF6, + ctrl: KeymapValue::CF6, + }); + keymap[ScanCodeValue::F7 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F7, + shift: KeymapValue::SF7, + alt1: KeymapValue::AF7, + alt2: KeymapValue::AF7, + alt_shift: KeymapValue::ASF7, + ctrl: KeymapValue::CF7, + }); + keymap[ScanCodeValue::F8 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F8, + shift: KeymapValue::SF8, + alt1: KeymapValue::AF8, + alt2: KeymapValue::AF8, + alt_shift: KeymapValue::ASF8, + ctrl: KeymapValue::CF8, + }); + keymap[ScanCodeValue::F9 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F9, + shift: KeymapValue::SF9, + alt1: KeymapValue::AF9, + alt2: KeymapValue::AF9, + alt_shift: KeymapValue::ASF9, + ctrl: KeymapValue::CF9, + }); + keymap[ScanCodeValue::F10 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F10, + shift: KeymapValue::SF10, + alt1: KeymapValue::AF10, + alt2: KeymapValue::AF10, + alt_shift: KeymapValue::ASF10, + ctrl: KeymapValue::CF10, + }); + keymap[ScanCodeValue::F11 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F11, + shift: KeymapValue::SF11, + alt1: KeymapValue::AF11, + alt2: KeymapValue::AF11, + alt_shift: KeymapValue::ASF11, + ctrl: KeymapValue::CF11, + }); + keymap[ScanCodeValue::F12 as usize] = Some(KeymapSet { + not_shift: KeymapValue::F12, + shift: KeymapValue::SF12, + alt1: KeymapValue::AF12, + alt2: KeymapValue::AF12, + alt_shift: KeymapValue::ASF12, + ctrl: KeymapValue::CF12, + }); + keymap[ScanCodeValue::ScrollLock as usize] = Some(KeymapSet { + not_shift: KeymapValue::ScrollLock, + shift: KeymapValue::ScrollLock, + alt1: KeymapValue::ScrollLock, + alt2: KeymapValue::ScrollLock, + alt_shift: KeymapValue::ScrollLock, + ctrl: KeymapValue::ScrollLock, + }); + keymap[ScanCodeValue::Insert as usize] = None; + keymap[ScanCodeValue::Home as usize] = None; + keymap[ScanCodeValue::PageUp as usize] = Some(KeymapSet { + not_shift: KeymapValue::PageUp, + shift: KeymapValue::PageUp, + alt1: KeymapValue::AltPageUp, + alt2: KeymapValue::AltPageUp, + alt_shift: KeymapValue::AltPageUp, + ctrl: KeymapValue::ControlPageUp, + }); + keymap[ScanCodeValue::Delete as usize] = Some(KeymapSet { + not_shift: KeymapValue::Delete, + shift: KeymapValue::Delete, + alt1: KeymapValue::AltDelete, + alt2: KeymapValue::AltDelete, + alt_shift: KeymapValue::AltDelete, + ctrl: KeymapValue::Delete, + }); + keymap[ScanCodeValue::End as usize] = None; + keymap[ScanCodeValue::PageDown as usize] = Some(KeymapSet { + not_shift: KeymapValue::PageDown, + shift: KeymapValue::PageDown, + alt1: KeymapValue::AltPageDown, + alt2: KeymapValue::AltPageDown, + alt_shift: KeymapValue::AltPageDown, + ctrl: KeymapValue::ControlPageDown, + }); + keymap[ScanCodeValue::CursorRight as usize] = Some(KeymapSet { + not_shift: KeymapValue::Right, + shift: KeymapValue::Right, + alt1: KeymapValue::AltRight, + alt2: KeymapValue::AltRight, + alt_shift: KeymapValue::AltRight, + ctrl: KeymapValue::ControlRight, + }); + keymap[ScanCodeValue::CursorLeft as usize] = Some(KeymapSet { + not_shift: KeymapValue::Left, + shift: KeymapValue::Left, + alt1: KeymapValue::AltLeft, + alt2: KeymapValue::AltLeft, + alt_shift: KeymapValue::AltLeft, + ctrl: KeymapValue::ControlLeft, + }); + keymap[ScanCodeValue::CursorDown as usize] = Some(KeymapSet { + not_shift: KeymapValue::Down, + shift: KeymapValue::Down, + alt1: KeymapValue::AltDown, + alt2: KeymapValue::AltDown, + alt_shift: KeymapValue::AltDown, + ctrl: KeymapValue::ControlDown, + }); + keymap[ScanCodeValue::CursorUp as usize] = Some(KeymapSet { + not_shift: KeymapValue::Up, + shift: KeymapValue::Up, + alt1: KeymapValue::AltUp, + alt2: KeymapValue::AltUp, + alt_shift: KeymapValue::AltUp, + ctrl: KeymapValue::ControlUp, + }); + keymap[ScanCodeValue::NumberLock as usize] = Some(KeymapSet { + not_shift: KeymapValue::NumberLock, + shift: KeymapValue::NumberLock, + alt1: KeymapValue::NumberLock, + alt2: KeymapValue::NumberLock, + alt_shift: KeymapValue::NumberLock, + ctrl: KeymapValue::NumberLock, + }); + keymap[ScanCodeValue::KeypadSlash as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('/'), + shift: KeymapValue::Ascii('/'), + alt1: KeymapValue::Alt('/'), + alt2: KeymapValue::Alt('/'), + alt_shift: KeymapValue::Alt('/'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::KeypadStar as usize] = Some(KeymapSet { + not_shift: KeymapValue::Ascii('*'), + shift: KeymapValue::Ascii('*'), + alt1: KeymapValue::Alt('*'), + alt2: KeymapValue::Alt('*'), + alt_shift: KeymapValue::Alt('*'), + ctrl: KeymapValue::Control('@'), + }); + keymap[ScanCodeValue::KeypadMin as usize] = None; + keymap[ScanCodeValue::KeypadPlus as usize] = None; + keymap[ScanCodeValue::KeypadEnter as usize] = Some(KeymapSet { + not_shift: KeymapValue::Control('M'), + shift: KeymapValue::Control('M'), + alt1: KeymapValue::ControlAlt('M'), + alt2: KeymapValue::ControlAlt('M'), + alt_shift: KeymapValue::ControlAlt('M'), + ctrl: KeymapValue::Control('J'), + }); + keymap[ScanCodeValue::Keypad1 as usize] = None; + keymap[ScanCodeValue::Keypad2 as usize] = None; + keymap[ScanCodeValue::Keypad3 as usize] = None; + keymap[ScanCodeValue::Keypad4 as usize] = None; + keymap[ScanCodeValue::Keypad5 as usize] = None; + keymap[ScanCodeValue::Keypad6 as usize] = None; + keymap[ScanCodeValue::Keypad7 as usize] = None; + keymap[ScanCodeValue::Keypad8 as usize] = None; + keymap[ScanCodeValue::Keypad9 as usize] = None; + keymap[ScanCodeValue::Keypad0 as usize] = None; + keymap[ScanCodeValue::KeypadDot as usize] = None; + keymap[ScanCodeValue::LeftControl as usize] = Some(KeymapSet { + not_shift: KeymapValue::LeftControl, + shift: KeymapValue::LeftControl, + alt1: KeymapValue::LeftControl, + alt2: KeymapValue::LeftControl, + alt_shift: KeymapValue::LeftControl, + ctrl: KeymapValue::LeftControl, + }); + keymap[ScanCodeValue::LeftShift as usize] = Some(KeymapSet { + not_shift: KeymapValue::LeftShift, + shift: KeymapValue::LeftShift, + alt1: KeymapValue::LeftShift, + alt2: KeymapValue::LeftShift, + alt_shift: KeymapValue::LeftShift, + ctrl: KeymapValue::LeftShift, + }); + keymap[ScanCodeValue::LeftAlt as usize] = Some(KeymapSet { + not_shift: KeymapValue::LeftAlt, + shift: KeymapValue::LeftAlt, + alt1: KeymapValue::LeftAlt, + alt2: KeymapValue::LeftAlt, + alt_shift: KeymapValue::LeftAlt, + ctrl: KeymapValue::LeftAlt, + }); + keymap[ScanCodeValue::LeftGUI as usize] = None; + keymap[ScanCodeValue::RightControl as usize] = Some(KeymapSet { + not_shift: KeymapValue::RightControl, + shift: KeymapValue::RightControl, + alt1: KeymapValue::RightControl, + alt2: KeymapValue::RightControl, + alt_shift: KeymapValue::RightControl, + ctrl: KeymapValue::RightControl, + }); + keymap[ScanCodeValue::RightShift as usize] = Some(KeymapSet { + not_shift: KeymapValue::RightShift, + shift: KeymapValue::RightShift, + alt1: KeymapValue::RightShift, + alt2: KeymapValue::RightShift, + alt_shift: KeymapValue::RightShift, + ctrl: KeymapValue::RightShift, + }); + keymap[ScanCodeValue::RightAlt as usize] = Some(KeymapSet { + not_shift: KeymapValue::RightAlt, + shift: KeymapValue::RightAlt, + alt1: KeymapValue::RightAlt, + alt2: KeymapValue::RightAlt, + alt_shift: KeymapValue::RightAlt, + ctrl: KeymapValue::RightAlt, + }); + keymap[ScanCodeValue::RightGUI as usize] = None; + keymap +}; diff --git a/src/driver/keyboard/keymaps/mod.rs b/src/driver/keyboard/keymaps/mod.rs index 474a556..87418a0 100644 --- a/src/driver/keyboard/keymaps/mod.rs +++ b/src/driver/keyboard/keymaps/mod.rs @@ -1,3 +1,6 @@ +#[cfg(feature = "azerty")] +pub mod fr_azerty; +#[cfg(not(feature = "azerty"))] pub mod us_qwerty; pub type Keymap = [Option; 0x80]; diff --git a/src/driver/keyboard/ps2.rs b/src/driver/keyboard/ps2.rs index e258601..63d0b7a 100644 --- a/src/driver/keyboard/ps2.rs +++ b/src/driver/keyboard/ps2.rs @@ -1,6 +1,10 @@ +#[cfg(feature = "azerty")] +use super::keymaps::fr_azerty::FR_AZERTY_KEYMAP; +#[cfg(not(feature = "azerty"))] +use super::keymaps::us_qwerty::US_QUERTY_KEYMAP; use super::{ fifo_buffer::FifoBuffer, - keymaps::{Keymap, KeymapValue, us_qwerty::US_QUERTY_KEYMAP}, + keymaps::{Keymap, KeymapValue}, }; use crate::{ driver::{ @@ -67,7 +71,10 @@ impl Keyboard { Self { buffer: FifoBuffer::new(), key_modifier: KeyModifier::new(), + #[cfg(not(feature = "azerty"))] keymap: &US_QUERTY_KEYMAP, + #[cfg(feature = "azerty")] + keymap: &FR_AZERTY_KEYMAP, scan_code_set: ScanCodeSet::new(), } } From 21c0eb6fbe90a442dec1083267e6169bf6a9230d Mon Sep 17 00:00:00 2001 From: nattensleplubo Date: Thu, 18 Jun 2026 14:57:27 +0200 Subject: [PATCH 2/3] fix(shell): switched keyboard layout switching from being a compile option to being an in kernel shell command --- Cargo.toml | 2 -- Makefile | 9 ++------- src/driver/keyboard/keymaps/mod.rs | 2 -- src/driver/keyboard/ps2.rs | 13 ++++++++----- src/driver/shell/mod.rs | 16 ++++++++++++++-- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1bb6e65..e74d080 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,5 +43,3 @@ unwrap_used = "deny" default = [] multiboot = [] multiboot2 = [] -# To use the french "azerty" keyboard layout instead of the default us qwerty -azerty = [] diff --git a/Makefile b/Makefile index 9d509a1..7c9ef5f 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,6 @@ BOOTLOADER := grub # BOOTLOADER := limine BOOTPROTOCOL := multiboot # BOOTPROTOCOL := multiboot2 -KEYMAP := qwerty -# KEYMAP := azerty # utlis CARGO := cargo @@ -19,11 +17,8 @@ GRUBCFG := boot/grub-${BOOTPROTOCOL}.cfg LIMINECONF := boot/limine-${BOOTPROTOCOL}.conf # flags -ifeq (${KEYMAP},azerty) -KEYMAPFEATURE := ,azerty -endif -CARGOFLAGS.debug := --features=${BOOTPROTOCOL}${KEYMAPFEATURE} -CARGOFLAGS.release := --features=${BOOTPROTOCOL}${KEYMAPFEATURE} --release +CARGOFLAGS.debug := --features=${BOOTPROTOCOL} +CARGOFLAGS.release := --features=${BOOTPROTOCOL} --release # dirs BUILDDIR := build/${BUILD} diff --git a/src/driver/keyboard/keymaps/mod.rs b/src/driver/keyboard/keymaps/mod.rs index 87418a0..e2d475a 100644 --- a/src/driver/keyboard/keymaps/mod.rs +++ b/src/driver/keyboard/keymaps/mod.rs @@ -1,6 +1,4 @@ -#[cfg(feature = "azerty")] pub mod fr_azerty; -#[cfg(not(feature = "azerty"))] pub mod us_qwerty; pub type Keymap = [Option; 0x80]; diff --git a/src/driver/keyboard/ps2.rs b/src/driver/keyboard/ps2.rs index 63d0b7a..11f3102 100644 --- a/src/driver/keyboard/ps2.rs +++ b/src/driver/keyboard/ps2.rs @@ -1,6 +1,4 @@ -#[cfg(feature = "azerty")] use super::keymaps::fr_azerty::FR_AZERTY_KEYMAP; -#[cfg(not(feature = "azerty"))] use super::keymaps::us_qwerty::US_QUERTY_KEYMAP; use super::{ fifo_buffer::FifoBuffer, @@ -71,14 +69,19 @@ impl Keyboard { Self { buffer: FifoBuffer::new(), key_modifier: KeyModifier::new(), - #[cfg(not(feature = "azerty"))] keymap: &US_QUERTY_KEYMAP, - #[cfg(feature = "azerty")] - keymap: &FR_AZERTY_KEYMAP, scan_code_set: ScanCodeSet::new(), } } + pub fn set_azerty(&mut self) { + self.keymap = &FR_AZERTY_KEYMAP; + } + + pub fn set_qwerty(&mut self) { + self.keymap = &US_QUERTY_KEYMAP; + } + pub fn get_input(&mut self) { let status = unsafe { inb(0x64) }; if status & 0x1 == 0x1 { diff --git a/src/driver/shell/mod.rs b/src/driver/shell/mod.rs index 19f139f..9e9043a 100644 --- a/src/driver/shell/mod.rs +++ b/src/driver/shell/mod.rs @@ -6,7 +6,9 @@ use super::{ vga::{BUFFER_WIDTH, Line}, }; use crate::{ - bootprotocol, gdt, memory, + bootprotocol, + driver::keyboard::ps2::KEYBOARD, + gdt, memory, mutex::Mutex, power::{halt, reboot, shutdown}, print, println, @@ -61,7 +63,9 @@ fn execute_command(line: &Line) { \tshutdown\n\ \ttest_colors\n\ \ttest_page_fault\n\ - \ttest_invalid_opcode" + \ttest_invalid_opcode\n\ + \tazerty\n\ + \tqwerty" ), "halt" => halt::halt(), "panic" => panic!(), @@ -113,6 +117,14 @@ fn execute_command(line: &Line) { "test_invalid_opcode" => unsafe { asm!("ud2", options(nomem, nostack)); }, + "azerty" => { + KEYBOARD.lock().set_azerty(); + println!("Keyboard layout set to AZERTY (fr)"); + } + "qwerty" => { + KEYBOARD.lock().set_qwerty(); + println!("Keyboard layout set to US QWERTY"); + } "" => {} _ => println!("command not found"), } From 609abee22cef194c89e8322d4c9faeb27a17a192 Mon Sep 17 00:00:00 2001 From: nattensleplubo Date: Thu, 18 Jun 2026 15:05:19 +0200 Subject: [PATCH 3/3] fix: clippy and fmt checks fixed --- src/driver/keyboard/keymaps/fr_azerty.rs | 2 +- src/driver/keyboard/ps2.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/driver/keyboard/keymaps/fr_azerty.rs b/src/driver/keyboard/keymaps/fr_azerty.rs index 1441008..72f95a4 100644 --- a/src/driver/keyboard/keymaps/fr_azerty.rs +++ b/src/driver/keyboard/keymaps/fr_azerty.rs @@ -314,7 +314,7 @@ pub const FR_AZERTY_KEYMAP: Keymap = { alt_shift: KeymapValue::Alt('+'), ctrl: KeymapValue::Control('@'), }); - // Ponctuation + // Ponctuation keymap[ScanCodeValue::LeftSquareBracket as usize] = Some(KeymapSet { // ^ dead key (¨ shifted) ASCII fallback '^' not_shift: KeymapValue::Ascii('^'), diff --git a/src/driver/keyboard/ps2.rs b/src/driver/keyboard/ps2.rs index 11f3102..2807629 100644 --- a/src/driver/keyboard/ps2.rs +++ b/src/driver/keyboard/ps2.rs @@ -1,8 +1,6 @@ -use super::keymaps::fr_azerty::FR_AZERTY_KEYMAP; -use super::keymaps::us_qwerty::US_QUERTY_KEYMAP; use super::{ fifo_buffer::FifoBuffer, - keymaps::{Keymap, KeymapValue}, + keymaps::{Keymap, KeymapValue, fr_azerty::FR_AZERTY_KEYMAP, us_qwerty::US_QUERTY_KEYMAP}, }; use crate::{ driver::{ @@ -74,11 +72,11 @@ impl Keyboard { } } - pub fn set_azerty(&mut self) { + pub const fn set_azerty(&mut self) { self.keymap = &FR_AZERTY_KEYMAP; } - pub fn set_qwerty(&mut self) { + pub const fn set_qwerty(&mut self) { self.keymap = &US_QUERTY_KEYMAP; }