x11: Wrap platform functions in XWindowsKeyState class

This commit is contained in:
Monika Kairaityte 2018-11-10 19:59:57 +02:00 committed by Adrian Lucrèce Céleste
parent 624a718f2d
commit 2c32270d49
6 changed files with 217 additions and 59 deletions

View File

@ -203,4 +203,31 @@ public:
virtual Atom* XListProperties(Display* display, Window w, virtual Atom* XListProperties(Display* display, Window w,
int* num_prop_return) = 0; int* num_prop_return) = 0;
virtual char* XGetAtomName(Display* display, Atom atom) = 0; virtual char* XGetAtomName(Display* display, Atom atom) = 0;
virtual void XkbFreeKeyboard(XkbDescPtr xkb, unsigned int which,
Bool freeDesc) = 0;
virtual XkbDescPtr XkbGetMap(Display* display, unsigned int which,
unsigned int deviceSpec) = 0;
virtual Status XkbGetState(Display* display, unsigned int deviceSet,
XkbStatePtr rtrnState) = 0;
virtual int XQueryKeymap(Display* display, char keys_return[32]) = 0;
virtual Status XkbGetUpdatedMap(Display* display, unsigned int which,
XkbDescPtr desc) = 0;
virtual Bool XkbLockGroup(Display* display, unsigned int deviceSpec,
unsigned int group) = 0;
virtual int XDisplayKeycodes(Display* display, int* min_keycodes_return,
int* max_keycodes_return) = 0;
virtual KeySym* XGetKeyboardMapping(Display* display,
unsigned int first_keycode,
int keycode_count,
int* keysyms_per_keycode_return) = 0;
virtual int do_XkbKeyNumGroups(XkbDescPtr m_xkb, KeyCode desc) = 0;
virtual XkbKeyTypePtr do_XkbKeyKeyType(XkbDescPtr m_xkb, KeyCode keycode,
int eGroup) = 0;
virtual KeySym do_XkbKeySymEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup) = 0;
virtual Bool do_XkbKeyHasActions(XkbDescPtr m_xkb, KeyCode keycode) = 0;
virtual XkbAction* do_XkbKeyActionEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup) = 0;
virtual unsigned char do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
KeyCode keycode) = 0;
}; };

View File

