Skip to content

Commit

Permalink
Move event_queue::event::type::caps_lock_state_changed handling to va…
Browse files Browse the repository at this point in the history
…lues_arrived method
  • Loading branch information
tekezo committed May 2, 2024
1 parent 0600a6b commit 441fec4
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions src/core/grabber/include/grabber/device_grabber.hpp
Expand Up @@ -227,28 +227,15 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
entries_[device_id] = entry;

entry->hid_queue_values_arrived.connect([this](auto&& entry, auto&& event_queue, auto&& hid_values) {
if (entry.is_karabiner_virtual_hid_device()) {
// Handle caps_lock_state_changed event only if the hid is Karabiner-DriverKit-VirtualHIDDevice.
for (const auto& e : event_queue->get_entries()) {
if (e.get_event().get_type() == event_queue::event::type::caps_lock_state_changed) {
if (auto state = e.get_event().get_integer_value()) {
last_caps_lock_state_ = *state;
post_caps_lock_state_changed_event(*state);
update_caps_lock_led();
}
}
}
} else {
values_arrived(entry, event_queue);
values_arrived(entry, event_queue);

//
// game pad stick to pointing motion
//
//
// game pad stick to pointing motion
//

if (entry.seized()) {
game_pad_stick_converter_->convert(entry.get_device_properties(),
hid_values);
}
if (entry.seized()) {
game_pad_stick_converter_->convert(entry.get_device_properties(),
hid_values);
}
});

Expand Down Expand Up @@ -662,40 +649,53 @@ class device_grabber final : public pqrs::dispatcher::extra::dispatcher_client {
// This method is executed in the shared dispatcher thread.
void values_arrived(device_grabber_details::entry& entry,
std::shared_ptr<event_queue::queue> event_queue) {
// Manipulate events

bool needs_regrab = false;
bool notify = false;

for (const auto& e : event_queue->get_entries()) {
if (auto ev = e.get_event().get_if<momentary_switch_event>()) {
needs_regrab |= entry.get_probable_stuck_events_manager()->update(
*ev,
e.get_event_type(),
entry.seized() ? device_state::seized
: device_state::observed);
if (entry.is_karabiner_virtual_hid_device()) {
// Handle caps_lock_state_changed event only if the hid is Karabiner-DriverKit-VirtualHIDDevice.
for (const auto& e : event_queue->get_entries()) {
if (e.get_event().get_type() == event_queue::event::type::caps_lock_state_changed) {
if (auto state = e.get_event().get_integer_value()) {
last_caps_lock_state_ = *state;
post_caps_lock_state_changed_event(*state);
update_caps_lock_led();
}
}
}
} else {
// Manipulate events

bool needs_regrab = false;
bool notify = false;

for (const auto& e : event_queue->get_entries()) {
if (auto ev = e.get_event().get_if<momentary_switch_event>()) {
needs_regrab |= entry.get_probable_stuck_events_manager()->update(
*ev,
e.get_event_type(),
entry.seized() ? device_state::seized
: device_state::observed);
}

if (!entry.get_disabled() && entry.seized()) {
event_queue::entry qe(e.get_device_id(),
e.get_event_time_stamp(),
e.get_event(),
e.get_event_type(),
e.get_original_event(),
e.get_state());
if (!entry.get_disabled() && entry.seized()) {
event_queue::entry qe(e.get_device_id(),
e.get_event_time_stamp(),
e.get_event(),
e.get_event_type(),
e.get_original_event(),
e.get_state());

merged_input_event_queue_->push_back_entry(qe);
merged_input_event_queue_->push_back_entry(qe);

notify = true;
notify = true;
}
}
}

if (needs_regrab) {
grab_device(entry);
}
if (needs_regrab) {
grab_device(entry);
}

if (notify) {
krbn_notification_center::get_instance().enqueue_input_event_arrived(*this);
if (notify) {
krbn_notification_center::get_instance().enqueue_input_event_arrived(*this);
}
}
}

Expand Down

0 comments on commit 441fec4

Please sign in to comment.