Пример #1
0
        void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev)
        {
            if (ev.Type == XiEventType.XI_Motion)
            {
                Vector scrollDelta = default;
                foreach (var v in ev.Valuators)
                {
                    foreach (var scroller in _pointerDevice.Scrollers)
                    {
                        if (scroller.Number == v.Key)
                        {
                            var old = _pointerDevice.Valuators[scroller.Number].Value;
                            // Value was zero after reset, ignore the event and use it as a reference next time
                            if (old == 0)
                            {
                                continue;
                            }
                            var diff = (old - v.Value) / scroller.Increment;
                            if (scroller.ScrollType == XiScrollType.Horizontal)
                            {
                                scrollDelta = scrollDelta.WithX(scrollDelta.X + diff);
                            }
                            else
                            {
                                scrollDelta = scrollDelta.WithY(scrollDelta.Y + diff);
                            }
                        }
                    }
                }

                if (scrollDelta != default)
                {
                    client.ScheduleInput(new RawMouseWheelEventArgs(_platform.MouseDevice, ev.Timestamp,
                                                                    //client.InputRoot,
                                                                    ev.Position, scrollDelta, ev.Modifiers));
                }
                if (_pointerDevice.HasMotion(ev))
                {
                    client.ScheduleInput(new RawPointerEventArgs(_platform.MouseDevice, ev.Timestamp, //client.InputRoot,
                                                                 RawPointerEventType.Move, ev.Position, ev.Modifiers));
                }
            }

            if (ev.Type == XiEventType.XI_ButtonPress || ev.Type == XiEventType.XI_ButtonRelease)
            {
                var down = ev.Type == XiEventType.XI_ButtonPress;
                var type =
                    ev.Button == 1 ? (down ? RawPointerEventType.LeftButtonDown : RawPointerEventType.LeftButtonUp)
                    : ev.Button == 2 ? (down ? RawPointerEventType.MiddleButtonDown : RawPointerEventType.MiddleButtonUp)
                    : ev.Button == 3 ? (down ? RawPointerEventType.RightButtonDown : RawPointerEventType.RightButtonUp)
                    : (RawPointerEventType?)null;
                if (type.HasValue)
                {
                    client.ScheduleInput(new RawPointerEventArgs(_platform.MouseDevice, ev.Timestamp, //client.InputRoot,
                                                                 type.Value, ev.Position, ev.Modifiers));
                }
            }

            _pointerDevice.UpdateValuators(ev.Valuators);
        }
Пример #2
0
            public bool HasMotion(ParsedDeviceEvent ev)
            {
                foreach (var val in ev.Valuators)
                {
                    if (Scrollers.All(s => s.Number != val.Key))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Пример #3
0
 void OnEnterLeaveEvent(IXI2Client client, ref XIEnterLeaveEvent ev)
 {
     if (ev.evtype == XiEventType.XI_Leave)
     {
         var buttons = ParsedDeviceEvent.ParseButtonState(ev.buttons.MaskLen, ev.buttons.Mask);
         var detail  = ev.detail;
         if ((detail == XiEnterLeaveDetail.XINotifyNonlinearVirtual ||
              detail == XiEnterLeaveDetail.XINotifyNonlinear ||
              detail == XiEnterLeaveDetail.XINotifyVirtual) &&
             buttons == default)
         {
             client.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, (ulong)ev.time.ToInt64(),
                                                             client.InputRoot,
                                                             RawPointerEventType.LeaveWindow, new Point(ev.event_x, ev.event_y), buttons));
         }
     }
 }
Пример #4
0
        void OnDeviceEvent(IXI2Client client, ParsedDeviceEvent ev)
        {
            if (ev.Type == XiEventType.XI_TouchBegin ||
                ev.Type == XiEventType.XI_TouchUpdate ||
                ev.Type == XiEventType.XI_TouchEnd)
            {
                var type = ev.Type == XiEventType.XI_TouchBegin ?
                           RawPointerEventType.TouchBegin :
                           (ev.Type == XiEventType.XI_TouchUpdate ?
                            RawPointerEventType.TouchUpdate :
                            RawPointerEventType.TouchEnd);
                client.ScheduleInput(new RawTouchEventArgs(client.TouchDevice,
                                                           ev.Timestamp, client.InputRoot, type, ev.Position, ev.Modifiers, ev.Detail));
                return;
            }

            if (_multitouch && ev.Emulated)
            {
                return;
            }

            if (ev.Type == XiEventType.XI_Motion)
            {
                Vector scrollDelta = default;
                foreach (var v in ev.Valuators)
                {
                    foreach (var scroller in _pointerDevice.Scrollers)
                    {
                        if (scroller.Number == v.Key)
                        {
                            var old = _pointerDevice.Valuators[scroller.Number].Value;
                            // Value was zero after reset, ignore the event and use it as a reference next time
                            if (old == 0)
                            {
                                continue;
                            }
                            var diff = (old - v.Value) / scroller.Increment;
                            if (scroller.ScrollType == XiScrollType.Horizontal)
                            {
                                scrollDelta = scrollDelta.WithX(scrollDelta.X + diff);
                            }
                            else
                            {
                                scrollDelta = scrollDelta.WithY(scrollDelta.Y + diff);
                            }
                        }
                    }
                }

                if (scrollDelta != default)
                {
                    client.ScheduleInput(new RawMouseWheelEventArgs(client.MouseDevice, ev.Timestamp,
                                                                    client.InputRoot, ev.Position, scrollDelta, ev.Modifiers));
                }
                if (_pointerDevice.HasMotion(ev))
                {
                    client.ScheduleInput(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
                                                                 RawPointerEventType.Move, ev.Position, ev.Modifiers));
                }
            }

            if (ev.Type == XiEventType.XI_ButtonPress || ev.Type == XiEventType.XI_ButtonRelease)
            {
                var down = ev.Type == XiEventType.XI_ButtonPress;
                var type = ev.Button switch
                {
                    1 => down ? RawPointerEventType.LeftButtonDown : RawPointerEventType.LeftButtonUp,
                    2 => down ? RawPointerEventType.MiddleButtonDown : RawPointerEventType.MiddleButtonUp,
                    3 => down ? RawPointerEventType.RightButtonDown : RawPointerEventType.RightButtonUp,
                    8 => down ? RawPointerEventType.XButton1Down : RawPointerEventType.XButton1Up,
                    9 => down ? RawPointerEventType.XButton2Down : RawPointerEventType.XButton2Up,
                    _ => (RawPointerEventType?)null
                };
                if (type.HasValue)
                {
                    client.ScheduleInput(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
                                                                 type.Value, ev.Position, ev.Modifiers));
                }
            }

            _pointerDevice.UpdateValuators(ev.Valuators);
        }
    }