/* _win_switch_out: * Puts the library in the background. */ void _win_switch_out(void) { int mode; _TRACE(PREFIX_I "switch out\n"); _win_app_foreground = FALSE; key_dinput_unacquire(); mouse_dinput_unacquire(); joystick_dinput_unacquire(); midi_switch_out(); if (win_gfx_driver && win_gfx_driver->switch_out) win_gfx_driver->switch_out(); /* handle switch modes */ mode = get_display_switch_mode(); if ((mode == SWITCH_AMNESIA) || (mode == SWITCH_PAUSE)) { _TRACE(PREFIX_I "AMNESIA or PAUSE mode suspension\n"); ResetEvent(foreground_event); /* if the thread doesn't stop, lower its priority only if another window is active */ allegro_thread_priority = GetThreadPriority(allegro_thread); if ((HINSTANCE)GetWindowLong(GetForegroundWindow(), GWL_HINSTANCE) != allegro_inst) SetThreadPriority(allegro_thread, THREAD_PRIORITY_LOWEST); } _switch_out(); }
/* mouse_dinput_grab: [window thread] * Grabs the mouse device. */ int mouse_dinput_grab(void) { HRESULT hr; DWORD level; HWND allegro_wnd = win_get_window(); if (mouse_dinput_device) { /* necessary in order to set the cooperative level */ mouse_dinput_unacquire(); if (gfx_driver && !gfx_driver->windowed) { level = DISCL_FOREGROUND | DISCL_EXCLUSIVE; _TRACE(PREFIX_I "foreground exclusive cooperative level requested for mouse\n"); } else { level = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE; _TRACE(PREFIX_I "foreground non-exclusive cooperative level requested for mouse\n"); } /* set cooperative level */ hr = IDirectInputDevice_SetCooperativeLevel(mouse_dinput_device, allegro_wnd, level); if (FAILED(hr)) { _TRACE(PREFIX_E "set cooperative level failed: %s\n", dinput_err_str(hr)); return -1; } mouse_dinput_acquire(); /* update the system cursor */ mouse_set_syscursor(); return 0; } else { /* update the system cursor */ mouse_set_syscursor(); return -1; } }