CopyKeyClass: did need to send XkbSendNewKeyboardNotify event?
I have a scanner, When using a Qt program to input, if the second character is uppercase, the first lowercase character will be converted to a character with shift during the first scan.
On my computer, using xdotool I can also reproduce this phenomenon. see error.mp4 and xdotool.sh
the video show the reproduce step:
- open a Qt program and type some character to make sure the keyboard is master device;
- then run xdotool.sh and active Qt window, select QLineEdit all text, wait xdotool input;
- you will see the first character is error.
note:
- reproduce this bug to make sure the second character is uppercase.
- xdotool sometime maybe can't reproduce,but scanner always exist.
video: error test shell: xdotool.sh IR code:
Process analysis:
- when use xdotool or scanner input, first of all, xorg-server will call CopyKeyClass and send XkbSendNewKeyboardNotify event to Qt program;
- when Qt program recvice this event, Qt will call updateKeymap, see Qt code: https://github.com/qt/qtbase/blob/dev/src/plugins/platforms/xcb/qxcbkeyboard.cpp#L393
- in the updateKeymap function, Qt will call libxkbcommon to reset xkbState, and this time, libxkbcommon will return Qt a new xkbState, but the value base_mods of xkbState's is not right;
My guess:
- When xorg-server send XkbSendNewKeyboardNotify event, Qt and libxkbcommon communicate will spend some time;
- If Qt didn't initialized yet, and shift if pressed, and this time xorg-server will give libxkbcommon a error base_mods value of xkbState's.
note:
- If you increase the scanner input delay between characters, the probability of recurrence will decrease;
- If xorg-server not send XkbSendNewKeyboardNotify event, this bug don't reproduce;
question:
- CopyKeyClass note say Copy the device->key into master->key and send a mapping notify to the clients if appropriate. Should we send xkbMapNotify instead of xkbNewKeyboardNotify?
- if we don't send xkbNewKeyboardNotify event, will it cause other bugs?
Edited by zhang hao