74 lines
2.8 KiB
C
74 lines
2.8 KiB
C
|
|
//SPDX-License-Identifier: LGPL-3.0-only
|
||
|
|
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
// The C side of the Win32 gamepad backend (Crafter.Graphics-GamepadWin32.c):
|
||
|
|
// Windows.Gaming.Input, through its C interface. mingw-w64's generated WinRT
|
||
|
|
// headers declare that interface only to C; in C++ they declare the ABI
|
||
|
|
// templates instead, and mingw-w64 14's windows.foundation.h doesn't compile
|
||
|
|
// as C++ (IReference<boolean> and IReference<BYTE> are one type). Gamepad.cpp
|
||
|
|
// drives it from the event loop's thread; only the connect and disconnect
|
||
|
|
// notifications arrive on another, and they just queue.
|
||
|
|
#ifndef CRAFTER_GRAPHICS_GAMEPAD_WIN32_H
|
||
|
|
#define CRAFTER_GRAPHICS_GAMEPAD_WIN32_H
|
||
|
|
|
||
|
|
#include <stddef.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
// A connected gamepad: Windows.Gaming.Input's IGamepad.
|
||
|
|
typedef struct CrafterWgiGamepad CrafterWgiGamepad;
|
||
|
|
|
||
|
|
typedef struct CrafterWgiEvent {
|
||
|
|
int added; // nonzero for a connect, zero for a disconnect
|
||
|
|
CrafterWgiGamepad* gamepad; // holds a reference, which CrafterWgiRelease drops
|
||
|
|
} CrafterWgiEvent;
|
||
|
|
|
||
|
|
// A GamepadReading. `buttons` holds GamepadButtons bits, named below.
|
||
|
|
typedef struct CrafterWgiReading {
|
||
|
|
uint32_t buttons;
|
||
|
|
double leftTrigger;
|
||
|
|
double rightTrigger;
|
||
|
|
double leftStickX;
|
||
|
|
double leftStickY;
|
||
|
|
double rightStickX;
|
||
|
|
double rightStickY;
|
||
|
|
} CrafterWgiReading;
|
||
|
|
|
||
|
|
enum {
|
||
|
|
CRAFTER_WGI_BUTTON_MENU = 0x1,
|
||
|
|
CRAFTER_WGI_BUTTON_VIEW = 0x2,
|
||
|
|
CRAFTER_WGI_BUTTON_A = 0x4,
|
||
|
|
CRAFTER_WGI_BUTTON_B = 0x8,
|
||
|
|
CRAFTER_WGI_BUTTON_X = 0x10,
|
||
|
|
CRAFTER_WGI_BUTTON_Y = 0x20,
|
||
|
|
CRAFTER_WGI_BUTTON_DPAD_UP = 0x40,
|
||
|
|
CRAFTER_WGI_BUTTON_DPAD_DOWN = 0x80,
|
||
|
|
CRAFTER_WGI_BUTTON_DPAD_LEFT = 0x100,
|
||
|
|
CRAFTER_WGI_BUTTON_DPAD_RIGHT = 0x200,
|
||
|
|
CRAFTER_WGI_BUTTON_LEFT_SHOULDER = 0x400,
|
||
|
|
CRAFTER_WGI_BUTTON_RIGHT_SHOULDER = 0x800,
|
||
|
|
CRAFTER_WGI_BUTTON_LEFT_THUMBSTICK = 0x1000,
|
||
|
|
CRAFTER_WGI_BUTTON_RIGHT_THUMBSTICK = 0x2000,
|
||
|
|
};
|
||
|
|
|
||
|
|
// Starts listening for gamepads the first time it is called. Nonzero when
|
||
|
|
// Windows.Gaming.Input is available, every time.
|
||
|
|
int CrafterWgiStart(void);
|
||
|
|
// Moves up to `capacity` of the connects and disconnects that came in since
|
||
|
|
// the last call into `out`, oldest first, and returns how many it moved.
|
||
|
|
size_t CrafterWgiTakeEvents(CrafterWgiEvent* out, size_t capacity);
|
||
|
|
// The gamepad's current state; nonzero on success.
|
||
|
|
int CrafterWgiRead(CrafterWgiGamepad* gamepad, CrafterWgiReading* out);
|
||
|
|
// Sets the two rumble motors, each 0..1, until set again.
|
||
|
|
void CrafterWgiVibrate(CrafterWgiGamepad* gamepad, double low, double high);
|
||
|
|
// Drops the reference an event handed over.
|
||
|
|
void CrafterWgiRelease(CrafterWgiGamepad* gamepad);
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif
|