/* Called when a DrawingArea has input (either mouse or keyboard). */ static void _do_input(Widget w, void *data, XADCS *call_data) { char *input; DrawInfo *di = (DrawInfo *) data; SetDrawArea(w); if (call_data->event->type == ButtonPress) { if (di->button_down) di->button_down(w, call_data->event->xbutton.button, call_data->event->xbutton.x,call_data->event->xbutton.y, di->user_data); } else if (call_data->event->type == ButtonRelease) { if (di->button_up) di->button_up(w, call_data->event->xbutton.button, call_data->event->xbutton.x, call_data->event->xbutton.y, di->user_data); } else if (call_data->event->type == KeyPress) { input = TranslateKeyCode(call_data->event); if (input && *input != '\0' && di->keypress) di->keypress(w, input, 0, di->user_data); } else if (call_data->event->type == KeyRelease) { input = TranslateKeyCode(call_data->event); if (input && *input != '\0' && di->keypress) di->keypress(w, input, 1, di->user_data); } }
gcc_visibility_default void Java_org_xcsoar_EventBridge_onKeyUp(JNIEnv *env, jclass cls, jint key_code) { if (event_queue == NULL) /* XCSoar not yet initialised */ return; event_queue->Push(Event(Event::KEY_UP, TranslateKeyCode(key_code))); }
gcc_visibility_default void Java_org_xcsoar_EventBridge_onKeyDown(JNIEnv *env, jclass cls, jint key_code) { if (event_queue == NULL) /* XCSoar not yet initialised */ return; if (!has_cursor_keys && IsCursorKey(key_code)) /* enable this flag as soon as we see the first cursor event; used by HasCursorKeys() */ has_cursor_keys = true; event_queue->Push(Event(Event::KEY_DOWN, TranslateKeyCode(key_code))); ResetUserIdle(); }
int PrintKey(Action *action, XEvent *xev) { char *string; DEBUG(D_CALLS) printf("PrintKey: %d %d\n",action, xev); string=(char *)TranslateKeyCode(xev); if (string == NULL) return; if (*string == '\r') printf("\n"); else if (strlen(string) == 1) printf("%s", string); else { /* PrintKey should not print things like <<Shift>> --let PrintEvent do that, since PrintKey is for printing out char-by-char type of output */ /* printf("<<%s>>", string); */ DEBUG(D_MISC) printf("String keycode.\n"); } fflush(stdout); }
inline void LinuxInputDevice::Read() { struct input_event buffer[64]; const ssize_t nbytes = fd.Read(buffer, sizeof(buffer)); if (nbytes < 0) { /* device has failed or was unplugged - bail out */ if (errno != EAGAIN && errno != EINTR) { fprintf(stderr, "device has failed or was unplugged <%s>\n", strerror(errno)); Close(); } return; } unsigned n = size_t(nbytes) / sizeof(buffer[0]); for (unsigned i = 0; i < n; ++i) { const struct input_event &e = buffer[i]; switch (e.type) { case EV_SYN: if (e.code == SYN_REPORT) { /* commit the finger movement */ const bool pressed = pressing; const bool released = releasing; pressing = releasing = false; if (pressed) merge.SetDown(true); if (released) merge.SetDown(false); if (IsKobo() && released) { /* workaround: on the Kobo Touch N905B, releasing the touch screen reliably produces a finger position that is way off; in that case, ignore finger movement */ moving = false; edit_position = public_position; } if (moving) { moving = false; public_position = edit_position; merge.MoveAbsolute(public_position.x, public_position.y, min_x, max_x, min_y, max_y); } else if (rel_x != 0 || rel_y != 0) { merge.MoveRelative(rel_x, rel_y); rel_x = rel_y = 0; } if (rel_wheel != 0) { merge.MoveWheel(rel_wheel); rel_wheel = 0; } } break; case EV_KEY: if (e.code == BTN_TOUCH || e.code == BTN_MOUSE) { bool new_down = e.value; if (new_down != down) { down = new_down; if (new_down) pressing = true; else releasing = true; } } else { /* Discard all data on stdin to avoid that keyboard input data is read * on the executing shell. This fixes #3403. */ tcflush(STDIN_FILENO, TCIFLUSH); queue.Push(Event(e.value ? Event::KEY_DOWN : Event::KEY_UP, TranslateKeyCode(e.code))); } break; case EV_ABS: moving = true; switch (e.code) { case ABS_X: edit_position.x = e.value; break; case ABS_Y: edit_position.y = e.value; break; case ABS_MT_SLOT: mt_current_slot = e.value; break; case ABS_MT_TRACKING_ID: if(mt_current_slot == 0) { if(mt_current_tracking_id == -1) { pressing = true; } if(e.value == -1) { releasing = false; } mt_current_tracking_id = e.value; } break; case ABS_MT_POSITION_X: if(mt_current_slot == 0) { edit_position.x = e.value; } case ABS_MT_POSITION_Y: if(mt_current_slot == 0) { edit_position.y = e.value; } break; } break; case EV_REL: switch (e.code) { case REL_X: rel_x += e.value; break; case REL_Y: rel_y += e.value; break; case REL_WHEEL: rel_wheel += e.value; break; } break; } } }
void Java_org_xcsoar_EventBridge_onKeyUp(JNIEnv *env, jclass cls, jint key_code) { event_queue->push(Event(Event::KEY_UP, TranslateKeyCode(key_code))); }
void LinuxInputDevice::Read() { struct input_event buffer[64]; const ssize_t nbytes = fd.Read(buffer, sizeof(buffer)); if (nbytes < 0) { /* device has failed or was unplugged - bail out */ if (errno != EAGAIN && errno != EINTR) Close(); return; } unsigned n = size_t(nbytes) / sizeof(buffer[0]); for (unsigned i = 0; i < n; ++i) { const struct input_event &e = buffer[i]; switch (e.type) { case EV_SYN: if (e.code == SYN_REPORT) { /* commit the finger movement */ const bool pressed = pressing; const bool released = releasing; pressing = releasing = false; if (pressed) merge.SetDown(true); if (released) merge.SetDown(false); if (IsKobo() && released) { /* workaround: on the Kobo Touch N905B, releasing the touch screen reliably produces a finger position that is way off; in that case, ignore finger movement */ moving = false; edit_position = public_position; } if (moving) { moving = false; public_position = edit_position; merge.MoveAbsolute(public_position.x, public_position.y); } else if (rel_x != 0 || rel_y != 0) { merge.MoveRelative(rel_x, rel_y); rel_x = rel_y = 0; } } break; case EV_KEY: if (e.code == BTN_TOUCH || e.code == BTN_MOUSE) { bool new_down = e.value; if (new_down != down) { down = new_down; if (new_down) pressing = true; else releasing = true; } } else queue.Push(Event(e.value ? Event::KEY_DOWN : Event::KEY_UP, TranslateKeyCode(e.code))); break; case EV_ABS: moving = true; switch (e.code) { case ABS_X: edit_position.x = e.value; break; case ABS_Y: edit_position.y = e.value; break; } break; case EV_REL: switch (e.code) { case REL_X: rel_x += e.value; break; case ABS_Y: rel_y += e.value; break; } break; } } }
inline void LinuxInputDevice::Read() { struct input_event buffer[64]; boost::system::error_code ec; const size_t nbytes = fd.read_some(boost::asio::buffer(buffer, sizeof(buffer)), ec); if (ec) { /* device has failed or was unplugged - bail out */ if (errno != boost::asio::error::try_again && errno != boost::asio::error::interrupted) Close(); return; } unsigned n = size_t(nbytes) / sizeof(buffer[0]); for (unsigned i = 0; i < n; ++i) { const struct input_event &e = buffer[i]; switch (e.type) { case EV_SYN: if (e.code == SYN_REPORT) { /* commit the finger movement */ const bool pressed = pressing; const bool released = releasing; pressing = releasing = false; if (pressed) merge.SetDown(true); if (released) merge.SetDown(false); if (IsKobo() && released) { /* workaround: on the Kobo Touch N905B, releasing the touch screen reliably produces a finger position that is way off; in that case, ignore finger movement */ moving = false; edit_position = public_position; } if (moving) { moving = false; public_position = edit_position; merge.MoveAbsolute(public_position.x, public_position.y, min_x, max_x, min_y, max_y); } else if (rel_x != 0 || rel_y != 0) { merge.MoveRelative(PixelPoint(rel_x, rel_y)); rel_x = rel_y = 0; } if (rel_wheel != 0) { merge.MoveWheel(rel_wheel); rel_wheel = 0; } } break; case EV_KEY: if (e.code == BTN_TOUCH || e.code == BTN_MOUSE) { bool new_down = e.value; if (new_down != down) { down = new_down; if (new_down) pressing = true; else releasing = true; } } else { /* Discard all data on stdin to avoid that keyboard input data is read * on the executing shell. This fixes #3403. */ tcflush(STDIN_FILENO, TCIFLUSH); bool is_char; Event ev(e.value ? Event::KEY_DOWN : Event::KEY_UP, TranslateKeyCode(e.code, is_char)); ev.is_char = is_char; queue.Push(ev); } break; case EV_ABS: moving = true; switch (e.code) { case ABS_X: edit_position.x = e.value; break; case ABS_Y: edit_position.y = e.value; break; case ABS_MT_POSITION_X: edit_position.x = e.value; break; case ABS_MT_POSITION_Y: edit_position.y = e.value; break; } break; case EV_REL: switch (e.code) { case REL_X: rel_x += e.value; break; case REL_Y: rel_y += e.value; break; case REL_WHEEL: rel_wheel += e.value; break; } break; } } }