Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/core/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ namespace lvh::reports {
std::vector<std::uint8_t> 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 {};
}

Expand Down Expand Up @@ -518,8 +517,7 @@ namespace lvh::reports {
}

GamepadOutput parse_output_report(const DeviceProfile &profile, const std::vector<std::uint8_t> &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();
}

Expand Down
17 changes: 8 additions & 9 deletions src/core/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 9 additions & 10 deletions src/platform/linux/uhid_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ namespace lvh::detail {
const std::filesystem::path &input_root,
const std::filesystem::path &hidraw_root
) {
using enum DeviceNodeKind;

std::vector<DeviceNode> nodes;
if (name.empty()) {
return nodes;
Expand All @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions tests/fixtures/linux_backend_test_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_linux_consumers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down