// ----------------------------------------------------------------------
void EventInputQueue::push_RelativePointerEventCallback(OSObject* target,
                                                        int buttons_raw,
                                                        int dx,
                                                        int dy,
                                                        AbsoluteTime ts,
                                                        OSObject* sender,
                                                        void* refcon) {
  GlobalLock::ScopedLock lk;
  if (!lk) return;

  Params_RelativePointerEventCallback::log(true, Buttons(buttons_raw), dx, dy);

  // ------------------------------------------------------------
  Buttons buttons(buttons_raw);
  Buttons justPressed;
  Buttons justReleased;

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

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

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

  // ------------------------------------------------------------
  justPressed = buttons.justPressed(item->get_previousbuttons());
  justReleased = buttons.justReleased(item->get_previousbuttons());
  item->set_previousbuttons(buttons);

  // ------------------------------------------------------------
  // divide an event into button and cursormove events.
  for (int i = 0; i < ButtonStatus::MAXNUM; ++i) {
    PointingButton btn(1 << i);
    if (justPressed.isOn(btn)) {
      Params_RelativePointerEventCallback params(buttons, 0, 0, btn, true);
      bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
      enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
    }
    if (justReleased.isOn(btn)) {
      Params_RelativePointerEventCallback params(buttons, 0, 0, btn, false);
      bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
      enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
    }
  }
  // If (dx == 0 && dy == 0), the event is either needless event or just pressing/releasing buttons event.
  // About just pressing/releasing buttons event, we handled these in the above processes.
  // So, we can drop (dx == 0 && dy == 0) events in here.
  if (dx != 0 || dy != 0) {
    Params_RelativePointerEventCallback params(buttons, dx, dy, PointingButton::NONE, false);
    bool retainFlagStatusTemporaryCount = true;
    enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());
  }

  setTimer();
}
  void
  EventInputQueue::push_ScrollWheelEventCallback(OSObject* target,
                                                 short deltaAxis1,
                                                 short deltaAxis2,
                                                 short deltaAxis3,
                                                 IOFixed fixedDelta1,
                                                 IOFixed fixedDelta2,
                                                 IOFixed fixedDelta3,
                                                 SInt32 pointDelta1,
                                                 SInt32 pointDelta2,
                                                 SInt32 pointDelta3,
                                                 SInt32 options,
                                                 AbsoluteTime ts,
                                                 OSObject* sender,
                                                 void* refcon)
  {
    GlobalLock::ScopedLock lk;
    if (! lk) return;

    Params_ScrollWheelEventCallback::log(true,
                                         deltaAxis1,
                                         deltaAxis2,
                                         deltaAxis3,
                                         fixedDelta1,
                                         fixedDelta2,
                                         fixedDelta3,
                                         pointDelta1,
                                         pointDelta2,
                                         pointDelta3,
                                         options);

    // ------------------------------------------------------------
    Params_ScrollWheelEventCallback::auto_ptr ptr(Params_ScrollWheelEventCallback::alloc(deltaAxis1, deltaAxis2, deltaAxis3,
                                                                                         fixedDelta1, fixedDelta2, fixedDelta3,
                                                                                         pointDelta1, pointDelta2, pointDelta3,
                                                                                         options));
    if (! ptr) return;
    Params_ScrollWheelEventCallback& params = *ptr;

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

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

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

    // ------------------------------------------------------------
    bool retainFlagStatusTemporaryCount = Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_lazy_modifiers_with_mouse_event);
    enqueue_(params, retainFlagStatusTemporaryCount, item->getDeviceIdentifier());

    setTimer();
  }