xref: /openbmc/linux/Documentation/input/notifier.rst (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1e2ba5731SMauro Carvalho Chehab=================
2e2ba5731SMauro Carvalho ChehabKeyboard notifier
3e2ba5731SMauro Carvalho Chehab=================
4e2ba5731SMauro Carvalho Chehab
5e2ba5731SMauro Carvalho ChehabOne can use register_keyboard_notifier to get called back on keyboard
6e2ba5731SMauro Carvalho Chehabevents (see kbd_keycode() function for details).  The passed structure is
7*365c6a3eSRandy Dunlapkeyboard_notifier_param (see <linux/keyboard.h>):
8e2ba5731SMauro Carvalho Chehab
9e2ba5731SMauro Carvalho Chehab- 'vc' always provide the VC for which the keyboard event applies;
10e2ba5731SMauro Carvalho Chehab- 'down' is 1 for a key press event, 0 for a key release;
11e2ba5731SMauro Carvalho Chehab- 'shift' is the current modifier state, mask bit indexes are KG_*;
12*365c6a3eSRandy Dunlap- 'ledstate' is the current LED state;
13e2ba5731SMauro Carvalho Chehab- 'value' depends on the type of event.
14e2ba5731SMauro Carvalho Chehab
15e2ba5731SMauro Carvalho Chehab- KBD_KEYCODE events are always sent before other events, value is the keycode.
16e2ba5731SMauro Carvalho Chehab- KBD_UNBOUND_KEYCODE events are sent if the keycode is not bound to a keysym.
17e2ba5731SMauro Carvalho Chehab  value is the keycode.
18e2ba5731SMauro Carvalho Chehab- KBD_UNICODE events are sent if the keycode -> keysym translation produced a
19e2ba5731SMauro Carvalho Chehab  unicode character. value is the unicode value.
20e2ba5731SMauro Carvalho Chehab- KBD_KEYSYM events are sent if the keycode -> keysym translation produced a
21e2ba5731SMauro Carvalho Chehab  non-unicode character. value is the keysym.
22e2ba5731SMauro Carvalho Chehab- KBD_POST_KEYSYM events are sent after the treatment of non-unicode keysyms.
23e2ba5731SMauro Carvalho Chehab  That permits one to inspect the resulting LEDs for instance.
24e2ba5731SMauro Carvalho Chehab
25e2ba5731SMauro Carvalho ChehabFor each kind of event but the last, the callback may return NOTIFY_STOP in
26e2ba5731SMauro Carvalho Chehaborder to "eat" the event: the notify loop is stopped and the keyboard event is
27e2ba5731SMauro Carvalho Chehabdropped.
28e2ba5731SMauro Carvalho Chehab
29e2ba5731SMauro Carvalho ChehabIn a rough C snippet, we have::
30e2ba5731SMauro Carvalho Chehab
31e2ba5731SMauro Carvalho Chehab    kbd_keycode(keycode) {
32e2ba5731SMauro Carvalho Chehab	...
33e2ba5731SMauro Carvalho Chehab	params.value = keycode;
34e2ba5731SMauro Carvalho Chehab	if (notifier_call_chain(KBD_KEYCODE,&params) == NOTIFY_STOP)
35e2ba5731SMauro Carvalho Chehab	    || !bound) {
36e2ba5731SMauro Carvalho Chehab		notifier_call_chain(KBD_UNBOUND_KEYCODE,&params);
37e2ba5731SMauro Carvalho Chehab		return;
38e2ba5731SMauro Carvalho Chehab	}
39e2ba5731SMauro Carvalho Chehab
40e2ba5731SMauro Carvalho Chehab	if (unicode) {
41e2ba5731SMauro Carvalho Chehab		param.value = unicode;
42e2ba5731SMauro Carvalho Chehab		if (notifier_call_chain(KBD_UNICODE,&params) == NOTIFY_STOP)
43e2ba5731SMauro Carvalho Chehab			return;
44e2ba5731SMauro Carvalho Chehab		emit unicode;
45e2ba5731SMauro Carvalho Chehab		return;
46e2ba5731SMauro Carvalho Chehab	}
47e2ba5731SMauro Carvalho Chehab
48e2ba5731SMauro Carvalho Chehab	params.value = keysym;
49e2ba5731SMauro Carvalho Chehab	if (notifier_call_chain(KBD_KEYSYM,&params) == NOTIFY_STOP)
50e2ba5731SMauro Carvalho Chehab		return;
51e2ba5731SMauro Carvalho Chehab	apply keysym;
52e2ba5731SMauro Carvalho Chehab	notifier_call_chain(KBD_POST_KEYSYM,&params);
53e2ba5731SMauro Carvalho Chehab    }
54e2ba5731SMauro Carvalho Chehab
55e2ba5731SMauro Carvalho Chehab.. note:: This notifier is usually called from interrupt context.
56