mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-25 03:10:47 +00:00
Switch keyboard handling to xcb (WIP, needs to be cleaned before merge)
This commit is contained in:
+1
-1
@@ -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 \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
|
||||
#include <iconv.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user