Apply clang-format across the whole tree
Run clang-format (the repo's .clang-format: LLVM base, 120 cols, tabs, Allman functions) over every source file so the tree is formatter-clean. Whitespace only -- no behavior change; full x64 + x86 suites pass. Also set SortIncludes: false in .clang-format. Windows include order is load-bearing (windows.h must precede tlhelp32.h / mmreg.h / xinput.h / dinput.h; winsock2.h must precede windows.h), and the default alphabetical sort reorders tlhelp32.h ahead of windows.h -- a build break. Leaving order alone keeps the manual, correct grouping.
This commit is contained in:
@@ -23,14 +23,12 @@
|
||||
|
||||
using namespace coop;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
int g_failures = 0;
|
||||
void check(bool ok, const char* what)
|
||||
{
|
||||
std::printf("%s %s\n", ok ? " ok:" : "FAIL:", what);
|
||||
if (!ok)
|
||||
{
|
||||
if (!ok) {
|
||||
++g_failures;
|
||||
}
|
||||
}
|
||||
@@ -44,8 +42,8 @@ HWND make_window()
|
||||
wc.hInstance = GetModuleHandleW(nullptr);
|
||||
wc.lpszClassName = L"coop_dinput_test";
|
||||
RegisterClassExW(&wc);
|
||||
return CreateWindowExW(0, wc.lpszClassName, L"", WS_OVERLAPPEDWINDOW, 0, 0, 16, 16, nullptr, nullptr,
|
||||
wc.hInstance, nullptr);
|
||||
return CreateWindowExW(0, wc.lpszClassName, L"", WS_OVERLAPPEDWINDOW, 0, 0, 16, 16, nullptr, nullptr, wc.hInstance,
|
||||
nullptr);
|
||||
}
|
||||
|
||||
// Create + acquire a DI device of `kind` (GUID_SysKeyboard / GUID_SysMouse) with `fmt`. Returns null
|
||||
@@ -53,13 +51,11 @@ HWND make_window()
|
||||
IDirectInputDevice8W* make_device(IDirectInput8W* di, const GUID& kind, const DIDATAFORMAT* fmt, HWND hwnd)
|
||||
{
|
||||
IDirectInputDevice8W* dev = nullptr;
|
||||
if (FAILED(di->CreateDevice(kind, &dev, nullptr)) || dev == nullptr)
|
||||
{
|
||||
if (FAILED(di->CreateDevice(kind, &dev, nullptr)) || dev == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (FAILED(dev->SetDataFormat(fmt)) ||
|
||||
FAILED(dev->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)) || FAILED(dev->Acquire()))
|
||||
{
|
||||
if (FAILED(dev->SetDataFormat(fmt)) || FAILED(dev->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))
|
||||
|| FAILED(dev->Acquire())) {
|
||||
dev->Release();
|
||||
return nullptr;
|
||||
}
|
||||
@@ -73,8 +69,7 @@ int main()
|
||||
|
||||
// Host side: the IPC block + a couple of forwarded events.
|
||||
SharedMemory shm;
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock)))
|
||||
{
|
||||
if (!shm.create(shared_memory_name(GetCurrentProcessId()), sizeof(SharedBlock))) {
|
||||
std::printf("Could not create shared memory -- skipping.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -99,35 +94,30 @@ int main()
|
||||
|
||||
IDirectInput8W* di = nullptr;
|
||||
if (FAILED(DirectInput8Create(GetModuleHandleW(nullptr), DIRECTINPUT_VERSION, IID_IDirectInput8W,
|
||||
reinterpret_cast<void**>(&di), nullptr)) ||
|
||||
di == nullptr)
|
||||
{
|
||||
reinterpret_cast<void**>(&di), nullptr))
|
||||
|| di == nullptr) {
|
||||
std::printf("DirectInput8Create failed -- skipping.\n");
|
||||
hook::remove_mkb_hooks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Keyboard: GetDeviceState must show our forwarded key (at its DIK = scan code).
|
||||
if (IDirectInputDevice8W* kbd = make_device(di, GUID_SysKeyboard, &c_dfDIKeyboard, hwnd))
|
||||
{
|
||||
if (IDirectInputDevice8W* kbd = make_device(di, GUID_SysKeyboard, &c_dfDIKeyboard, hwnd)) {
|
||||
BYTE keys[256] = {};
|
||||
const HRESULT hr = kbd->GetDeviceState(sizeof(keys), keys);
|
||||
const BYTE dik = static_cast<BYTE>(MapVirtualKeyW(vk, MAPVK_VK_TO_VSC) & 0xFF);
|
||||
std::printf(" keyboard GetDeviceState hr=0x%08lX dik=0x%02X state=0x%02X\n",
|
||||
static_cast<unsigned long>(hr), dik, keys[dik]);
|
||||
std::printf(" keyboard GetDeviceState hr=0x%08lX dik=0x%02X state=0x%02X\n", static_cast<unsigned long>(hr),
|
||||
dik, keys[dik]);
|
||||
check(SUCCEEDED(hr), "keyboard GetDeviceState succeeded");
|
||||
check((keys[dik] & 0x80) != 0, "forwarded 'A' appears in the DirectInput keyboard state");
|
||||
kbd->Unacquire();
|
||||
kbd->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::printf(" keyboard device unavailable -- skipping keyboard assertion.\n");
|
||||
}
|
||||
|
||||
// Mouse: GetDeviceState must show our forwarded left button.
|
||||
if (IDirectInputDevice8W* ms = make_device(di, GUID_SysMouse, &c_dfDIMouse, hwnd))
|
||||
{
|
||||
if (IDirectInputDevice8W* ms = make_device(di, GUID_SysMouse, &c_dfDIMouse, hwnd)) {
|
||||
DIMOUSESTATE m{};
|
||||
const HRESULT hr = ms->GetDeviceState(sizeof(m), &m);
|
||||
std::printf(" mouse GetDeviceState hr=0x%08lX btn0=0x%02X\n", static_cast<unsigned long>(hr),
|
||||
@@ -136,20 +126,16 @@ int main()
|
||||
check((m.rgbButtons[0] & 0x80) != 0, "forwarded left button appears in the DirectInput mouse state");
|
||||
ms->Unacquire();
|
||||
ms->Release();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
std::printf(" mouse device unavailable -- skipping mouse assertion.\n");
|
||||
}
|
||||
|
||||
di->Release();
|
||||
hook::remove_mkb_hooks();
|
||||
if (hwnd != nullptr)
|
||||
{
|
||||
if (hwnd != nullptr) {
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
if (com)
|
||||
{
|
||||
if (com) {
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user