Exemplo n.º 1
0
/* Changes to anticipate: renaming functions to avoid mention of popping. */
int main (void) {
  delay_queue priority = construct_delay_queue ();
  delay_queue left = construct_delay_queue ();
  delay_queue right = construct_delay_queue ();
  int out_key;
  add_key_to_queue (34, &priority);
  add_key_to_queue (5, &left);
  add_key_to_queue (7, &right);
  add_key_to_queue (13, &priority);
  add_key_to_queue (9, &left);
  increment_delay (&right);
  while ((out_key = select_from_queues (&priority, &left, &right))) {
    printf ("%i\n",out_key);
  }
}
Exemplo n.º 2
0
static int process_event(struct input_event *event) {
  if (event->type != EV_KEY)
   return 0;

  if (event->value == KEYHOLD && keystate.hold.num_active && modifiable(event->code))
    return 0;

  add_key_to_queue(event->code, event->value);

  if (!modifiable(event->code)) {
    flush_queue(ACTION_NONE, 0);
    keystate.tap.code = event->code;
    keystate.hold.code = event->code;
    return 0;
  }

  switch (event->value) {
    case KEYDOWN:
      cancel_hold_timeout();
      if (keystate.tap.code == event->code && within_tap_threshold(event)) {
        if (keystate.tap.state == STATE_IDLE) {
          syslog(LOG_WARNING, "Missed tap action due to timeout");
        }
        else {
          tap_action();
          memcpy(&keystate.tap.time, &event->time, sizeof keystate.tap.time);
        }
      }  
      else {
        flush_queue(ACTION_NONE, 0);
        if (keystate.hold.num_active) {
          keystate.hold.code = event->code;
          start_hold_timeout();
        }
        if (keystate.tap.num_active) {
          keystate.tap.code = event->code;
          memcpy(&keystate.tap.time, &event->time, sizeof keystate.tap.time);
          start_tap_timeout();
        }
      }
      break;
    case KEYUP:
      cancel_hold_timeout();
      if (keystate.tap.code != event->code || keystate.tap.state == STATE_IDLE) {
        flush_queue(ACTION_NONE, 0);
        stop_tap();
      }
      break;
    case KEYHOLD:
      if (!keystate.hold.num_active) {
        stop_tap();
        flush_queue(ACTION_NONE, 0);
      }
      break;
    default:
      break;
  }

  return 0;
}