@ -225,12 +225,14 @@ Bool XWindowsImpl::XkbSelectEvents(Display* display, unsigned int deviceID,
return ::XkbSelectEvents(display, deviceID, affect, values); return ::XkbSelectEvents(display, deviceID, affect, values);
} }
Bool XWindowsImpl::XkbSelectEventDetails(Display* display, unsigned int deviceID, Bool XWindowsImpl::XkbSelectEventDetails(Display* display,
unsigned int deviceID,
unsigned int eventType, unsigned int eventType,
unsigned long affect, unsigned long affect,
unsigned long details) unsigned long details)
{ {
return ::XkbSelectEventDetails(display, deviceID, eventType, affect, details); return ::XkbSelectEventDetails(display, deviceID, eventType, affect,
details);
} }
Bool XWindowsImpl::XRRQueryExtension(Display* display, int* event_base_return, Bool XWindowsImpl::XRRQueryExtension(Display* display, int* event_base_return,
@ -271,8 +273,7 @@ Bool XWindowsImpl::XineramaIsActive(Display* display)
#endif #endif
} }
void* XWindowsImpl::XineramaQueryScreens(Display* display, void* XWindowsImpl::XineramaQueryScreens(Display* display, int* number)
int* number)
{ {
#if HAVE_X11_EXTENSIONS_XINERAMA_H #if HAVE_X11_EXTENSIONS_XINERAMA_H
return ::XineramaQueryScreens(display, number); return ::XineramaQueryScreens(display, number);
@ -281,7 +282,8 @@ void* XWindowsImpl::XineramaQueryScreens(Display* display,
#endif #endif
} }
Window XWindowsImpl::XCreateWindow(Display* display, Window parent, int x, int y, Window XWindowsImpl::XCreateWindow(Display* display, Window parent,
int x, int y,
unsigned int width, unsigned int height, unsigned int width, unsigned int height,
unsigned int border_width, int depth, unsigned int border_width, int depth,
unsigned int klass, Visual* visual, unsigned int klass, Visual* visual,
@ -326,7 +328,8 @@ int XWindowsImpl::XSelectInput(Display* display, Window w, long event_mask)
} }
Bool XWindowsImpl::XCheckIfEvent(Display* display, XEvent* event, Bool XWindowsImpl::XCheckIfEvent(Display* display, XEvent* event,
Bool (*predicate)(Display *, XEvent *, XPointer), Bool (*predicate)(Display *, XEvent *,
XPointer),
XPointer arg) XPointer arg)
{ {
return ::XCheckIfEvent(display, event, predicate, arg); return ::XCheckIfEvent(display, event, predicate, arg);
@ -482,13 +485,13 @@ int XWindowsImpl::XRefreshKeyboardMapping(XMappingEvent* event_map)
} }
int XWindowsImpl::XISelectEvents(Display* display, Window w, XIEventMask* masks, int XWindowsImpl::XISelectEvents(Display* display, Window w, XIEventMask* masks,
int num_masks) int num_masks)
{ {
return ::XISelectEvents(display, w, masks, num_masks); return ::XISelectEvents(display, w, masks, num_masks);
} }
Atom XWindowsImpl::XInternAtom(Display* display, _Xconst char* atom_name, Atom XWindowsImpl::XInternAtom(Display* display, _Xconst char* atom_name,
Bool only_if_exists) Bool only_if_exists)
{ {
return ::XInternAtom(display, atom_name, only_if_exists); return ::XInternAtom(display, atom_name, only_if_exists);
} }
@ -550,3 +553,89 @@ char* XWindowsImpl::XGetAtomName(Display* display, Atom atom)
{ {
return ::XGetAtomName(display, atom); return ::XGetAtomName(display, atom);
} }
void XWindowsImpl::XkbFreeKeyboard(XkbDescPtr xkb, unsigned int which,
Bool freeDesc)
{
::XkbFreeKeyboard(xkb, which, freeDesc);
}
XkbDescPtr XWindowsImpl::XkbGetMap(Display* display, unsigned int which,
unsigned int deviceSpec)
{
return ::XkbGetMap(display, which, deviceSpec);
}
Status XWindowsImpl::XkbGetState(Display* display, unsigned int deviceSet,
XkbStatePtr rtrnState)
{
return ::XkbGetState(display, deviceSet, rtrnState);
}
int XWindowsImpl::XQueryKeymap(Display* display, char keys_return[32])
{
return ::XQueryKeymap(display, keys_return);
}
Status XWindowsImpl::XkbGetUpdatedMap(Display* display, unsigned int which,
XkbDescPtr desc)
{
return ::XkbGetUpdatedMap(display, which, desc);
}
Bool XWindowsImpl::XkbLockGroup(Display* display, unsigned int deviceSpec,
unsigned int group)
{
return ::XkbLockGroup(display, deviceSpec, group);
}
int XWindowsImpl::XDisplayKeycodes(Display* display, int* min_keycodes_return,
int* max_keycodes_return)
{
return ::XDisplayKeycodes(display, min_keycodes_return,
max_keycodes_return);
}
KeySym* XWindowsImpl::XGetKeyboardMapping(Display* display,
unsigned int first_keycode,
int keycode_count,
int* keysyms_per_keycode_return)
{
return ::XGetKeyboardMapping(display, first_keycode, keycode_count,
keysyms_per_keycode_return);
}
int XWindowsImpl::do_XkbKeyNumGroups(XkbDescPtr m_xkb, KeyCode desc)
{
return XkbKeyNumGroups(m_xkb, desc);
}
XkbKeyTypePtr XWindowsImpl::do_XkbKeyKeyType(XkbDescPtr m_xkb, KeyCode keycode,
int eGroup)
{
return do_XkbKeyKeyType(m_xkb, keycode, eGroup);
}
KeySym XWindowsImpl::do_XkbKeySymEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup)
{
return do_XkbKeySymEntry(m_xkb, keycode, level, eGroup);
}
Bool XWindowsImpl::do_XkbKeyHasActions(XkbDescPtr m_xkb, KeyCode keycode)
{
return do_XkbKeyHasActions(m_xkb, keycode);
}
XkbAction* XWindowsImpl::do_XkbKeyActionEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup)
{
return do_XkbKeyActionEntry(m_xkb, keycode, level, eGroup);
}
unsigned char XWindowsImpl::do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
KeyCode keycode)
{
return do_XkbKeyGroupInfo(m_xkb, keycode);
}

View File

