diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index cc68370..4d6b83c 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -223,8 +223,7 @@ void StreamSession::SendFeedbackState() } #endif - state.buttons |= keyboard_state.buttons; - + chiaki_controller_state_or(&state, &state, &keyboard_state); chiaki_session_set_controller_state(&session, &state); } diff --git a/lib/include/chiaki/controller.h b/lib/include/chiaki/controller.h index 4b744ac..0239c6c 100644 --- a/lib/include/chiaki/controller.h +++ b/lib/include/chiaki/controller.h @@ -85,6 +85,8 @@ static inline bool chiaki_controller_state_equals(ChiakiControllerState *a, Chia && a->right_y == b->right_y; } +CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b); + #ifdef __cplusplus } #endif diff --git a/lib/src/controller.c b/lib/src/controller.c index 5be5b1f..f71371c 100644 --- a/lib/src/controller.c +++ b/lib/src/controller.c @@ -25,3 +25,18 @@ CHIAKI_EXPORT void chiaki_controller_state_set_idle(ChiakiControllerState *state state->right_x = 0; state->right_y = 0; } + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define ABS(a) ((a) > 0 ? (a) : -(a)) +#define MAX_ABS(a, b) (ABS(a) > ABS(b) ? (a) : (b)) + +CHIAKI_EXPORT void chiaki_controller_state_or(ChiakiControllerState *out, ChiakiControllerState *a, ChiakiControllerState *b) +{ + out->buttons = a->buttons | b->buttons; + out->l2_state = MAX(a->l2_state, b->l2_state); + out->r2_state = MAX(a->r2_state, b->r2_state); + out->left_x = MAX_ABS(a->left_x, b->left_x); + out->left_y = MAX_ABS(a->left_y, b->left_y); + out->right_x = MAX_ABS(a->right_x, b->right_x); + out->right_y = MAX_ABS(a->right_y, b->right_y); +}