Esempio n. 1
0
// ======================================================================
bool
org_pqrs_driver_Karabiner::initialize_notification(void)
{
  notifier_hookKeyboard_ = addMatchingNotification(gIOMatchedNotification,
                                                   serviceMatching("IOHIKeyboard"),
                                                   org_pqrs_Karabiner::Core::IOHIKeyboard_gIOMatchedNotification_callback,
                                                   this, NULL, 0);
  if (notifier_hookKeyboard_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_hookKeyboard_ == NULL\n");
    return false;
  }

  notifier_unhookKeyboard_ = addMatchingNotification(gIOTerminatedNotification,
                                                     serviceMatching("IOHIKeyboard"),
                                                     org_pqrs_Karabiner::Core::IOHIKeyboard_gIOTerminatedNotification_callback,
                                                     this, NULL, 0);
  if (notifier_unhookKeyboard_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_unhookKeyboard_ == NULL\n");
    return false;
  }

  // ----------------------------------------
  notifier_hookPointing_ = addMatchingNotification(gIOMatchedNotification,
                                                   serviceMatching("IOHIPointing"),
                                                   org_pqrs_Karabiner::Core::IOHIPointing_gIOMatchedNotification_callback,
                                                   this, NULL, 0);
  if (notifier_hookPointing_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_hookPointing_ == NULL\n");
    return false;
  }

  notifier_unhookPointing_ = addMatchingNotification(gIOTerminatedNotification,
                                                     serviceMatching("IOHIPointing"),
                                                     org_pqrs_Karabiner::Core::IOHIPointing_gIOTerminatedNotification_callback,
                                                     this, NULL, 0);
  if (notifier_unhookPointing_ == NULL) {
    IOLOG_ERROR("initialize_notification notifier_unhookPointing_ == NULL\n");
    return false;
  }

  return true;
}
Esempio n. 2
0
void Config::set_essential_config(const int32_t* newvalues, size_t num) {
  if (num != BRIDGE_ESSENTIAL_CONFIG_INDEX__END__) {
    IOLOG_ERROR("Config::set_essential_config wrong 'num' parameter. (%d)\n", static_cast<int>(num));
    load_essential_config_default();

  } else {
    for (int i = 0; i < BRIDGE_ESSENTIAL_CONFIG_INDEX__END__; ++i) {
      essential_config_[i] = newvalues[i];
    }
  }
}
    void
    DropScrollWheel::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_OPTION:
        {
          Option option(newval);
          if (Option::DROPSCROLLWHEEL_DROP_HORIZONTAL_SCROLL == option) {
            dropHorizontalScroll_ = true;
          } else {
            IOLOG_ERROR("DropScrollWheel::add unknown option:%d\n", newval);
          }
          break;
        }

        default:
          IOLOG_ERROR("DropScrollWheel::add invalid datatype:%d\n", datatype);
          break;
      }
    }
    void
    DropScrollWheel::add(AddDataType datatype, AddValue newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_OPTION:
        {
          Option option(newval);
          if (Option::DROPSCROLLWHEEL_DROP_HORIZONTAL_SCROLL == option) {
            dropHorizontalScroll_ = true;
          } else {
            IOLOG_ERROR("DropScrollWheel::add unknown option:%u\n", static_cast<unsigned int>(newval));
          }
          break;
        }

        default:
          IOLOG_ERROR("DropScrollWheel::add invalid datatype:%u\n", static_cast<unsigned int>(datatype));
          break;
      }
    }
Esempio n. 5
0
 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;
   }
 }
Esempio n. 6
0
  bool
  Config::set_essential_config_one(uint32_t index, int32_t value)
  {
    if (index >= BRIDGE_ESSENTIAL_CONFIG_INDEX__END__) {
      IOLOG_ERROR("Config::set_essential_config_one wrong 'index' parameter. (%d)\n", static_cast<int>(index));
      return false;
    }

    essential_config_[index] = value;
    return true;
  }
Esempio n. 7
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;
   }
 }
