static void *linuxraw_input_init(void)
{
   struct sigaction sa         = {{0}};
   linuxraw_input_t *linuxraw  = NULL;
   settings_t *settings        = config_get_ptr();

   /* Only work on terminals. */
   if (!isatty(0))
      return NULL;

   if (linux_terminal_grab_stdin(NULL))
   {
      RARCH_WARN("stdin is already used for content loading. Cannot use stdin for input.\n");
      return NULL;
   }

   linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
   if (!linuxraw)
      return NULL;

   if (!linux_terminal_disable_input())
   {
      linux_terminal_restore_input();
      free(linuxraw);
      return NULL;
   }

   linuxraw->joypad = input_joypad_init_driver(
         settings->input.joypad_driver, linuxraw);
   input_keymaps_init_keyboard_lut(rarch_key_map_linux);

   linux_terminal_claim_stdin();

   return linuxraw;
}
Esempio n. 2
0
static void *dinput_init(void)
{
   struct dinput_input *di = NULL;

   if (!dinput_init_context())
   {
      RARCH_ERR("Failed to start DirectInput driver.\n");
      return NULL;
   }

   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)))
   {
      RARCH_ERR("Failed to create keyboard device.\n");
      di->keyboard = NULL;
   }

   if (FAILED(IDirectInput8_CreateDevice(g_ctx, GUID_SysMouse, &di->mouse, NULL)))
   {
      RARCH_ERR("Failed to create mouse device.\n");
      di->mouse = NULL;
   }
#else
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, &GUID_SysKeyboard, &di->keyboard, NULL)))
   {
      RARCH_ERR("Failed to create keyboard device.\n");
      di->keyboard = NULL;
   }
   if (FAILED(IDirectInput8_CreateDevice(g_ctx, &GUID_SysMouse, &di->mouse, NULL)))
   {
      RARCH_ERR("Failed to create mouse device.\n");
      di->mouse = NULL;
   }
