Beispiel #1
0
bool DropAllKeys::remap(RemapParams& remapParams) {
  // We do not drop key events in `remap`.
  // We need to drop key events in `cancelEventOutputQueueItems`.
  //
  // Why:
  // __DropAllKeys__ will be used in mode in order to ignore invalid keys.
  // (eg. enable only hjkl keys in simple vi mode v2.)
  //
  // In this case, we should not drop modifier keys in order to use shift+hjkl keys.
  // Therefore, we do not drop modifier keys.
  // When we enabled "change space to shift", space+hjkl should be shift+hjkl and
  // the shift modifier should not be dropped.
  // If we set `remapParams.remapped` in `remap`,
  // the space key will not be changed to shift key and space+hjkl will be hjkl without modifier.
  //
  // So, we pass key events to other remap functions and drop key events in `cancelEventOutputQueueItems`.

  helper_.registerSerialNumber();

  if (fromModifierFlags_.empty()) {
    IOLOG_WARN("Ignore __DropAllKeys__ with no ModifierFlag.\n");

    modifierMatched_ = false;
    doCancel_ = false;
    return false;
  } else {
    modifierMatched_ = FlagStatus::globalFlagStatus().isOn(fromModifierFlags_);
    doCancel_ = true;
    return true;
  }
}
Beispiel #2
0
// ----------------------------------------
bool org_pqrs_driver_NoEjectDelay::IOHIKeyboard_gIOMatchedNotification_callback(void* target, void* refCon, IOService* newService, IONotifier* notifier) {
  org_pqrs_NoEjectDelay::GlobalLock::ScopedLock lk;
  if (!lk) return false;

  // ----------------------------------------
  org_pqrs_driver_NoEjectDelay* self = reinterpret_cast<org_pqrs_driver_NoEjectDelay*>(target);
  if (!self) return false;

  if (!newService) return false;

  // ----------------------------------------
  const char* name = newService->getName();
  const char* pname = getProductPropertyCStringNoCopy(newService);
  if (name && pname) {
    IOLOG_INFO("device: %s (%s)\n", pname, name);
  }

  // ----------------------------------------
  for (int i = 0; i < MAXNUM_DEVICES; ++i) {
    if (!self->devices_[i]) {
      self->devices_[i] = newService;
      return true;
    }
  }

  IOLOG_WARN("There is no space for the new device. Please increase MAXNUM_DEVICES.\n");
  return true;
}
 void
 CommonData::increase_alloccount(void)
 {
   ++alloccount_;
   if (alloccount_ > 1024) {
     IOLOG_WARN("alloccount_ > 1024\n");
   }
   // IOLOG_DEVEL("CommonData::increase_alloccount alloccount_:%d\n", alloccount_);
 }
Beispiel #4
0
  void
  CommonData::increase_alloccount(void)
  {
    IOLockWrapper::ScopedLock lk(alloccount_lock_);
    if (! lk) return;

    ++alloccount_;
    if (alloccount_ > 1024) {
      IOLOG_WARN("alloccount_ > 1024\n");
    }
    //IOLOG_DEVEL("CommonData::increase_alloccount alloccount_:%d\n", alloccount_);
  }
Beispiel #5
0
  DeviceFilter(unsigned int type, const unsigned int* vec, size_t length) : RemapFilterBase(type) {
    targets_.reserve(length / 3);

    for (int i = 0; i < static_cast<int>(length) - 2; i += 3) {
      targets_.push_back(DeviceIdentifier(DeviceVendor(vec[i]),
                                          DeviceProduct(vec[i + 1]),
                                          DeviceLocation(vec[i + 2])));
    }

    if (length % 3 > 0) {
      IOLOG_WARN("Invalid length(%d) in BRIDGE_FILTERTYPE_DEVICE_*\n", static_cast<int>(length));
    }
  }