IOReturn
org_pqrs_driver_KeyRemap4MacBook_UserClient_kext::callback_open(void)
{
  if (provider_ == NULL || isInactive()) {
    // Return an error if we don't have a provider. This could happen if the user process
    // called callback_open without calling IOServiceOpen first. Or, the user client could be
    // in the process of being terminated and is thus inactive.
    IOLOG_ERROR("UserClient_kext::callback_open kIOReturnNotAttached\n");
    return kIOReturnNotAttached;
  }

  if (! provider_->open(this)) {
    // The most common reason this open call will fail is because the provider is already open
    // and it doesn't support being opened by more than one client at a time.
    IOLOG_ERROR("UserClient_kext::callback_open kIOReturnExclusiveAccess\n");
    return kIOReturnExclusiveAccess;
  }

  return kIOReturnSuccess;
}
Esempio n. 9
0
// ============================================================
// initWithTask is called as a result of the user process calling IOServiceOpen.
bool USERCLIENT_KEXT_CLASSNAME::initWithTask(task_t owningTask, void* securityToken, UInt32 type) {
  if (clientHasPrivilege(owningTask, kIOClientPrivilegeLocalUser) != KERN_SUCCESS) {
    IOLOG_ERROR("UserClient_kext::initWithTask clientHasPrivilege failed\n");
    return false;
  }

  if (!super::initWithTask(owningTask, securityToken, type)) {
    IOLOG_ERROR("UserClient_kext::initWithTask super::initWithTask failed\n");
    return false;
  }

  provider_ = nullptr;

  // Don't change static values here. (For example, notification_enabled_)
  // initWithTask is called by each IOServiceOpen.
  //
  // If IOService is opened, other client will be failed.
  // Changing static values by other IOServiceOpen may destroy the current connection.

  return true;
}
Esempio n. 10
0
    void
    FlipScrollWheel::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_OPTION:
        {
          /*  */ if (Option::FLIPSCROLLWHEEL_HORIZONTAL == newval) {
            flipHorizontalScroll_ = true;
          } else if (Option::FLIPSCROLLWHEEL_VERTICAL == newval) {
            flipVerticalScroll_ = true;
          } else {
            IOLOG_ERROR("FlipScrollWheel::add unknown option:%d\n", newval);
          }
          break;
        }

        default:
          IOLOG_ERROR("FlipScrollWheel::add invalid datatype:%d\n", datatype);
          break;
      }
    }
Esempio n. 11
0
  void
  RemapClass::Item::append_filter(const unsigned int* vec, size_t length)
  {
    // ------------------------------------------------------------
    // check parameters.
    //
    if (! vec || length <= 0) {
      IOLOG_ERROR("RemapClass::Item::append_filter invalid parameter.\n");
      return;
    }

    // ------------------------------------------------------------
    // append to filters_.
    //
    RemapFilter::FilterUnion* newp = new RemapFilter::FilterUnion(vec, length);
    if (! newp) {
      IOLOG_ERROR("RemapClass::Item::append_filter failed to allocate.\n");
      return;
    }

    filters_.push_back(newp);
  }
    void
    FlipPointingRelative::add(AddDataType datatype, AddValue newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_OPTION:
        {
          Option option(newval);
          /*  */ if (Option::FLIPPOINTINGRELATIVE_HORIZONTAL == option) {
            flipHorizontal_ = true;
          } else if (Option::FLIPPOINTINGRELATIVE_VERTICAL == option) {
            flipVertical_ = true;
          } else {
            IOLOG_ERROR("FlipPointingRelative::add unknown option:%u\n", static_cast<unsigned int>(newval));
          }
          break;
        }

        default:
          IOLOG_ERROR("FlipPointingRelative::add invalid datatype:%u\n", static_cast<unsigned int>(datatype));
          break;
      }
    }
    void
    FlipScrollWheel::add(AddDataType datatype, AddValue newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_OPTION:
        {
          Option option(newval);
          /*  */ if (Option::FLIPSCROLLWHEEL_HORIZONTAL == option) {
            flipHorizontalScroll_ = true;
          } else if (Option::FLIPSCROLLWHEEL_VERTICAL == option) {
            flipVerticalScroll_ = true;
          } else {
            IOLOG_ERROR("FlipScrollWheel::add unknown option:%u\n", static_cast<unsigned int>(newval));
          }
          break;
        }

        default:
          IOLOG_ERROR("FlipScrollWheel::add invalid datatype:%u\n", static_cast<unsigned int>(datatype));
          break;
      }
    }
