Ejemplo n.º 1
0
 public static extern void XIFreeDeviceInfo(XIDeviceInfo *info);
Ejemplo n.º 2
0
        void UpdateDevices()
        {
            lock (Sync)
            {
                devices.Clear();
                keyboards.Clear();

                int count;
                unsafe
                {
                    XIDeviceInfo *list = (XIDeviceInfo *)XI.QueryDevice(window.Display,
                                                                        XI.XIAllDevices, out count);

                    Debug.Print("Refreshing input device list");
                    Debug.Print("{0} input devices detected", count);

                    for (int i = 0; i < count; i++)
                    {
                        switch ((list + i)->use)
                        {
                        case XIDeviceType.MasterKeyboard:
                            //case XIDeviceType.SlaveKeyboard:
                        {
                            XIKeyboard k = new XIKeyboard();
                            k.DeviceInfo = *(list + i);
                            k.State.SetIsConnected(k.DeviceInfo.enabled);
                            k.Name = Marshal.PtrToStringAnsi(k.DeviceInfo.name);
                            int id = k.DeviceInfo.deviceid;
                            if (!keyboard_ids.ContainsKey(id))
                            {
                                keyboard_ids.Add(k.DeviceInfo.deviceid, 0);
                            }
                            keyboard_ids[id] = keyboards.Count;
                            keyboards.Add(k);
                        }
                        break;

                        case XIDeviceType.MasterPointer:
                        //case XIDeviceType.SlavePointer:
                        case XIDeviceType.FloatingSlave:
                        {
                            XIMouse d = new XIMouse();
                            d.DeviceInfo = *(list + i);

                            d.State.SetIsConnected(d.DeviceInfo.enabled);
                            d.Name = Marshal.PtrToStringAnsi(d.DeviceInfo.name);
                            Debug.Print("Device {0} \"{1}\" is {2} and has:",
                                        i, d.Name, d.DeviceInfo.enabled ? "enabled" : "disabled");

                            // Decode the XIDeviceInfo to axes, buttons and scroll types
                            for (int j = 0; j < d.DeviceInfo.num_classes; j++)
                            {
                                XIAnyClassInfo *class_info = *((XIAnyClassInfo **)d.DeviceInfo.classes + j);
                                switch (class_info->type)
                                {
                                case XIClassType.Button:
                                {
                                    XIButtonClassInfo *button = (XIButtonClassInfo *)class_info;
                                    Debug.Print("\t{0} buttons", button->num_buttons);
                                }
                                break;

                                case XIClassType.Scroll:
                                {
                                    XIScrollClassInfo *scroll = (XIScrollClassInfo *)class_info;
                                    switch (scroll->scroll_type)
                                    {
                                    case XIScrollType.Vertical:
                                        Debug.WriteLine("\tSmooth vertical scrolling");
                                        d.ScrollY = *scroll;
                                        break;

                                    case XIScrollType.Horizontal:
                                        Debug.WriteLine("\tSmooth horizontal scrolling");
                                        d.ScrollX = *scroll;
                                        break;

                                    default:
                                        Debug.Print("\tUnknown scrolling type {0}", scroll->scroll_type);
                                        break;
                                    }
                                }
                                break;

                                case XIClassType.Valuator:
                                {
                                    // We use relative x/y valuators for mouse movement.
                                    // Iff these are not available, we fall back to
                                    // absolute x/y valuators.
                                    XIValuatorClassInfo *valuator = (XIValuatorClassInfo *)class_info;
                                    if (valuator->label == XI.RelativeX)
                                    {
                                        Debug.WriteLine("\tRelative X movement");
                                        d.MotionX = *valuator;
                                    }
                                    else if (valuator->label == XI.RelativeY)
                                    {
                                        Debug.WriteLine("\tRelative Y movement");
                                        d.MotionY = *valuator;
                                    }
                                    else if (valuator->label == XI.AbsoluteX)
                                    {
                                        Debug.WriteLine("\tAbsolute X movement");
                                        if (d.MotionX.number == -1)
                                        {
                                            d.MotionX = *valuator;
                                        }
                                    }
                                    else if (valuator->label == XI.AbsoluteY)
                                    {
                                        Debug.WriteLine("\tAbsolute X movement");
                                        if (d.MotionY.number == -1)
                                        {
                                            d.MotionY = *valuator;
                                        }
                                    }
                                    else
                                    {
                                        IntPtr label = Functions.XGetAtomName(window.Display, valuator->label);
                                        Debug.Print("\tUnknown valuator {0}",
                                                    Marshal.PtrToStringAnsi(label));
                                        Functions.XFree(label);
                                    }
                                }
                                break;
                                }
                            }

                            // Map the hardware device id to the current XIMouse id
                            int id = d.DeviceInfo.deviceid;
                            if (!rawids.ContainsKey(id))
                            {
                                rawids.Add(id, 0);
                            }
                            rawids[id] = devices.Count;
                            devices.Add(d);
                        }
                        break;
                        }
                    }
                    XI.FreeDeviceInfo((IntPtr)list);
                }
            }
        }
Ejemplo n.º 3
0
 internal static extern void XIFreeDeviceInfo(XIDeviceInfo *info);