From 56c21608551381bd6ff41e9f5358f580b461b254 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Sat, 15 Dec 2018 00:22:28 +0100 Subject: [PATCH] attempting to fix some potential input dialog crashes --- src/libui_sdl/libui/unix/area.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/libui_sdl/libui/unix/area.c b/src/libui_sdl/libui/unix/area.c index 40f86249..2da9baba 100644 --- a/src/libui_sdl/libui/unix/area.c +++ b/src/libui_sdl/libui/unix/area.c @@ -523,16 +523,26 @@ char* uiKeyName(int scancode) { scancode = scancode_normal2unix(scancode); + char* ret; guint* keyvals; int num; - GdkKeymap* keymap = gdk_keymap_get_default(); - gdk_keymap_get_entries_for_keycode(keymap, scancode, NULL, &keyvals, &num); + GdkKeymap* keymap = gdk_keymap_get_for_display(gdk_display_get_default()); + if (gdk_keymap_get_entries_for_keycode(keymap, scancode, NULL, &keyvals, &num)) + { + // TODO: pick smarter?? + int keyval = keyvals[0]; + + g_free(keyvals); + + ret = gdk_keyval_name(keyval); + } + else + { + char tmp[16]; + sprintf(tmp, "#%03X", scancode); + ret = tmp; + } - // TODO: pick smarter?? - int keyval = keyvals[0]; - - g_free(keyvals); - - return uiUnixStrdupText(gdk_keyval_name(keyval)); + return uiUnixStrdupText(ret); } enum {