diff --git a/src/core/report.cpp b/src/core/report.cpp index c7fd178..d90027f 100644 --- a/src/core/report.cpp +++ b/src/core/report.cpp @@ -227,8 +227,7 @@ namespace lvh::reports { std::vector pack_dualsense_input_report(const DeviceProfile &profile, const GamepadState &state) { const auto is_bluetooth = profile.bus_type == BusType::bluetooth; const auto payload_offset = is_bluetooth ? 2U : 1U; - const auto minimum_report_size = is_bluetooth ? 78U : 64U; - if (profile.input_report_size < minimum_report_size) { + if (const auto minimum_report_size = is_bluetooth ? 78U : 64U; profile.input_report_size < minimum_report_size) { return {}; } @@ -518,8 +517,7 @@ namespace lvh::reports { } GamepadOutput parse_output_report(const DeviceProfile &profile, const std::vector &report) { - const auto outputs = parse_output_reports(profile, report); - if (!outputs.empty()) { + if (const auto outputs = parse_output_reports(profile, report); !outputs.empty()) { return outputs.front(); } diff --git a/src/core/runtime.cpp b/src/core/runtime.cpp index c7ab338..2970f9a 100644 --- a/src/core/runtime.cpp +++ b/src/core/runtime.cpp @@ -377,15 +377,14 @@ namespace lvh { OperationStatus Gamepad::dispatch_output(const GamepadOutput &output) { OutputCallback callback; - const auto status = with_device(device_, [&callback](auto &device) { - if (!device.open) { - return OperationStatus::failure(ErrorCode::device_closed, "gamepad is closed"); - } - callback = device.output_callback; - return OperationStatus::success(); - }); - - if (!status.ok()) { + if (const auto status = with_device(device_, [&callback](auto &device) { + if (!device.open) { + return OperationStatus::failure(ErrorCode::device_closed, "gamepad is closed"); + } + callback = device.output_callback; + return OperationStatus::success(); + }); + !status.ok()) { return status; } if (callback) { diff --git a/src/platform/linux/uhid_backend.cpp b/src/platform/linux/uhid_backend.cpp index f532d55..f76c4ed 100644 --- a/src/platform/linux/uhid_backend.cpp +++ b/src/platform/linux/uhid_backend.cpp @@ -393,6 +393,8 @@ namespace lvh::detail { const std::filesystem::path &input_root, const std::filesystem::path &hidraw_root ) { + using enum DeviceNodeKind; + std::vector nodes; if (name.empty()) { return nodes; @@ -403,22 +405,20 @@ namespace lvh::detail { for (std::filesystem::directory_iterator it {input_root, error}, end; !error && it != end; it.increment(error)) { const auto filename = it->path().filename().string(); const auto is_event_node = filename.starts_with("event"); - const auto is_joystick_node = filename.starts_with("js"); - if (!is_event_node && !is_joystick_node) { + if (const auto is_joystick_node = filename.starts_with("js"); !is_event_node && !is_joystick_node) { continue; } - const auto sysfs_name = read_first_line(it->path() / "device" / "name"); - if (!sysfs_name || *sysfs_name != name) { + if (const auto sysfs_name = read_first_line(it->path() / "device" / "name"); !sysfs_name || *sysfs_name != name) { continue; } append_node( nodes, - is_event_node ? DeviceNodeKind::input_event : DeviceNodeKind::joystick, + is_event_node ? input_event : joystick, std::filesystem::path {"/dev/input"} / it->path().filename() ); - append_node(nodes, DeviceNodeKind::sysfs, it->path()); + append_node(nodes, sysfs, it->path()); } } @@ -428,8 +428,8 @@ namespace lvh::detail { continue; } - append_node(nodes, DeviceNodeKind::hidraw, std::filesystem::path {"/dev"} / it->path().filename()); - append_node(nodes, DeviceNodeKind::sysfs, it->path()); + append_node(nodes, hidraw, std::filesystem::path {"/dev"} / it->path().filename()); + append_node(nodes, sysfs, it->path()); } } @@ -749,8 +749,7 @@ namespace lvh::detail { return 0; } - const auto steps = distance / 120; - if (steps != 0) { + if (const auto steps = distance / 120; steps != 0) { return steps; } return distance > 0 ? 1 : -1; diff --git a/tests/fixtures/linux_backend_test_hooks.cpp b/tests/fixtures/linux_backend_test_hooks.cpp index f2babb1..8f7fb7c 100644 --- a/tests/fixtures/linux_backend_test_hooks.cpp +++ b/tests/fixtures/linux_backend_test_hooks.cpp @@ -220,8 +220,8 @@ std::ptrdiff_t lvh_linux_test_write(int fd, const void *buffer, std::size_t size int lvh_linux_test_ioctl(int fd, unsigned long request, unsigned long argument) { if (lvh::detail::test::active_test_syscalls != nullptr && lvh::detail::test::active_test_syscalls->override_ioctl) { - const auto call_count = ++lvh::detail::test::active_test_syscalls->ioctl_call_count; - if (lvh::detail::test::active_test_syscalls->fail_ioctl_call == call_count) { + if (const auto call_count = ++lvh::detail::test::active_test_syscalls->ioctl_call_count; + lvh::detail::test::active_test_syscalls->fail_ioctl_call == call_count) { errno = EINVAL; return -1; } @@ -616,8 +616,7 @@ namespace lvh::detail::test { pollfd descriptor {}; descriptor.fd = fd; descriptor.events = POLLIN; - const auto poll_result = ::poll(&descriptor, 1, 1000); - if (poll_result <= 0 || (descriptor.revents & POLLIN) == 0) { + if (const auto poll_result = ::poll(&descriptor, 1, 1000); poll_result <= 0 || (descriptor.revents & POLLIN) == 0) { return false; } diff --git a/tests/unit/test_linux_consumers.cpp b/tests/unit/test_linux_consumers.cpp index 93f50f8..387618e 100644 --- a/tests/unit/test_linux_consumers.cpp +++ b/tests/unit/test_linux_consumers.cpp @@ -152,8 +152,7 @@ namespace { } bool sdl_joystick_matches_profile(int index, const lvh::DeviceProfile &profile) { - const auto *name = SDL_JoystickNameForIndex(index); - if (name != nullptr && profile.name == name) { + if (const auto *name = SDL_JoystickNameForIndex(index); name != nullptr && profile.name == name) { return true; } @@ -305,9 +304,9 @@ namespace { const auto controller_button_pressed = sdl_controller_has_pressed_button(controller); const auto controller_axis_moved = sdl_controller_has_moved_axis(controller); const auto joystick_button_pressed = joystick != nullptr && sdl_joystick_has_pressed_button(joystick); - const auto joystick_axis_moved = joystick != nullptr && sdl_joystick_has_moved_axis(joystick); - if ((controller_button_pressed || joystick_button_pressed) && (controller_axis_moved || joystick_axis_moved)) { + if (const auto joystick_axis_moved = joystick != nullptr && sdl_joystick_has_moved_axis(joystick); + (controller_button_pressed || joystick_button_pressed) && (controller_axis_moved || joystick_axis_moved)) { return true; }