bool VirtualKey::VK_CONFIG::handle(const Params_KeyboardEventCallBack& params, AutogenId autogenId) { RemapClass* remapclass = nullptr; bool value_old = false; for (size_t i = 0; i < items_.size(); ++i) { remapclass = items_[i].remapclass; KeyCode keycode_toggle(items_[i].keycode_toggle); KeyCode keycode_force_on(items_[i].keycode_force_on); KeyCode keycode_force_off(items_[i].keycode_force_off); KeyCode keycode_sync_keydownup(items_[i].keycode_sync_keydownup); if (!remapclass) return false; value_old = remapclass->enabled(); if (params.key == keycode_toggle) { if (params.repeat) goto finish; if (params.ex_iskeydown) { remapclass->toggleEnabled(); goto refresh; } goto finish; } else if (params.key == keycode_force_on) { if (params.repeat) goto finish; if (params.ex_iskeydown) { remapclass->setEnabled(true); goto refresh; } goto finish; } else if (params.key == keycode_force_off) { if (params.repeat) goto finish; if (params.ex_iskeydown) { remapclass->setEnabled(false); goto refresh; } goto finish; } else if (params.key == keycode_sync_keydownup) { if (params.repeat) goto finish; if (params.ex_iskeydown) { remapclass->setEnabled(true); } else { remapclass->setEnabled(false); } goto refresh; } } return false; refresh: if (remapclass) { bool value_new = remapclass->enabled(); // * send_notification_to_userspace takes a time. // * VK_CONFIG_FORCE_OFF_* might not change remapclass state. // Therefore, we call send_notification_to_userspace only if needed. if (value_old != value_new) { RemapClassManager::refresh(); // Tell remapclass status is changed to userspace. org_pqrs_driver_Karabiner_UserClient_kext::send_notification_to_userspace(BRIDGE_USERCLIENT_NOTIFICATION_TYPE_CONFIG_ENABLED_UPDATED, remapclass->get_configindex()); } } finish: EventOutputQueue::FireModifiers::fire(); return true; }
bool VirtualKey::VK_CONFIG::handle(const Params_KeyboardEventCallBack& params) { if (! items_) return false; RemapClass* remapclass = NULL; for (size_t i = 0; i < items_->size(); ++i) { remapclass = (*items_)[i].remapclass; unsigned int keycode_toggle = (*items_)[i].keycode_toggle; unsigned int keycode_force_on = (*items_)[i].keycode_force_on; unsigned int keycode_force_off = (*items_)[i].keycode_force_off; unsigned int keycode_sync_keydownup = (*items_)[i].keycode_sync_keydownup; if (! remapclass) return false; if (params.ex_iskeydown && params.repeat == false) { /* */ if (params.key == keycode_toggle) { remapclass->toggleEnabled(); goto refresh; } else if (params.key == keycode_force_on) { remapclass->setEnabled(true); goto refresh; } else if (params.key == keycode_force_off) { remapclass->setEnabled(false); goto refresh; } else if (params.key == keycode_sync_keydownup) { remapclass->setEnabled(true); goto refresh; } } else if (params.eventType == EventType::UP) { if (params.key == keycode_toggle || params.key == keycode_force_on || params.key == keycode_force_off) { goto finish; } if (params.key == keycode_sync_keydownup) { remapclass->setEnabled(false); goto refresh; } } } return false; refresh: RemapClassManager::refresh(); // Tell remapclass status is changed to userspace. if (remapclass) { org_pqrs_driver_KeyRemap4MacBook_UserClient_kext::send_notification_to_userspace(BRIDGE_USERCLIENT_NOTIFICATION_TYPE_CONFIG_ENABLED_UPDATED, remapclass->get_configindex()); } finish: EventOutputQueue::FireModifiers::fire(); return true; }