@ -77,14 +77,13 @@ public:
virtual Bool XineramaQueryExtension(Display* display, int* event_base, virtual Bool XineramaQueryExtension(Display* display, int* event_base,
int* error_base); int* error_base);
virtual Bool XineramaIsActive(Display* display); virtual Bool XineramaIsActive(Display* display);
virtual void* XineramaQueryScreens(Display* display, virtual void* XineramaQueryScreens(Display* display, int* number);
int* number);
virtual Window XCreateWindow(Display* display, Window parent, int x, int y, virtual Window XCreateWindow(Display* display, Window parent, int x, int y,
unsigned int width, unsigned int height, unsigned int width, unsigned int height,
unsigned int border_width, int depth, unsigned int border_width, int depth,
unsigned int klass, Visual* visual, unsigned int klass, Visual* visual,
unsigned long valuemask, unsigned long valuemask,
XSetWindowAttributes* attributes); XSetWindowAttributes* attributes);
virtual XIM XOpenIM(Display* display, _XrmHashBucketRec* rdb, virtual XIM XOpenIM(Display* display, _XrmHashBucketRec* rdb,
char* res_name, char* res_class); char* res_name, char* res_class);
virtual char* XGetIMValues(XIM im, const char* type, void* ptr); virtual char* XGetIMValues(XIM im, const char* type, void* ptr);
@ -151,10 +150,11 @@ public:
virtual Atom XInternAtom(Display* display, _Xconst char* atom_name, virtual Atom XInternAtom(Display* display, _Xconst char* atom_name,
Bool only_if_exists); Bool only_if_exists);
virtual int XGetScreenSaver(Display* display, int* timeout_return, virtual int XGetScreenSaver(Display* display, int* timeout_return,
int* interval_return, int* prefer_blanking_return, int* interval_return,
int* allow_exposures_return); int* prefer_blanking_return,
int* allow_exposures_return);
virtual int XSetScreenSaver(Display* display, int timeout, int interval, virtual int XSetScreenSaver(Display* display, int timeout, int interval,
int prefer_blanking, int allow_exposures); int prefer_blanking, int allow_exposures);
virtual int XForceScreenSaver(Display* display, int mode); virtual int XForceScreenSaver(Display* display, int mode);
virtual int XFree(void* data); virtual int XFree(void* data);
virtual Status DPMSEnable(Display* display); virtual Status DPMSEnable(Display* display);
@ -165,4 +165,31 @@ public:
virtual Atom* XListProperties(Display* display, Window w, virtual Atom* XListProperties(Display* display, Window w,
int* num_prop_return); int* num_prop_return);
virtual char* XGetAtomName(Display* display, Atom atom); virtual char* XGetAtomName(Display* display, Atom atom);
virtual void XkbFreeKeyboard(XkbDescPtr xkb, unsigned int which,
Bool freeDesc);
virtual XkbDescPtr XkbGetMap(Display* display, unsigned int which,
unsigned int deviceSpec);
virtual Status XkbGetState(Display* display, unsigned int deviceSet,
XkbStatePtr rtrnState);
virtual int XQueryKeymap(Display* display, char keys_return[32]);
virtual Status XkbGetUpdatedMap(Display* display, unsigned int which,
XkbDescPtr desc);
virtual Bool XkbLockGroup(Display* display, unsigned int deviceSpec,
unsigned int group);
virtual int XDisplayKeycodes(Display* display, int* min_keycodes_return,
int* max_keycodes_return);
virtual KeySym* XGetKeyboardMapping(Display* display,
unsigned int first_keycode,
int keycode_count,
int* keysyms_per_keycode_return);
virtual int do_XkbKeyNumGroups(XkbDescPtr m_xkb, KeyCode desc);
virtual XkbKeyTypePtr do_XkbKeyKeyType(XkbDescPtr m_xkb, KeyCode keycode,
int eGroup);
virtual KeySym do_XkbKeySymEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup);
virtual Bool do_XkbKeyHasActions(XkbDescPtr m_xkb, KeyCode keycode);
virtual XkbAction* do_XkbKeyActionEntry(XkbDescPtr m_xkb, KeyCode keycode,
int level, int eGroup);
virtual unsigned char do_XkbKeyGroupInfo(XkbDescPtr m_xkb,
KeyCode keycode);
}; };

View File