unsigned int
DependingPressingPeriodKeyToKey::PeriodMS::get(PeriodMS::Type::Value type) {
  if (overwritten_value_[mode_][type] >= 0) {
    return overwritten_value_[mode_][type];
  }

  switch (mode_) {
  case Mode::HOLDING_KEY_TO_KEY:
    switch (type) {
    case Type::SHORT_PERIOD:
      return Config::get_holdingkeytokey_wait();
    case Type::LONG_LONG_PERIOD:
      return 0;
    case Type::PRESSING_TARGET_KEY_ONLY:
      return 0;
    case Type::__END__:
      return 0;
    }

  case Mode::KEY_OVERLAID_MODIFIER:
    switch (type) {
    case Type::SHORT_PERIOD:
      return Config::get_keyoverlaidmodifier_initial_modifier_wait();
    case Type::LONG_LONG_PERIOD:
      return 0;
    case Type::PRESSING_TARGET_KEY_ONLY:
      return Config::get_keyoverlaidmodifier_timeout();
    case Type::__END__:
      return 0;
    }

  case Mode::KEY_OVERLAID_MODIFIER_WITH_REPEAT:
    switch (type) {
    case Type::SHORT_PERIOD:
      return Config::get_keyoverlaidmodifier_initial_modifier_wait();
    case Type::LONG_LONG_PERIOD:
      return Config::get_keyoverlaidmodifier_initial_wait();
    case Type::PRESSING_TARGET_KEY_ONLY:
      return Config::get_keyoverlaidmodifier_timeout();
    case Type::__END__:
      return 0;
    }

  case Mode::NONE:
  case Mode::__END__:
    IOLOG_ERROR("Invalid DependingPressingPeriodKeyToKey::PeriodMS::get\n");
    return 0;
  }

  return 0;
}
Esempio n. 15
0
    // ======================================================================
    static void
    refresh_timer_callback(OSObject* owner, IOTimerEventSource* sender)
    {
      if (! remapclasses_) {
        IOLOG_ERROR("RemapClassManager::refresh_core remapclasses_ == NULL.\n");
        return;
      }

      // ----------------------------------------
      if (enabled_remapclasses_) {
        delete enabled_remapclasses_;
      }
      enabled_remapclasses_ = new Vector_RemapClassPointer();
      if (! enabled_remapclasses_) return;

      // ----------------------------------------
      KeyboardRepeat::cancel();

      statusmessage_[0] = '\0';

      isEventInputQueueDelayEnabled_ = false;

      for (size_t i = 0; i < remapclasses_->size(); ++i) {
        RemapClass* p = (*remapclasses_)[i];
        if (! p) continue;

        if (p->enabled()) {
          enabled_remapclasses_->push_back(p);

          const char* msg = p->get_statusmessage();
          if (msg) {
            strlcat(statusmessage_, msg, sizeof(statusmessage_));
            strlcat(statusmessage_, " ", sizeof(statusmessage_));
          }

          if (p->is_simultaneouskeypresses()) {
            isEventInputQueueDelayEnabled_ = true;
          }
        }
      }

      if (strcmp(statusmessage_, lastmessage_) != 0) {
        strlcpy(lastmessage_, statusmessage_, sizeof(lastmessage_));

        int index = BRIDGE_USERCLIENT_STATUS_MESSAGE_EXTRA;
        CommonData::clear_statusmessage(index);
        CommonData::append_statusmessage(index, statusmessage_);
        CommonData::send_notification_statusmessage(index);
      }
    }
