<commit_before>#include "base.hpp"
#include "EventOutputQueue.hpp"
#include "FlagStatus.hpp"
#include "UserClient_kext.hpp"
#include "VK_CONFIG.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  VirtualKey::VK_CONFIG::Vector_Item* VirtualKey::VK_CONFIG::items_ = NULL;

  void
  VirtualKey::VK_CONFIG::initialize(void)
  {
    items_ = new Vector_Item();
  }

  void
  VirtualKey::VK_CONFIG::terminate(void)
  {
    if (items_) {
      delete items_;
    }
  }

  void
  VirtualKey::VK_CONFIG::add_item(RemapClass* remapclass,
                                  unsigned int keycode_toggle,
                                  unsigned int keycode_force_on,
                                  unsigned int keycode_force_off,
                                  unsigned int keycode_sync_keydownup)
  {
    if (! items_) return;

    items_->push_back(Item(remapclass, keycode_toggle, keycode_force_on, keycode_force_off, keycode_sync_keydownup));
  }

  void
  VirtualKey::VK_CONFIG::clear_items(void)
  {
    items_->clear();
  }

  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:<commit_msg>improved repeated key handing @ VK_CONFIG<commit_after>#include "base.hpp"
#include "EventOutputQueue.hpp"
#include "FlagStatus.hpp"
#include "UserClient_kext.hpp"
#include "VK_CONFIG.hpp"

namespace org_pqrs_KeyRemap4MacBook {
  VirtualKey::VK_CONFIG::Vector_Item* VirtualKey::VK_CONFIG::items_ = NULL;

  void
  VirtualKey::VK_CONFIG::initialize(void)
  {
    items_ = new Vector_Item();
  }

  void
  VirtualKey::VK_CONFIG::terminate(void)
  {
    if (items_) {
      delete items_;
    }
  }

  void
  VirtualKey::VK_CONFIG::add_item(RemapClass* remapclass,
                                  unsigned int keycode_toggle,
                                  unsigned int keycode_force_on,
                                  unsigned int keycode_force_off,
                                  unsigned int keycode_sync_keydownup)
  {
    if (! items_) return;

    items_->push_back(Item(remapclass, keycode_toggle, keycode_force_on, keycode_force_off, keycode_sync_keydownup));
  }

  void
  VirtualKey::VK_CONFIG::clear_items(void)
  {
    items_->clear();
  }

  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.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:
{'fraction_non_alphanumeric': 0.10621662852784135, 'fraction_numerical': 0.0007627765064836003, 'mean_word_length': 2.286340852130326, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3090757', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1631, 'n_words': 302}