Beispiel #6
0
      ModifierFilter(unsigned int type, const unsigned int* vec, size_t length) :
        RemapFilterBase(type)
      {
        targets_.reserve(length / 2);

        {
          Vector_ModifierFlag v;
          targets_.push_back(v);
        }

        for (size_t i = 0; i < length - 1; i += 2) {
          AddDataType datatype(vec[i]);
          AddValue newval(vec[i + 1]);

          switch (datatype) {
            case BRIDGE_DATATYPE_MODIFIERFLAG:
              if (! targets_.empty()) {
                targets_.back().push_back(ModifierFlag(datatype, newval));
              }
              break;

            case BRIDGE_DATATYPE_MODIFIERFLAGS_END:
            {
              Vector_ModifierFlag v;
              targets_.push_back(v);
              break;
            }

            default:
              IOLOG_ERROR("ModifierFilter::add invalid datatype:%u\n", static_cast<unsigned int>(datatype));
              break;
          }
        }

        if (length % 2 > 0) {
          IOLOG_WARN("Invalid length(%d) in BRIDGE_FILTERTYPE_MODIFIER_*\n", static_cast<int>(length));
        }
      }
Beispiel #7
0
void DropKey::settle(RemapParams& remapParams) {
  if (fromModifierFlags_.empty()) {
    IOLOG_WARN("Ignore __DropKey__ with no ModifierFlag.\n");
    return;
  }

  if (remapParams.isremapped) return;

  // Do not drop any modifier flags.
  if (remapParams.paramsBase.isModifier()) return;

  {
    auto params = remapParams.paramsBase.get_Params_KeyboardEventCallBack();
    if (params && dropKey_) {
      dropKey(remapParams);
      return;
    }
  }
  {
    auto params = remapParams.paramsBase.get_Params_KeyboardSpecialEventCallback();
    if (params && dropConsumerKey_) {
      dropKey(remapParams);
      return;
    }
  }

  {
    auto params = remapParams.paramsBase.get_Params_RelativePointerEventCallback();
    if (params && dropPointingButton_) {
      if (FlagStatus::globalFlagStatus().isOn(fromModifierFlags_) &&
          !(params->buttons).isNONE()) {
        remapParams.isremapped = true;
        return;
      }
    }
  }
}
Beispiel #8
0
    void
    FilterUnion::initialize(const unsigned int* vec, size_t length)
    {
      type_ = BRIDGE_FILTERTYPE_NONE;

      // ------------------------------------------------------------
      // check parameters.
      //
      if (! vec || length == 0) {
        IOLOG_ERROR("FilterUnion::initialize invalid parameter.\n");
        goto error;
      }

      // ------------------------------------------------------------
      // initialize values.
      //
      type_ = vec[0];

      switch (type_) {
        case BRIDGE_FILTERTYPE_APPLICATION_NOT:
        case BRIDGE_FILTERTYPE_APPLICATION_ONLY:
          p_.applicationFilter = new ApplicationFilter(type_);
          if (p_.applicationFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.applicationFilter)->add(AddValue(vec[i]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_CONFIG_NOT:
        case BRIDGE_FILTERTYPE_CONFIG_ONLY:
          p_.configFilter = new ConfigFilter(type_);
          if (p_.configFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.configFilter)->add(AddValue(vec[i]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_DEVICE_NOT:
        case BRIDGE_FILTERTYPE_DEVICE_ONLY:
          p_.deviceFilter = new DeviceFilter(type_);
          if (p_.deviceFilter) {
            for (size_t i = 1; i < length - 2; i += 3) {
              (p_.deviceFilter)->add(DeviceVendor(vec[i]),
                                     DeviceProduct(vec[i + 1]),
                                     DeviceLocation(vec[i + 2]));
            }
            if ((length - 1) % 3 > 0) {
              IOLOG_WARN("Invalid length(%d) in BRIDGE_FILTERTYPE_DEVICE_*\n", static_cast<int>(length));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_ELAPSEDTIMESINCELASTPRESSED_GREATERTHAN:
        case BRIDGE_FILTERTYPE_ELAPSEDTIMESINCELASTPRESSED_LESSTHAN:
          p_.elapsedTimeSinceLastPressedFilter = new ElapsedTimeSinceLastPressedFilter(type_);
          if (p_.elapsedTimeSinceLastPressedFilter) {
            for (size_t i = 1; i < length - 1; i += 2) {
              (p_.elapsedTimeSinceLastPressedFilter)->add(AddDataType(vec[i]), AddValue(vec[i + 1]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_INPUTSOURCE_NOT:
        case BRIDGE_FILTERTYPE_INPUTSOURCE_ONLY:
        case BRIDGE_FILTERTYPE_INPUTSOURCEDETAIL_NOT:
        case BRIDGE_FILTERTYPE_INPUTSOURCEDETAIL_ONLY:
          p_.inputSourceFilter = new InputSourceFilter(type_);
          if (p_.inputSourceFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.inputSourceFilter)->add(AddValue(vec[i]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_LASTPRESSEDPHYSICALKEY_NOT:
        case BRIDGE_FILTERTYPE_LASTPRESSEDPHYSICALKEY_ONLY:
          p_.lastPressedPhysicalKeyFilter = new LastPressedPhysicalKeyFilter(type_);
          if (p_.lastPressedPhysicalKeyFilter) {
            for (size_t i = 1; i < length - 1; i += 2) {
              (p_.lastPressedPhysicalKeyFilter)->add(AddDataType(vec[i]), AddValue(vec[i + 1]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_MODIFIER_NOT:
        case BRIDGE_FILTERTYPE_MODIFIER_ONLY:
          p_.modifierFilter = new ModifierFilter(type_);
          if (p_.modifierFilter) {
            for (size_t i = 1; i < length - 1; i += 2) {
              (p_.modifierFilter)->add(AddDataType(vec[i]), AddValue(vec[i + 1]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_WINDOWNAME_NOT:
        case BRIDGE_FILTERTYPE_WINDOWNAME_ONLY:
          p_.windowNameFilter = new WindowNameFilter(type_);
          if (p_.windowNameFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.windowNameFilter)->add(AddValue(vec[i]));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_UIELEMENTROLE_NOT:
        case BRIDGE_FILTERTYPE_UIELEMENTROLE_ONLY:
          p_.uiElementRoleFilter = new UIElementRoleFilter(type_);
          if (p_.uiElementRoleFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.uiElementRoleFilter)->add(AddValue(vec[i]));
            }
          }
          break;

        default:
          IOLOG_ERROR("FilterUnion::initialize unknown type_:%d.\n", type_);
          goto error;
      }

      return;

    error:
      terminate();
    }
Beispiel #9
0
    void
    FilterUnion::initialize(const unsigned int* vec, size_t length)
    {
      type_ = BRIDGE_FILTERTYPE_NONE;

      // ------------------------------------------------------------
      // check parameters.
      //
      if (! vec || length == 0) {
        IOLOG_ERROR("FilterUnion::initialize invalid parameter.\n");
        goto error;
      }

      // ------------------------------------------------------------
      // initialize values.
      //
      type_ = vec[0];

      switch (type_) {
        case BRIDGE_FILTERTYPE_APPLICATION_NOT:
        case BRIDGE_FILTERTYPE_APPLICATION_ONLY:
          p_.applicationFilter = new ApplicationFilter(type_);
          if (p_.applicationFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.applicationFilter)->add(vec[i]);
            }
          }
          break;

        case BRIDGE_FILTERTYPE_CONFIG_NOT:
        case BRIDGE_FILTERTYPE_CONFIG_ONLY:
          p_.configFilter = new ConfigFilter(type_);
          if (p_.configFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.configFilter)->add(vec[i]);
            }
          }
          break;

        case BRIDGE_FILTERTYPE_MODIFIER_NOT:
        case BRIDGE_FILTERTYPE_MODIFIER_ONLY:
          p_.modifierFilter = new ModifierFilter(type_);
          if (p_.modifierFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.modifierFilter)->add(vec[i]);
            }
          }
          break;

        case BRIDGE_FILTERTYPE_DEVICE_NOT:
        case BRIDGE_FILTERTYPE_DEVICE_ONLY:
          p_.deviceFilter = new DeviceFilter(type_);
          if (p_.deviceFilter) {
            for (size_t i = 1; i < length - 2; i += 3) {
              (p_.deviceFilter)->add(vec[i], vec[i + 1], vec[i + 2]);
            }
            if ((length - 1) % 3 > 0) {
              IOLOG_WARN("Invalid length(%d) in BRIDGE_FILTERTYPE_DEVICE_*\n", static_cast<int>(length));
            }
          }
          break;

        case BRIDGE_FILTERTYPE_INPUTSOURCE_NOT:
        case BRIDGE_FILTERTYPE_INPUTSOURCE_ONLY:
        case BRIDGE_FILTERTYPE_INPUTSOURCEDETAIL_NOT:
        case BRIDGE_FILTERTYPE_INPUTSOURCEDETAIL_ONLY:
          p_.inputSourceFilter = new InputSourceFilter(type_);
          if (p_.inputSourceFilter) {
            for (size_t i = 1; i < length; ++i) {
              (p_.inputSourceFilter)->add(vec[i]);
            }
          }
          break;

        default:
          IOLOG_ERROR("FilterUnion::initialize unknown type_:%d.\n", type_);
          goto error;
      }

      return;

    error:
      terminate();
    }
Beispiel #10
0
 static void push_back(const RemapClass::Item* p, Item::Type t) {
   list_.push_back(new Item(p, t));
   if (list_.size() > 60000) {
     IOLOG_WARN("RemapClass::ActiveItems too many item count: %ld\n", list_.size());
   }
 }
    bool
    PointingRelativeToScroll::remap(RemapParams& remapParams)
    {
      // ------------------------------------------------------------
      // PointingRelativeToScroll grabs all pointing movement events.
      // Therefore, if user write inappropriate <autogen> (empty flags and empty buttons),
      // user cannot control pointing device at all.
      //
      // For example:
      //   <autogen>__PointingRelativeToScroll__ PointingButton::LEFT | PointingButton::RIGHT</autogen>
      //
      // (Buttons(LEFT | RIGHT) will be ignored. So, this autogen is interpreted as
      // <autogen>__PointingRelativeToScroll__</autogen>.)
      //
      // Skip on error in order to avoid this situation.
      if (fromEvent_.getType() == FromEvent::Type::NONE &&
          fromFlags_ == Flags(0)) {
        IOLOG_WARN("Ignore __PointingRelativeToScroll__ with no option. "
                   "Please use \"__PointingRelativeToScroll__ PointingButton::NONE\".\n");
        return false;
      }

      // ------------------------------------------------------------
      if (remapParams.isremapped) return false;

      bool useFromEvent = true;
      if (fromEvent_.getType() == FromEvent::Type::NONE) {
        useFromEvent = false;
      }
      if (fromEvent_.getType() == FromEvent::Type::POINTING_BUTTON &&
          fromEvent_.getPointingButton() == PointingButton::NONE) {
        useFromEvent = false;
      }

      if (! useFromEvent) {
        if (! FlagStatus::makeFlags().isOn(fromFlags_)) return false;
        goto doremap;

      } else {
        // FromEvent == KeyCode or ConsumerKeyCode or PointingButton.

        bool pressingStateChanged = fromEvent_.changePressingState(remapParams.paramsUnion,
                                                                   FlagStatus::makeFlags(),
                                                                   fromFlags_);
        if (pressingStateChanged) {
          if (fromEvent_.isPressing()) {
            // down event
            FlagStatus::decrease(fromEvent_.getModifierFlag());
            ButtonStatus::decrease(fromEvent_.getPointingButton());

            absolute_distance_ = 0;
            begin_ic_.begin();
            chained_ic_.begin();
            chained_delta1_ = 0;
            chained_delta2_ = 0;

          } else {
            // up event
            FlagStatus::increase(fromEvent_.getModifierFlag());
            ButtonStatus::increase(fromEvent_.getPointingButton());

            cancelScroll();

            const uint32_t DISTANCE_THRESHOLD = 5;
            const uint32_t TIME_THRESHOLD = 300;
            if (absolute_distance_ <= DISTANCE_THRESHOLD && begin_ic_.getmillisec() < TIME_THRESHOLD) {
              // Fire by a click event.
              if (isToKeysDefined_) {
                keytokey_.call_remap_with_VK_PSEUDO_KEY(EventType::DOWN);
                keytokey_.call_remap_with_VK_PSEUDO_KEY(EventType::UP);

              } else {
                toEvent_.fire_downup(FlagStatus::makeFlags());
              }
            }
          }

          // ignore this event.
          goto returntrue;

        } else {
          if (! fromEvent_.isPressing()) {
            return false;
          }
        }
      }

    doremap:
      // change only cursor move events.
      {
        Params_RelativePointerEventCallback* params = remapParams.paramsUnion.get_Params_RelativePointerEventCallback();
        if (! params) return false;
        if (params->ex_button != PointingButton::NONE) return false;
      }

      // We need to call EventWatcher::on here.
      // See the comments in EventInputQueue::fire_timer_callback.
      EventWatcher::on();
      toscroll(remapParams);

    returntrue:
      remapParams.isremapped = true;
      return true;
    }