Esempio n. 16
0
IOReturn
org_pqrs_driver_KeyRemap4MacBook_UserClient_kext::callback_notification_from_kext(OSAsyncReference64 asyncReference)
{
  if (provider_ == NULL || isInactive()) {
    // Return an error if we don't have a provider. This could happen if the user process
    // called callback_notification_from_kext without calling IOServiceOpen first.
    // Or, the user client could be in the process of being terminated and is thus inactive.
    IOLOG_ERROR("UserClient_kext::callback_notification_from_kext kIOReturnNotAttached\n");
    return kIOReturnNotAttached;
  }

  if (! provider_->isOpen(this)) {
    // Return an error if we do not have the driver open. This could happen if the user process
    // did not call callback_open before calling this function.
    IOLOG_ERROR("UserClient_kext::callback_notification_from_kext kIOReturnNotOpen\n");
    return kIOReturnNotOpen;
  }

  // ----------------------------------------
  bcopy(asyncReference, asyncref_, sizeof(OSAsyncReference64));
  notification_enabled_ = true;
  return kIOReturnSuccess;
}
  // ======================================================================
  void
  ListHookedConsumer::Item::apply(const Params_KeyboardSpecialEventCallback& params)
  {
    if (params.key >= ConsumerKeyCode::VK__BEGIN__) {
      // Invalid keycode
      IOLOG_ERROR("%s invalid key:%d\n", __PRETTY_FUNCTION__, params.key.get());
      return;
    }
    if (params.flags.isVirtualModifiersOn()) {
      IOLOG_ERROR("%s invalid flags:%d\n", __PRETTY_FUNCTION__, params.flags.get());
      return;
    }

    // ------------------------------------------------------------
    KeyboardSpecialEventCallback callback = orig_keyboardSpecialEventAction_;
    if (! callback) return;

    OSObject* target = orig_keyboardSpecialEventTarget_;
    if (! target) return;

    OSObject* sender = OSDynamicCast(OSObject, device_);
    if (! sender) return;

    const AbsoluteTime& ts = CommonData::getcurrent_ts();
    OSObject* refcon = NULL;

    Params_KeyboardSpecialEventCallback::log(false, params.eventType, params.flags, params.key,
                                             params.flavor, params.guid, params.repeat);
    {
      // We need to unlock the global lock while we are calling the callback function.
      // For more information, See ListHookedKeyboard::Item::apply(const Params_KeyboardEventCallBack& params)
      GlobalLock::ScopedUnlock lk;
      callback(target, params.eventType.get(), params.flags.get(), params.key.get(),
               params.flavor, params.guid, params.repeat, ts, sender, refcon);
    }
  }
Esempio n. 18
0
    bool
    isEnabled(size_t configindex)
    {
      if (! remapclasses_) return false;

      if (configindex >= remapclasses_->size()) {
        IOLOG_ERROR("RemapClass::isEnabled invalid configindex.\n");
        return false;
      }

      RemapClass* p = (*remapclasses_)[configindex];
      if (! p) return false;

      return p->enabled();
    }
    bool
    InputModeFilter::isblocked(void)
    {
      if (! targets_) return false;

      unsigned int current = 0;
      switch (type_) {
        case BRIDGE_FILTERTYPE_INPUTMODE_NOT:
        case BRIDGE_FILTERTYPE_INPUTMODE_ONLY:
          current = CommonData::getcurrent_workspacedata().inputmode;
          break;

        case BRIDGE_FILTERTYPE_INPUTMODEDETAIL_NOT:
        case BRIDGE_FILTERTYPE_INPUTMODEDETAIL_ONLY:
          current = CommonData::getcurrent_workspacedata().inputmodedetail;
          break;
      }

      switch (type_) {
        case BRIDGE_FILTERTYPE_INPUTMODE_NOT:
        case BRIDGE_FILTERTYPE_INPUTMODEDETAIL_NOT:
        {
          for (size_t i = 0; i < targets_->size(); ++i) {
            if ((*targets_)[i] == current) {
              return true;
            }
          }
          return false;
        }

        case BRIDGE_FILTERTYPE_INPUTMODE_ONLY:
        case BRIDGE_FILTERTYPE_INPUTMODEDETAIL_ONLY:
        {
          for (size_t i = 0; i < targets_->size(); ++i) {
            if ((*targets_)[i] == current) {
              return false;
            }
          }
          return true;
        }

        default:
          IOLOG_ERROR("InputModeFilter::isblocked unknown type_(%d)\n", type_);
          break;
      }

      return false;
    }