#endif

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

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

   input_keymaps_init_keyboard_lut(rarch_key_map_dinput);
   di->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);

   return di;
}
Esempio n. 3
0
static void *qnx_input_init(const char *joypad_driver)
{
   int i;
   qnx_input_t *qnx     = (qnx_input_t*)calloc(1, sizeof(*qnx));

   if (!qnx)
      return NULL;

   input_keymaps_init_keyboard_lut(rarch_key_map_qnx);

   for (i = 0; i < MAX_TOUCH; ++i)
   {
      qnx->pointer[i].contact_id = -1;
      qnx->touch_map[i] = -1;
   }

   qnx->joypad = input_joypad_init_driver(joypad_driver, qnx);

   for (i = 0; i < MAX_PADS; ++i)
   {
      qnx_init_controller(qnx, &qnx->devices[i]);
   }

#ifdef HAVE_BB10
   qnx_discover_controllers(qnx);
#else
   /* Initialize Playbook keyboard. */
   strlcpy(qnx->devices[0].id, "0A5C-8502",
         sizeof(qnx->devices[0].id));
   qnx_input_autodetect_gamepad(qnx, &qnx->devices[0]);
   qnx->pads_connected = 1;
#endif

   return qnx;
}
Esempio n. 4
0
static void *sdl_input_init(void)
{
   input_keymaps_init_keyboard_lut(rarch_key_map_sdl);
   settings_t *settings = config_get_ptr();
   sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
   if (!sdl)
      return NULL;

   sdl->joypad = input_joypad_init_driver(settings->input.joypad_driver, sdl);

   RARCH_LOG("[SDL]: Input driver initialized.\n");
   return sdl;
}
Esempio n. 5
0
static void *cocoa_input_init(void)
{
   settings_t *settings = config_get_ptr();
   cocoa_input_data_t *apple = (cocoa_input_data_t*)calloc(1, sizeof(*apple));
   if (!apple)
      return NULL;
    
   input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid);

   apple->joypad = input_joypad_init_driver(settings->input.joypad_driver, apple);
    
   return apple;
}
Esempio n. 6
0
static void *sdl_input_init(const char *joypad_driver)
{
   sdl_input_t     *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
   if (!sdl)
      return NULL;

   input_keymaps_init_keyboard_lut(rarch_key_map_sdl);

   sdl->joypad = input_joypad_init_driver(joypad_driver, sdl);

   RARCH_LOG("[SDL]: Input driver initialized.\n");
   return sdl;
}
Esempio n. 7
0
bool input_wl_init(void *data, const char *joypad_name)
{
   input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data;

   if (!wl)
      return false;

   wl->joypad = input_joypad_init_driver(joypad_name, wl);

   if (!wl->joypad)
      return false;

   input_keymaps_init_keyboard_lut(rarch_key_map_linux);
   return true;
}
Esempio n. 8
0
static void* dos_input_init(const char *joypad_driver)
{
   dos_input_t *dos = (dos_input_t*)calloc(1, sizeof(*dos));

   if (!dos)
      return NULL;

   dos_keyboard_free();

   dos->joypad = input_joypad_init_driver(joypad_driver, dos);

   input_keymaps_init_keyboard_lut(rarch_key_map_dos);

   return dos;
}
Esempio n. 9
0
static void* wiiu_input_init(const char *joypad_driver)
{
   wiiu_input_t *wiiu = (wiiu_input_t*)calloc(1, sizeof(*wiiu));
   if (!wiiu)
      return NULL;

   DEBUG_STR(joypad_driver);
   wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu);

   KBDSetup(&kb_connection_callback,
         &kb_disconnection_callback,&kb_key_callback);

   input_keymaps_init_keyboard_lut(rarch_key_map_wiiu);

   return wiiu;
}
Esempio n. 10
0
static void *cocoa_input_init(const char *joypad_driver)
{
   cocoa_input_data_t *apple = (cocoa_input_data_t*)calloc(1, sizeof(*apple));
   if (!apple)
      return NULL;
    
   input_keymaps_init_keyboard_lut(rarch_key_map_apple_hid);

   apple->joypad = input_joypad_init_driver(joypad_driver, apple);
    
#ifdef HAVE_MFI
   apple->sec_joypad = input_joypad_init_driver("mfi", apple);
#endif
    
   return apple;
}
Esempio n. 11
0
static void *linuxraw_input_init(void)
{
   linuxraw_input_t *linuxraw;
   struct sigaction sa;

   /* Only work on terminals. */
   if (!isatty(0))
      return NULL;

   if (driver.stdin_claimed)
   {
      RARCH_WARN("stdin is already used for content loading. Cannot use stdin for input.\n");
      return NULL;
   }

   linuxraw = (linuxraw_input_t*)calloc(1, sizeof(*linuxraw));
   if (!linuxraw)
      return NULL;

   if (oldKbmd == 0xffff)
   {
      tcgetattr(0, &oldTerm);
      newTerm = oldTerm;
      newTerm.c_lflag &= ~(ECHO | ICANON | ISIG);
      newTerm.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
      newTerm.c_cc[VMIN] = 0;
      newTerm.c_cc[VTIME] = 0;

      if (ioctl(0, KDGKBMODE, &oldKbmd) != 0)
      {
         free(linuxraw);
         return NULL;
      }
   }

   tcsetattr(0, TCSAFLUSH, &newTerm);

   if (ioctl(0, KDSKBMODE, K_MEDIUMRAW) != 0)
   {
      linuxraw_resetKbmd();
      free(linuxraw);
      return NULL;
   }

   sa.sa_handler = linuxraw_exitGracefully;
   sa.sa_flags = SA_RESTART | SA_RESETHAND;
   sigemptyset(&sa.sa_mask);

   /* Trap some standard termination codes so we 
    * can restore the keyboard before we lose control. */
   sigaction(SIGABRT, &sa, NULL);
   sigaction(SIGBUS, &sa, NULL);
   sigaction(SIGFPE, &sa, NULL);
   sigaction(SIGILL, &sa, NULL);
   sigaction(SIGQUIT, &sa, NULL);
   sigaction(SIGSEGV, &sa, NULL);

   atexit(linuxraw_resetKbmd);

   linuxraw->joypad = input_joypad_init_driver(g_settings.input.joypad_driver);
   input_keymaps_init_keyboard_lut(rarch_key_map_linux);

   /* We need to disable use of stdin command interface if 
    * stdin is supposed to be used for input. */
   driver.stdin_claimed = true; 

   return linuxraw;
}
Esempio n. 12
0
static void *udev_input_init(void)
{
   settings_t *settings = config_get_ptr();
   udev_input_t *udev = (udev_input_t*)calloc(1, sizeof(*udev));

   if (!udev)
      return NULL;

   udev->udev = udev_new();
   if (!udev->udev)
   {
      RARCH_ERR("Failed to create udev handle.\n");
      goto error;
   }

   udev->monitor = udev_monitor_new_from_netlink(udev->udev, "udev");
   if (udev->monitor)
   {
      udev_monitor_filter_add_match_subsystem_devtype(udev->monitor, "input", NULL);
      udev_monitor_enable_receiving(udev->monitor);
   }

#ifdef HAVE_XKBCOMMON
   udev->mod_map_idx = (xkb_mod_index_t *)calloc(MOD_MAP_SIZE, sizeof(xkb_mod_index_t));

   if (!udev->mod_map_idx)
      goto error;

   udev->mod_map_bit = (uint16_t*)calloc(MOD_MAP_SIZE, sizeof(uint16_t));

   if (!udev->mod_map_bit)
      goto error;

   udev->xkb_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
   if (udev->xkb_ctx)
   {
      struct string_list *list = NULL;
      struct xkb_rule_names rule = {0};

      rule.rules = "evdev";

      if (*settings->input.keyboard_layout)
      {
         list = string_split(settings->input.keyboard_layout, ":");
         if (list && list->size >= 2)
            rule.variant = list->elems[1].data;
         if (list && list->size >= 1)
            rule.layout = list->elems[0].data;
      }

      udev->xkb_map = xkb_keymap_new_from_names(udev->xkb_ctx, &rule, XKB_MAP_COMPILE_NO_FLAGS);
      if (list)
         string_list_free(list);
   }
   if (udev->xkb_map)
   {
      xkb_mod_index_t *map_idx = (xkb_mod_index_t*)&udev->mod_map_idx[0];
      uint16_t        *map_bit = (uint16_t*)&udev->mod_map_bit[0];

      udev->xkb_state = xkb_state_new(udev->xkb_map);

      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_CAPS);
      map_idx++;
      *map_bit = RETROKMOD_CAPSLOCK;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_SHIFT);
      map_idx++;
      *map_bit = RETROKMOD_SHIFT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_CTRL);
      map_idx++;
      *map_bit = RETROKMOD_CTRL;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_ALT);
      map_idx++;
      *map_bit = RETROKMOD_ALT;
      map_bit++;
      *map_idx = xkb_keymap_mod_get_index(udev->xkb_map, XKB_MOD_NAME_LOGO);
      *map_bit = RETROKMOD_META;
   }
