Пример #1
0
static void
_wkb_ibus_key_from_str(const char *key_str, struct wkb_ibus_key *key)
{
   key->modifiers = 0;

   if (!strcmp(key_str, "shift"))
     {
        key->sym = XKB_KEY_Shift_L;
        key->code = KEY_LEFTSHIFT;
        return;
     }

   if (!strcmp(key_str, "backspace"))
     {
        key->sym = XKB_KEY_BackSpace;
        key->code = KEY_BACKSPACE;
        return;
     }

   if (!strcmp(key_str, "enter"))
     {
        key->sym = XKB_KEY_Return;
        key->code = KEY_ENTER;
        return;
     }

   if (!strcmp(key_str, "space"))
     {
        key->sym = XKB_KEY_space;
        key->code = KEY_SPACE;
        return;
     }

   key->sym = *key_str;

#define CASE_KEY_SYM(_sym, _alt, _code) \
   case XKB_KEY_ ## _alt: \
      key->modifiers = 1; \
   case XKB_KEY_ ## _sym: \
      key->code = KEY_ ## _code; \
      return

#define CASE_NUMBER(_num, _alt) \
   CASE_KEY_SYM(_num, _alt, _num)

#define CASE_LETTER(_low, _up) \
   CASE_KEY_SYM(_low, _up, _up)

   switch(key->sym)
     {
      CASE_KEY_SYM(grave, asciitilde, GRAVE);
      CASE_NUMBER(1, exclam);
      CASE_NUMBER(2, at);
      CASE_NUMBER(3, numbersign);
      CASE_NUMBER(4, dollar);
      CASE_NUMBER(5, percent);
      CASE_NUMBER(6, asciicircum);
      CASE_NUMBER(7, ampersand);
      CASE_NUMBER(8, asterisk);
      CASE_NUMBER(9, parenleft);
      CASE_NUMBER(0, parenright);
      CASE_KEY_SYM(minus, underscore, MINUS);
      CASE_KEY_SYM(equal, plus, EQUAL);

      CASE_LETTER(q, Q);
      CASE_LETTER(w, W);
      CASE_LETTER(e, E);
      CASE_LETTER(r, R);
      CASE_LETTER(t, T);
      CASE_LETTER(y, Y);
      CASE_LETTER(u, U);
      CASE_LETTER(i, I);
      CASE_LETTER(o, O);
      CASE_LETTER(p, P);
      CASE_KEY_SYM(bracketleft, braceleft, LEFTBRACE);
      CASE_KEY_SYM(bracketright, braceright, RIGHTBRACE);
      CASE_KEY_SYM(backslash, bar, BACKSLASH);

      CASE_LETTER(a, A);
      CASE_LETTER(s, S);
      CASE_LETTER(d, D);
      CASE_LETTER(f, F);
      CASE_LETTER(g, G);
      CASE_LETTER(h, H);
      CASE_LETTER(j, J);
      CASE_LETTER(k, K);
      CASE_LETTER(l, L);
      CASE_KEY_SYM(semicolon, colon, SEMICOLON);
      CASE_KEY_SYM(apostrophe, quotedbl, APOSTROPHE);

      CASE_LETTER(z, Z);
      CASE_LETTER(x, X);
      CASE_LETTER(c, C);
      CASE_LETTER(v, V);
      CASE_LETTER(b, B);
      CASE_LETTER(n, N);
      CASE_LETTER(m, M);
      CASE_KEY_SYM(comma, less, COMMA);
      CASE_KEY_SYM(period, greater, DOT);
      CASE_KEY_SYM(slash, question, SLASH);

#if 0
      CASE_KEY_SYM(yen, ); /* '¥' */
      CASE_KEY_SYM(EuroSign, ; /* '€' */
      CASE_KEY_SYM(WonSign, ); /* '₩' */
      CASE_KEY_SYM(cent, ); /* '¢' */
      CASE_KEY_SYM(degree, ); /* '°' */
      CASE_KEY_SYM(periodcentered, ); /* '˙' */
      CASE_KEY_SYM(registered, ); /* '®' */
      CASE_KEY_SYM(copyright, ); /* '©' */
      CASE_KEY_SYM(questiondown, ); /* '¿' */
#endif

      default:
         ERR("Unexpected key '%s'", key_str);
         key->sym = XKB_KEY_NoSymbol;
         key->code = KEY_RESERVED;
     }

#undef CASE_SYM
#undef CASE_NUMBER
#undef CASE_LETTER
}
Пример #2
0
static void
_wkb_ibus_key_from_str(const char *key_str, struct wkb_ibus_key *key)
{
   key->modifiers = 0;

   if (!strcmp(key_str, "shift"))
     {
        key->sym = XKB_KEY_Shift_L;
        key->code = KEY_LEFTSHIFT;
        return;
     }

   if (!strcmp(key_str, "backspace"))
     {
        key->sym = XKB_KEY_BackSpace;
        key->code = KEY_BACKSPACE;
        return;
     }

   if (!strcmp(key_str, "enter"))
     {
        key->sym = XKB_KEY_Return;
        key->code = KEY_ENTER;
        return;
     }

   if (!strcmp(key_str, "space"))
     {
        key->sym = XKB_KEY_space;
        key->code = KEY_SPACE;
        return;
     }

   /* For special symbols we use the definitions in "data/symbols/wkb"
    * layout file. We currently use the numeric keypad keys with a shift
    * modifier.
    *
    * In runtime, it is necessary to specify the modified layout in weston.ini,
    * as follows:
    *
    * [keyboard]
    * keymap_layout=wkb
    */
#define IF_UTF8(_str, _sym, _code) \
   if (!strcmp(key_str, _str)) \
     { \
        key->sym = _sym; \
        key->code = _code; \
        key->modifiers = 1; \
        return; \
     } \

   IF_UTF8("£", XKB_KEY_KP_0,  KEY_KP0)
   IF_UTF8("¥", XKB_KEY_KP_1,  KEY_KP1)
   IF_UTF8("€", XKB_KEY_KP_2,  KEY_KP2)
   IF_UTF8("₩", XKB_KEY_KP_3,  KEY_KP3)
   IF_UTF8("¢", XKB_KEY_KP_4,  KEY_KP4)
   IF_UTF8("°", XKB_KEY_KP_5,  KEY_KP5)
   IF_UTF8("˙", XKB_KEY_KP_6,  KEY_KP6)
   IF_UTF8("®", XKB_KEY_KP_7,  KEY_KP7)
   IF_UTF8("©", XKB_KEY_KP_8,  KEY_KP8)
   IF_UTF8("¿", XKB_KEY_KP_9,  KEY_KP9)

#undef IF_UTF8

#define CASE_KEY_SYM(_sym, _alt, _code) \
   case XKB_KEY_ ## _alt: \
      key->modifiers = 1; \
   case XKB_KEY_ ## _sym: \
      key->code = KEY_ ## _code; \
      return

#define CASE_NUMBER(_num, _alt) \
   CASE_KEY_SYM(_num, _alt, _num)

#define CASE_LETTER(_low, _up) \
   CASE_KEY_SYM(_low, _up, _up)

   key->sym = *key_str;

   switch(key->sym)
     {
      CASE_KEY_SYM(grave, asciitilde, GRAVE);
      CASE_NUMBER(1, exclam);
      CASE_NUMBER(2, at);
      CASE_NUMBER(3, numbersign);
      CASE_NUMBER(4, dollar);
      CASE_NUMBER(5, percent);
      CASE_NUMBER(6, asciicircum);
      CASE_NUMBER(7, ampersand);
      CASE_NUMBER(8, asterisk);
      CASE_NUMBER(9, parenleft);
      CASE_NUMBER(0, parenright);
      CASE_KEY_SYM(minus, underscore, MINUS);
      CASE_KEY_SYM(equal, plus, EQUAL);

      CASE_LETTER(q, Q);
      CASE_LETTER(w, W);
      CASE_LETTER(e, E);
      CASE_LETTER(r, R);
      CASE_LETTER(t, T);
      CASE_LETTER(y, Y);
      CASE_LETTER(u, U);
      CASE_LETTER(i, I);
      CASE_LETTER(o, O);
      CASE_LETTER(p, P);
      CASE_KEY_SYM(bracketleft, braceleft, LEFTBRACE);
      CASE_KEY_SYM(bracketright, braceright, RIGHTBRACE);
      CASE_KEY_SYM(backslash, bar, BACKSLASH);

      CASE_LETTER(a, A);
      CASE_LETTER(s, S);
      CASE_LETTER(d, D);
      CASE_LETTER(f, F);
      CASE_LETTER(g, G);
      CASE_LETTER(h, H);
      CASE_LETTER(j, J);
      CASE_LETTER(k, K);
      CASE_LETTER(l, L);
      CASE_KEY_SYM(semicolon, colon, SEMICOLON);
      CASE_KEY_SYM(apostrophe, quotedbl, APOSTROPHE);

      CASE_LETTER(z, Z);
      CASE_LETTER(x, X);
      CASE_LETTER(c, C);
      CASE_LETTER(v, V);
      CASE_LETTER(b, B);
      CASE_LETTER(n, N);
      CASE_LETTER(m, M);
      CASE_KEY_SYM(comma, less, COMMA);
      CASE_KEY_SYM(period, greater, DOT);
      CASE_KEY_SYM(slash, question, SLASH);

      default:
         ERR("Unexpected key '%s', sym = %d", key_str, key->sym);
         key->sym = XKB_KEY_NoSymbol;
         key->code = KEY_RESERVED;
     }

#undef CASE_NUMBER
#undef CASE_LETTER
#undef CASE_KEY_SYM
}