bool
DependingPressingPeriodKeyToKey::PeriodMS::enabled(PeriodMS::Type::Value type) {
  switch (mode_) {
  case Mode::HOLDING_KEY_TO_KEY:
    switch (type) {
    case Type::SHORT_PERIOD:
      return true;
    case Type::LONG_LONG_PERIOD:
      return false;
    case Type::PRESSING_TARGET_KEY_ONLY:
      return false;
    case Type::__END__:
      return false;
    }

  case Mode::KEY_OVERLAID_MODIFIER:
    switch (type) {
    case Type::SHORT_PERIOD:
      return true;
    case Type::LONG_LONG_PERIOD:
      return false;
    case Type::PRESSING_TARGET_KEY_ONLY:
      return true;
    case Type::__END__:
      return false;
    }

  case Mode::KEY_OVERLAID_MODIFIER_WITH_REPEAT:
    switch (type) {
    case Type::SHORT_PERIOD:
      return true;
    case Type::LONG_LONG_PERIOD:
      return true;
    case Type::PRESSING_TARGET_KEY_ONLY:
      return true;
    case Type::__END__:
      return false;
    }

  case Mode::NONE:
  case Mode::__END__:
    IOLOG_ERROR("Invalid DependingPressingPeriodKeyToKey::PeriodMS::enabled\n");
    return false;
  }

  return false;
}
Esempio n. 21
0
bool VirtualKey::VK_LAZY::handle(const Params_KeyboardEventCallBack& params, AutogenId autogenId, PhysicalEventType physicalEventType) {
  ModifierFlag f = getModifierFlag(params.key);
  if (f == ModifierFlag::ZERO) return false;

  // ----------------------------------------
  if (params.repeat) return true;

  if (params.eventType == EventType::DOWN) {
    FlagStatus::globalFlagStatus().lazy_increase(f);
  } else if (params.eventType == EventType::UP) {
    FlagStatus::globalFlagStatus().lazy_decrease(f);
  } else {
    IOLOG_ERROR("Handle_VK_LAZY invalid EventType.\n");
  }

  return true;
}
    void
    IgnoreMultipleSameKeyPress::add(unsigned int datatype, unsigned int newval)
    {
      switch (datatype) {
        case BRIDGE_DATATYPE_KEYCODE:
          fromKey_.key = newval;
          break;

        case BRIDGE_DATATYPE_FLAGS:
          fromKey_.flags = newval;
          break;

        default:
          IOLOG_ERROR("IgnoreMultipleSameKeyPress::add invalid datatype:%d\n", datatype);
          break;
      }
    }
Esempio n. 23
0
      bool
      isblocked(void)
      {
        if (get_type() == BRIDGE_FILTERTYPE_MODIFIER_NOT ||
            get_type() == BRIDGE_FILTERTYPE_MODIFIER_ONLY ||
            get_type() == BRIDGE_FILTERTYPE_MODIFIER_LOCKED_NOT ||
            get_type() == BRIDGE_FILTERTYPE_MODIFIER_LOCKED_ONLY ||
            get_type() == BRIDGE_FILTERTYPE_MODIFIER_STUCK_NOT ||
            get_type() == BRIDGE_FILTERTYPE_MODIFIER_STUCK_ONLY) {

          bool isnot = (get_type() == BRIDGE_FILTERTYPE_MODIFIER_NOT ||
                        get_type() == BRIDGE_FILTERTYPE_MODIFIER_LOCKED_NOT ||
                        get_type() == BRIDGE_FILTERTYPE_MODIFIER_STUCK_NOT);

          for (size_t i = 0; i < targets_.size(); ++i) {
            if (targets_[i].empty()) continue;

            if (get_type() == BRIDGE_FILTERTYPE_MODIFIER_NOT ||
                get_type() == BRIDGE_FILTERTYPE_MODIFIER_ONLY) {
              if (FlagStatus::globalFlagStatus().isOn(targets_[i])) {
                return isnot ? true : false;
              }
            }

            if (get_type() == BRIDGE_FILTERTYPE_MODIFIER_LOCKED_NOT ||
                get_type() == BRIDGE_FILTERTYPE_MODIFIER_LOCKED_ONLY) {
              if (FlagStatus::globalFlagStatus().isLocked(targets_[i])) {
                return isnot ? true : false;
              }
            }

            if (get_type() == BRIDGE_FILTERTYPE_MODIFIER_STUCK_NOT ||
                get_type() == BRIDGE_FILTERTYPE_MODIFIER_STUCK_ONLY) {
              if (FlagStatus::globalFlagStatus().isStuck(targets_[i])) {
                return isnot ? true : false;
              }
            }
          }

          return isnot ? false : true;
        }

        IOLOG_ERROR("ModifierFilter::isblocked unknown type(%d)\n", get_type());
        return false;
      }
