private void ProcessRawEvent(ref XGenericEventCookie cookie)
        {
            lock (Sync)
            {
                unsafe
                {
                    var        raw = *(XIRawEvent *)cookie.data;
                    XIMouse    mouse;
                    XIKeyboard keyboard;

                    switch (raw.evtype)
                    {
                    case XIEventType.RawMotion:
                        if (GetMouseDevice(raw.deviceid, out mouse))
                        {
                            ProcessRawMotion(mouse, ref raw);
                        }

                        break;

                    case XIEventType.RawButtonPress:
                    case XIEventType.RawButtonRelease:
                        if (GetMouseDevice(raw.deviceid, out mouse))
                        {
                            float dx, dy;
                            var   button = X11KeyMap.TranslateButton(raw.detail, out dx, out dy);
                            mouse.State[button] = raw.evtype == XIEventType.RawButtonPress;
                            if (mouse.ScrollX.number == -1 && mouse.ScrollY.number == -1)
                            {
                                mouse.State.SetScrollRelative(dx, dy);
                            }
                        }

                        break;

                    case XIEventType.RawKeyPress:
                    case XIEventType.RawKeyRelease:
                        if (GetKeyboardDevice(raw.deviceid, out keyboard))
                        {
                            Key key;
                            if (KeyMap.TranslateKey(raw.detail, out key))
                            {
                                keyboard.State[key] = raw.evtype == XIEventType.RawKeyPress;
                            }
                        }

                        break;
                    }
                }
            }
        }
Exemple #2
0
        void ProcessRawEvent(ref XGenericEventCookie cookie)
        {
            lock (Sync)
            {
                unsafe
                {
                    XIRawEvent raw = *(XIRawEvent*)cookie.data;
                    XIMouse mouse;
                    XIKeyboard keyboard;

                    switch (raw.evtype)
                    {
                        case XIEventType.RawMotion:
                            if (GetMouseDevice(raw.deviceid, out mouse))
                            {
                                ProcessRawMotion(mouse, ref raw);
                            }
                            break;

                        case XIEventType.RawButtonPress:
                        case XIEventType.RawButtonRelease:
                            if (GetMouseDevice(raw.deviceid, out mouse))
                            {
                                float dx, dy;
                                MouseButton button = X11KeyMap.TranslateButton(raw.detail, out dx, out dy);
                                mouse.State[button] = raw.evtype == XIEventType.RawButtonPress;
                                if (mouse.ScrollX.number == -1 && mouse.ScrollY.number == -1)
                                    mouse.State.SetScrollRelative(dx, dy);
                            }
                            break;

                        case XIEventType.RawKeyPress:
                        case XIEventType.RawKeyRelease:
                            if (GetKeyboardDevice(raw.deviceid, out keyboard))
                            {
                                Key key;
                                if (KeyMap.TranslateKey(raw.detail, out key))
                                {
                                    keyboard.State[key] = raw.evtype == XIEventType.RawKeyPress;
                                }
                            }
                            break;
                    }
                }
            }
        }
Exemple #3
0
 public static extern void XFreeEventData(IntPtr display, ref XGenericEventCookie cookie);
Exemple #4
0
 public static extern int XGetEventData(IntPtr display, ref XGenericEventCookie cookie);
Exemple #5
0
 public static extern void XFreeEventData(IntPtr display, ref XGenericEventCookie cookie);
Exemple #6
0
 public static extern int XGetEventData(IntPtr display, ref XGenericEventCookie cookie);
Exemple #7
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);
                }
            }
        }