bool GetMouseDevice(int deviceid, out XIMouse mouse) { if (!rawids.ContainsKey(deviceid)) { Debug.Print("Unknown mouse device {0} encountered, ignoring.", deviceid); mouse = null; return(false); } mouse = devices[rawids[deviceid]]; return(true); }
private static void ProcessRawMotion(XIMouse d, ref XIRawEvent raw) { // Note: we use the raw values here, without pointer // ballistics and any other modification. double x = 0; double y = 0; double h = 0; double v = 0; if (d.MotionX.number != -1) { x = ReadRawValue(ref raw, d.MotionX.number); } if (d.MotionY.number != -1) { y = ReadRawValue(ref raw, d.MotionY.number); } if (d.ScrollX.number != -1) { h = ReadRawValue(ref raw, d.ScrollX.number) / d.ScrollX.increment; } if (d.ScrollY.number != -1) { v = ReadRawValue(ref raw, d.ScrollY.number) / d.ScrollY.increment; } if (d.MotionX.mode == XIMode.Relative) { d.State.X += (int)Math.Round(x); } else { d.State.X = (int)Math.Round(x); } if (d.MotionY.mode == XIMode.Relative) { d.State.Y += (int)Math.Round(y); } else { d.State.Y = (int)Math.Round(y); } // Note: OpenTK follows the windows scrolling convention where // (+h, +v) = (right, up). XI2 uses (+h, +v) = (right, down) // instead, so we need to flip the vertical offset. d.State.SetScrollRelative((float)h, (float)-v); }
unsafe static void ProcessRawMotion(XIMouse d, ref XIRawEvent raw) { // Note: we use the raw values here, without pointer // ballistics and any other modification. double x = ReadRawValue(ref raw, d.MotionX.number); double y = ReadRawValue(ref raw, d.MotionY.number); double h = ReadRawValue(ref raw, d.ScrollX.number) / d.ScrollX.increment; double v = ReadRawValue(ref raw, d.ScrollY.number) / d.ScrollY.increment; d.State.X += (int)Math.Round(x); d.State.Y += (int)Math.Round(y); d.State.SetScrollRelative((float)h, (float)v); }
unsafe static void ProcessRawMotion(XIMouse d, ref XIRawEvent raw) { // Note: we use the raw values here, without pointer // ballistics and any other modification. double x = 0; double y = 0; double h = 0; double v = 0; if (d.MotionX.number != -1) x = ReadRawValue(ref raw, d.MotionX.number); if (d.MotionY.number != -1) y = ReadRawValue(ref raw, d.MotionY.number); if (d.ScrollX.number != -1) h = ReadRawValue(ref raw, d.ScrollX.number) / d.ScrollX.increment; if (d.ScrollY.number != -1) v = ReadRawValue(ref raw, d.ScrollY.number) / d.ScrollY.increment; if (d.MotionX.mode == XIMode.Relative) d.State.X += (int)Math.Round(x); else d.State.X = (int)Math.Round(x); if (d.MotionY.mode == XIMode.Relative) d.State.Y += (int)Math.Round(y); else d.State.Y = (int)Math.Round(y); // Note: OpenTK follows the windows scrolling convention where // (+h, +v) = (right, up). XI2 uses (+h, +v) = (right, down) // instead, so we need to flip the vertical offset. d.State.SetScrollRelative((float)h, (float)(-v)); }
bool GetMouseDevice(int deviceid, out XIMouse mouse) { if (!rawids.ContainsKey(deviceid)) { Debug.Print("Unknown mouse device {0} encountered, ignoring.", deviceid); mouse = null; return false; } mouse = devices[rawids[deviceid]]; return true; }
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); } } }
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); } } }