From af09dbb64899c08b854552d134af30fe3f4255ed Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 22 Sep 2015 13:50:48 +0200 Subject: [PATCH] Switch keyboard handling to xcb (WIP, needs to be cleaned before merge) --- renderdoc/Makefile | 2 +- renderdoc/driver/vulkan/Makefile | 1 - .../driver/vulkan/wrappers/vk_wsi_funcs.cpp | 16 ++++++ renderdoc/os/linux/linux_stringio.cpp | 49 ++++++++++++------- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/renderdoc/Makefile b/renderdoc/Makefile index 5f66e8611..4425c7554 100644 --- a/renderdoc/Makefile +++ b/renderdoc/Makefile @@ -7,7 +7,7 @@ MACROS=-DLINUX \ -DGIT_COMMIT_HASH="\"$(COMMIT)\"" CFLAGS=-c -Wall -Werror -Wno-unused -Wno-unknown-pragmas -fPIC $(MACROS) -I. -I3rdparty/ CPPFLAGS=-std=c++11 -g -Wno-reorder -fvisibility=hidden -fvisibility-inlines-hidden -LDFLAGS=-lpthread -lrt -shared -ldl -lX11 +LDFLAGS=-lpthread -lrt -shared -ldl -lX11 -lxcb-keysyms LIBS=driver/gl/rdoc_gl.a driver/vulkan/rdoc_vulkan.a driver/shaders/spirv/rdoc_spirv.a $(VULKAN_SDK_SRC)/build/layers/liblayer_utils.so OBJDIR=.obj OBJECTS=replay/replay_output.o \ diff --git a/renderdoc/driver/vulkan/Makefile b/renderdoc/driver/vulkan/Makefile index 06f924910..1594042d1 100644 --- a/renderdoc/driver/vulkan/Makefile +++ b/renderdoc/driver/vulkan/Makefile @@ -7,7 +7,6 @@ MACROS=-DLINUX \ -DGIT_COMMIT_HASH="\"$(COMMIT)\"" CFLAGS=-c -Wall -Werror -Wno-unused -Wno-unknown-pragmas -fPIC $(MACROS) -I../../ -I../../3rdparty/ -I$(VULKAN_SDK)/include/vulkan CPPFLAGS=-std=c++11 -g -Wno-reorder -fvisibility=hidden -fvisibility-inlines-hidden -LDFLAGS=-lpthread -lrt -shared -ldl -lX11 OBJDIR=.obj OBJECTS=vk_dispatchtables.o \ vk_tracelayer.o \ diff --git a/renderdoc/driver/vulkan/wrappers/vk_wsi_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_wsi_funcs.cpp index dd106f9e7..a09e302c1 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_wsi_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_wsi_funcs.cpp @@ -29,6 +29,11 @@ #include "jpeg-compressor/jpge.h" +struct xcb_connection_t; + +// bit of a hack +namespace Keyboard { void UseConnection(xcb_connection_t *conn); } + /////////////////////////////////////////////////////////////////////////////////////// // WSI extension @@ -165,6 +170,17 @@ bool WrappedVulkan::Serialise_vkCreateSwapChainWSI( SERIALISE_ELEMENT(VkSwapChainCreateInfoWSI, info, *pCreateInfo); SERIALISE_ELEMENT(ResourceId, id, GetResID(*pSwapChain)); + if(pCreateInfo && pCreateInfo->pSurfaceDescription) + { + VkSurfaceDescriptionWindowWSI *surf = (VkSurfaceDescriptionWindowWSI*)pCreateInfo->pSurfaceDescription; + + if(surf->platform == VK_PLATFORM_XCB_WSI) + { + VkPlatformHandleXcbWSI *handle = (VkPlatformHandleXcbWSI *)surf->pPlatformHandle; + Keyboard::UseConnection(handle->connection); + } + } + uint32_t numIms = 0; if(m_State >= WRITING) diff --git a/renderdoc/os/linux/linux_stringio.cpp b/renderdoc/os/linux/linux_stringio.cpp index 359016ba8..1a6203285 100644 --- a/renderdoc/os/linux/linux_stringio.cpp +++ b/renderdoc/os/linux/linux_stringio.cpp @@ -37,6 +37,8 @@ #include #include +#include + #include // for dladdr @@ -55,13 +57,15 @@ namespace Keyboard { } - Display *CurrentXDisplay = NULL; + xcb_connection_t *connection; + xcb_key_symbols_t *symbols; - void CloneDisplay(Display *dpy) + void CloneDisplay(Display *dpy) {} + + void UseConnection(xcb_connection_t *conn) { - if(CurrentXDisplay || dpy == NULL) return; - - CurrentXDisplay = XOpenDisplay(XDisplayString(dpy)); + connection = conn; + symbols = xcb_key_symbols_alloc(conn); } void AddInputWindow(void *wnd) @@ -77,7 +81,7 @@ namespace Keyboard { KeySym ks = 0; - if(CurrentXDisplay == NULL) return false; + if(symbols == NULL) return false; if(key >= eRENDERDOC_Key_A && key <= eRENDERDOC_Key_Z) ks = key; if(key >= eRENDERDOC_Key_0 && key <= eRENDERDOC_Key_9) ks = key; @@ -116,18 +120,29 @@ namespace Keyboard if(ks == 0) return false; + + xcb_keycode_t *keyCodes = xcb_key_symbols_get_keycode(symbols, ks); + + if(!keyCodes) + return false; + + xcb_query_keymap_cookie_t keymapcookie = xcb_query_keymap(connection); + xcb_query_keymap_reply_t *keys = xcb_query_keymap_reply(connection, keymapcookie, NULL); + + bool ret = false; - KeyCode kc = XKeysymToKeycode(CurrentXDisplay, ks); - - char keyState[32]; - XQueryKeymap(CurrentXDisplay, keyState); - - int byteIdx = (kc/8); - int bitMask = 1 << (kc%8); - - uint8_t keyByte = (uint8_t)keyState[byteIdx]; - - return (keyByte & bitMask) != 0; + if(keys && keyCodes[0] != XCB_NO_SYMBOL) + { + int byteIdx = (keyCodes[0]/8); + int bitMask = 1 << (keyCodes[0]%8); + + ret = (keys->keys[byteIdx] & bitMask) != 0; + } + + free(keyCodes); + free(keys); + + return ret; } }