Generate KeySym -> Unicode mapping, so we don't need to make fake events in getDescription now
This commit is contained in:
parent
7a862c917a
commit
ba513484fc
1414
src/SFML/Window/Unix/KeySymToUnicodeMapping.hpp
Normal file
1414
src/SFML/Window/Unix/KeySymToUnicodeMapping.hpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1607,7 +1607,7 @@ void WindowImplX11::initialize()
|
|||
createHiddenCursor();
|
||||
|
||||
// init X11 keycode <-> SFML scancode mapping
|
||||
X11InputManager::getInstance().initialize(m_display, m_inputContext);
|
||||
X11InputManager::getInstance().initialize(m_display);
|
||||
|
||||
// Flush the commands queue
|
||||
XFlush(m_display);
|
||||
|
|
|
@ -25,9 +25,10 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <SFML/Window/Unix/X11InputManager.hpp>
|
||||
#include <SFML/System/Utf.hpp>
|
||||
#include <SFML/Window/Unix/Display.hpp>
|
||||
#include <SFML/Window/Unix/KeySymToUnicodeMapping.hpp>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
@ -39,6 +40,7 @@ namespace priv
|
|||
{
|
||||
|
||||
namespace {
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
sf::Keyboard::Key keysymToSF(KeySym symbol)
|
||||
{
|
||||
|
@ -450,8 +452,7 @@ sf::Keyboard::Scancode translateKeyCode(Display* display, KeyCode keycode)
|
|||
|
||||
////////////////////////////////////////////////////////////
|
||||
X11InputManager::X11InputManager() :
|
||||
m_display(NULL),
|
||||
m_inputContext(NULL)
|
||||
m_display(NULL)
|
||||
{
|
||||
for (int i = 0; i < sf::Keyboard::ScanCodeCount; ++i)
|
||||
{
|
||||
|
@ -474,10 +475,9 @@ X11InputManager& X11InputManager::getInstance()
|
|||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void X11InputManager::initialize(Display* display, XIC inputContext)
|
||||
void X11InputManager::initialize(Display* display)
|
||||
{
|
||||
m_display = display;
|
||||
m_inputContext = inputContext;
|
||||
|
||||
// Find the X11 key code -> SFML key code mapping
|
||||
// This code was inspired by GLFW implementation
|
||||
|
@ -634,43 +634,11 @@ sf::String X11InputManager::getDescription(Keyboard::Scancode code) const
|
|||
|
||||
if (checkInput)
|
||||
{
|
||||
// fake keypress event
|
||||
XKeyPressedEvent ev;
|
||||
ev.keycode = SFtoKeyCode(code);
|
||||
ev.display = m_display;
|
||||
ev.type = KeyPress;
|
||||
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
if (m_inputContext)
|
||||
{
|
||||
Status status;
|
||||
Uint8 keyBuffer[16];
|
||||
|
||||
int length = Xutf8LookupString(
|
||||
m_inputContext,
|
||||
&ev,
|
||||
reinterpret_cast<char*>(keyBuffer),
|
||||
sizeof(keyBuffer),
|
||||
NULL,
|
||||
&status
|
||||
);
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
Uint32 unicode = 0;
|
||||
Utf8::decode(keyBuffer, keyBuffer + length, unicode, 0);
|
||||
if (unicode != 0)
|
||||
return sf::String(unicode);
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
static XComposeStatus status;
|
||||
char keyBuffer[16];
|
||||
if (XLookupString(&ev, keyBuffer, sizeof(keyBuffer), NULL, &status))
|
||||
return sf::String(static_cast<Uint32>(keyBuffer[0]));
|
||||
}
|
||||
KeyCode keycode = SFtoKeyCode(code);
|
||||
KeySym keysym = XkbKeycodeToKeysym(m_display, keycode, 0, 0);
|
||||
sf::Uint32 unicode = keysymToUnicode(keysym);
|
||||
if (unicode != 0)
|
||||
return sf::String(unicode);
|
||||
}
|
||||
|
||||
// Fallback to our best guess for the keys that are known to be independent of the layout.
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
/// X11 keycodes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void initialize(Display* display, XIC inputContext);
|
||||
void initialize(Display* display);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \copydoc sf::Keyboard::isKeyPressed(Key)
|
||||
|
@ -164,10 +164,10 @@ private:
|
|||
KeyCode m_scancodeToKeycode[sf::Keyboard::ScanCodeCount]; ///< Mapping of SFML scancode to X11 KeyCode
|
||||
sf::Keyboard::Scancode m_keycodeToScancode[256]; ///< Mapping of X11 KeyCode to SFML scancode
|
||||
Display* m_display; ///< Pointer to the display
|
||||
XIC m_inputContext; ///< Input context used to get unicode input in our window (used for getDescription)
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
#endif // SFML_X11INPUTMANAGER_HPP
|
||||
|
|
Loading…
Reference in a new issue