Example #1
1
static PyObject *
virtkey_get_keysyms_from_keycode_internal(virtkey *cvirt, long keycode,
                                         const long* mod_masks, int num_masks)
{
    static const long mods[] = {0};
    int m;
    unsigned int mods_rtn;
    KeySym keysym = 0;

    if (mod_masks == NULL)
    {
        mod_masks = mods;
        num_masks = (sizeof(mods)/sizeof(*mods));
    }
    PyObject* tuple = PyTuple_New(num_masks);

    /* get effective group index */
    XkbStateRec state;
    int group = 0;
    if (Success == XkbGetState(cvirt->display, XkbUseCoreKbd, &state) &&
        XkbIsLegalGroup(state.locked_group))  /* be defensive */
        group = state.locked_group;

    for(m = 0; m < num_masks; m++)
    {
        if (!XkbTranslateKeyCode (cvirt->kbd, (KeyCode) keycode,
                                  XkbBuildCoreState (mod_masks[m], group),
                                  &mods_rtn, &keysym)){
            keysym = 0;
        }
        PyTuple_SetItem(tuple, m, PyLong_FromLong(keysym));
    }
    return tuple;
}
Example #2
0
Bool
XkbLookupKeySym(	register Display *	dpy,
			KeyCode 		key,
			register unsigned int 	mods,
			unsigned int *		mods_rtrn,
			KeySym *		keysym_rtrn)
{
    if (_XkbUnavailable(dpy))
	return _XTranslateKey(dpy, key, mods, mods_rtrn, keysym_rtrn);
    _XkbCheckPendingRefresh(dpy,dpy->xkb_info);
    return XkbTranslateKeyCode(dpy->xkb_info->desc,key,mods,mods_rtrn,
								keysym_rtrn);
}
G_GNUC_END_IGNORE_DEPRECATIONS

gint
_clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
                                         guint                hardware_keycode,
                                         ClutterModifierType *modifier_state_p,
                                         ClutterModifierType *mods_p)
{
  ClutterBackendX11 *backend_x11;
  ClutterModifierType unconsumed_modifiers = 0;
  ClutterModifierType modifier_state = *modifier_state_p;
  gint retval;

  g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), 0);

  backend_x11 = CLUTTER_BACKEND_X11 (keymap->backend);

#ifdef HAVE_XKB
  if (backend_x11->use_xkb)
    {
      XkbDescRec *xkb = get_xkb (keymap);
      KeySym tmp_keysym;

      if (XkbTranslateKeyCode (xkb, hardware_keycode, modifier_state,
                               &unconsumed_modifiers,
                               &tmp_keysym))
        {
          retval = tmp_keysym;
        }
      else
        retval = 0;
    }
  else
