Files
bsnes/ruby/input/windows.cpp
T
Tim Allen 3b4e8b6d75 Update to v106r56 release.
byuu says:

I fixed all outstanding bugs that I'm aware of, including all of the
errata I listed yesterday.

And now it's time for lots of regression testing.

After that, I need to add Talarubi's XAudio2 DRC code, and then get a
new public bsnes WIP out for final testing.

New errata: when setting an icon (nall::image) larger than a Canvas on
Windows, it's not centering the image, so you end up seeing the overscan
area in the state manager previews, and the bottom of the image gets cut
off. I also need to forcefully disable the Xlib screensaver disable
support. I think I'll remove the GUI option to bypass it as well, and
just force screensaver disable always on with Windows. I'll improve it
in the future to toggle the effect between emulator pauses.
2018-08-06 17:46:00 +10:00

95 lines
2.9 KiB
C++

#include <xinput.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "shared/rawinput.cpp"
#include "keyboard/rawinput.cpp"
#include "mouse/rawinput.cpp"
#include "joypad/xinput.cpp"
#include "joypad/directinput.cpp"
struct InputWindows : InputDriver {
InputWindows& self = *this;
InputWindows(Input& super) : InputDriver(super), keyboard(super), mouse(super), joypadXInput(super), joypadDirectInput(super) {}
~InputWindows() { terminate(); }
auto create() -> bool override {
return initialize();
}
auto driver() -> string override { return "Windows"; }
auto ready() -> bool override { return isReady; }
auto hasContext() -> bool override { return true; }
auto setContext(uintptr context) -> bool override { return initialize(); }
auto acquired() -> bool override { return mouse.acquired(); }
auto acquire() -> bool override { return mouse.acquire(); }
auto release() -> bool override { return mouse.release(); }
auto poll() -> vector<shared_pointer<HID::Device>> override {
vector<shared_pointer<HID::Device>> devices;
keyboard.poll(devices);
mouse.poll(devices);
joypadXInput.poll(devices);
joypadDirectInput.poll(devices);
return devices;
}
auto rumble(uint64_t id, bool enable) -> bool override {
if(joypadXInput.rumble(id, enable)) return true;
if(joypadDirectInput.rumble(id, enable)) return true;
return false;
}
private:
auto initialize() -> bool {
terminate();
if(!self.context) return false;
//TODO: this won't work if Input is recreated post-initialization; nor will it work with multiple Input instances
if(!rawinput.initialized) {
rawinput.initialized = true;
rawinput.mutex = CreateMutex(nullptr, false, nullptr);
CreateThread(nullptr, 0, RawInputThreadProc, 0, 0, nullptr);
do {
Sleep(1);
WaitForSingleObject(rawinput.mutex, INFINITE);
ReleaseMutex(rawinput.mutex);
} while(!rawinput.ready);
}
DirectInput8Create(GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&directInputContext, 0);
if(!directInputContext) return false;
if(!keyboard.initialize()) return false;
if(!mouse.initialize(self.context)) return false;
bool xinputAvailable = joypadXInput.initialize();
if(!joypadDirectInput.initialize(self.context, directInputContext, xinputAvailable)) return false;
return isReady = true;
}
auto terminate() -> void {
isReady = false;
keyboard.terminate();
mouse.terminate();
joypadXInput.terminate();
joypadDirectInput.terminate();
if(directInputContext) {
directInputContext->Release();
directInputContext = nullptr;
}
}
bool isReady = false;
InputKeyboardRawInput keyboard;
InputMouseRawInput mouse;
InputJoypadXInput joypadXInput;
InputJoypadDirectInput joypadDirectInput;
LPDIRECTINPUT8 directInputContext = nullptr;
};