Exemplo n.º 1
0
static void *sdl_input_init(void)
{
   init_lut();
   sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
   if (!sdl)
      return NULL;

   sdl->joypad = input_joypad_init_first();
   return sdl;
}
Exemplo n.º 2
0
/**
 * input_joypad_init_driver:
 * @ident                           : identifier of driver to initialize.
 *
 * Initialize a joypad driver of name @ident.
 *
 * If ident points to NULL or a zero-length string, 
 * equivalent to calling input_joypad_init_first().
 *
 * Returns: joypad driver if found, otherwise NULL.
 **/
const input_device_driver_t *input_joypad_init_driver(const char *ident, void *data)
{
   unsigned i;
   if (!ident || !*ident)
      return input_joypad_init_first(data);

   for (i = 0; joypad_drivers[i]; i++)
   {
      if (!strcmp(ident, joypad_drivers[i]->ident)
            && joypad_drivers[i]->init(data))
      {
         RARCH_LOG("Found joypad driver: \"%s\".\n",
               joypad_drivers[i]->ident);
         return joypad_drivers[i];
      }
   }

   return input_joypad_init_first(data);
}
Exemplo n.º 3
0
const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident)
{
   unsigned i;
   if (!ident || !*ident)
      return input_joypad_init_first();

   for (i = 0; joypad_drivers[i]; i++)
   {
      if (strcmp(ident, joypad_drivers[i]->ident) == 0
            && joypad_drivers[i]->init())
      {
         RARCH_LOG("Found joypad driver: \"%s\".\n",
               joypad_drivers[i]->ident);
         return joypad_drivers[i];
      }
   }

   return input_joypad_init_first();
}
Exemplo n.º 4
0
static void *dinput_init(void)
{
   if (!dinput_init_context())
      return NULL;

   struct dinput_input *di = (struct dinput_input*)calloc(1, sizeof(*di));
   if (!di)
      return NULL;

#ifdef __cplusplus
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, GUID_SysKeyboard, &di->keyboard, NULL)))
      goto error;
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, GUID_SysMouse, &di->mouse, NULL)))
      goto error;
#else
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, &GUID_SysKeyboard, &di->keyboard, NULL)))
      goto error;
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, &GUID_SysMouse, &di->mouse, NULL)))
      goto error;
