Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public XEventMask AddWindow(IntPtr xid, IXI2Client window)
        {
            _clients[xid] = window;

            XiSelectEvents(_x11.Display, xid, new Dictionary <int, List <XiEventType> >
            {
                [_pointerDevice.Id] = new List <XiEventType>()
                {
                    XiEventType.XI_Motion,
                    XiEventType.XI_ButtonPress,
                    XiEventType.XI_ButtonRelease,
                }
            });

            // We are taking over mouse input handling from here
            return(XEventMask.PointerMotionMask
                   | XEventMask.ButtonMotionMask
                   | XEventMask.Button1MotionMask
                   | XEventMask.Button2MotionMask
                   | XEventMask.Button3MotionMask
                   | XEventMask.Button4MotionMask
                   | XEventMask.Button5MotionMask
                   | XEventMask.ButtonPressMask
                   | XEventMask.ButtonReleaseMask);
        }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 4
0
        public XEventMask AddWindow(IntPtr xid, IXI2Client window)
        {
            _clients[xid] = window;

            var eventsLength = DefaultEventTypes.Length;

            if (_multitouch)
            {
                eventsLength += MultiTouchEventTypes.Length;
            }

            var events = new List <XiEventType>(eventsLength);

            events.AddRange(DefaultEventTypes);

            if (_multitouch)
            {
                events.AddRange(MultiTouchEventTypes);
            }

            XiSelectEvents(_x11.Display, xid,
                           new Dictionary <int, List <XiEventType> > {
                [_pointerDevice.Id] = events
            });

            // We are taking over mouse input handling from here
            return(XEventMask.PointerMotionMask
                   | XEventMask.ButtonMotionMask
                   | XEventMask.Button1MotionMask
                   | XEventMask.Button2MotionMask
                   | XEventMask.Button3MotionMask
                   | XEventMask.Button4MotionMask
                   | XEventMask.Button5MotionMask
                   | XEventMask.ButtonPressMask
                   | XEventMask.ButtonReleaseMask
                   | XEventMask.LeaveWindowMask
                   | XEventMask.EnterWindowMask);
        }
Ejemplo n.º 5
0
        public XEventMask AddWindow(IntPtr xid, IXI2Client window)
        {
            _clients[xid] = window;
            var events = new List <XiEventType>
            {
                XiEventType.XI_Motion,
                XiEventType.XI_ButtonPress,
                XiEventType.XI_ButtonRelease
            };

            if (_multitouch)
            {
                events.AddRange(new[]
                {
                    XiEventType.XI_TouchBegin,
                    XiEventType.XI_TouchUpdate,
                    XiEventType.XI_TouchEnd
                });
            }

            XiSelectEvents(_x11.Display, xid,
                           new Dictionary <int, List <XiEventType> > {
                [_pointerDevice.Id] = events
            });

            // We are taking over mouse input handling from here
            return(XEventMask.PointerMotionMask
                   | XEventMask.ButtonMotionMask
                   | XEventMask.Button1MotionMask
                   | XEventMask.Button2MotionMask
                   | XEventMask.Button3MotionMask
                   | XEventMask.Button4MotionMask
                   | XEventMask.Button5MotionMask
                   | XEventMask.ButtonPressMask
                   | XEventMask.ButtonReleaseMask);
        }
Ejemplo n.º 6
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);
        }
    }