[XCB] Avoid emitting text events when a key press does not generate text

Many keys will generate key press events but return an empty string from
`xkb_state_key_get_utf8`, like modifier keys, arrow keys, function keys,
etc. This checks if the string retrieved from such a key press is empty
before emitting an associated text event for it, to avoid notifying a
potentially large number of listeners about an empty string.

Signed-off-by: Chris Burel <burelc@amazon.com>
This commit is contained in:
Chris Burel
2021-10-06 09:09:05 -07:00
parent 3e0535e211
commit 8668d8b2fe
2 changed files with 55 additions and 8 deletions
@@ -148,8 +148,13 @@ namespace AzFramework
if (responseType == XCB_KEY_PRESS)
{
const auto* keyPress = reinterpret_cast<xcb_key_press_event_t*>(event);
QueueRawTextEvent(TextFromKeycode(m_xkbState.get(), keyPress->detail));
{
auto text = TextFromKeycode(m_xkbState.get(), keyPress->detail);
if (!text.empty())
{
QueueRawTextEvent(AZStd::move(text));
}
}
if (const InputChannelId* key = InputChannelFromKeyEvent(keyPress->detail))
{