static int dd_read(de_dev_t *dd) { struct input_event ie; event_t *e = NULL; int i; if(read(dd->dd_fd, &ie, 16) != 16) return 1; if(ie.type == EV_REL) { if(ie.code == REL_WHEEL) { int action = ie.value < 0 ? ACTION_DOWN : ACTION_UP; int cnt = abs(ie.value); if(cnt > 4) cnt = 4; while(cnt--) { e = event_create_action(action); event_to_ui(e); } } return 0; } if(ie.type != EV_KEY) return 0; doqual(dd, &ie, KEY_LEFTSHIFT, QUAL_LEFT_SHIFT); doqual(dd, &ie, KEY_RIGHTSHIFT, QUAL_RIGHT_SHIFT); if(ie.value == 0) return 0; // release int shift = !!(dd->dd_qual & (QUAL_LEFT_SHIFT | QUAL_RIGHT_SHIFT)); for(i = 0; key_to_action[i][0]; i++) { if(key_to_action[i][0] == ie.code) { event_to_ui(event_create_action(key_to_action[i][1+shift])); return 0; } } switch(ie.code) { case KEY_SPACE: e = event_create_int(EVENT_UNICODE, 32); break; case KEY_ENTER: e = event_create_action_multi((const action_type_t[]){ ACTION_ACTIVATE, ACTION_ENTER}, 2); break; case KEY_BACKSPACE: e = event_create_action_multi((const action_type_t[]){ ACTION_BS, ACTION_NAV_BACK}, 2);
static int hc_utf8(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { const char *str = http_arg_get_req(hc, "str"); int c; event_t *e; if(str == NULL) return HTTP_STATUS_BAD_REQUEST; while((c = utf8_get(&str)) != 0) { switch(c) { case 8: e = event_create_action_multi( (const action_type_t[]){ ACTION_BS, ACTION_NAV_BACK}, 2); break; default: e = event_create_int(EVENT_UNICODE, c); break; } event_to_ui(e); }
static int hc_action(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { if(remain == NULL) return 404; event_to_ui(event_create_action_str(remain)); return HTTP_STATUS_OK; }
static int gl_keypress(glw_x11_t *gx11, XEvent *event) { char str[16], c; KeySym keysym; int len; char buf[32]; event_t *e = NULL; wchar_t wc; mbstate_t ps = {0}; int n, i; char *s; action_type_t av[10]; int state = event->xkey.state & (ShiftMask | ControlMask | Mod1Mask); XComposeStatus composestatus; if(gx11->ic != NULL) { len = Xutf8LookupString(gx11->ic,(XKeyPressedEvent*)event, str, sizeof(str), &keysym, &gx11->status); } else { len = XLookupString(&event->xkey, str, sizeof(str), &keysym, &composestatus); } if(len > 1) { buf[0] = 0; s = str; int something = 0; while((n = mbrtowc(&wc, s, len, &ps)) > 0) { strncpy(buf, s, n); buf[n] = '\0'; e = event_create_int(EVENT_UNICODE, wc); event_to_ui(e); s += n; len -= n; something = 1; } return something; } else if((state & ~ShiftMask) == 0 && len == 1) { c = str[0]; switch(c) { /* Static key mappings, these cannot be changed */ case 8: e = event_create_action_multi( (const action_type_t[]){ ACTION_BS, ACTION_NAV_BACK}, 2); break; case 13: e = event_create_action_multi( (const action_type_t[]){ ACTION_ACTIVATE, ACTION_ENTER}, 2);
static int hc_screenshot(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { hts_mutex_lock(&screenshot_mutex); if(screenshot_connection != NULL) { hts_mutex_unlock(&screenshot_mutex); return 502; } screenshot_connection = hc; hts_mutex_unlock(&screenshot_mutex); event_to_ui(event_create(EVENT_MAKE_SCREENSHOT, sizeof(event_t))); return 0; }
void showtime_shutdown(int retcode) { TRACE(TRACE_DEBUG, "core", "Shutdown requested, returncode = %d", retcode); if(gconf.exit_code != 1) { // Force exit gconf.exit_code = retcode; arch_exit(); } gconf.exit_code = retcode; // run early shutdown hooks (those must be fast) shutdown_hook_run(1); htsmsg_store_flush(); event_to_ui(event_create_type(EVENT_STOP_UI)); }
static int keypress(void *aux, const cec_keypress kp) { event_t *e = NULL; if(gconf.enable_cec_debug) TRACE(TRACE_DEBUG, "CEC", "Got keypress code=0x%x duration=0x%x", kp.keycode, kp.duration); if(longpress_select) { if(kp.keycode == CEC_USER_CONTROL_CODE_SELECT) { if(kp.duration == 0) return 0; if(kp.duration < 500) e = event_create_action(ACTION_ACTIVATE); else e = event_create_action(ACTION_ITEMMENU); } } if(e == NULL) { const action_type_t *avec = NULL; if(kp.duration == 0 || kp.keycode == cec_config.comboKey) { avec = btn_to_action[kp.keycode]; } if(avec != NULL) { int i = 0; while(avec[i] != 0) i++; e = event_create_action_multi(avec, i); } } if(e != NULL) { e->e_flags |= EVENT_KEYPRESS; event_to_ui(e); } return 1; }
static void * lirc_thread(void *aux) { char buf[200]; uint64_t ircode; uint32_t repeat; char keyname[100]; int i, r, fd, len, n; htsbuf_queue_t q; struct pollfd fds; event_t *e; fd = lirc_fd; htsbuf_queue_init(&q, 0); fds.fd = fd; fds.events = POLLIN; while(1) { r = poll(&fds, 1, -1); if(r > 0) { if((r = read(fd, buf, sizeof(buf))) < 1) { TRACE(TRACE_ERROR, "lircd", "Read error: %s", strerror(errno)); break; } htsbuf_append(&q, buf, r); } while((len = htsbuf_find(&q, 0xa)) != -1) { if(len >= sizeof(buf) - 1) { TRACE(TRACE_ERROR, "lircd", "Command buffer size exceeded"); goto out; } htsbuf_read(&q, buf, len); buf[len] = 0; while(len > 0 && buf[len - 1] < 32) buf[--len] = 0; htsbuf_drop(&q, 1); /* Drop the \n */ n = sscanf(buf, "%"PRIx64" %x %s", &ircode, &repeat, keyname); if(n != 3) { TRACE(TRACE_INFO, "lircd", "Invalid LIRC input: \"%s\"", buf); continue; } if(keyname[0] && keyname[1] == 0) { /* ASCII input */ e = event_create_int(EVENT_UNICODE, keyname[0]); } else { e = NULL; for(i = 0; i < sizeof(lircmap) / sizeof(lircmap[0]); i++) { if(!strcasecmp(keyname, lircmap[i].name)) { action_type_t av[3] = { lircmap[i].action1, lircmap[i].action2, }; if(av[1] != ACTION_NONE) e = event_create_action_multi(av, 2); else e = event_create_action_multi(av, 1); break; } } } if(e == NULL) { snprintf(buf, sizeof(buf), "IR+%s", keyname); e = event_create_str(EVENT_KEYDESC, buf); } event_to_ui(e); } } out: close(fd); htsbuf_queue_flush(&q); return NULL; }
static void handle_btn(glw_ps3_t *gp, int pad, int code, int pressed, int sel, int pre) { if(gp->button_assign == 0) { // Swap X and O if(code == BTN_CROSS) code = BTN_CIRCLE; else if(code == BTN_CIRCLE) code = BTN_CROSS; } int16_t *store = &button_counter[pad][code]; int rate = KEY_REPEAT_RATE; int xrep = 0; if(code == 0) return; if(pressed) { if(pre > 200 && *store > KEY_REPEAT_DELAY) xrep = 1; if(pre > 150) rate = 1; else if(pre > 100) rate = 2; if(*store == 0 || (*store > KEY_REPEAT_DELAY && (*store % rate == 0))) { int uc = 0; event_t *e = NULL; if(code >= BTN_KEY_1 && code <= BTN_KEY_9) { uc = code - BTN_KEY_1 + '1'; } else if(code == BTN_KEY_0) { uc = '0'; } if(uc != 0) e = event_create_int(EVENT_UNICODE, uc); if(e == NULL) { const action_type_t *avec = sel ? btn_to_action_sel[code] : btn_to_action[code]; if(avec) { int i = 0; while(avec[i] != 0) i++; e = event_create_action_multi(avec, i); } } if(e != NULL) { e->e_flags |= EVENT_KEYPRESS; event_addref(e); event_to_ui(e); if(xrep) { event_addref(e); event_to_ui(e); } event_release(e); } } (*store)++; } else { *store = 0; } }
static void handle_kb(glw_ps3_t *gp) { KbInfo kbinfo; KbData kbdata; int i, j; int uc; event_t *e; action_type_t av[3]; int mods; if(ioKbGetInfo(&kbinfo)) return; for(i=0; i<MAX_KEYBOARDS; i++) { if(kbinfo.status[i] == 0) { if(gp->kb_present[i]) TRACE(TRACE_INFO, "PS3", "Keyboard %d disconnected", i); } else { if(!gp->kb_present[i]) { ioKbGetConfiguration(i, &gp->kb_config[i]); TRACE(TRACE_INFO, "PS3", "Keyboard %d connected, mapping=%d, rmode=%d, codetype=%d", i, gp->kb_config[i].mapping, gp->kb_config[i].rmode, gp->kb_config[i].codetype); ioKbSetCodeType(i, KB_CODETYPE_RAW); } if(!ioKbRead(i, &kbdata)) { for(j = 0; j < kbdata.nb_keycode; j++) { if(0) TRACE(TRACE_DEBUG, "PS3", "Keystrike %x %x %x %x", gp->kb_config[i].mapping, kbdata.mkey.mkeys, kbdata.led.leds, kbdata.keycode[j]); uc = ioKbCnvRawCode(gp->kb_config[i].mapping, kbdata.mkey, kbdata.led, kbdata.keycode[j]); mods = 0; if(kbdata.mkey.l_shift || kbdata.mkey.r_shift) mods |= KB_SHIFTMASK; if(kbdata.mkey.l_alt || kbdata.mkey.r_alt) mods |= KB_ALTMASK; if(kbdata.mkey.l_ctrl || kbdata.mkey.r_ctrl) mods |= KB_CTRLMASK; for(i = 0; i < sizeof(kb2action) / sizeof(*kb2action); i++) { if(kb2action[i].code == uc && (kb2action[i].modifier == -1 || kb2action[i].modifier == mods)) { av[0] = kb2action[i].action1; av[1] = kb2action[i].action2; av[2] = kb2action[i].action3; if(kb2action[i].action3 != ACTION_NONE) e = event_create_action_multi(av, 3); else if(kb2action[i].action2 != ACTION_NONE) e = event_create_action_multi(av, 2); else if(kb2action[i].action1 != ACTION_NONE) e = event_create_action_multi(av, 1); else if(kb2action[i].sym != NULL) { char buf[128]; snprintf(buf, sizeof(buf), "%s%s%s%s", mods & KB_SHIFTMASK ? "Shift+" : "", mods & KB_ALTMASK ? "Alt+" : "", mods & KB_CTRLMASK ? "Ctrl+" : "", kb2action[i].sym); e = event_create_str(EVENT_KEYDESC, buf); } else { e = NULL; } if(e != NULL) { e->e_flags |= EVENT_KEYPRESS; event_to_ui(e); break; } } } if(i == sizeof(kb2action) / sizeof(*kb2action) && uc < 0x8000 && uc) { e = event_create_int(EVENT_UNICODE, uc); event_to_ui(e); } } } } gp->kb_present[i] = kbinfo.status[i]; } }