#endif

   IDirectInputDevice8_SetDataFormat(di->keyboard, &c_dfDIKeyboard);
   IDirectInputDevice8_SetCooperativeLevel(di->keyboard,
         (HWND)driver.video_window, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
   IDirectInputDevice8_Acquire(di->keyboard);

   IDirectInputDevice8_SetDataFormat(di->mouse, &c_dfDIMouse2);
   IDirectInputDevice8_SetCooperativeLevel(di->mouse, (HWND)driver.video_window,
         DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
   IDirectInputDevice8_Acquire(di->mouse);

   input_init_keyboard_lut(rarch_key_map_dinput);
   di->joypad = input_joypad_init_first();

   return di;

error:
   dinput_destroy_context();
   free(di);
   return NULL;
}
Exemplo n.º 5
0
static void *x_input_init(void)
{
    if (driver.display_type != RARCH_DISPLAY_X11)
    {
        RARCH_ERR("Currently active window is not an X11 window. Cannot use this driver.\n");
        return NULL;
    }

    x11_input_t *x11 = (x11_input_t*)calloc(1, sizeof(*x11));
    if (!x11)
        return NULL;

    // Borrow the active X window ...
    x11->display = (Display*)driver.video_display;
    x11->win     = (Window)driver.video_window;

    x11->joypad = input_joypad_init_first();
    input_init_keyboard_lut(rarch_key_map_x11);

    return x11;
}
Exemplo n.º 6
0
static void get_binds(config_file_t *conf, int player, int joypad)
{
   const rarch_joypad_driver_t *driver = input_joypad_init_first();
   if (!driver)
   {
      fprintf(stderr, "Cannot find any valid input driver.\n");
      exit(1);
   }

   if (!driver->query_pad(joypad))
   {
      fprintf(stderr, "Couldn't open joystick #%u.\n", joypad);
      exit(1);
   }

   fprintf(stderr, "Found joypad driver: %s\n", driver->ident);

   int16_t initial_axes[MAX_AXES] = {0};
   struct poll_data old_poll = {{0}};
   struct poll_data new_poll = {{0}};

   int last_axis   = -1;
   bool block_axis = false;

   poll_joypad(driver, joypad, &old_poll);

   for (int i = 0; i < MAX_AXES; i++)
   {
      int16_t initial = input_joypad_axis_raw(driver, joypad, i);
      if (abs(initial) < 20000)
         initial = 0;

      // Certain joypads (such as XBox360 controller on Linux) has a default negative axis for shoulder triggers,
      // which makes configuration very awkward.
      // If default negative, we can't trigger on the negative axis, and similar with defaulted positive axes.

      if (initial)
         fprintf(stderr, "Axis %d is defaulted to %s axis value of %d\n", i, initial > 0 ? "positive" : "negative", initial);

      initial_axes[i] = initial;
   }

   fprintf(stderr, "Configuring binds for player #%d on joypad #%d.\n\n",
         player + 1, joypad);

   for (unsigned i = 0; i < sizeof(binds) / sizeof(binds[0]) && (g_use_misc || !binds[i].is_misc) ; i++)
   {
      fprintf(stderr, "%s\n", binds[i].keystr);

      unsigned player_index = binds[i].is_misc ? 0 : player;

      for (;;)
      {
         old_poll = new_poll;

         // To avoid pegging CPU.
         // Ideally use an event-based joypad scheme,
         // but it adds far more complexity, so, meh.
         rarch_sleep(10);

         poll_joypad(driver, joypad, &new_poll);
         for (int j = 0; j < MAX_BUTTONS; j++)
         {
            if (new_poll.buttons[j] && !old_poll.buttons[j])
            {
               fprintf(stderr, "\tJoybutton pressed: %u\n", j);
               config_set_int(conf, binds[i].confbtn[player_index], j);
               goto out;
            }
         }

         for (int j = 0; j < MAX_AXES; j++)
         {
            if (new_poll.axes[j] != old_poll.axes[j])
            {
               int16_t value         = new_poll.axes[j];
               bool same_axis        = last_axis == j;
               bool require_negative = initial_axes[j] > 0;
               bool require_positive = initial_axes[j] < 0;

               // Block the axis config until we're sure axes have returned to their neutral state.
               if (same_axis)
               {
                  if (abs(value) < 10000 ||
                        (require_positive && value < 0) ||
                        (require_negative && value > 0))
                     block_axis = false;
               }

               // If axes are in their neutral state, we can't allow it.
               if (require_negative && value >= 0)
                  continue;
               if (require_positive && value <= 0)
                  continue;

               if (block_axis)
                  continue;

               if (abs(value) > 20000)
               {
                  last_axis = j;
                  fprintf(stderr, "\tJoyaxis moved: Axis %d, Value %d\n", j, value);

                  char buf[8];
                  snprintf(buf, sizeof(buf),
                        value > 0 ? "+%d" : "-%d", j);

                  config_set_string(conf, binds[i].confaxis[player_index], buf);
                  block_axis = true;
                  goto out;
               }
            }
         }

         for (int j = 0; j < MAX_HATS; j++)
         {
            const char *quark  = NULL;
            uint16_t value     = new_poll.hats[j];
            uint16_t old_value = old_poll.hats[j];

            if ((value & HAT_UP_MASK) && !(old_value & HAT_UP_MASK))
               quark = "up";
            else if ((value & HAT_LEFT_MASK) && !(old_value & HAT_LEFT_MASK))
               quark = "left";
            else if ((value & HAT_RIGHT_MASK) && !(old_value & HAT_RIGHT_MASK))
               quark = "right";
            else if ((value & HAT_DOWN_MASK) && !(old_value & HAT_DOWN_MASK))
               quark = "down";

            if (quark)
            {
               fprintf(stderr, "\tJoyhat moved: Hat %d, direction %s\n", j, quark);
               char buf[16];
               snprintf(buf, sizeof(buf), "h%d%s", j, quark);
               config_set_string(conf, binds[i].confbtn[player_index], buf);
               goto out;
            }
         }
      }
out:
      old_poll = new_poll;
   }
}