JNIEXPORT jboolean JNICALL Java_com_showtimemediacenter_showtime_STCore_glwKeyDown(JNIEnv *env, jobject obj, jint id, jint keycode) { android_glw_root_t *agr = (android_glw_root_t *)id; glw_root_t *gr = &agr->gr; event_t *e = NULL; if(keycode < end_of_AKEYCODE) { const action_type_t *avec = btn_to_action[keycode]; if(avec) { int i = 0; while(avec[i] != 0) i++; e = event_create_action_multi(avec, i); } } TRACE(TRACE_DEBUG, "ANDROID", "Input key %d -> %p", keycode, e); if(e != NULL) glw_inject_event(gr, e); return e != NULL; }
static void handle_btn(glw_ps3_t *gp, int pad, int code, int pressed) { int16_t *store = &button_counter[pad][code]; if(code == 0) return; if(pressed) { if(*store == 0 || (*store > KEY_REPEAT_DELAY && (*store % KEY_REPEAT_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 = btn_to_action[code]; if(avec) { int i = 0; while(avec[i] != 0) i++; e = event_create_action_multi(avec, i); } } if(e != NULL) { glw_dispatch_event(&gp->gr.gr_uii, e); event_release(e); } } (*store)++; } else { *store = 0; } }
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; }
event_t * event_create_action(action_type_t action) { return event_create_action_multi(&action, 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_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) { glw_dispatch_event(&gp->gr.gr_uii, e); event_release(e); break; } } } if(i == sizeof(kb2action) / sizeof(*kb2action) && uc < 0x8000 && uc) { e = event_create_int(EVENT_UNICODE, uc); glw_dispatch_event(&gp->gr.gr_uii, e); event_release(e); } } } } gp->kb_present[i] = kbinfo.status[i]; } }
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; } }