@ -40,17 +40,19 @@
static const size_t ModifiersFromXDefaultSize = 32; static const size_t ModifiersFromXDefaultSize = 32;
XWindowsKeyState::XWindowsKeyState( XWindowsKeyState::XWindowsKeyState(IXWindowsImpl* impl,
Display* display, bool useXKB, Display* display, bool useXKB,
IEventQueue* events) : IEventQueue* events) :
KeyState(events), KeyState(events),
m_display(display), m_display(display),
m_modifierFromX(ModifiersFromXDefaultSize) m_modifierFromX(ModifiersFromXDefaultSize)
{ {
m_impl = impl;
init(display, useXKB); init(display, useXKB);
} }
XWindowsKeyState::XWindowsKeyState( XWindowsKeyState::XWindowsKeyState(IXWindowsImpl* impl,
Display* display, bool useXKB, Display* display, bool useXKB,
IEventQueue* events, barrier::KeyMap& keyMap) : IEventQueue* events, barrier::KeyMap& keyMap) :
KeyState(events, keyMap), KeyState(events, keyMap),
@ -64,7 +66,7 @@ XWindowsKeyState::~XWindowsKeyState()
{ {
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (m_xkb != NULL) { if (m_xkb != NULL) {
XkbFreeKeyboard(m_xkb, 0, True); m_impl->XkbFreeKeyboard(m_xkb, 0, True);
} }
#endif #endif
} }
@ -75,8 +77,9 @@ XWindowsKeyState::init(Display* display, bool useXKB)
XGetKeyboardControl(m_display, &m_keyboardState); XGetKeyboardControl(m_display, &m_keyboardState);
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (useXKB) { if (useXKB) {
m_xkb = XkbGetMap(m_display, XkbKeyActionsMask | XkbKeyBehaviorsMask | m_xkb = m_impl->XkbGetMap(m_display,
XkbAllClientInfoMask, XkbUseCoreKbd); XkbKeyActionsMask | XkbKeyBehaviorsMask |
XkbAllClientInfoMask, XkbUseCoreKbd);
} }
else { else {
m_xkb = NULL; m_xkb = NULL;
@ -177,8 +180,9 @@ XWindowsKeyState::pollActiveModifiers() const
Window root = DefaultRootWindow(m_display), window; Window root = DefaultRootWindow(m_display), window;
int xRoot, yRoot, xWindow, yWindow; int xRoot, yRoot, xWindow, yWindow;
unsigned int state = 0; unsigned int state = 0;
if (XQueryPointer(m_display, root, &root, &window, if (m_impl->XQueryPointer(m_display, root, &root, &window,
&xRoot, &yRoot, &xWindow, &yWindow, &state) == False) { &xRoot, &yRoot, &xWindow, &yWindow, &state
) == False) {
state = 0; state = 0;
} }
return mapModifiersFromX(state); return mapModifiersFromX(state);
@ -195,7 +199,7 @@ XWindowsKeyState::pollActiveGroup() const
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (m_xkb != NULL) { if (m_xkb != NULL) {
XkbStateRec state; XkbStateRec state;
if (XkbGetState(m_display, XkbUseCoreKbd, &state) == Success) { if (m_impl->XkbGetState(m_display, XkbUseCoreKbd, &state) == Success) {
return state.group; return state.group;
} }
} }
@ -207,7 +211,7 @@ void
XWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const XWindowsKeyState::pollPressedKeys(KeyButtonSet& pressedKeys) const
{ {
char keys[32]; char keys[32];
XQueryKeymap(m_display, keys); m_impl->XQueryKeymap(m_display, keys);
for (UInt32 i = 0; i < 32; ++i) { for (UInt32 i = 0; i < 32; ++i) {
for (UInt32 j = 0; j < 8; ++j) { for (UInt32 j = 0; j < 8; ++j) {
if ((keys[i] & (1u << j)) != 0) { if ((keys[i] & (1u << j)) != 0) {
@ -228,8 +232,9 @@ XWindowsKeyState::getKeyMap(barrier::KeyMap& keyMap)
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (m_xkb != NULL) { if (m_xkb != NULL) {
if (XkbGetUpdatedMap(m_display, XkbKeyActionsMask | unsigned mask = XkbKeyActionsMask | XkbKeyBehaviorsMask |
XkbKeyBehaviorsMask | XkbAllClientInfoMask, m_xkb) == Success) { XkbAllClientInfoMask;
if (m_impl->XkbGetUpdatedMap(m_display, mask, m_xkb) == Success) {
updateKeysymMapXKB(keyMap); updateKeysymMapXKB(keyMap);
return; return;
} }
@ -254,9 +259,9 @@ XWindowsKeyState::fakeKey(const Keystroke& keystroke)
break; break;
} }
} }
XTestFakeKeyEvent(m_display, keystroke.m_data.m_button.m_button, m_impl->XTestFakeKeyEvent(m_display, keystroke.m_data.m_button.m_button,
keystroke.m_data.m_button.m_press ? True : False, keystroke.m_data.m_button.m_press,
CurrentTime); CurrentTime);
break; break;
case Keystroke::kGroup: case Keystroke::kGroup:
@ -264,8 +269,9 @@ XWindowsKeyState::fakeKey(const Keystroke& keystroke)
LOG((CLOG_DEBUG1 " group %d", keystroke.m_data.m_group.m_group)); LOG((CLOG_DEBUG1 " group %d", keystroke.m_data.m_group.m_group));
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (m_xkb != NULL) { if (m_xkb != NULL) {
if (XkbLockGroup(m_display, XkbUseCoreKbd, if (m_impl->XkbLockGroup(m_display, XkbUseCoreKbd,
keystroke.m_data.m_group.m_group) == False) { keystroke.m_data.m_group.m_group
) == False) {
LOG((CLOG_DEBUG1 "XkbLockGroup request not sent")); LOG((CLOG_DEBUG1 "XkbLockGroup request not sent"));
} }
} }
@ -279,9 +285,10 @@ XWindowsKeyState::fakeKey(const Keystroke& keystroke)
LOG((CLOG_DEBUG1 " group %+d", keystroke.m_data.m_group.m_group)); LOG((CLOG_DEBUG1 " group %+d", keystroke.m_data.m_group.m_group));
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
if (m_xkb != NULL) { if (m_xkb != NULL) {
if (XkbLockGroup(m_display, XkbUseCoreKbd, if (m_impl->XkbLockGroup(m_display, XkbUseCoreKbd,
getEffectiveGroup(pollActiveGroup(), getEffectiveGroup(pollActiveGroup(),
keystroke.m_data.m_group.m_group)) == False) { keystroke.m_data.m_group.m_group)
) == False) {
LOG((CLOG_DEBUG1 "XkbLockGroup request not sent")); LOG((CLOG_DEBUG1 "XkbLockGroup request not sent"));
} }
} }
@ -320,14 +327,14 @@ XWindowsKeyState::updateKeysymMap(barrier::KeyMap& keyMap)
// get the number of keycodes // get the number of keycodes
int minKeycode, maxKeycode; int minKeycode, maxKeycode;
XDisplayKeycodes(m_display, &minKeycode, &maxKeycode); m_impl->XDisplayKeycodes(m_display, &minKeycode, &maxKeycode);
int numKeycodes = maxKeycode - minKeycode + 1; int numKeycodes = maxKeycode - minKeycode + 1;
// get the keyboard mapping for all keys // get the keyboard mapping for all keys
int keysymsPerKeycode; int keysymsPerKeycode;
KeySym* allKeysyms = XGetKeyboardMapping(m_display, KeySym* allKeysyms = m_impl->XGetKeyboardMapping(m_display,
minKeycode, numKeycodes, minKeycode, numKeycodes,
&keysymsPerKeycode); &keysymsPerKeycode);
// it's more convenient to always have maxKeysyms KeySyms per key // it's more convenient to always have maxKeysyms KeySyms per key
{ {
@ -343,7 +350,7 @@ XWindowsKeyState::updateKeysymMap(barrier::KeyMap& keyMap)
} }
} }
} }
XFree(allKeysyms); m_impl->XFree(allKeysyms);
allKeysyms = tmpKeysyms; allKeysyms = tmpKeysyms;
} }
@ -365,7 +372,7 @@ XWindowsKeyState::updateKeysymMap(barrier::KeyMap& keyMap)
// going to ignore all KeySyms except the first modifier KeySym, // going to ignore all KeySyms except the first modifier KeySym,
// which means button 1 above won't map to Meta, just Alt. // which means button 1 above won't map to Meta, just Alt.
std::map<KeyCode, unsigned int> modifierButtons; std::map<KeyCode, unsigned int> modifierButtons;
XModifierKeymap* modifiers = XGetModifierMapping(m_display); XModifierKeymap* modifiers = m_impl->XGetModifierMapping(m_display);
for (unsigned int i = 0; i < 8; ++i) { for (unsigned int i = 0; i < 8; ++i) {
const KeyCode* buttons = const KeyCode* buttons =
modifiers->modifiermap + i * modifiers->max_keypermod; modifiers->modifiermap + i * modifiers->max_keypermod;
@ -560,7 +567,7 @@ XWindowsKeyState::updateKeysymMapXKB(barrier::KeyMap& keyMap)
// find the number of groups // find the number of groups
int maxNumGroups = 0; int maxNumGroups = 0;
for (int i = m_xkb->min_key_code; i <= m_xkb->max_key_code; ++i) { for (int i = m_xkb->min_key_code; i <= m_xkb->max_key_code; ++i) {
int numGroups = XkbKeyNumGroups(m_xkb, static_cast<KeyCode>(i)); int numGroups = m_impl->do_XkbKeyNumGroups(m_xkb, static_cast<KeyCode>(i));
if (numGroups > maxNumGroups) { if (numGroups > maxNumGroups) {
maxNumGroups = numGroups; maxNumGroups = numGroups;
} }
@ -596,7 +603,7 @@ XWindowsKeyState::updateKeysymMapXKB(barrier::KeyMap& keyMap)
item.m_client = 0; item.m_client = 0;
// skip keys with no groups (they generate no symbols) // skip keys with no groups (they generate no symbols)
if (XkbKeyNumGroups(m_xkb, keycode) == 0) { if (m_impl->do_XkbKeyNumGroups(m_xkb, keycode) == 0) {
continue; continue;
} }
@ -612,7 +619,8 @@ XWindowsKeyState::updateKeysymMapXKB(barrier::KeyMap& keyMap)
int eGroup = getEffectiveGroup(keycode, group); int eGroup = getEffectiveGroup(keycode, group);
// get key info // get key info
XkbKeyTypePtr type = XkbKeyKeyType(m_xkb, keycode, eGroup); XkbKeyTypePtr type = m_impl->do_XkbKeyKeyType(m_xkb, keycode,
eGroup);
// set modifiers the item is sensitive to // set modifiers the item is sensitive to
item.m_sensitive = type->mods.mask; item.m_sensitive = type->mods.mask;
@ -641,16 +649,18 @@ XWindowsKeyState::updateKeysymMapXKB(barrier::KeyMap& keyMap)
} }
// get the keysym for this item // get the keysym for this item
KeySym keysym = XkbKeySymEntry(m_xkb, keycode, level, eGroup); KeySym keysym = m_impl->do_XkbKeySymEntry(m_xkb, keycode, level,
eGroup);
// check for group change actions, locking modifiers, and // check for group change actions, locking modifiers, and
// modifier masks. // modifier masks.
item.m_lock = false; item.m_lock = false;
bool isModifier = false; bool isModifier = false;
UInt32 modifierMask = m_xkb->map->modmap[keycode]; UInt32 modifierMask = m_xkb->map->modmap[keycode];
if (XkbKeyHasActions(m_xkb, keycode) == True) { if (m_impl->do_XkbKeyHasActions(m_xkb, keycode) == True) {
XkbAction* action = XkbAction* action =
XkbKeyActionEntry(m_xkb, keycode, level, eGroup); m_impl->do_XkbKeyActionEntry(m_xkb, keycode, level,
eGroup);
if (action->type == XkbSA_SetMods || if (action->type == XkbSA_SetMods ||
action->type == XkbSA_LockMods) { action->type == XkbSA_LockMods) {
isModifier = true; isModifier = true;
@ -799,19 +809,19 @@ XWindowsKeyState::hasModifiersXKB() const
// iterate over all keycodes // iterate over all keycodes
for (int i = m_xkb->min_key_code; i <= m_xkb->max_key_code; ++i) { for (int i = m_xkb->min_key_code; i <= m_xkb->max_key_code; ++i) {
KeyCode keycode = static_cast<KeyCode>(i); KeyCode keycode = static_cast<KeyCode>(i);
if (XkbKeyHasActions(m_xkb, keycode) == True) { if (m_impl->do_XkbKeyHasActions(m_xkb, keycode) == True) {
// iterate over all groups // iterate over all groups
int numGroups = XkbKeyNumGroups(m_xkb, keycode); int numGroups = m_impl->do_XkbKeyNumGroups(m_xkb, keycode);
for (int group = 0; group < numGroups; ++group) { for (int group = 0; group < numGroups; ++group) {
// iterate over all shift levels for the button (including none) // iterate over all shift levels for the button (including none)
XkbKeyTypePtr type = XkbKeyKeyType(m_xkb, keycode, group); XkbKeyTypePtr type = m_impl->do_XkbKeyKeyType(m_xkb, keycode, group);
for (int j = -1; j < type->map_count; ++j) { for (int j = -1; j < type->map_count; ++j) {
if (j != -1 && !type->map[j].active) { if (j != -1 && !type->map[j].active) {
continue; continue;
} }
int level = ((j == -1) ? 0 : type->map[j].level); int level = ((j == -1) ? 0 : type->map[j].level);
XkbAction* action = XkbAction* action =
XkbKeyActionEntry(m_xkb, keycode, level, group); m_impl->do_XkbKeyActionEntry(m_xkb, keycode, level, group);
if (action->type == XkbSA_SetMods || if (action->type == XkbSA_SetMods ||
action->type == XkbSA_LockMods) { action->type == XkbSA_LockMods) {
return true; return true;
@ -830,9 +840,9 @@ XWindowsKeyState::getEffectiveGroup(KeyCode keycode, int group) const
(void)keycode; (void)keycode;
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
// get effective group for key // get effective group for key
int numGroups = XkbKeyNumGroups(m_xkb, keycode); int numGroups = m_impl->do_XkbKeyNumGroups(m_xkb, keycode);
if (group >= numGroups) { if (group >= numGroups) {
unsigned char groupInfo = XkbKeyGroupInfo(m_xkb, keycode); unsigned char groupInfo = m_impl->do_XkbKeyGroupInfo(m_xkb, keycode);
switch (XkbOutOfRangeGroupAction(groupInfo)) { switch (XkbOutOfRangeGroupAction(groupInfo)) {
case XkbClampIntoRange: case XkbClampIntoRange:
group = numGroups - 1; group = numGroups - 1;

View File

@ -21,6 +21,7 @@
#include "barrier/KeyState.h" #include "barrier/KeyState.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include "common/stdvector.h" #include "common/stdvector.h"
#include "XWindowsImpl.h"
#if X_DISPLAY_MISSING #if X_DISPLAY_MISSING
# error X11 is required to build barrier # error X11 is required to build barrier
@ -50,9 +51,10 @@ public:
kGroupPollAndSet = -2 kGroupPollAndSet = -2
}; };
XWindowsKeyState(Display*, bool useXKB, IEventQueue* events); XWindowsKeyState(IXWindowsImpl* impl, Display*, bool useXKB,
XWindowsKeyState(Display*, bool useXKB, IEventQueue* events);
IEventQueue* events, barrier::KeyMap& keyMap); XWindowsKeyState(IXWindowsImpl* impl, Display*, bool useXKB,
IEventQueue* events, barrier::KeyMap& keyMap);
~XWindowsKeyState(); ~XWindowsKeyState();
//! @name modifiers //! @name modifiers
@ -145,6 +147,8 @@ private:
typedef std::map<KeyCode, unsigned int> NonXKBModifierMap; typedef std::map<KeyCode, unsigned int> NonXKBModifierMap;
typedef std::map<UInt32, XKBModifierInfo> XKBModifierMap; typedef std::map<UInt32, XKBModifierInfo> XKBModifierMap;
IXWindowsImpl* m_impl;
Display* m_display; Display* m_display;
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
XkbDescPtr m_xkb; XkbDescPtr m_xkb;

View File

@ -116,7 +116,8 @@ XWindowsScreen::XWindowsScreen(
m_window = openWindow(); m_window = openWindow();
m_screensaver = new XWindowsScreenSaver(m_impl, m_display, m_screensaver = new XWindowsScreenSaver(m_impl, m_display,
m_window, getEventTarget(), events); m_window, getEventTarget(), events);
m_keyState = new XWindowsKeyState(m_display, m_xkb, events, m_keyMap); m_keyState = new XWindowsKeyState(m_impl, m_display, m_xkb, events,
m_keyMap);
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : "")); LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_xinerama ? "(xinerama)" : ""));
LOG((CLOG_DEBUG "window is 0x%08x", m_window)); LOG((CLOG_DEBUG "window is 0x%08x", m_window));
} }