void
    ConsumerToConsumer::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_CONSUMERKEYCODE:
        {
          switch (index_) {
            case 0:
              fromKey_.key = ConsumerKeyCode(newval);
              break;
            default:
              toKeys_.push_back(PairConsumerKeyFlags(ConsumerKeyCode(newval)));
              break;
          }
          ++index_;

          break;
        }

        case BRIDGE_DATATYPE_FLAGS:
        {
          switch (index_) {
            case 0:
              IOLOG_ERROR("Invalid ConsumerToConsumer::add\n");
              break;
            case 1:
              fromKey_.flags = Flags(newval);
              break;
            default:
              if (! toKeys_.empty()) {
                toKeys_.back().flags = Flags(newval);
              }
              break;
          }
          break;
        }

        case BRIDGE_DATATYPE_OPTION:
        {
          if (Option::NOREPEAT == Option(newval)) {
            isRepeatEnabled_ = false;
          } else {
            IOLOG_ERROR("ConsumerToConsumer::add unknown option:%d\n", newval);
          }
          break;
        }

        default:
          IOLOG_ERROR("ConsumerToConsumer::add invalid datatype:%d\n", datatype);
          break;
      }
    }
// ----------------------------------------------------------------------
void EventInputQueue::push_KeyboardSpecialEventCallback(OSObject* target,
                                                        unsigned int eventType,
                                                        unsigned int flags,
                                                        unsigned int key,
                                                        unsigned int flavor,
                                                        UInt64 guid,
                                                        bool repeat,
                                                        AbsoluteTime ts,
                                                        OSObject* sender,
                                                        void* refcon) {
  GlobalLock::ScopedLock lk;
  if (!lk) return;

  Params_KeyboardSpecialEventCallback::log(true, EventType(eventType), Flags(flags), ConsumerKeyCode(key), flavor, guid, repeat);

  // ------------------------------------------------------------
  Params_KeyboardSpecialEventCallback params(EventType(eventType),
                                             Flags(flags),
                                             ConsumerKeyCode(key),
                                             flavor, guid, repeat);

  // ------------------------------------------------------------
  IOHIKeyboard* device = OSDynamicCast(IOHIKeyboard, sender);
  if (!device) return;

  ListHookedConsumer::Item* item = static_cast<ListHookedConsumer::Item*>(ListHookedConsumer::instance().get(device));
  if (!item) return;

  // ------------------------------------------------------------
  // Device Hacks

  // Drop events if "Disable an internal keyboard while external keyboards are connected" is enabled.
  if (Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_disable_internal_keyboard_if_external_keyboard_exsits)) {
    if (item->isInternalDevice() &&
        ListHookedKeyboard::instance().isExternalDevicesConnected()) {
      return;
    }
  }

  // ------------------------------------------------------------
  CommonData::setcurrent_ts(ts);

  // ------------------------------------------------------------
  // Because we handle the key repeat ourself, drop the key repeat by hardware.
  if (repeat) return;

  // ------------------------------------------------------------
  bool retainFlagStatusTemporaryCount = false;
  enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());

  setTimer();
}
Exemple #3
0
 ToEvent(unsigned int datatype, unsigned int v) {
   switch (datatype) {
   case BRIDGE_DATATYPE_KEYCODE:
     type_ = Type::KEY;
     key_ = KeyCode(v);
     break;
   case BRIDGE_DATATYPE_CONSUMERKEYCODE:
     type_ = Type::CONSUMER_KEY;
     consumer_ = ConsumerKeyCode(v);
     break;
   case BRIDGE_DATATYPE_POINTINGBUTTON:
     type_ = Type::POINTING_BUTTON;
     button_ = PointingButton(v);
     break;
   default:
     IOLOG_ERROR("Unknown datatype: %d\n", datatype);
     type_ = Type::NONE;
     break;
   }
 }
 FromEvent(AddDataType datatype, AddValue v) : isPressing_(false) {
   switch (datatype) {
     case BRIDGE_DATATYPE_KEYCODE:         type_ = Type::KEY;             key_      = KeyCode(v);         break;
     case BRIDGE_DATATYPE_CONSUMERKEYCODE: type_ = Type::CONSUMER_KEY;    consumer_ = ConsumerKeyCode(v); break;
     case BRIDGE_DATATYPE_POINTINGBUTTON:  type_ = Type::POINTING_BUTTON; button_   = PointingButton(v);  break;
     default:
       IOLOG_ERROR("Unknown datatype: %u\n", static_cast<unsigned int>(datatype));
       type_ = Type::NONE;
       break;
   }
 }
  // ----------------------------------------------------------------------
  void
  EventInputQueue::push_KeyboardSpecialEventCallback(OSObject* target,
                                                     unsigned int eventType,
                                                     unsigned int flags,
                                                     unsigned int key,
                                                     unsigned int flavor,
                                                     UInt64 guid,
                                                     bool repeat,
                                                     AbsoluteTime ts,
                                                     OSObject* sender,
                                                     void* refcon)
  {
    GlobalLock::ScopedLock lk;
    if (! lk) return;

    Params_KeyboardSpecialEventCallback::log(true, EventType(eventType), Flags(flags), ConsumerKeyCode(key), flavor, guid, repeat);

    // ------------------------------------------------------------
    Params_KeyboardSpecialEventCallback::auto_ptr ptr(Params_KeyboardSpecialEventCallback::alloc(EventType(eventType), Flags(flags), ConsumerKeyCode(key),
                                                                                                 flavor, guid, repeat));
    if (! ptr) return;
    Params_KeyboardSpecialEventCallback& params = *ptr;

    // ------------------------------------------------------------
    IOHIKeyboard* device = OSDynamicCast(IOHIKeyboard, sender);
    if (! device) return;

    ListHookedConsumer::Item* item = static_cast<ListHookedConsumer::Item*>(ListHookedConsumer::instance().get(device));
    if (! item) return;

    // ------------------------------------------------------------
    CommonData::setcurrent_ts(ts);

    // ------------------------------------------------------------
    // Because we handle the key repeat ourself, drop the key repeat by hardware.
    if (repeat) return;

    // ------------------------------------------------------------
    bool retainFlagStatusTemporaryCount = false;
    enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());

    setTimer();
  }
  // ----------------------------------------------------------------------
  void
  EventInputQueue::push_KeyboardSpecialEventCallback(OSObject* target,
                                                     unsigned int eventType,
                                                     unsigned int flags,
                                                     unsigned int key,
                                                     unsigned int flavor,
                                                     UInt64 guid,
                                                     bool repeat,
                                                     AbsoluteTime ts,
                                                     OSObject* sender,
                                                     void* refcon)
  {
    IOLockWrapper::ScopedLock lk_eventlock(CommonData::getEventLock());
    if (! lk_eventlock) return;
    IOLockWrapper::ScopedLock lk(timer_.getlock());
    if (! lk) return;

    // ------------------------------------------------------------
    Params_KeyboardSpecialEventCallback::auto_ptr ptr(Params_KeyboardSpecialEventCallback::alloc(EventType(eventType), Flags(flags), ConsumerKeyCode(key),
                                                                                                 flavor, guid, repeat));
    if (! ptr) return;
    Params_KeyboardSpecialEventCallback& params = *ptr;

    // ------------------------------------------------------------
    DeviceVendor deviceVendor(0);
    DeviceProduct deviceProduct(0);
    {
      IOLockWrapper::ScopedLock lk_device(ListHookedKeyboard::instance().getListLock());
      if (! lk_device) return;

      IOHIKeyboard* device = OSDynamicCast(IOHIKeyboard, sender);
      if (! device) return;

      ListHookedConsumer::Item* item = static_cast<ListHookedConsumer::Item*>(ListHookedConsumer::instance().get_nolock(device));

      // ------------------------------------------------------------
      CommonData::setcurrent_ts(ts);
      deviceVendor = item->getVendor();
      deviceProduct = item->getProduct();
    }

    // ------------------------------------------------------------
    // Because we handle the key repeat ourself, drop the key repeat by hardware.
    if (repeat) return;

    // ------------------------------------------------------------
    bool retainFlagStatusTemporaryCount = false;
    enqueue_(params, retainFlagStatusTemporaryCount, deviceVendor, deviceProduct);

    setTimer();
  }
    void
    ConsumerToKey::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_CONSUMERKEYCODE:
        {
          switch (index_) {
            case 0:
              fromKey_.key = newval;
              consumertoconsumer_.add(ConsumerKeyCode(newval));
              consumertoconsumer_.add(ConsumerKeyCode::VK_NONE);
              break;
            default:
              IOLOG_ERROR("Invalid ConsumerToKey::add\n");
              break;
          }
          ++index_;

          break;
        }

        case BRIDGE_DATATYPE_KEYCODE:
        {
          switch (index_) {
            case 0:
              IOLOG_ERROR("Invalid ConsumerToKey::add\n");
              break;

            case 1:
              // pass-through (== no break)
              keytokey_.add(KeyCode::VK_PSEUDO_KEY);
              keytokey_.add(fromKey_.flags);
            default:
              keytokey_.add(KeyCode(newval));
              break;
          }
          ++index_;

          break;
        }

        case BRIDGE_DATATYPE_FLAGS:
        {
          switch (index_) {
            case 0:
              break;
            case 1:
              fromKey_.flags = newval;
              break;
            default:
              keytokey_.add(Flags(newval));
              break;
          }
          break;
        }

        default:
          IOLOG_ERROR("ConsumerToKey::add invalid datatype:%d\n", datatype);
          break;
      }
    }