/* Handles a "pointer move" event * Param: * mts_state - MTS state descriptor. * slot_index - Pointer's index in the MTS's array of tracked pointers. * x, y - New pointer coordinates, * pressure - Pressure value for the pointer. */ static void _mts_pointer_move(MTSState* mts_state, int slot_index, int x, int y, int pressure) { MTSPointerState* ptr_state = &mts_state->tracked_pointers[slot_index]; /* Make sure that coordinates have really changed. */ if (ptr_state->x == x && ptr_state->y == y) { /* Coordinates didn't change. Bail out. */ return; } /* Make sure that the right slot is selected. */ if (slot_index != mts_state->current_slot) { _push_event(EV_ABS, ABS_MT_SLOT, slot_index); mts_state->current_slot = slot_index; } /* Push the changes down. */ if (ptr_state->pressure != pressure && pressure != 0) { _push_event(EV_ABS, ABS_MT_PRESSURE, pressure); ptr_state->pressure = pressure; } if (ptr_state->x != x) { _push_event(EV_ABS, ABS_MT_POSITION_X, x); ptr_state->x = x; } if (ptr_state->y != y) { _push_event(EV_ABS, ABS_MT_POSITION_Y, y); ptr_state->y = y; } _push_event(EV_SYN, SYN_REPORT, 0); }
static int conio_get_event(caca_display_t *dp, caca_privevent_t *ev) { uint8_t ch; caca_privevent_t release; if(!_conio_kbhit()) { ev->type = CACA_EVENT_NONE; return 0; } ch = getch(); ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = ch; ev->data.key.utf32 = ch; ev->data.key.utf8[0] = ch; ev->data.key.utf8[1] = '\0'; release = *ev; release.type = CACA_EVENT_KEY_RELEASE; _push_event(dp, &release); return 1; }
/* Handles a "pointer down" event * Param: * mts_state - MTS state descriptor. * tracking_id - Tracking ID of the "downed" pointer. * x, y - "Downed" pointer coordinates, * pressure - Pressure value for the pointer. */ static void _mts_pointer_down(MTSState* mts_state, int tracking_id, int x, int y, int pressure) { /* Get first available slot for the new pointer. */ const int slot_index = _mtsstate_get_available_pointer_index(mts_state); /* Make sure there is a place for the pointer. */ if (slot_index >= 0) { /* Initialize pointer's entry. */ mts_state->tracked_ptr_num++; mts_state->tracked_pointers[slot_index].tracking_id = tracking_id; mts_state->tracked_pointers[slot_index].x = x; mts_state->tracked_pointers[slot_index].y = y; mts_state->tracked_pointers[slot_index].pressure = pressure; /* Send events indicating a "pointer down" to the EventHub */ /* Make sure that correct slot is selected. */ if (slot_index != mts_state->current_slot) { _push_event(EV_ABS, ABS_MT_SLOT, slot_index); } _push_event(EV_ABS, ABS_MT_TRACKING_ID, slot_index); _push_event(EV_ABS, ABS_MT_TOUCH_MAJOR, ++mts_state->touch_major); _push_event(EV_ABS, ABS_MT_PRESSURE, pressure); _push_event(EV_ABS, ABS_MT_POSITION_X, x); _push_event(EV_ABS, ABS_MT_POSITION_Y, y); _push_event(EV_SYN, SYN_REPORT, 0); mts_state->current_slot = slot_index; } else { D("MTS pointer count is exceeded."); return; } }
/* Handles a "pointer up" event * Param: * mts_state - MTS state descriptor. * slot_index - Pointer's index in the MTS's array of tracked pointers. */ static void _mts_pointer_up(MTSState* mts_state, int slot_index) { /* Make sure that correct slot is selected. */ if (slot_index != mts_state->current_slot) { _push_event(EV_ABS, ABS_MT_SLOT, slot_index); } /* Send event indicating "pointer up" to the EventHub. */ _push_event(EV_ABS, ABS_MT_TRACKING_ID, -1); _push_event(EV_SYN, SYN_REPORT, 0); /* Update MTS descriptor, removing the tracked pointer. */ mts_state->tracked_pointers[slot_index].tracking_id = MTS_POINTER_UP; mts_state->tracked_pointers[slot_index].x = 0; mts_state->tracked_pointers[slot_index].y = 0; mts_state->tracked_pointers[slot_index].pressure = 0; /* Since current slot is no longer tracked, make sure we will do a "select" * next time we send events to the EventHub. */ mts_state->current_slot = -1; mts_state->tracked_ptr_num--; assert(mts_state->tracked_ptr_num >= 0); }
static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev) { int intkey; /* If SIGINT was caught, we pass it to the application as Ctrl-C. */ if(dp->drv.p->sigint_event > 0) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = CACA_KEY_CTRL_C; ev->data.key.utf32 = 0x03; ev->data.key.utf8[0] = 0x03; ev->data.key.utf8[1] = 0; dp->drv.p->sigint_event--; return 1; } if(!SLang_input_pending(0)) { ev->type = CACA_EVENT_NONE; return 0; } /* We first use SLang_getkey() to see whether Esc was pressed * alone, then (if it wasn't) we unget the key and use SLkp_getkey() * instead, so that escape sequences are interpreted. */ intkey = SLang_getkey(); if(intkey != 0x1b /* Esc */ || SLang_input_pending(0)) { SLang_ungetkey(intkey); intkey = SLkp_getkey(); } /* If the key was ASCII, return it immediately */ if(intkey < 0x7f) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = intkey; ev->data.key.utf32 = intkey; ev->data.key.utf8[0] = intkey; ev->data.key.utf8[1] = '\0'; return 1; } /* If the key was UTF-8, parse the whole sequence */ if(intkey >= 0x80 && intkey < 0x100) { int keys[7]; /* Necessary for ungetkey(); */ char utf8[7]; uint32_t utf32; size_t i, bytes = 0; keys[0] = intkey; utf8[0] = intkey; for(i = 1; i < 6; i++) { if(!SLang_input_pending(0)) break; keys[i] = SLang_getkey(); utf8[i] = (unsigned char)keys[i]; } utf8[i] = '\0'; utf32 = caca_utf8_to_utf32(utf8, &bytes); while(i > bytes) SLang_ungetkey(keys[--i]); if(bytes) { ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.ch = 0; ev->data.key.utf32 = utf32; strcpy(ev->data.key.utf8, utf8); return 1; } } if(intkey == 0x3e9) { int button = (SLang_getkey() - ' ' + 1) & 0xf; int x = SLang_getkey() - '!'; int y = SLang_getkey() - '!'; ev->data.mouse.button = button; ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev); ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev); if(dp->mouse.x == x && dp->mouse.y == y) return _pop_event(dp, ev); dp->mouse.x = x; dp->mouse.y = y; ev->type = CACA_EVENT_MOUSE_MOTION; ev->data.mouse.x = dp->mouse.x; ev->data.mouse.y = dp->mouse.y; return 1; } switch(intkey) { case SL_KEY_UP: ev->data.key.ch = CACA_KEY_UP; break; case SL_KEY_DOWN: ev->data.key.ch = CACA_KEY_DOWN; break; case SL_KEY_LEFT: ev->data.key.ch = CACA_KEY_LEFT; break; case SL_KEY_RIGHT: ev->data.key.ch = CACA_KEY_RIGHT; break; case SL_KEY_IC: ev->data.key.ch = CACA_KEY_INSERT; break; case SL_KEY_DELETE: ev->data.key.ch = CACA_KEY_DELETE; break; case 0x7f: case SL_KEY_BACKSPACE: ev->data.key.ch = CACA_KEY_BACKSPACE; break; case SL_KEY_HOME: ev->data.key.ch = CACA_KEY_HOME; break; case SL_KEY_END: ev->data.key.ch = CACA_KEY_END; break; case SL_KEY_PPAGE: ev->data.key.ch = CACA_KEY_PAGEUP; break; case SL_KEY_NPAGE: ev->data.key.ch = CACA_KEY_PAGEDOWN; break; case SL_KEY_F(1): ev->data.key.ch = CACA_KEY_F1; break; case SL_KEY_F(2): ev->data.key.ch = CACA_KEY_F2; break; case SL_KEY_F(3): ev->data.key.ch = CACA_KEY_F3; break; case SL_KEY_F(4): ev->data.key.ch = CACA_KEY_F4; break; case SL_KEY_F(5): ev->data.key.ch = CACA_KEY_F5; break; case SL_KEY_F(6): ev->data.key.ch = CACA_KEY_F6; break; case SL_KEY_F(7): ev->data.key.ch = CACA_KEY_F7; break; case SL_KEY_F(8): ev->data.key.ch = CACA_KEY_F8; break; case SL_KEY_F(9): ev->data.key.ch = CACA_KEY_F9; break; case SL_KEY_F(10): ev->data.key.ch = CACA_KEY_F10; break; case SL_KEY_F(11): ev->data.key.ch = CACA_KEY_F11; break; case SL_KEY_F(12): ev->data.key.ch = CACA_KEY_F12; break; default: /* Unknown key */ ev->type = CACA_EVENT_NONE; return 0; } ev->type = CACA_EVENT_KEY_PRESS; ev->data.key.utf32 = 0; ev->data.key.utf8[0] = '\0'; return 1; }