void user_event_keycodes(int *kcodes, int count) { int nn; for (nn = 0; nn < count; nn++) user_event_keycode(kcodes[nn]); }
void user_event_key(unsigned code, unsigned down) { if(code == 0) { return; } if (VERBOSE_CHECK(keys)) printf(">> KEY [0x%03x,%s]\n", (code & 0x1ff), down ? "down" : " up " ); user_event_keycode((code & 0x1ff) | (down ? 0x200 : 0)); }
static void handle_key_command( void* opaque, SkinKeyCommand command, int down ) { static const struct { SkinKeyCommand cmd; AndroidKeyCode kcode; } keycodes[] = { { SKIN_KEY_COMMAND_BUTTON_CALL, kKeyCodeCall }, { SKIN_KEY_COMMAND_BUTTON_HOME, kKeyCodeHome }, { SKIN_KEY_COMMAND_BUTTON_BACK, kKeyCodeBack }, { SKIN_KEY_COMMAND_BUTTON_HANGUP, kKeyCodeEndCall }, { SKIN_KEY_COMMAND_BUTTON_POWER, kKeyCodePower }, { SKIN_KEY_COMMAND_BUTTON_SEARCH, kKeyCodeSearch }, { SKIN_KEY_COMMAND_BUTTON_MENU, kKeyCodeMenu }, { SKIN_KEY_COMMAND_BUTTON_DPAD_UP, kKeyCodeDpadUp }, { SKIN_KEY_COMMAND_BUTTON_DPAD_LEFT, kKeyCodeDpadLeft }, { SKIN_KEY_COMMAND_BUTTON_DPAD_RIGHT, kKeyCodeDpadRight }, { SKIN_KEY_COMMAND_BUTTON_DPAD_DOWN, kKeyCodeDpadDown }, { SKIN_KEY_COMMAND_BUTTON_DPAD_CENTER, kKeyCodeDpadCenter }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_UP, kKeyCodeVolumeUp }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_DOWN, kKeyCodeVolumeDown }, { SKIN_KEY_COMMAND_BUTTON_CAMERA, kKeyCodeCamera }, { SKIN_KEY_COMMAND_BUTTON_TV, kKeyCodeTV }, { SKIN_KEY_COMMAND_BUTTON_EPG, kKeyCodeEPG }, { SKIN_KEY_COMMAND_BUTTON_DVR, kKeyCodeDVR }, { SKIN_KEY_COMMAND_BUTTON_PREV, kKeyCodePrevious }, { SKIN_KEY_COMMAND_BUTTON_NEXT, kKeyCodeNext }, { SKIN_KEY_COMMAND_BUTTON_PLAY, kKeyCodePlay }, { SKIN_KEY_COMMAND_BUTTON_PAUSE, kKeyCodePause }, { SKIN_KEY_COMMAND_BUTTON_STOP, kKeyCodeStop }, { SKIN_KEY_COMMAND_BUTTON_REWIND, kKeyCodeRewind }, { SKIN_KEY_COMMAND_BUTTON_FFWD, kKeyCodeFastForward }, { SKIN_KEY_COMMAND_BUTTON_BOOKMARKS, kKeyCodeBookmarks }, { SKIN_KEY_COMMAND_BUTTON_WINDOW, kKeyCodeCycleWindows }, { SKIN_KEY_COMMAND_BUTTON_CHANNELUP, kKeyCodeChannelUp }, { SKIN_KEY_COMMAND_BUTTON_CHANNELDOWN, kKeyCodeChannelDown }, { SKIN_KEY_COMMAND_NONE, 0 } }; int nn; #ifdef CONFIG_TRACE static int tracing = 0; #endif QEmulator* emulator = opaque; for (nn = 0; keycodes[nn].kcode != 0; nn++) { if (command == keycodes[nn].cmd) { unsigned code = keycodes[nn].kcode; if (down) code |= 0x200; user_event_keycode( code ); return; } } if (command == SKIN_KEY_COMMAND_SHOW_TRACKBALL) { emulator->show_trackball = (down != 0); skin_window_show_trackball( emulator->window, emulator->show_trackball ); return; } if (down == 0) return; switch (command) { case SKIN_KEY_COMMAND_TOGGLE_NETWORK: { corecmd_toggle_network(); D( "network is now %s", corecmd_is_network_disabled() ? "disconnected" : "connected" ); } break; case SKIN_KEY_COMMAND_TOGGLE_FULLSCREEN: if (emulator->window) { skin_window_toggle_fullscreen(emulator->window); } break; case SKIN_KEY_COMMAND_TOGGLE_TRACING: { #ifdef CONFIG_TRACE tracing = !tracing; corecmd_trace_control(tracing); #endif } break; case SKIN_KEY_COMMAND_TOGGLE_TRACKBALL: emulator->show_trackball = !emulator->show_trackball; skin_window_show_trackball( emulator->window, emulator->show_trackball ); qemulator_set_title(emulator); break; case SKIN_KEY_COMMAND_ONION_ALPHA_UP: case SKIN_KEY_COMMAND_ONION_ALPHA_DOWN: if (emulator->onion) { int alpha = emulator->onion_alpha; if (command == SKIN_KEY_COMMAND_ONION_ALPHA_UP) alpha += 16; else alpha -= 16; if (alpha > 256) alpha = 256; else if (alpha < 0) alpha = 0; emulator->onion_alpha = alpha; skin_window_set_onion( emulator->window, emulator->onion, emulator->onion_rotation, alpha ); skin_window_redraw( emulator->window, NULL ); } break; case SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV: case SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT: { SkinLayout* layout = NULL; if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT) { layout = emulator->layout->next; if (layout == NULL) layout = emulator->layout_file->layouts; } else if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV) { layout = emulator->layout_file->layouts; while (layout->next && layout->next != emulator->layout) layout = layout->next; } if (layout != NULL) { SkinRotation rotation; emulator->layout = layout; skin_window_reset( emulator->window, layout ); rotation = skin_layout_get_dpad_rotation( layout ); if (emulator->keyboard) skin_keyboard_set_rotation( emulator->keyboard, rotation ); if (emulator->trackball) { skin_trackball_set_rotation( emulator->trackball, rotation ); skin_window_set_trackball( emulator->window, emulator->trackball ); skin_window_show_trackball( emulator->window, emulator->show_trackball ); } skin_window_set_lcd_brightness( emulator->window, emulator->lcd_brightness ); qframebuffer_invalidate_all(); qframebuffer_check_updates(); } } break; default: ; } }
/* Asynchronous I/O callback reading user events. * Param: * opaque - UserEventsImpl instance. */ static void _userEventsImpl_io_func(void* opaque, int fd, unsigned events) { UserEventsImpl* ueimpl; AsyncStatus status; if (events & LOOP_IO_WRITE) { // We don't use async writer here, so we don't expect // any write callbacks. derror("Unexpected LOOP_IO_WRITE in _userEventsImpl_io_func\n"); return; } ueimpl = (UserEventsImpl*)opaque; // Read whatever is expected from the socket. status = asyncReader_read(&ueimpl->user_events_reader); switch (status) { case ASYNC_COMPLETE: switch (ueimpl->state) { case EXPECTS_HEADER: // We just read event header. Now we expect event parameters. ueimpl->state = EXPECTS_PARAMETERS; // Setup the reader depending on the event type. switch (ueimpl->event_header.event_type) { case AUSER_EVENT_MOUSE: asyncReader_init(&ueimpl->user_events_reader, &ueimpl->mouse_event, sizeof(ueimpl->mouse_event), &ueimpl->io); break; case AUSER_EVENT_KEYCODE: asyncReader_init(&ueimpl->user_events_reader, &ueimpl->keycode_event, sizeof(ueimpl->keycode_event), &ueimpl->io); break; case AUSER_EVENT_GENERIC: asyncReader_init(&ueimpl->user_events_reader, &ueimpl->generic_event, sizeof(ueimpl->generic_event), &ueimpl->io); break; default: derror("Unexpected user event type %d\n", ueimpl->event_header.event_type); break; } break; case EXPECTS_PARAMETERS: // We just read event parameters. Lets fire the event. switch (ueimpl->event_header.event_type) { case AUSER_EVENT_MOUSE: user_event_mouse(ueimpl->mouse_event.dx, ueimpl->mouse_event.dy, ueimpl->mouse_event.dz, ueimpl->mouse_event.buttons_state); break; case AUSER_EVENT_KEYCODE: user_event_keycode(ueimpl->keycode_event.keycode); break; case AUSER_EVENT_GENERIC: user_event_generic(ueimpl->generic_event.type, ueimpl->generic_event.code, ueimpl->generic_event.value); break; default: derror("Unexpected user event type %d\n", ueimpl->event_header.event_type); break; } // Prepare to receive the next event header. ueimpl->event_header.event_type = -1; ueimpl->state = EXPECTS_HEADER; asyncReader_init(&ueimpl->user_events_reader, &ueimpl->event_header, sizeof(ueimpl->event_header), &ueimpl->io); break; } break; case ASYNC_ERROR: loopIo_dontWantRead(&ueimpl->io); if (errno == ECONNRESET) { // UI has exited. We need to destroy user event service. destroy_user_events_client(); } else { derror("User event read error %d -> %s\n", errno, errno_str); } break; case ASYNC_NEED_MORE: // Transfer will eventually come back into this routine. return; } }