Example #1
0
 public override IMouseDriver2 CreateMouseDriver()
 {
     if (XI2Mouse.IsSupported(IntPtr.Zero))
     {
         return(new XI2Mouse()); // Requires xorg 1.7 or higher.
     }
     else
     {
         return(new X11Mouse()); // Always supported.
     }
 }
Example #2
0
 public virtual IMouseDriver2 CreateMouseDriver()
 {
     if (XI2Mouse.IsSupported(IntPtr.Zero))
     {
         return((IMouseDriver2) new XI2Mouse());
     }
     else
     {
         return((IMouseDriver2) new X11Mouse());
     }
 }
Example #3
0
 public XI2Mouse()
 {
     using (new XLock(API.DefaultDisplay))
     {
         this.window              = new X11WindowInfo();
         this.window.Display      = API.DefaultDisplay;
         this.window.Screen       = Functions.XDefaultScreen(this.window.Display);
         this.window.RootWindow   = Functions.XRootWindow(this.window.Display, this.window.Screen);
         this.window.WindowHandle = this.window.RootWindow;
     }
     if (!XI2Mouse.IsSupported(this.window.Display))
     {
         throw new NotSupportedException("XInput2 not supported.");
     }
     using (XIEventMask mask = new XIEventMask(1, (XIEventMasks)229376))
     {
         Functions.XISelectEvents(this.window.Display, this.window.WindowHandle, mask);
         Functions.XISelectEvents(this.window.Display, this.window.RootWindow, mask);
     }
 }
Example #4
0
        private void ProcessEvents()
        {
            while (true)
            {
                XEvent e = new XEvent();
                using (new XLock(this.window.Display))
                {
                    if (!Functions.XCheckIfEvent(this.window.Display, ref e, this.Predicate, new IntPtr(XI2Mouse.XIOpCode)))
                    {
                        break;
                    }
                    XGenericEventCookie cookie = e.GenericEventCookie;
                    if (Functions.XGetEventData(this.window.Display, ref cookie) != 0)
                    {
                        XIRawEvent xiRawEvent = (XIRawEvent)Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent));
                        if (!this.rawids.ContainsKey(xiRawEvent.deviceid))
                        {
                            this.mice.Add(new MouseState());
                            this.rawids.Add(xiRawEvent.deviceid, this.mice.Count - 1);
                        }
                        MouseState mouseState = this.mice[this.rawids[xiRawEvent.deviceid]];
                        switch (xiRawEvent.evtype)
                        {
                        case XIEventType.RawButtonPress:
                            switch (xiRawEvent.detail)
                            {
                            case 1:
                                mouseState.EnableBit(0);
                                break;

                            case 2:
                                mouseState.EnableBit(1);
                                break;

                            case 3:
                                mouseState.EnableBit(2);
                                break;

                            case 4:
                                ++mouseState.WheelPrecise;
                                break;

                            case 5:
                                --mouseState.WheelPrecise;
                                break;

                            case 6:
                                mouseState.EnableBit(3);
                                break;

                            case 7:
                                mouseState.EnableBit(4);
                                break;

                            case 8:
                                mouseState.EnableBit(5);
                                break;

                            case 9:
                                mouseState.EnableBit(6);
                                break;

                            case 10:
                                mouseState.EnableBit(7);
                                break;

                            case 11:
                                mouseState.EnableBit(8);
                                break;

                            case 12:
                                mouseState.EnableBit(9);
                                break;

                            case 13:
                                mouseState.EnableBit(10);
                                break;

                            case 14:
                                mouseState.EnableBit(11);
                                break;
                            }

                        case XIEventType.RawButtonRelease:
                            switch (xiRawEvent.detail)
                            {
                            case 1:
                                mouseState.DisableBit(0);
                                break;

                            case 2:
                                mouseState.DisableBit(1);
                                break;

                            case 3:
                                mouseState.DisableBit(2);
                                break;

                            case 6:
                                mouseState.DisableBit(3);
                                break;

                            case 7:
                                mouseState.DisableBit(4);
                                break;

                            case 8:
                                mouseState.DisableBit(5);
                                break;

                            case 9:
                                mouseState.DisableBit(6);
                                break;

                            case 10:
                                mouseState.DisableBit(7);
                                break;

                            case 11:
                                mouseState.DisableBit(8);
                                break;

                            case 12:
                                mouseState.DisableBit(9);
                                break;

                            case 13:
                                mouseState.DisableBit(10);
                                break;

                            case 14:
                                mouseState.DisableBit(11);
                                break;
                            }

                        case XIEventType.RawMotion:
                            double x = 0.0;
                            double y = 0.0;
                            if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 0))
                            {
                                x = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 0));
                            }
                            if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 1))
                            {
                                y = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 8));
                            }
                            if (!this.CheckMouseWarp(x, y))
                            {
                                mouseState.X += (int)x;
                                mouseState.Y += (int)y;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        this.mice[this.rawids[xiRawEvent.deviceid]] = mouseState;
                    }
                    Functions.XFreeEventData(this.window.Display, ref cookie);
                }
            }
        }