api: check for window focus when accepting input (#317)

## Link to GitHub Issue, if one exists
Fixes #139 

## Description of change
Add an option for detecting window focus when accepting input.

The new default will be to have the following:
 * naive bindings will check for window focus
* rawinput binds are not affected, will continue to be accepted
regardless of focus

Other options (always / never choices) can be picked by the user to
tweak the behavior if needed.

Clean up usage of `0xff` constant to represent invalid naive vkey.

## Testing
Still in progress, especially in regards to performance.

On a i7-9700 system, 10000 calls to `superexit::has_focus()` takes
250-350 microseconds, so this should not be a big deal at all.
This commit is contained in:
bicarus-dev
2025-05-07 13:22:29 -07:00
committed by GitHub
parent 6e7bf99af8
commit 26ea8a1b92
8 changed files with 75 additions and 9 deletions
+6 -4
View File
@@ -33,12 +33,14 @@ enum ButtonAnalogType {
extern const char *ButtonAnalogTypeStr[];
constexpr unsigned short INVALID_VKEY = UINT16_C(0xFF);
class Button {
private:
std::vector<Button> alternatives;
std::string name;
std::string device_identifier = "";
unsigned short vKey = 0xFF;
unsigned short vKey = INVALID_VKEY;
ButtonAnalogType analog_type = BAT_NONE;
double debounce_up = 0.0;
double debounce_down = 0.0;
@@ -68,12 +70,12 @@ public:
if (this->override_enabled) {
return true;
}
if (this->vKey != 0xFF) {
if (this->vKey != INVALID_VKEY) {
return true;
}
for (auto &alternative : this->alternatives) {
if (alternative.vKey != 0xFF) {
if (alternative.vKey != INVALID_VKEY) {
return true;
}
}
@@ -82,7 +84,7 @@ public:
}
inline void clearBindings() {
vKey = 0xFF;
vKey = INVALID_VKEY;
alternatives.clear();
device_identifier = "";
analog_type = BAT_NONE;