Xlib input text-case handling

This commit is contained in:
Jack Andersen 2015-12-22 20:10:46 -10:00
parent fd01dbb17a
commit 1ed592e0a1
2 changed files with 15 additions and 29 deletions

View File

@ -100,31 +100,7 @@ enum class EModifierKey
Shift = 1<<3,
Command = 1<<4
};
inline EModifierKey operator|(EModifierKey a, EModifierKey b)
{
using T = std::underlying_type_t<EModifierKey>;
return EModifierKey(static_cast<T>(a) | static_cast<T>(b));
}
inline EModifierKey operator&(EModifierKey a, EModifierKey b)
{
using T = std::underlying_type_t<EModifierKey>;
return EModifierKey(static_cast<T>(a) & static_cast<T>(b));
}
inline EModifierKey& operator|=(EModifierKey& a, const EModifierKey& b)
{
using T = std::underlying_type_t<EModifierKey>;
a = EModifierKey(static_cast<T>(a) | static_cast<T>(b));
return a;
}
inline EModifierKey operator~(const EModifierKey& key)
{
using T = std::underlying_type_t<EModifierKey>;
return EModifierKey(~static_cast<T>(key));
}
ENABLE_BITWISE_ENUM(EModifierKey)
class IWindowCallback
{

View File

@ -19,6 +19,7 @@
#define XK_LATIN1
#include <X11/keysymdef.h>
#include <xkbcommon/xkbcommon.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XInput2.h>
#include <X11/Xatom.h>
#include <LogVisor/LogVisor.hpp>
@ -70,7 +71,8 @@ void GLXEnableVSync(Display* disp, GLXWindow drawable);
extern int XINPUT_OPCODE;
static uint32_t translateKeysym(KeySym sym, ESpecialKey& specialSym, EModifierKey& modifierSym)
static uint32_t translateKeysym(KeySym sym, ESpecialKey& specialSym, EModifierKey& modifierSym,
Display* d, unsigned state)
{
specialSym = ESpecialKey::None;
modifierSym = EModifierKey::None;
@ -109,7 +111,15 @@ static uint32_t translateKeysym(KeySym sym, ESpecialKey& specialSym, EModifierKe
else if (sym == XK_Alt_L || sym == XK_Alt_R)
modifierSym = EModifierKey::Alt;
else
return xkb_keysym_to_utf32(sym);
{
unsigned n;
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
uint32_t utf = xkb_keysym_to_utf32(sym);
if ((n & 0x01) != 0 ^ (state & ShiftMask) != 0)
return toupper(utf);
else
return utf;
}
return 0;
}
@ -995,7 +1005,7 @@ public:
ESpecialKey specialKey;
EModifierKey modifierKey;
uint32_t charCode = translateKeysym(XLookupKeysym(&event->xkey, 0),
specialKey, modifierKey);
specialKey, modifierKey, m_xDisp, event->xkey.state);
EModifierKey modifierMask = translateModifiers(event->xkey.state);
if (charCode)
m_callback->charKeyDown(charCode, modifierMask, false);
@ -1013,7 +1023,7 @@ public:
ESpecialKey specialKey;
EModifierKey modifierKey;
uint32_t charCode = translateKeysym(XLookupKeysym(&event->xkey, 0),
specialKey, modifierKey);
specialKey, modifierKey, m_xDisp, event->xkey.state);
EModifierKey modifierMask = translateModifiers(event->xkey.state);
if (charCode)
m_callback->charKeyUp(charCode, modifierMask);