^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Keyboard notifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) One can use register_keyboard_notifier to get called back on keyboard
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) events (see kbd_keycode() function for details). The passed structure is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) keyboard_notifier_param:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) - 'vc' always provide the VC for which the keyboard event applies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) - 'down' is 1 for a key press event, 0 for a key release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) - 'shift' is the current modifier state, mask bit indexes are KG_*;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) - 'value' depends on the type of event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) - KBD_KEYCODE events are always sent before other events, value is the keycode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) - KBD_UNBOUND_KEYCODE events are sent if the keycode is not bound to a keysym.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) value is the keycode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) - KBD_UNICODE events are sent if the keycode -> keysym translation produced a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unicode character. value is the unicode value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) - KBD_KEYSYM events are sent if the keycode -> keysym translation produced a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) non-unicode character. value is the keysym.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) - KBD_POST_KEYSYM events are sent after the treatment of non-unicode keysyms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) That permits one to inspect the resulting LEDs for instance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) For each kind of event but the last, the callback may return NOTIFY_STOP in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) order to "eat" the event: the notify loop is stopped and the keyboard event is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) In a rough C snippet, we have::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) kbd_keycode(keycode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) params.value = keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) if (notifier_call_chain(KBD_KEYCODE,¶ms) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) || !bound) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) notifier_call_chain(KBD_UNBOUND_KEYCODE,¶ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (unicode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) param.value = unicode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (notifier_call_chain(KBD_UNICODE,¶ms) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) emit unicode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) params.value = keysym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (notifier_call_chain(KBD_KEYSYM,¶ms) == NOTIFY_STOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) apply keysym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) notifier_call_chain(KBD_POST_KEYSYM,¶ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .. note:: This notifier is usually called from interrupt context.