#endif

   udev->epfd = epoll_create(32);
   if (udev->epfd < 0)
   {
      RARCH_ERR("Failed to create epoll FD.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_KEYBOARD", udev_handle_keyboard))
   {
      RARCH_ERR("Failed to open keyboard.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_MOUSE", udev_handle_mouse))
   {
      RARCH_ERR("Failed to open mouse.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_TOUCHPAD", udev_handle_touchpad))
   {
      RARCH_ERR("Failed to open touchpads.\n");
      goto error;
   }

   /* If using KMS and we forgot this, 
    * we could lock ourselves out completely. */
   if (!udev->num_devices)
      RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");

   udev->joypad = input_joypad_init_driver(settings->input.joypad_driver, udev);
   input_keymaps_init_keyboard_lut(rarch_key_map_linux);

   disable_terminal_input();
   return udev;

error:
   udev_input_free(udev);
   return NULL;
}
Esempio n. 13
0
static void *dinput_init(void)
{
   struct dinput_input *di = NULL;
   settings_t *settings = config_get_ptr();

   if (!dinput_init_context())
   {
      RARCH_ERR("Failed to start DirectInput driver.\n");
      return NULL;
   }

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

#ifdef __cplusplus
   if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, GUID_SysKeyboard, &di->keyboard, NULL)))
   {
      RARCH_ERR("Failed to create keyboard device.\n");
      di->keyboard = NULL;
   }

   if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, GUID_SysMouse, &di->mouse, NULL)))
   {
      RARCH_ERR("Failed to create mouse device.\n");
      di->mouse = NULL;
   }
