Ejemplo n.º 1
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));
         }
     }
 }
Ejemplo n.º 2
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.ScheduleXI2Input(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.ScheduleXI2Input(new RawMouseWheelEventArgs(client.MouseDevice, ev.Timestamp,
                                                                       client.InputRoot, ev.Position, scrollDelta, ev.Modifiers));
                }
                if (_pointerDevice.HasMotion(ev))
                {
                    client.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
                                                                    RawPointerEventType.Move, ev.Position, ev.Modifiers));
                }
            }

            if (ev.Type == XiEventType.XI_ButtonPress && ev.Button >= 4 && ev.Button <= 7 && !ev.Emulated)
            {
                var scrollDelta = ev.Button switch
                {
                    4 => new Vector(0, 1),
                    5 => new Vector(0, -1),
                    6 => new Vector(1, 0),
                    7 => new Vector(-1, 0),
                    _ => (Vector?)null
                };

                if (scrollDelta.HasValue)
                {
                    client.ScheduleXI2Input(new RawMouseWheelEventArgs(client.MouseDevice, ev.Timestamp,
                                                                       client.InputRoot, ev.Position, scrollDelta.Value, 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.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
                                                                    type.Value, ev.Position, ev.Modifiers));
                }
            }

            _pointerDevice.UpdateValuators(ev.Valuators);
        }
    }

    unsafe class ParsedDeviceEvent