Example #1
0
            /// <summary>
            /// Determines whether the specified ev has scroll.
            /// </summary>
            /// <param name="ev">The ev.</param>
            /// <returns><c>true</c> if the specified ev has scroll; otherwise, <c>false</c>.</returns>
            public bool HasScroll(ParsedDeviceEvent ev)
            {
                foreach (var val in ev.Valuators)
                {
                    if (Scrollers.Any(s => s.Number == val.Key))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Example #2
0
        /// <summary>
        /// Called when [device event].
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="ev">The ev.</param>
        private 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.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.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
                                                                    type.Value, ev.Position, ev.Modifiers));
                }
            }

            _pointerDevice.UpdateValuators(ev.Valuators);
        }