#endif /* HAVE_XKB */
    retval = translate_keysym (keymap, hardware_keycode);

  if (mods_p)
    *mods_p = unconsumed_modifiers;

  *modifier_state_p = modifier_state & ~(keymap->num_lock_mask |
                                         keymap->scroll_lock_mask |
                                         LockMask);

  return retval;
}
void KeyboardLayoutWidget::drawKeyLabel(QPainter* painter, uint keycode, int angle, int xkb_origin_x, int xkb_origin_y, int xkb_width, int xkb_height, bool is_pressed)
{
    int x, y, width, height;
    int padding;
    int g, l, glp;

    if (!xkb)
        return;

    padding = 23 * ratio;   /* 2.3mm */

    x = xkbToPixmapCoord (xkb_origin_x);
    y = xkbToPixmapCoord (xkb_origin_y);
    width = xkbToPixmapCoord (xkb_origin_x + xkb_width) - x;
    height = xkbToPixmapCoord (xkb_origin_y + xkb_height) - y;

    for (glp = KEYBOARD_DRAWING_POS_TOPLEFT;
         glp < KEYBOARD_DRAWING_POS_TOTAL; glp++) {
        if (groupLevels[glp] == NULL)
            continue;
        g = groupLevels[glp]->group;
        l = groupLevels[glp]->level;

        if (g < 0 || g >= XkbKeyNumGroups (xkb, keycode))
            continue;
        if (l < 0
            || l >= XkbKeyGroupWidth (xkb, keycode, g))
            continue;

        /* Skip "exotic" levels like the "Ctrl" level in PC_SYSREQ */
        if (l > 0) {
            uint mods = XkbKeyKeyType (xkb, keycode,
                            g)->mods.mask;
            if ((mods & (ShiftMask | l3mod)) == 0)
                continue;
        }

        if (trackModifiers) {
            uint mods_rtrn;
            KeySym keysym;

            if (XkbTranslateKeyCode (xkb, keycode,
                         XkbBuildCoreState(mods, g),
                         &mods_rtrn, &keysym)) {
                drawKeyLabelHelper (painter, keysym, angle, glp,
                               x, y, width, height,
                               padding,
                               is_pressed);
                /* reverse y order */
            }
        } else {
            KeySym keysym;

            keysym =
                XkbKeySymEntry (xkb, keycode, l, g);

            drawKeyLabelHelper (painter, keysym,
                           angle, glp, x, y, width,
                           height, padding,
                           is_pressed);
            /* reverse y order */
        }
    }
}
Example #5
0
File: gwin.c Project: deadpixi/sam
static void
Keyaction(Widget w, XEvent *e, String *p, Cardinal *np)
{
    static unsigned char compose[5];
    static int composing = -2;
    int kind = Kraw;

    int c, len, minmod;
    KeySym k, mk;
    Charfunc f;
    Modifiers md;
    char buf[100] = {0};

    c = 0;
    len = 0;

    /* Translate the keycode into a key symbol. */
    if(e->xany.type != KeyPress)
        return;
    XkbTranslateKeyCode(xkb, (KeyCode)e->xkey.keycode, e->xkey.state, &md, &k);
    XkbTranslateKeySym(e->xany.display, &k, e->xkey.state, buf, sizeof(buf) - 1, &len);

    /* Check to see if it's a specially-handled key first. */
    for (Keymapping *m = keymappings; m; m = m->next){
        KeySym u = NoSymbol;
        KeySym l = NoSymbol;
        XConvertCase(k, &l, &u);

        /* Note that magic bit manipulation here - we want to check that the
         * modifiers that are specified for the binding are all pressed, but
         * we allow other modifiers to be as well. This is because when NumLock
         * is on, it's always added to the modifier mask.
         */
        if (l == m->s || m->s == XK_VoidSymbol){
            if (m->m == 0 || (m->m & ~e->xkey.state) == 0){
                switch (m->c){
                    case Cnone:
                        return;

                    case Cdefault:
                        continue;

                    default:
                        f = ((GwinWidget)w)->gwin.gotchar;
                        if (f)
                            (*f)(m->c, m->k, Tcurrent, 0, 0, m->a);
                        return;
                }
            }
        }
    }

    /*
     * The following song and dance is so we can have our chosen
     * modifier key behave like a compose key, i.e, press and release
     * and then type the compose sequence, like Plan 9.  We have
     * to find out which key is the compose key first though.
     */
    if (IsModifierKey(k) && ((GwinWidget)w)->gwin.compose
            && composing == -2 && modmap) {
        minmod = (((GwinWidget)w)->gwin.compose+2)*keypermod;
        for (c = minmod; c < minmod+keypermod; c++) {
            XtTranslateKeycode(e->xany.display,
                    modmap->modifiermap[c],
                        e->xkey.state, &md, &mk);
            if (k == mk) {
                composing = -1;
                break;
            }
        }
        return;
    }

    /* Handle Multi_key separately, since it isn't a modifier */
    if(k == XK_Multi_key) {
        composing = -1;
        return;
    }

    if(k == NoSymbol || k > 0xff00)
        return;

    /* Check to see if we are in a composition sequence */
    if (!((GwinWidget)w)->gwin.compose && (e->xkey.state & Mod1Mask)
            && composing == -2)
        composing = -1;
    if (composing > -2) {
        compose[++composing] = k;
        if ((*compose == 'X') && (composing > 0)) {
            if ((k < '0') || (k > 'f') ||
                    ((k > '9') && (k < 'a'))) {
                STUFFCOMPOSE();
                c = (uint16_t)k;
                composing = -2;
            } else if (composing == 4) {
                c = unicode(compose);
                if (c == -1) {
                    STUFFCOMPOSE();
                    c = (uint16_t)compose[4];
                }
                composing = -2;
            }
        } else if (composing == 1) {
            c = (int)latin1(compose);
            if (c == -1) {
                STUFFCOMPOSE();
                c = (uint16_t)compose[1];
            }
            composing = -2;
        }
    } else {
        if (composing >= 0) {
            composing++;
            STUFFCOMPOSE();
        }
        c = keysymtoshort(k);
        composing = -2;
    }

    if (composing >= -1)
        return;

    f = ((GwinWidget)w)->gwin.gotchar;
    if(f)
        (*f)(c, kind, Tcurrent, 0, 0, NULL);
}
Example #6
0
KeyCode vncKeysymToKeycode(KeySym keysym, unsigned state, unsigned *new_state)
{
	XkbDescPtr xkb;
	unsigned int key; // KeyCode has insufficient range for the loop
	KeyCode fallback;
	KeySym ks;
	unsigned level_three_mask;

	if (new_state != NULL)
		*new_state = state;

	fallback = 0;
	xkb = GetMaster(vncKeyboardDev, KEYBOARD_OR_FLOAT)->key->xkbInfo->desc;
	for (key = xkb->min_key_code; key <= xkb->max_key_code; key++) {
		unsigned int state_out;
		KeySym dummy;
		size_t fakeIdx;

		XkbTranslateKeyCode(xkb, key, state, &state_out, &ks);
		if (ks == NoSymbol)
			continue;

		/*
		 * Despite every known piece of documentation on
		 * XkbTranslateKeyCode() stating that mods_rtrn returns
		 * the unconsumed modifiers, in reality it always
		 * returns the _potentially consumed_ modifiers.
		 */
		state_out = state & ~state_out;
		if (state_out & LockMask)
			XkbConvertCase(ks, &dummy, &ks);

		if (ks != keysym)
			continue;

		/*
		 * Some keys are never sent by a real keyboard and are
		 * used in the default layouts as a fallback for
		 * modifiers. Make sure we use them last as some
		 * applications can be confused by these normally
		 * unused keys.
		 */
		for (fakeIdx = 0;
		     fakeIdx < sizeof(fakeKeys)/sizeof(fakeKeys[0]);
		     fakeIdx++) {
			if (key == fakeKeys[fakeIdx]) {
				if (fallback == 0)
					fallback = key;
				break;
			}
		}
		if (fakeIdx < sizeof(fakeKeys)/sizeof(fakeKeys[0]))
			continue;

		return key;
	}

	/* Use the fallback key, if one was found */
	if (fallback != 0)
		return fallback;

	if (new_state == NULL)
		return 0;

	*new_state = (state & ~ShiftMask) |
	             ((state & ShiftMask) ? 0 : ShiftMask);
	key = vncKeysymToKeycode(keysym, *new_state, NULL);
	if (key != 0)
		return key;

	level_three_mask = vncGetLevelThreeMask();
	if (level_three_mask == 0)
		return 0;

	*new_state = (state & ~level_three_mask) | 
	             ((state & level_three_mask) ? 0 : level_three_mask);
	key = vncKeysymToKeycode(keysym, *new_state, NULL);
	if (key != 0)
		return key;

	*new_state = (state & ~(ShiftMask | level_three_mask)) | 
	             ((state & ShiftMask) ? 0 : ShiftMask) |
	             ((state & level_three_mask) ? 0 : level_three_mask);
	key = vncKeysymToKeycode(keysym, *new_state, NULL);
	if (key != 0)
		return key;

	return 0;
}