From 9ae778a00fb065283aec2632651f6324c2a00a22 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Sat, 9 Aug 2014 22:09:32 +0200 Subject: [PATCH] [X11] Fixed absolute motion valuators --- Source/OpenTK/Platform/X11/XI2MouseKeyboard.cs | 69 ++++++++++---------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/Source/OpenTK/Platform/X11/XI2MouseKeyboard.cs b/Source/OpenTK/Platform/X11/XI2MouseKeyboard.cs index 0cab2e7..e308f39 100644 --- a/Source/OpenTK/Platform/X11/XI2MouseKeyboard.cs +++ b/Source/OpenTK/Platform/X11/XI2MouseKeyboard.cs @@ -60,21 +60,6 @@ namespace OpenTK.Platform.X11 public string Name; } - // Atoms - //static readonly IntPtr ButtonLeft; - //static readonly IntPtr ButtonMiddle; - ////static readonly IntPtr ButtonRight; - //static readonly IntPtr ButtonWheelUp; - //static readonly IntPtr ButtonWheelDown; - //static readonly IntPtr ButtonWheelLeft; - //static readonly IntPtr ButtonWheelRight; - static readonly IntPtr RelX; - static readonly IntPtr RelY; - //static readonly IntPtr RelHorizScroll; - //static readonly IntPtr RelVertScroll; - //static readonly IntPtr RelHorizWheel; - //static readonly IntPtr RelVertWheel; - long cursor_x, cursor_y; // For GetCursorState() List devices = new List(); // list of connected mice Dictionary rawids = new Dictionary(); // maps hardware device ids to XIMouse ids @@ -93,31 +78,6 @@ namespace OpenTK.Platform.X11 { using (new XLock(API.DefaultDisplay)) { - // Mouse - //ButtonLeft = Functions.XInternAtom(API.DefaultDisplay, "Button Left", false); - //ButtonMiddle = Functions.XInternAtom(API.DefaultDisplay, "Button Middle", false); - //ButtonRight = Functions.XInternAtom(API.DefaultDisplay, "Button Right", false); - //ButtonWheelUp = Functions.XInternAtom(API.DefaultDisplay, "Button Wheel Up", false); - //ButtonWheelDown = Functions.XInternAtom(API.DefaultDisplay, "Button Wheel Down", false); - //ButtonWheelLeft = Functions.XInternAtom(API.DefaultDisplay, "Button Horiz Wheel Left", false); - //ButtonWheelRight = Functions.XInternAtom(API.DefaultDisplay, "Button Horiz Wheel Right", false); - RelX = Functions.XInternAtom(API.DefaultDisplay, "Rel X", false); - RelY = Functions.XInternAtom(API.DefaultDisplay, "Rel Y", false); - //RelHorizWheel = Functions.XInternAtom(API.DefaultDisplay, "Rel Horiz Wheel", false); - //RelVertWheel = Functions.XInternAtom(API.DefaultDisplay, "Rel Vert Wheel", false); - //RelHorizScroll = Functions.XInternAtom(API.DefaultDisplay, "Rel Horiz Scroll", false); - //RelVertScroll = Functions.XInternAtom(API.DefaultDisplay, "Rel Vert Scroll", false); - - // Multitouch - //TouchX = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Position X", false); - //TouchY = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Position Y", false); - //TouchMajor = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Touch Major", false); - //TouchMinor = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Touch Minor", false); - //TouchPressure = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Pressure", false); - //TouchId = Functions.XInternAtom(API.DefaultDisplay, "Abs MT Tracking ID", false); - //TouchMaxContacts = Functions.XInternAtom(API.DefaultDisplay, "Max Contacts", false); - - // Custom ExitAtom = Functions.XInternAtom(API.DefaultDisplay, "Exit Input Thread Message", false); } } @@ -391,17 +351,32 @@ namespace OpenTK.Platform.X11 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 == RelX) + if (valuator->label == XI.RelativeX) { Debug.WriteLine("\tRelative X movement"); d.MotionX = *valuator; } - else if (valuator->label == RelY) + 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); @@ -575,8 +550,14 @@ namespace OpenTK.Platform.X11 if (d.ScrollY.number != -1) v = ReadRawValue(ref raw, d.ScrollY.number) / d.ScrollY.increment; - d.State.X += (int)Math.Round(x); - d.State.Y += (int)Math.Round(y); + 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.Absolute) + 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) -- 2.7.4