notifier.txt 1.7 KB

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