[UI] Fixed GTK from propagating lowercase input to ImGUI
This commit is contained in:
@@ -482,6 +482,8 @@ VirtualKey GTKWindow::TranslateVirtualKey(guint keyval) {
|
|||||||
return VirtualKey::kRShift;
|
return VirtualKey::kRShift;
|
||||||
case GDK_KEY_space:
|
case GDK_KEY_space:
|
||||||
return VirtualKey::kSpace;
|
return VirtualKey::kSpace;
|
||||||
|
case GDK_KEY_Caps_Lock:
|
||||||
|
return VirtualKey::kCapital;
|
||||||
default:
|
default:
|
||||||
XELOGW("Unhandled key code: {}", keyval);
|
XELOGW("Unhandled key code: {}", keyval);
|
||||||
return VirtualKey(keyval);
|
return VirtualKey(keyval);
|
||||||
@@ -569,18 +571,34 @@ bool GTKWindow::HandleKeyboard(
|
|||||||
bool ctrl_pressed = modifiers & GDK_CONTROL_MASK;
|
bool ctrl_pressed = modifiers & GDK_CONTROL_MASK;
|
||||||
bool alt_pressed = modifiers & GDK_META_MASK;
|
bool alt_pressed = modifiers & GDK_META_MASK;
|
||||||
bool super_pressed = modifiers & GDK_SUPER_MASK;
|
bool super_pressed = modifiers & GDK_SUPER_MASK;
|
||||||
uint32_t key_char = gdk_keyval_to_unicode(event->keyval);
|
|
||||||
KeyEvent e(this, TranslateVirtualKey(event->keyval), 1,
|
// Translate GTK to VK
|
||||||
event->type == GDK_KEY_RELEASE, shift_pressed, ctrl_pressed,
|
VirtualKey vk = TranslateVirtualKey(event->keyval);
|
||||||
alt_pressed, super_pressed);
|
uint32_t unicode_char = gdk_keyval_to_unicode(event->keyval);
|
||||||
|
|
||||||
|
bool is_key_pressed = false;
|
||||||
|
|
||||||
|
// Backspace has unicode value but is not printable therefore we want
|
||||||
|
// OnKeyDown not OnKeyChar
|
||||||
|
if (unicode_char > 0) {
|
||||||
|
if (std::isprint(unicode_char)) {
|
||||||
|
is_key_pressed = true;
|
||||||
|
vk = static_cast<VirtualKey>(unicode_char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyEvent e(this, vk, 1, event->type == GDK_KEY_RELEASE, shift_pressed,
|
||||||
|
ctrl_pressed, alt_pressed, super_pressed);
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case GDK_KEY_PRESS:
|
case GDK_KEY_PRESS:
|
||||||
OnKeyDown(e, destruction_receiver);
|
if (is_key_pressed) {
|
||||||
if (destruction_receiver.IsWindowDestroyedOrClosed()) {
|
|
||||||
return e.is_handled();
|
|
||||||
}
|
|
||||||
if (key_char > 0) {
|
|
||||||
OnKeyChar(e, destruction_receiver);
|
OnKeyChar(e, destruction_receiver);
|
||||||
|
} else {
|
||||||
|
OnKeyDown(e, destruction_receiver);
|
||||||
|
|
||||||
|
if (destruction_receiver.IsWindowDestroyedOrClosed()) {
|
||||||
|
return e.is_handled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GDK_KEY_RELEASE:
|
case GDK_KEY_RELEASE:
|
||||||
|
|||||||
Reference in New Issue
Block a user