Esempio n. 24
0
  RemapClass::Item::~Item(void)
  {
#define DELETE_UNLESS_NULL(POINTER) { \
    if (POINTER) { delete POINTER; }  \
}

    switch (type_) {
      case BRIDGE_REMAPTYPE_NONE:                                                                                  break;
      case BRIDGE_REMAPTYPE_KEYTOKEY:                       DELETE_UNLESS_NULL(p_.keyToKey);                       break;
      case BRIDGE_REMAPTYPE_KEYTOCONSUMER:                  DELETE_UNLESS_NULL(p_.keyToConsumer);                  break;
      case BRIDGE_REMAPTYPE_KEYTOPOINTINGBUTTON:            DELETE_UNLESS_NULL(p_.keyToPointingButton);            break;
      case BRIDGE_REMAPTYPE_CONSUMERTOCONSUMER:             DELETE_UNLESS_NULL(p_.consumerToConsumer);             break;
      case BRIDGE_REMAPTYPE_CONSUMERTOKEY:                  DELETE_UNLESS_NULL(p_.consumerToKey);                  break;
      case BRIDGE_REMAPTYPE_DOUBLEPRESSMODIFIER:            DELETE_UNLESS_NULL(p_.doublePressModifier);            break;
      case BRIDGE_REMAPTYPE_DROPKEYAFTERREMAP:              DELETE_UNLESS_NULL(p_.dropKeyAfterRemap);              break;
      case BRIDGE_REMAPTYPE_DROPPOINTINGRELATIVECURSORMOVE: DELETE_UNLESS_NULL(p_.dropPointingRelativeCursorMove); break;
      case BRIDGE_REMAPTYPE_DROPSCROLLWHEEL:                DELETE_UNLESS_NULL(p_.dropScrollWheel);                break;
      case BRIDGE_REMAPTYPE_FORCENUMLOCKON:                 DELETE_UNLESS_NULL(p_.forceNumLockOn);                 break;
      case BRIDGE_REMAPTYPE_HOLDINGKEYTOKEY:                DELETE_UNLESS_NULL(p_.holdingKeyToKey);                break;
      case BRIDGE_REMAPTYPE_IGNOREMULTIPLESAMEKEYPRESS:     DELETE_UNLESS_NULL(p_.ignoreMultipleSameKeyPress);     break;
      case BRIDGE_REMAPTYPE_KEYOVERLAIDMODIFIER:            DELETE_UNLESS_NULL(p_.keyOverlaidModifier);            break;
      case BRIDGE_REMAPTYPE_POINTINGBUTTONTOKEY:            DELETE_UNLESS_NULL(p_.pointingButtonToKey);            break;
      case BRIDGE_REMAPTYPE_POINTINGBUTTONTOPOINTINGBUTTON: DELETE_UNLESS_NULL(p_.pointingButtonToPointingButton); break;
      case BRIDGE_REMAPTYPE_POINTINGRELATIVETOSCROLL:       DELETE_UNLESS_NULL(p_.pointingRelativeToScroll);       break;
      case BRIDGE_REMAPTYPE_SIMULTANEOUSKEYPRESSES:         DELETE_UNLESS_NULL(p_.simultaneousKeyPresses);         break;
      case BRIDGE_REMAPTYPE_SETKEYBOARDTYPE:                DELETE_UNLESS_NULL(p_.setKeyboardType);                break;
      case BRIDGE_REMAPTYPE_STRIPMODIFIERFROMSCROLLWHEEL:   DELETE_UNLESS_NULL(p_.stripModifierFromScrollWheel);   break;
      default:
        IOLOG_ERROR("RemapClass::Item::terminate unknown type_ (%d)\n", type_);
        break;
    }

