요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=================
Keyboard notifier
=================
One can use register_keyboard_notifier to get called back on keyboard
events (see kbd_keycode() function for details). The passed structure is
keyboard_notifier_param (see <linux/keyboard.h>):
- 'vc' always provide the VC for which the keyboard event applies;
- 'down' is 1 for a key press event, 0 for a key release;
- 'shift' is the current modifier state, mask bit indexes are KG_*;
- 'ledstate' is the current LED state;
- 'value' depends on the type of event.
- KBD_KEYCODE events are always sent before other events, value is the keycode.
- KBD_UNBOUND_KEYCODE events are sent if the keycode is not bound to a keysym.
value is the keycode.
- KBD_UNICODE events are sent if the keycode -> keysym translation produced a
unicode character. value is the unicode value.
- KBD_KEYSYM events are sent if the keycode -> keysym translation produced a
non-unicode character. value is the keysym.
- KBD_POST_KEYSYM events are sent after the treatment of non-unicode keysyms.
That permits one to inspect the resulting LEDs for instance.
For each kind of event but the last, the callback may return NOTIFY_STOP in
order to "eat" the event: the notify loop is stopped and the keyboard event is
dropped.
In a rough C snippet, we have::
kbd_keycode(keycode) {
...
params.value = keycode;
if (notifier_call_chain(KBD_KEYCODE,¶ms) == NOTIFY_STOP)
|| !bound) {
notifier_call_chain(KBD_UNBOUND_KEYCODE,¶ms);
return;
}
if (unicode) {
param.value = unicode;
if (notifier_call_chain(KBD_UNICODE,¶ms) == NOTIFY_STOP)
return;
emit unicode;
return;
}
params.value = keysym;
if (notifier_call_chain(KBD_KEYSYM,¶ms) == NOTIFY_STOP)
return;
apply keysym;
notifier_call_chain(KBD_POST_KEYSYM,¶ms);
}
.. note:: This notifier is usually called from interrupt context.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Keyboard notifier parameter와 event 종류
1-28`register_keyboard_notifier`를 사용하면 keyboard event에서 callback을 받을 수 있습니다. 자세한 발생 지점은 `kbd_keycode()`를 참고하며 전달 구조체는 `<linux/keyboard.h>`의 `keyboard_notifier_param`입니다.
Callback에 전달되는 keyboard 상태입니다.
Keycode translation 단계별 notification과 value입니다.
마지막 `KBD_POST_KEYSYM`을 제외한 각 event에서 callback은 `NOTIFY_STOP`을 반환해 event를 소비할 수 있습니다. 그러면 notify loop가 멈추고 keyboard event가 drop됩니다. Post event는 결과 LED 등을 검사하는 단계입니다.
Keycode부터 Unicode 또는 keysym 처리 후 상태 관찰까지의 경로입니다.
=================
Keyboard notifier
=================
One can use register_keyboard_notifier to get called back on keyboard
events (see kbd_keycode() function for details). The passed structure is
keyboard_notifier_param (see <linux/keyboard.h>):
- 'vc' always provide the VC for which the keyboard event applies;
- 'down' is 1 for a key press event, 0 for a key release;
- 'shift' is the current modifier state, mask bit indexes are KG_*;
- 'ledstate' is the current LED state;
- 'value' depends on the type of event.
- KBD_KEYCODE events are always sent before other events, value is the keycode.
- KBD_UNBOUND_KEYCODE events are sent if the keycode is not bound to a keysym.
value is the keycode.
- KBD_UNICODE events are sent if the keycode -> keysym translation produced a
unicode character. value is the unicode value.
- KBD_KEYSYM events are sent if the keycode -> keysym translation produced a
non-unicode character. value is the keysym.
- KBD_POST_KEYSYM events are sent after the treatment of non-unicode keysyms.
That permits one to inspect the resulting LEDs for instance.
For each kind of event but the last, the callback may return NOTIFY_STOP in
order to "eat" the event: the notify loop is stopped and the keyboard event is
dropped.
`kbd_keycode()` notifier 제어 흐름
29-55개략 C 흐름에서 먼저 `params.value=keycode`로 두고 `KBD_KEYCODE` chain을 호출합니다. Callback이 `NOTIFY_STOP`을 반환하거나 keycode가 unbound이면 `KBD_UNBOUND_KEYCODE` chain을 호출하고 반환합니다.
Unicode translation이면 `param.value=unicode`로 바꾸고 `KBD_UNICODE` chain을 호출합니다. Stop이면 반환하고 그렇지 않으면 Unicode를 emit한 뒤 반환합니다.
Non-Unicode keysym이면 `params.value=keysym`으로 설정해 `KBD_KEYSYM` chain을 호출합니다. Stop이면 반환하고, 아니면 keysym을 적용한 뒤 `KBD_POST_KEYSYM` chain을 호출합니다.
마지막 post notification을 제외한 단계에서 event 처리를 중단할 수 있습니다.
각 translation 단계의 callback 결과가 후속 처리를 결정합니다.
이 notifier는 보통 interrupt context에서 호출됩니다. Callback은 그 문맥에 맞게 sleep하지 않고 빠르게 끝나도록 작성해야 합니다.
In a rough C snippet, we have::
kbd_keycode(keycode) {
...
params.value = keycode;
if (notifier_call_chain(KBD_KEYCODE,¶ms) == NOTIFY_STOP)
|| !bound) {
notifier_call_chain(KBD_UNBOUND_KEYCODE,¶ms);
return;
}
if (unicode) {
param.value = unicode;
if (notifier_call_chain(KBD_UNICODE,¶ms) == NOTIFY_STOP)
return;
emit unicode;
return;
}
params.value = keysym;
if (notifier_call_chain(KBD_KEYSYM,¶ms) == NOTIFY_STOP)
return;
apply keysym;
notifier_call_chain(KBD_POST_KEYSYM,¶ms);
}
.. note:: This notifier is usually called from interrupt context.
요약·해설
notifier.rst:1-55Keyboard notifier는 keycode가 Unicode 또는 keysym으로 변환되는 단계마다 callback을 제공하며, post 단계 전까지 `NOTIFY_STOP`으로 event를 소비할 수 있습니다. 보통 interrupt context에서 호출된다는 제약이 중요합니다.
Notification 흐름과 callback 제어를 요약했습니다.
Keycode에서 최종 적용과 post 관찰까지입니다.