Example #1
0
int menu_input_bind_iterate_keyboard(void)
{
   char msg[PATH_MAX_LENGTH];
   int64_t current;
   int timeout = 0;
   bool timed_out = false;
   menu_handle_t *menu = menu_driver_resolve();

   if (!menu)
      return -1;

   if (driver.video_data && driver.menu_ctx &&
         driver.menu_ctx->render)
      driver.menu_ctx->render();

   current = rarch_get_time_usec();
   timeout = (menu->binds.timeout_end - current) / 1000000;
   snprintf(msg, sizeof(msg), "[%s]\npress keyboard\n(timeout %d seconds)",
         input_config_bind_map[
         menu->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc,
         timeout);

   if (driver.video_data && driver.menu_ctx 
         && driver.menu_ctx->render_messagebox)
      driver.menu_ctx->render_messagebox(msg);

   if (timeout <= 0)
   {
      menu->binds.begin++;

      /* Could be unsafe, but whatever. */
      menu->binds.target->key = RETROK_UNKNOWN;

      menu->binds.target++;
      menu->binds.timeout_end = rarch_get_time_usec() +
         MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
      timed_out = true;
   }

   /* binds.begin is updated in keyboard_press callback. */
   if (menu->binds.begin > menu->binds.last)
   {
      /* Avoid new binds triggering things right away. */
      driver.flushing_input = true;

      /* We won't be getting any key events, so just cancel early. */
      if (timed_out)
         input_keyboard_wait_keys_cancel();

      return 1;
   }

   return 0;
}
Example #2
0
/**
 * input_keyboard_event:
 * @down                     : Keycode was pressed down?
 * @code                     : Keycode.
 * @character                : Character inputted.
 * @mod                      : TODO/FIXME: ???
 *
 * Keyboard event utils. Called by drivers when keyboard events are fired.
 * This interfaces with the global system driver struct and libretro callbacks.
 **/
void input_keyboard_event(bool down, unsigned code,
      uint32_t character, uint16_t mod, unsigned device)
{
   static bool deferred_wait_keys;
   rarch_system_info_t *system = rarch_system_info_get_ptr();

   if (deferred_wait_keys)
   {
      if (down)
         return;

      input_keyboard_wait_keys_cancel();
      deferred_wait_keys = false;
   }
   else if (g_keyboard_press_cb)
   {
      if (!down)
         return;
      if (code == RETROK_UNKNOWN)
         return;
      if (g_keyboard_press_cb(g_keyboard_press_data, code))
         return;
      deferred_wait_keys = true;
   }
   else if (g_keyboard_line)
   {
      if (!down)
         return;

      switch (device)
      {
         case RETRO_DEVICE_POINTER:
            if (!input_keyboard_line_event(g_keyboard_line, (code != 0x12d) ? (char)code : character))
               return;
            break;
         default:
            if (!input_keyboard_line_event(g_keyboard_line, character))
               return;
            break;
      }

      /* Line is complete, can free it now. */
      input_keyboard_line_free(g_keyboard_line);
      g_keyboard_line = NULL;

      /* Unblock all hotkeys. */
      input_driver_keyboard_mapping_set_block(false);
   }
   else if (system->key_event)
      system->key_event(down, code, character, mod);
}
Example #3
0
static int menu_input_key_bind_iterate_keyboard(int64_t current, int timeout, bool timed_out)
{
   menu_input_t *menu_input = menu_input_get_ptr();
   driver_t         *driver = driver_get_ptr();

   if (!menu_input)
      return -1;

   /* binds.begin is updated in keyboard_press callback. */
   if (menu_input->binds.begin > menu_input->binds.last)
   {
      /* Avoid new binds triggering things right away. */
      driver->flushing_input = true;

      /* We won't be getting any key events, so just cancel early. */
      if (timed_out)
         input_keyboard_wait_keys_cancel();

      return 1;
   }

   return 0;
}
Example #4
0
static int menu_input_bind_iterate_keyboard(int64_t current, int timeout)
{
   bool           timed_out = false;
   menu_input_t *menu_input = menu_input_get_ptr();
   driver_t         *driver = driver_get_ptr();

   if (!menu_input)
      return -1;

   if (timeout <= 0)
   {
      /* Could be unsafe, but whatever. */
      menu_input->binds.target->key = RETROK_UNKNOWN;

      menu_input->binds.begin++;
      menu_input->binds.target++;
      menu_input->binds.timeout_end = rarch_get_time_usec() +
         MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
      timed_out = true;
   }

   /* binds.begin is updated in keyboard_press callback. */
   if (menu_input->binds.begin > menu_input->binds.last)
   {
      /* Avoid new binds triggering things right away. */
      driver->flushing_input = true;

      /* We won't be getting any key events, so just cancel early. */
      if (timed_out)
         input_keyboard_wait_keys_cancel();

      return 1;
   }

   return 0;
}
Example #5
0
int menu_input_key_bind_iterate(char *s, size_t len)
{
   struct menu_bind_state binds;
   bool               timed_out = false;
   menu_input_t *menu_input     = menu_input_get_ptr();
   driver_t *driver             = driver_get_ptr();
   int64_t current              = retro_get_time_usec();
   int timeout                  = (menu_input->binds.timeout_end - current) / 1000000;

   if (timeout <= 0)
   {
      input_driver_keyboard_mapping_set_block(false);

      menu_input->binds.begin++;
      menu_input->binds.target++;
      menu_input->binds.timeout_end = retro_get_time_usec() +
         MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
      timed_out = true;
   }

   snprintf(s, len,
         "[%s]\npress keyboard or joypad\n(timeout %d %s)",
         input_config_bind_map[
         menu_input->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc,
         timeout,
         menu_hash_to_str(MENU_VALUE_SECONDS));

   /* binds.begin is updated in keyboard_press callback. */
   if (menu_input->binds.begin > menu_input->binds.last)
   {
      /* Avoid new binds triggering things right away. */
      driver->flushing_input = true;

      /* We won't be getting any key events, so just cancel early. */
      if (timed_out)
         input_keyboard_wait_keys_cancel();

      return 1;
   }

   binds = menu_input->binds;

   input_driver_keyboard_mapping_set_block(true);
   menu_input_key_bind_poll_bind_state(&binds, bind_port, timed_out);

   if ((binds.skip && !menu_input->binds.skip) ||
         menu_input_key_bind_poll_find_trigger(&menu_input->binds, &binds))
   {
      input_driver_keyboard_mapping_set_block(false);

      /* Avoid new binds triggering things right away. */
      driver->flushing_input = true;

      binds.begin++;

      if (binds.begin > binds.last)
         return 1;

      binds.target++;
      binds.timeout_end = retro_get_time_usec() +
         MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
   }
   menu_input->binds = binds;

   return 0;
}