The open source OpenXR runtime

st/oxr: Check to see if a dpad path is actually for emulation before assuming it is

This caused issues when implementing an OpenXR interaction profile which natively contained dpad paths.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2486>

authored by

Beyley Cardellio and committed by
Marge Bot
3797d46f 40fcca9b

+41 -5
+41 -5
src/xrt/state_trackers/oxr/oxr_input.c
··· 1505 1505 &action_input->transform_count); // 1506 1506 } 1507 1507 1508 + static bool 1509 + is_dpad_region_for_emulation(const char *start, const char *end) 1510 + { 1511 + // go before the first slash 1512 + end--; 1513 + 1514 + while (end > start) { 1515 + char curr = *end; 1516 + 1517 + // once we find a slash, 1518 + if (curr == '/') { 1519 + const char *to_check[] = {"/thumbstick_", "/thumbstick/", "/trackpad_", "/trackpad/"}; 1520 + 1521 + // check if the passed path is a sub-path of "thumbstick[_|/]" or "trackpad[_|/]" 1522 + for (size_t i = 0; i < ARRAY_SIZE(to_check); i++) { 1523 + if (strncmp(end, to_check[i], strlen(to_check[i])) == 0) { 1524 + // this is for emulation 1525 + return true; 1526 + } 1527 + } 1528 + 1529 + // it's not for emulation and is an actual dpad region 1530 + return false; 1531 + } 1532 + 1533 + end--; 1534 + } 1535 + 1536 + return false; 1537 + } 1538 + 1508 1539 // based on get_subaction_path_from_path 1509 1540 static bool 1510 1541 get_dpad_region_from_path(struct oxr_logger *log, ··· 1522 1553 } 1523 1554 1524 1555 // TODO: surely there's a better way to do this? 1525 - if (length >= 10 && strncmp("/dpad_left", str + (length - 10), 10) == 0) { 1556 + if (length >= 10 && strncmp("/dpad_left", str + (length - 10), 10) == 0 && 1557 + is_dpad_region_for_emulation(str, str + (length - 10))) { 1526 1558 *out_dpad_region = OXR_DPAD_REGION_LEFT; 1527 1559 return true; 1528 1560 } 1529 - if (length >= 11 && strncmp("/dpad_right", str + (length - 11), 11) == 0) { 1561 + if (length >= 11 && strncmp("/dpad_right", str + (length - 11), 11) == 0 && 1562 + is_dpad_region_for_emulation(str, str + (length - 11))) { 1530 1563 *out_dpad_region = OXR_DPAD_REGION_RIGHT; 1531 1564 return true; 1532 1565 } 1533 - if (length >= 8 && strncmp("/dpad_up", str + (length - 8), 8) == 0) { 1566 + if (length >= 8 && strncmp("/dpad_up", str + (length - 8), 8) == 0 && 1567 + is_dpad_region_for_emulation(str, str + (length - 8))) { 1534 1568 *out_dpad_region = OXR_DPAD_REGION_UP; 1535 1569 return true; 1536 1570 } 1537 - if (length >= 10 && strncmp("/dpad_down", str + (length - 10), 10) == 0) { 1571 + if (length >= 10 && strncmp("/dpad_down", str + (length - 10), 10) == 0 && 1572 + is_dpad_region_for_emulation(str, str + (length - 10))) { 1538 1573 *out_dpad_region = OXR_DPAD_REGION_DOWN; 1539 1574 return true; 1540 1575 } 1541 - if (length >= 12 && strncmp("/dpad_center", str + (length - 12), 12) == 0) { 1576 + if (length >= 12 && strncmp("/dpad_center", str + (length - 12), 12) == 0 && 1577 + is_dpad_region_for_emulation(str, str + (length - 12))) { 1542 1578 *out_dpad_region = OXR_DPAD_REGION_CENTER; 1543 1579 return true; 1544 1580 }