/* _al_win_joystick_dinput_grab: [window thread]
 * Grabs the joystick devices.
 */
void _al_win_joystick_dinput_grab(void *param)
{
   int i;

   if (!joystick_dinput)
      return;

   /* Release the input from the previous window just in case,
      otherwise set cooperative level will fail. */
   if (win_disp) {
      _al_win_wnd_call_proc(win_disp->window, _al_win_joystick_dinput_unacquire, NULL);
   }

   win_disp = param;

   /* set cooperative level */
   for (i = 0; i < MAX_JOYSTICKS; i++) {
      HRESULT hr;

      if (!joydx_joystick[i].device)
         continue;

      hr = IDirectInputDevice8_SetCooperativeLevel(joydx_joystick[i].device, win_disp->window,
         DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
      if (FAILED(hr)) {
         ALLEGRO_ERROR("IDirectInputDevice8_SetCooperativeLevel failed.\n");
         return;
      }
   }

   joystick_dinput_acquire();
}
Пример #2
0
/* _win_switch_in:
 *  Puts the library in the foreground.
 */
void _win_switch_in(void)
{
   int mode;

   _TRACE(PREFIX_I "switch in\n");

   _win_app_foreground = TRUE;

   key_dinput_acquire();
   mouse_dinput_acquire();
   joystick_dinput_acquire();

   if (win_gfx_driver && win_gfx_driver->switch_in)
      win_gfx_driver->switch_in();

   /* handle switch modes */
   mode = get_display_switch_mode();

   if ((mode == SWITCH_AMNESIA) || (mode == SWITCH_PAUSE)) {
      _TRACE(PREFIX_I "AMNESIA or PAUSE mode recovery\n");
      SetEvent(foreground_event);

      /* restore old priority and wake up */
      SetThreadPriority(allegro_thread, allegro_thread_priority);
   }

   _switch_in();
}
static void joydx_merge(void)
{
   unsigned i;
   HRESULT hr;

   config_needs_merging = false;
   joydx_num_joysticks = 0;

   for (i = 0; i < MAX_JOYSTICKS; i++) {
      ALLEGRO_JOYSTICK_DIRECTX *joy = &joydx_joystick[i];

      switch (joy->config_state) {
         case STATE_UNUSED:
            break;

         case STATE_BORN:
            hr = IDirectInputDevice8_Acquire(joy->device);
            if (FAILED(hr)) {
               ALLEGRO_ERROR("acquire joystick %d failed: %s\n",
                  i, dinput_err_str(hr));
            }
            joy->config_state = STATE_ALIVE;
            /* fall through */
         case STATE_ALIVE:
            JOYSTICK_WAKER(joydx_num_joysticks) = joy->waker_event;
            joydx_num_joysticks++;
            break;

         case STATE_DYING:
            joydx_inactivate_joy(joy);
            break;
      }
   }

   ALLEGRO_INFO("Merged, num joysticks=%d\n", joydx_num_joysticks);

   joystick_dinput_acquire();
}