- if(cb->event->type == KeyPress) {
- XKeyEvent *xkey = &cb->event->xkey;
-
- static XComposeStatus compose = {NULL, 0};
- char chars[8];
- KeySym keysym;
- int nchars;
-
- char keystr[64];
- keystr[0] = 0;
-
- nchars = XLookupString(xkey, chars, 8, &keysym, &compose);
- if(nchars == 1) {
- if(chars[0] >= 'a' && chars[0] <= 'z') {
- keystr[0] = chars[0];
- keystr[1] = 0;
- } else if(chars[0] == ' ') {
- memcpy(keystr, "space", 6);
- }
- }
-
- if(keystr[0] != 0) {
- char cmdbuf[STR_BUFSIZE];
- if(snprintf(cmdbuf, STR_BUFSIZE, "{ \"command\": [\"keypress\", \"%s\"] }\n", keystr) >= STR_BUFSIZE) {
- // error: buffer to small
- return;
- }
- write(p->ipc, cmdbuf, strlen(cmdbuf));
- }
- }