Skip to content

Commit

Permalink
Add is_keyboard,is_pointing_device,is_game_pad into libkrbn_hid_value…
Browse files Browse the repository at this point in the history
…_arrived
  • Loading branch information
tekezo committed Aug 16, 2024
1 parent d2aeb4a commit 0c0c70e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions appendix/GamePadViewer/src/EventObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import SwiftUI

private func callback(
_ deviceId: UInt64,
_ isKeyboard: Bool,
_ isPointingDevice: Bool,
_ isGamePad: Bool,
_ usagePage: Int32,
_ usage: Int32,
_ logicalMax: Int64,
_ logicalMin: Int64,
_ integerValue: Int64
) {
Task { @MainActor in
EventObserver.shared.update(usagePage, usage, logicalMax, logicalMin, integerValue)
if isGamePad {
Task { @MainActor in
EventObserver.shared.update(usagePage, usage, logicalMax, logicalMin, integerValue)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/apps/EventViewer/src/EventHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import SwiftUI

private func callback(
_ deviceId: UInt64,
_ isKeyboard: Bool,
_ isPointingDevice: Bool,
_ isGamePad: Bool,
_ usagePage: Int32,
_ usage: Int32,
_ logicalMax: Int64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class libkrbn_hid_value_monitor final : public pqrs::dispatcher::extra::dispatch
observed_ = true;
});

hid_queue_value_monitor->values_arrived.connect([this, device_id](auto&& values_ptr) {
values_arrived(device_id, values_ptr);
hid_queue_value_monitor->values_arrived.connect([this, device_id, device_properties](auto&& values_ptr) {
values_arrived(device_id,
device_properties,
values_ptr);
});

hid_queue_value_monitor->async_start(kIOHIDOptionsTypeNone,
Expand Down Expand Up @@ -104,6 +106,7 @@ class libkrbn_hid_value_monitor final : public pqrs::dispatcher::extra::dispatch

private:
void values_arrived(krbn::device_id device_id,
gsl::not_null<std::shared_ptr<krbn::device_properties>> device_properties,
std::shared_ptr<std::vector<pqrs::cf::cf_ptr<IOHIDValueRef>>> values) {
for (const auto& value : *values) {
auto v = pqrs::osx::iokit_hid_value(*value);
Expand All @@ -114,6 +117,9 @@ class libkrbn_hid_value_monitor final : public pqrs::dispatcher::extra::dispatch
if (auto logical_min = v.get_logical_min()) {
for (const auto& c : callback_manager_.get_callbacks()) {
c(type_safe::get(device_id),
device_properties->get_is_keyboard().value_or(false),
device_properties->get_is_pointing_device().value_or(false),
device_properties->get_is_game_pad().value_or(false),
type_safe::get(*usage_page),
type_safe::get(*usage),
*logical_max,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/libkrbn/include/libkrbn/libkrbn.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ void libkrbn_enable_hid_value_monitor(void);
void libkrbn_disable_hid_value_monitor(void);

typedef void (*libkrbn_hid_value_arrived)(uint64_t device_id,
bool is_keyboard,
bool is_pointing_device,
bool is_game_pad,
int32_t usage_page,
int32_t usage,
int64_t logical_max,
Expand Down

0 comments on commit 0c0c70e

Please sign in to comment.