unsigned vncGetKeyboardState(void) { DeviceIntPtr master; master = GetMaster(vncKeyboardDev, KEYBOARD_OR_FLOAT); return XkbStateFieldFromRec(&master->key->xkbInfo->state); }
void ProcessPointerEvent( register xEvent * xE, register DeviceIntPtr mouse, int count) { DeviceIntPtr dev = (DeviceIntPtr)LookupKeyboardDevice(); XkbSrvInfoPtr xkbi = dev->key->xkbInfo; unsigned changed = 0; xkbi->shiftKeyCount = 0; xkbi->lastPtrEventTime= xE->u.keyButtonPointer.time; if (xE->u.u.type==ButtonPress) { changed |= XkbPointerButtonMask; } else if (xE->u.u.type==ButtonRelease) { xkbi->lockedPtrButtons&= ~(1<<(xE->u.u.detail&0x7)); changed |= XkbPointerButtonMask; } CoreProcessPointerEvent(xE,mouse,count); xkbi->state.ptr_buttons = mouse->button->state; /* clear any latched modifiers */ if ( xkbi->state.latched_mods && (xE->u.u.type==ButtonRelease) ) { unsigned changed_leds; XkbStateRec oldState; XkbSrvLedInfoPtr sli; sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,0); oldState= xkbi->state; XkbLatchModifiers(dev,0xFF,0x00); XkbComputeDerivedState(xkbi); changed |= XkbStateChangedFlags(&oldState,&xkbi->state); if (changed&sli->usedComponents) { changed_leds= XkbIndicatorsToUpdate(dev,changed,False); if (changed_leds) { XkbEventCauseRec cause; XkbSetCauseKey(&cause,(xE->u.u.detail&0x7),xE->u.u.type); XkbUpdateIndicators(dev,changed_leds,True,NULL,&cause); } } dev->key->state= XkbStateFieldFromRec(&xkbi->state); } if (((xkbi->flags&_XkbStateNotifyInProgress)==0)&&(changed!=0)) { xkbStateNotify sn; sn.keycode= xE->u.u.detail; sn.eventType= xE->u.u.type; sn.requestMajor = sn.requestMinor = 0; sn.changed= changed; XkbSendStateNotify(dev,&sn); } } /* ProcessPointerEvent */
/* * Port of Mark McLoughlin's Xnest fix for focus in + modifier bug. * See https://bugs.freedesktop.org/show_bug.cgi?id=3030 */ void ephyrUpdateModifierState(unsigned int state) { DeviceIntPtr pDev = inputInfo.keyboard; KeyClassPtr keyc = pDev->key; int i; CARD8 mask; int xkb_state; if (!pDev) return; xkb_state = XkbStateFieldFromRec(&pDev->key->xkbInfo->state); state = state & 0xff; if (xkb_state == state) return; for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { int key; /* Modifier is down, but shouldn't be */ if ((xkb_state & mask) && !(state & mask)) { int count = keyc->modifierKeyCount[i]; for (key = 0; key < MAP_LENGTH; key++) if (keyc->xkbInfo->desc->map->modmap[key] & mask) { if (mask == XCB_MOD_MASK_LOCK) { KdEnqueueKeyboardEvent(ephyrKbd, key, FALSE); KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); } else if (key_is_down(pDev, key, KEY_PROCESSED)) KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); if (--count == 0) break; } } /* Modifier shoud be down, but isn't */ if (!(xkb_state & mask) && (state & mask)) for (key = 0; key < MAP_LENGTH; key++) if (keyc->xkbInfo->desc->map->modmap[key] & mask) { KdEnqueueKeyboardEvent(ephyrKbd, key, FALSE); if (mask == XCB_MOD_MASK_LOCK) KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); break; } } }
void xnestUpdateModifierState(unsigned int state) { DeviceIntPtr pDev = xnestKeyboardDevice; KeyClassPtr keyc = pDev->key; int i; CARD8 mask; int xkb_state; if (!pDev) return; xkb_state = XkbStateFieldFromRec(&pDev->key->xkbInfo->state); state = state & 0xff; if (xkb_state == state) return; for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { int key; /* Modifier is down, but shouldn't be */ if ((xkb_state & mask) && !(state & mask)) { int count = keyc->modifierKeyCount[i]; for (key = 0; key < MAP_LENGTH; key++) if (keyc->xkbInfo->desc->map->modmap[key] & mask) { if (mask == LockMask) { xnestQueueKeyEvent(KeyPress, key); xnestQueueKeyEvent(KeyRelease, key); } else if (key_is_down(pDev, key, KEY_PROCESSED)) xnestQueueKeyEvent(KeyRelease, key); if (--count == 0) break; } } /* Modifier shoud be down, but isn't */ if (!(xkb_state & mask) && (state & mask)) for (key = 0; key < MAP_LENGTH; key++) if (keyc->xkbInfo->desc->map->modmap[key] & mask) { xnestQueueKeyEvent(KeyPress, key); if (mask == LockMask) xnestQueueKeyEvent(KeyRelease, key); break; } } }
static int getValuatorEvents(DeviceEvent *ev, deviceValuator * xv) { int i; int state = 0; int first_valuator, num_valuators; num_valuators = countValuators(ev, &first_valuator); if (num_valuators > 0) { DeviceIntPtr dev = NULL; dixLookupDevice(&dev, ev->deviceid, serverClient, DixUseAccess); /* State needs to be assembled BEFORE the device is updated. */ state = (dev && dev->key) ? XkbStateFieldFromRec(&dev->key->xkbInfo-> state) : 0; state |= (dev && dev->button) ? (dev->button->state) : 0; } for (i = 0; i < num_valuators; i += 6, xv++) { INT32 *valuators = &xv->valuator0; // Treat all 6 vals as an array int j; xv->type = DeviceValuator; xv->first_valuator = first_valuator + i; xv->num_valuators = ((num_valuators - i) > 6) ? 6 : (num_valuators - i); xv->deviceid = ev->deviceid; xv->device_state = state; /* Unset valuators in masked valuator events have the proper data values * in the case of an absolute axis in between two set valuators. */ for (j = 0; j < xv->num_valuators; j++) valuators[j] = ev->valuators.data[xv->first_valuator + j]; if (i + 6 < num_valuators) xv->deviceid |= MORE_EVENTS; } return (num_valuators + 5) / 6; }
void winRestoreModeKeyStates (void) { DWORD dwKeyState; BOOL processEvents = TRUE; unsigned short internalKeyStates; /* X server is being initialized */ if (!inputInfo.keyboard) return; /* Only process events if the rootwindow is mapped. The keyboard events * will cause segfaults otherwise */ if (screenInfo.screens[0]->root && screenInfo.screens[0]->root->mapped == FALSE) processEvents = FALSE; /* Force to process all pending events in the mi event queue */ if (processEvents) mieqProcessInputEvents (); /* Read the mode key states of our X server */ /* (stored in the virtual core keyboard) */ internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); /* * NOTE: The C XOR operator, ^, will not work here because it is * a bitwise operator, not a logical operator. C does not * have a logical XOR operator, so we use a macro instead. */ /* Has the key state changed? */ dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001; if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState)) { winSendKeyEvent (KEY_NumLock, TRUE); winSendKeyEvent (KEY_NumLock, FALSE); } /* Has the key state changed? */ dwKeyState = GetKeyState (VK_CAPITAL) & 0x0001; if (WIN_XOR (internalKeyStates & LockMask, dwKeyState)) { winSendKeyEvent (KEY_CapsLock, TRUE); winSendKeyEvent (KEY_CapsLock, FALSE); } /* Has the key state changed? */ dwKeyState = GetKeyState (VK_SCROLL) & 0x0001; if (WIN_XOR (internalKeyStates & ScrollLockMask, dwKeyState)) { winSendKeyEvent (KEY_ScrollLock, TRUE); winSendKeyEvent (KEY_ScrollLock, FALSE); } /* Has the key state changed? */ dwKeyState = GetKeyState (VK_KANA) & 0x0001; if (WIN_XOR (internalKeyStates & KanaMask, dwKeyState)) { winSendKeyEvent (KEY_HKTG, TRUE); winSendKeyEvent (KEY_HKTG, FALSE); } }
void winRestoreModeKeyStates(void) { DWORD dwKeyState; BOOL processEvents = TRUE; unsigned short internalKeyStates; /* X server is being initialized */ if (!inputInfo.keyboard) return; /* Only process events if the rootwindow is mapped. The keyboard events * will cause segfaults otherwise */ if (screenInfo.screens[0]->root && screenInfo.screens[0]->root->mapped == FALSE) processEvents = FALSE; /* Force to process all pending events in the mi event queue */ if (processEvents) mieqProcessInputEvents(); /* Read the mode key states of our X server */ /* (stored in the virtual core keyboard) */ internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); { /* Make sure the message queue is empty, otherwise the GetKeyState will not always return the correct state of the numlock key, capslock key, ... This is mainly because this function is called from the WM_SETFOCUS handler. From MSDN GetKeyState: The key status returned from this function changes as a thread reads key messages from its message queue.*/ MSG msg; /* Process all messages on our queue */ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { DispatchMessage (&msg); } } /* Check if modifier keys are pressed, and if so, fake a press */ { BOOL ctrl = (GetAsyncKeyState(VK_CONTROL) < 0); BOOL shift = (GetAsyncKeyState(VK_SHIFT) < 0); BOOL alt = (GetAsyncKeyState(VK_LMENU) < 0); BOOL altgr = (GetAsyncKeyState(VK_RMENU) < 0); if (ctrl && altgr) ctrl = FALSE; if (LOGICAL_XOR(internalKeyStates & ControlMask, ctrl)) winSendKeyEvent(KEY_LCtrl, ctrl); if (LOGICAL_XOR(internalKeyStates & ShiftMask, shift)) winSendKeyEvent(KEY_ShiftL, shift); if (LOGICAL_XOR(internalKeyStates & Mod1Mask, alt)) winSendKeyEvent(KEY_Alt, alt); if (LOGICAL_XOR(internalKeyStates & Mod5Mask, altgr)) winSendKeyEvent(KEY_AltLang, altgr); } /* Check if latching modifier key states have changed, and if so, fake a press and a release to toggle the modifier to the correct state */ dwKeyState = GetKeyState(VK_NUMLOCK) & 0x0001; if (LOGICAL_XOR(internalKeyStates & NumLockMask, dwKeyState)) { winSendKeyEvent(KEY_NumLock, TRUE); winSendKeyEvent(KEY_NumLock, FALSE); } dwKeyState = GetKeyState(VK_CAPITAL) & 0x0001; if (LOGICAL_XOR(internalKeyStates & LockMask, dwKeyState)) { winSendKeyEvent(KEY_CapsLock, TRUE); winSendKeyEvent(KEY_CapsLock, FALSE); } dwKeyState = GetKeyState(VK_SCROLL) & 0x0001; if (LOGICAL_XOR(internalKeyStates & ScrollLockMask, dwKeyState)) { winSendKeyEvent(KEY_ScrollLock, TRUE); winSendKeyEvent(KEY_ScrollLock, FALSE); } dwKeyState = GetKeyState(VK_KANA) & 0x0001; if (LOGICAL_XOR(internalKeyStates & KanaMask, dwKeyState)) { winSendKeyEvent(KEY_HKTG, TRUE); winSendKeyEvent(KEY_HKTG, FALSE); } }
void winRestoreModeKeyStates(void) { DWORD dwKeyState; BOOL processEvents = TRUE; unsigned short internalKeyStates; /* X server is being initialized */ if (!inputInfo.keyboard) return; /* Only process events if the rootwindow is mapped. The keyboard events * will cause segfaults otherwise */ if (screenInfo.screens[0]->root && screenInfo.screens[0]->root->mapped == FALSE) processEvents = FALSE; /* Force to process all pending events in the mi event queue */ if (processEvents) mieqProcessInputEvents(); /* Read the mode key states of our X server */ /* (stored in the virtual core keyboard) */ internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); /* Check if modifier keys are pressed, and if so, fake a press */ { BOOL lctrl = (GetAsyncKeyState(VK_LCONTROL) < 0); BOOL rctrl = (GetAsyncKeyState(VK_RCONTROL) < 0); BOOL lshift = (GetAsyncKeyState(VK_LSHIFT) < 0); BOOL rshift = (GetAsyncKeyState(VK_RSHIFT) < 0); BOOL alt = (GetAsyncKeyState(VK_LMENU) < 0); BOOL altgr = (GetAsyncKeyState(VK_RMENU) < 0); /* If AltGr and CtrlL appear to be pressed, assume the CtrL is a fake one */ if (lctrl && altgr) lctrl = FALSE; if (lctrl) winSendKeyEvent(KEY_LCtrl, TRUE); if (rctrl) winSendKeyEvent(KEY_RCtrl, TRUE); if (lshift) winSendKeyEvent(KEY_ShiftL, TRUE); if (rshift) winSendKeyEvent(KEY_ShiftL, TRUE); if (alt) winSendKeyEvent(KEY_Alt, TRUE); if (altgr) winSendKeyEvent(KEY_AltLang, TRUE); } /* Check if latching modifier key states have changed, and if so, fake a press and a release to toggle the modifier to the correct state */ dwKeyState = GetKeyState(VK_NUMLOCK) & 0x0001; if (LOGICAL_XOR(internalKeyStates & NumLockMask, dwKeyState)) { winSendKeyEvent(KEY_NumLock, TRUE); winSendKeyEvent(KEY_NumLock, FALSE); } dwKeyState = GetKeyState(VK_CAPITAL) & 0x0001; if (LOGICAL_XOR(internalKeyStates & LockMask, dwKeyState)) { winSendKeyEvent(KEY_CapsLock, TRUE); winSendKeyEvent(KEY_CapsLock, FALSE); } dwKeyState = GetKeyState(VK_SCROLL) & 0x0001; if (LOGICAL_XOR(internalKeyStates & ScrollLockMask, dwKeyState)) { winSendKeyEvent(KEY_ScrollLock, TRUE); winSendKeyEvent(KEY_ScrollLock, FALSE); } dwKeyState = GetKeyState(VK_KANA) & 0x0001; if (LOGICAL_XOR(internalKeyStates & KanaMask, dwKeyState)) { winSendKeyEvent(KEY_HKTG, TRUE); winSendKeyEvent(KEY_HKTG, FALSE); } /* For strict correctness, we should also press any non-modifier keys which are already down when we gain focus, but nobody has complained yet :-) */ }