#undef DELETE_UNLESS_NULL

    // ------------------------------------------------------------
    if (filters_) {
      for (size_t i = 0; i < filters_->size(); ++i) {
        RemapFilter::FilterUnion* p = (*filters_)[i];
        if (p) {
          delete p;
        }
      }
      delete filters_;
    }
  }
Esempio n. 25
0
  // ----------------------------------------------------------------------
  bool
  FlagStatus::initialize(void)
  {
    for (int i = 0;; ++i) {
      if (i >= MAXNUM) {
#ifndef FLAGSTATUS_TEST
        IOLOG_ERROR("FlagStatus::initialize MAXNUM is too small. Expand it.");
#endif
        return false;
      }

      ModifierFlag f = Flags::getModifierFlagByIndex(i);
      item_[i].initialize(f);
      if (f == ModifierFlag::NONE) break;
    }

    return true;
  }
Esempio n. 26
0
    bool
    isEnabled(size_t configindex)
    {
      // isEnabled called in remap_key, remap_consumer, ...
      // So, don't make ScopedLock(lock_).

      if (! remapclasses_) return false;

      if (configindex >= remapclasses_->size()) {
        IOLOG_ERROR("RemapClass::isEnabled invalid configindex.\n");
        return false;
      }

      RemapClass* p = (*remapclasses_)[configindex];
      if (! p) return false;

      return p->enabled();
    }
Esempio n. 27
0
  bool
  VirtualKey::VK_LAZY::handle(const Params_KeyboardEventCallBack& params)
  {
    ModifierFlag f = getModifierFlag(params.key);
    if (f == ModifierFlag::NONE) return false;

    // ----------------------------------------
    if (params.repeat) return true;

    if (params.eventType == EventType::DOWN) {
      FlagStatus::increase(f);
    } else if (params.eventType == EventType::UP) {
      FlagStatus::decrease(f);
    } else {
      IOLOG_ERROR("Handle_VK_LAZY invalid EventType.\n");
    }

    return true;
  }
Esempio n. 28
0
  bool isblocked(void) override {
    if (get_type() == BRIDGE_FILTERTYPE_DEVICEEXISTS_NOT ||
        get_type() == BRIDGE_FILTERTYPE_DEVICEEXISTS_ONLY) {

      bool isnot = (get_type() == BRIDGE_FILTERTYPE_DEVICEEXISTS_NOT);

      for (size_t i = 0; i < targets_.size(); ++i) {
        DeviceIdentifier& v = targets_[i];
        if (ListHookedDevice::existsAll(v)) {
          return isnot ? true : false;
        }
      }

      return isnot ? false : true;
    }

    IOLOG_ERROR("DeviceExistsFilter::isblocked unknown type(%d)\n", get_type());
    return false;
  }
Esempio n. 29
0
// clientClose is called as a result of the user process calling IOServiceClose.
IOReturn
USERCLIENT_KEXT_CLASSNAME::clientClose(void) {
  // Defensive coding in case the user process called IOServiceClose
  // without calling BRIDGE_USERCLIENT_CLOSE first.
  callback_close();

  // Inform the user process that this user client is no longer available. This will also cause the
  // user client instance to be destroyed.
  //
  // terminate would return false if the user process still had this user client open.
  // This should never happen in our case because this code path is only reached if the user process
  // explicitly requests closing the connection to the user client.
  if (!terminate()) {
    IOLOG_ERROR("UserClient_kext::clientClose terminate() failed\n");
  }

  // DON'T call super::clientClose, which just returns kIOReturnUnsupported.
  return kIOReturnSuccess;
}
Esempio n. 30
0
  bool
  isblocked(void) override {
    if (get_type() == BRIDGE_FILTERTYPE_WINDOWNAME_NOT ||
        get_type() == BRIDGE_FILTERTYPE_WINDOWNAME_ONLY) {

      bool isnot = (get_type() == BRIDGE_FILTERTYPE_WINDOWNAME_NOT);

      for (size_t i = 0; i < targets_.size(); ++i) {
        if (CommonData::getcurrent_workspaceWindowNameIds().is_include(targets_[i])) {
          return isnot ? true : false;
        }
      }

      return isnot ? false : true;
    }

    IOLOG_ERROR("WindowNameFilter::isblocked unknown type(%d)\n", get_type());
    return false;
  }