Skip to content

orbkb: Keyboard handling library for Orbital

Jeremy Soller requested to merge kaedroho:feature/orbkb into master

Created by: kaedroho

First up, apologies for this massive drive-by PR! I did this for fun and wasn't expecting to write this much code (or even submit any of it) when I started so please don't feel any pressure to merge it. I think this contains some useful new features so thought you might be interested!

Problem:

There's a number of basic features missing from RedoxOS's current keyboard implementation.

Solution:

I've created a new library called orbkb* which contains a bunch of keyboard handling code and integrated it into the rest of the system. This adds the following new features to RedoxOS:

  • Modifier keys
  • Alt-Gr key (US layout treats it as another Alt key)
  • Lock keys
  • Numpad (including actions when numlock is off)
  • Key repeat detection
  • Logical keyboard input

* The reason it's separate from orbclient is because I couldn't get cargo test to work.

Components of orbkb

  • KeyboardState: tracks the state of a physical keyboard and converts physical keyboard events ("key 30 has been pressed") into logical keyboard events ("the letter 'a' has been inputted")
  • ScancodeReader: A struct that takes a stream of ps2 scancodes. Remaps scancodes to keycodes (using Linux's keycode mapping) and emits key events
  • Key: An struct that wraps a keycode and provides some convenience methods.
  • Layout: A mapping of keycodes to symbols and other layout configuration (eg, does the layout have an Alt-Gr key?)
  • KeyboardEvent/LogicalKeyboardEvent: Structs used to communicate keyboard events around redox

orbkb is rexported from orbclient as orbclient::kb. I think it would be best to merge it into orbclient when the test issues are fixed.

Why logical keyboard events?

Logical keyboard events simplify the keyboard handling in applications that are driven by text input (terminals, text editors, etc) as there's a number of cases when these type of applications should not intepret a a physical "key press" event as user input, for example:

  • When a key is pressed with the control key pressed (Ctrl+c)
  • When a numpad key is pressed with the numlock off
  • When using compose/multi-key input
  • When using accesibility features such as sticky keys or debouncing

LKEs allow these features to be implemented centrally in ps2d and applications just have to listen for keyboard events that contain a "logical" part. Applications that rely on physical keyboard input, such as games, can just ignore the "logical" part.

Changes introduced by this pull request:

  • Implemented orbkb library
  • Integrated with orbclient
  • Integrated with terminal, browser, orbtk and vesad then updated these where necessary to use logical events

Drawbacks:

  • Logical keyboard events are something I made up and I've not seen anything like them used anywhere else so they could be a bad idea.

TODOs:

  • Rewrite bepo and azerty layouts in new format
  • Keyboard leds
  • Investigate non-latin keyboard support

Fixes:

None of the issues above are reported in a Github issue

State: Ready

Blocking/related:

Merge request reports