Skip to main content

strat9_kernel/arch/x86_64/
keyboard_layout.rs

1//! Keyboard Layout Configuration
2//!
3//! Allows selection between different keyboard layouts (US QWERTY, French AZERTY, etc.)
4
5use core::sync::atomic::{AtomicBool, Ordering};
6
7// Flag to determine which keyboard layout to use
8// true = French AZERTY, false = US QWERTY
9static USE_FRENCH_LAYOUT: AtomicBool = AtomicBool::new(true);
10
11/// Set the keyboard layout to French AZERTY
12pub fn set_french_layout() {
13    USE_FRENCH_LAYOUT.store(true, Ordering::SeqCst);
14}
15
16/// Set the keyboard layout to US QWERTY
17pub fn set_us_layout() {
18    USE_FRENCH_LAYOUT.store(false, Ordering::SeqCst);
19}
20
21/// Get the current keyboard layout setting
22pub fn is_french_layout() -> bool {
23    USE_FRENCH_LAYOUT.load(Ordering::SeqCst)
24}
25
26/// Handle a keyboard scancode based on the current layout
27pub fn handle_scancode() -> Option<u8> {
28    if is_french_layout() {
29        crate::arch::x86_64::keyboard::handle_scancode()
30    } else {
31        crate::arch::x86_64::keyboard_us::handle_scancode()
32    }
33}
34
35/// Handle a pre-read raw scancode (port 0x60 already consumed by caller).
36pub fn handle_scancode_raw(scancode: u8) -> Option<u8> {
37    if is_french_layout() {
38        crate::arch::x86_64::keyboard::handle_scancode_raw(scancode)
39    } else {
40        crate::arch::x86_64::keyboard_us::handle_scancode_raw(scancode)
41    }
42}