Exemplo n.º 1
0
void
rxvt_term::set_utf8_property (Atom prop, const char *str, int len)
{
  wchar_t *ws = rxvt_mbstowcs (str, len);
  char *s = rxvt_wcstoutf8 (ws);

  XChangeProperty (dpy, parent[0],
                   prop, xa[XA_UTF8_STRING], 8, PropModeReplace,
                   (const unsigned char *)s, strlen (s));

  free (s);
  free (ws);
}
Exemplo n.º 2
0
// a wrapper for register_keymap,
// so that outside codes don't have to know so much details.
//
// the string 'trans' is copied to an internal managed buffer,
// so the caller can free memory of 'trans' at any time.
void
keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans)
{
    keysym_t *key = new keysym_t;
    wchar_t *wc = rxvt_mbstowcs (trans);
    char *translation = rxvt_wcstoutf8 (wc);
    free (wc);

    if (key && translation)
    {
        key->keysym = keysym;
        key->state  = state;
        key->range  = 1;
        key->str    = translation;
        key->type   = keysym_t::STRING;

        if (strncmp (translation, "list", 4) == 0 && translation [4])
        {
            char *middle = strchr  (translation + 5, translation [4]);
            char *suffix = strrchr (translation + 5, translation [4]);

            if (suffix && middle && suffix > middle + 1)
            {
                key->type  = keysym_t::LIST;
                key->range = suffix - middle - 1;

                memmove (translation, translation + 4, strlen (translation + 4) + 1);
            }
            else
                rxvt_warn ("cannot parse list-type keysym '%s', treating as normal keysym.\n", translation);
        }
        else if (strncmp (translation, "builtin:", 8) == 0)
            key->type = keysym_t::BUILTIN;

        register_keymap (key);
    }
    else
    {
        delete key;
        free ((void *)translation);
        rxvt_fatal ("out of memory, aborting.\n");
    }
}