diff options
Diffstat (limited to 'src/osd/modules/input/input_dinput.h')
-rw-r--r-- | src/osd/modules/input/input_dinput.h | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/osd/modules/input/input_dinput.h b/src/osd/modules/input/input_dinput.h index 2f8331f5e5f..a2b6c2edcbb 100644 --- a/src/osd/modules/input/input_dinput.h +++ b/src/osd/modules/input/input_dinput.h @@ -50,6 +50,12 @@ typedef HRESULT (WINAPI *dinput_create_fn)(HINSTANCE, DWORD, LPDIRECTINPUT8 *, L typedef HRESULT (WINAPI *dinput_create_fn)(HINSTANCE, DWORD, LPDIRECTINPUT *, LPUNKNOWN); #endif +enum class dinput_cooperative_level +{ + FOREGROUND, + BACKGROUND +}; + class dinput_api_helper { private: @@ -74,9 +80,11 @@ public: LPCDIDEVICEINSTANCE instance, LPCDIDATAFORMAT format1, LPCDIDATAFORMAT format2, - DWORD cooperative_level) + dinput_cooperative_level cooperative_level) { HRESULT result; + std::shared_ptr<win_window_info> window; + HWND hwnd; // convert instance name to utf8 std::string utf8_instance_name = osd::text::from_tstring(instance->tszInstanceName); @@ -120,8 +128,33 @@ public: goto error; } + // default window to the first window in the list + window = std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front()); + DWORD di_cooperative_level; + if (window->attached_mode()) + { + // in attached mode we have to ignore the caller and hook up to the desktop window + hwnd = GetDesktopWindow(); + di_cooperative_level = DISCL_BACKGROUND | DISCL_NONEXCLUSIVE; + } + else + { + hwnd = window->platform_window(); + switch (cooperative_level) + { + case dinput_cooperative_level::BACKGROUND: + di_cooperative_level = DISCL_BACKGROUND | DISCL_NONEXCLUSIVE; + break; + case dinput_cooperative_level::FOREGROUND: + di_cooperative_level = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE; + break; + default: + throw false; + } + } + // set the cooperative level - result = devinfo->dinput.device->SetCooperativeLevel(std::static_pointer_cast<win_window_info>(osd_common_t::s_window_list.front())->platform_window(), cooperative_level); + result = devinfo->dinput.device->SetCooperativeLevel(hwnd, di_cooperative_level); if (result != DI_OK) goto error; |