In my last blog post I explain how to access and manage input devices in KWin. In this post, I’ll take a closer look at devices,keyboard events and keyboard price in Pakistan.
Keyboard are not keyboards
Keyboards in Linux are weird. You don’t have one keyboard, you have many. Many devices also advertise themselves as keyboards and only support one key. A good example of this is an over-ear headset with a power button or mute and volume up/down buttons. Diffrent keyboard price in pakistan in terms of input, these devices are also keyboards.
It’s important for us at KWin to understand what the keyboard actually supports. If no “real” keyboard is connect (or not active), our virtual keyboard should turn on automatically. For example. if you disconnect the keyboard from the convertible, it should revert to tablet mode with a virtual keyboard. When installing a keyboard, the virtual keyboard must be disable as the primary text input device. libinput provides a function to check which keys are support. We use this to differentiate between keyboard classes.
Keyboards are the simplest input devices on the market. Libinput triggers a single event of type LIBINPUT EVENT KEYBOARD KEY containing only one press or release key. KWin reads events from libinput into a special header, so each event is just queued and our main thread is notify of the new event. After the event is handl by the main thread, it is pass to our input redirection classes.
All connection events go through the inbound redirection, regardless of the source from which the events are delivere. KWin not only supports libinput events, but also nest configurations (KWin runs on X11 or another Wayland server) and dummy events used in our integration tests. This means that when an event hits an inbound redirect, we generally lose the information about which device generate the event. We’ve recently extend the internal API to include the device in event processing when need. It is use by the debugging console to show which device generate the event. But more on that later.
The key press/release event has now reach our core Keyboard Input Redirection::process Key delivery method. The first (and most important) task is to update the keyboard status in xkbcommon. Xkbcommon is use to convert a hardware key with a keyboard state base layout (such as an active modifier) into a real key character. To clarify, if I press the “y” key (keycode 21) and press the “Shift” key, it creates “Z” on the German keyboard layout, but “Y” on the English layout. In a nutshell, this is what xkbcommon does.
In KWin I wrapp all functions for xkbcommon in a custom class called Xkb. This class keeps track of the active layout for us and handles layout changes (including displaying the OSD when the layout changes). Learn about the most recently create key symbols, currently active modifiers, and modifiers related to enabling shortcuts.
When we update xkb’s status, we also check what has change. Has the user activate number blocking? If so, we need to declare that the LEDs have change so that our libin input code can update the LEDs on the physical keyboard. Has the modifier change? If so, we need to inform our Wayland windows about the new set of modifiers. In Wayland, this is track on the server, but the actual key tokenization is done on the client. So why does KWin also do the translation? Also KWin needs keysym in several places, e.g. Filter Windows currently or globally to enable global shortcuts.
Filter via KWin
KWin now has enough information to process the key event. Create your own QKeyEvent for it and pass it through the input filter chain. KWin’s input processing uses a chain of input filters. Each filter can perform an action base on an event and decide whether the event should be further process or whether event processing should end.
The last filter in the chain is our redirect filter. The purpose of this filter is to pass events to the window. Forwards the event to the KWayland::Server where it is sent to the current surface of Wayland.
Focused keyboard surface
To do this, the Wayland server needs a focused keyboard surface. In the case of keyboard focus, which is relatively unimportant in KWin. KWin has the concept of an “active” window. Before sending the event, KWin checks which keyboard window has the focus. If there is an active window, that window’s surface will be marked as the focuse keyboard surface in KWayland::Server.
Our KWayland::Server library takes care of sending keyboard and login events to the correct windows, so KWin doesn’t have to take care of that. This is one of the advantages of abstracting with KWayland::Server: anything not relate to the assembler is processe directly in the library.
Handling important events in Wayland
The client receives the key event via a callback and now also sends it via xkbcommon. In Wayland, the keyboard layout is sent from the server to the client so that both server and client have the same layout. The customer can now translate the key code into a key symbol, as KWin use to do.
Other events are handle within the client. For example. In Qt this will create a QKeyEvent which will then be sent to the focuse widget.
Keyboard input also has a special mode: repeat keys. Pressing a key should produce several repeat keys. KWin uses the configuration of the keyboard module to decide when and how often to repeat a keystroke. The duplicate key will not be sent to Wayland customers. Instead, KWin communicates the key repeat setting via the Wayland keyboard protocol, and this is handle directly on the client.
Unfortunately this doesn’t work in Qt and uses a hard-code value. So currently in a Plasma Wayland session, key duplication is pretty much broken because it’s handle differently depending on which application is being use. KWin is correct when running on Wayland, X11 applications are correct, GTK applications are correct, Qt applications are incorrect.
Read more: Keyboard Price in Pakistan