#else
   if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, &GUID_SysKeyboard, &di->keyboard, NULL)))
   {
      RARCH_ERR("Failed to create keyboard device.\n");
      di->keyboard = NULL;
   }
   if (FAILED(IDirectInput8_CreateDevice(g_dinput_ctx, &GUID_SysMouse, &di->mouse, NULL)))
   {
      RARCH_ERR("Failed to create mouse device.\n");
      di->mouse = NULL;
   }
#endif

   if (di->keyboard)
   {
      IDirectInputDevice8_SetDataFormat(di->keyboard, &c_dfDIKeyboard);
      IDirectInputDevice8_SetCooperativeLevel(di->keyboard,
            (HWND)video_driver_window_get(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
      IDirectInputDevice8_Acquire(di->keyboard);
   }

   if (di->mouse)
   {
      DIDATAFORMAT c_dfDIMouse2_custom = c_dfDIMouse2;

      c_dfDIMouse2_custom.dwFlags = DIDF_ABSAXIS;
      IDirectInputDevice8_SetDataFormat(di->mouse, &c_dfDIMouse2_custom);
      IDirectInputDevice8_SetCooperativeLevel(di->mouse, (HWND)video_driver_window_get(),
            DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
      IDirectInputDevice8_Acquire(di->mouse);
   }

   input_keymaps_init_keyboard_lut(rarch_key_map_dinput);
   di->joypad = input_joypad_init_driver(settings->input.joypad_driver, di);

   return di;
}
Esempio n. 14
0
static void *udev_input_init(const char *joypad_driver)
{
   udev_input_t *udev   = (udev_input_t*)calloc(1, sizeof(*udev));

   if (!udev)
      return NULL;

   udev->udev = udev_new();
   if (!udev->udev)
   {
      RARCH_ERR("Failed to create udev handle.\n");
      goto error;
   }

   udev->monitor = udev_monitor_new_from_netlink(udev->udev, "udev");
   if (udev->monitor)
   {
      udev_monitor_filter_add_match_subsystem_devtype(udev->monitor, "input", NULL);
      udev_monitor_enable_receiving(udev->monitor);
   }

#ifdef HAVE_XKBCOMMON
   if (init_xkb(-1, 0) == -1)
      goto error;
#endif

   if (!epoll_new(&udev->epfd))
   {
      RARCH_ERR("Failed to create epoll FD.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_KEYBOARD", udev_handle_keyboard))
   {
      RARCH_ERR("Failed to open keyboard.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_MOUSE", udev_handle_mouse))
   {
      RARCH_ERR("Failed to open mouse.\n");
      goto error;
   }

   if (!open_devices(udev, "ID_INPUT_TOUCHPAD", udev_handle_touchpad))
   {
      RARCH_ERR("Failed to open touchpads.\n");
      goto error;
   }

   /* If using KMS and we forgot this, 
    * we could lock ourselves out completely. */
   if (!udev->num_devices)
      RARCH_WARN("[udev]: Couldn't open any keyboard, mouse or touchpad. Are permissions set correctly for /dev/input/event*?\n");

   udev->joypad = input_joypad_init_driver(joypad_driver, udev);
   input_keymaps_init_keyboard_lut(rarch_key_map_linux);

   linux_terminal_disable_input();

   return udev;

error:
   udev_input_free(udev);
   return NULL;
}
Esempio n. 15
0
static void *winraw_init(const char *joypad_driver)
{
   bool r;
   winraw_input_t *wr = (winraw_input_t *)
      calloc(1, sizeof(winraw_input_t));
   g_keyboard         = (winraw_keyboard_t*)
      calloc(1, sizeof(winraw_keyboard_t));

   if (!wr || !g_keyboard)
      goto error;

   RARCH_LOG("[WINRAW]: Initializing input driver... \n");

   input_keymaps_init_keyboard_lut(rarch_key_map_winraw);

   wr->window = winraw_create_window(winraw_callback);
   if (!wr->window)
      goto error;

   r = winraw_init_devices(&g_mice, &g_mouse_cnt);
   if (!r)
      goto error;

   if (!g_mouse_cnt)
   {
      RARCH_LOG("[WINRAW]: Mouse unavailable.\n");
   }
   else
   {
      wr->mice = (winraw_mouse_t*)
         malloc(g_mouse_cnt * sizeof(winraw_mouse_t));
      if (!wr->mice)
         goto error;

      memcpy(wr->mice, g_mice, g_mouse_cnt * sizeof(winraw_mouse_t));
   }

   r = winraw_set_keyboard_input(wr->window);
   if (!r)
      goto error;

   r = winraw_set_mouse_input(wr->window, false);
   if (!r)
      goto error;

   wr->joypad = input_joypad_init_driver(joypad_driver, wr);

   return wr;

error:
   if (wr && wr->window)
   {
      winraw_set_mouse_input(NULL, false);
      winraw_set_keyboard_input(NULL);
      winraw_destroy_window(wr->window);
   }
   free(g_keyboard);
   free(g_mice);
   if (wr)
      free(wr->mice);
   free(wr);
   return NULL;
}
Esempio n. 16
0
static void *winraw_init(const char *joypad_driver)
{
   bool r;
   video_viewport_t dst_vid_info;
   struct retro_system_av_info *src_vid_info;
   winraw_input_t *wr = (winraw_input_t *)calloc(1, sizeof(winraw_input_t));
   g_keyboard         = (winraw_keyboard_t*)calloc(1, sizeof(winraw_keyboard_t));

   if (!wr || !g_keyboard)
   {
      WINRAW_ERR("calloc failed.");
      goto error;
   }

   WINRAW_LOG("Initializing input driver ...");

   input_keymaps_init_keyboard_lut(rarch_key_map_winraw);

   wr->window = winraw_create_window(winraw_callback);
   if (!wr->window)
   {
      WINRAW_ERR("winraw_create_window failed.");
      goto error;
   }

   r = winraw_init_devices(&g_mice, &g_mouse_cnt);
   if (!r)
   {
      WINRAW_ERR("winraw_init_devices failed.");
      goto error;
   }

   if (!g_mouse_cnt)
      WINRAW_LOG("Mouse unavailable.");
   else
   {
      wr->mice = (winraw_mouse_t*)malloc(g_mouse_cnt * sizeof(winraw_mouse_t));
      if (!wr->mice)
      {
         WINRAW_ERR("malloc failed.");
         goto error;
      }

      memcpy(wr->mice, g_mice, g_mouse_cnt * sizeof(winraw_mouse_t));
   }

   r = winraw_set_keyboard_input(wr->window);
   if (!r)
   {
      WINRAW_ERR("winraw_set_keyboard_input failed.");
      goto error;
   }

   r = winraw_set_mouse_input(wr->window, false);
   if (!r)
   {
      WINRAW_ERR("winraw_set_mouse_input failed.");
      goto error;
   }

   wr->joypad = input_joypad_init_driver(joypad_driver, wr);

   WINRAW_LOG("Input driver initialized.");
   return wr;

error:
   if (wr && wr->window)
   {
      winraw_set_mouse_input(NULL, false);
      winraw_set_keyboard_input(NULL);
      winraw_destroy_window(wr->window);
   }
   free(g_keyboard);
   free(g_mice);
   if (wr)
      free(wr->mice);
   free(wr);
   WINRAW_ERR("Input driver initialization failed.");
   return NULL;
}