From 906216fb70003c0340a61ae75fc9f12d25da5e1d Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:06:10 +0000 Subject: [PATCH 01/24] libinput v0.4 removed libinput_udev_create_for_seat and replaced with two functions libinput_udev_create_context and libinput_udev_assign_seat to separately create a context and assign it a seat name. --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 8dd2b69d..79911251 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -45,9 +45,12 @@ namespace OpenTK.Platform.Linux { internal const string lib = "libinput"; - [DllImport(lib, EntryPoint = "libinput_udev_create_for_seat", CallingConvention = CallingConvention.Cdecl)] + [DllImport(lib, EntryPoint = "libinput_udev_create_context", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr CreateContext(InputInterface @interface, - IntPtr user_data, IntPtr udev, string seat_id); + IntPtr user_data, IntPtr udev); + + [DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)] + public static extern int AssignSeat(IntPtr @libinput, string seat_id); [DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)] public static extern void DestroyContext(IntPtr libinput); From 1e2a8168e35bb3babd59c6426be0b78199b28ff6 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:13:37 +0000 Subject: [PATCH 02/24] libinput v0.8 removed libinput_event_pointer_get_axis and replace with libinput_event_pointer_has_axis and libinput_event_pointer_get_axis_value now takes a specified PointerAxis --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 79911251..53381939 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -278,8 +278,8 @@ namespace OpenTK.Platform.Linux public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } } public uint ButtonCount { get { return GetButtonCount(@event); } } public ButtonState ButtonState { get { return GetButtonState(@event); } } - public PointerAxis Axis { get { return GetAxis(@event); } } - public Fixed24 AxisValue { get { return GetAxisValue(@event); } } + public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; } + public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); } public Fixed24 DeltaX { get { return GetDX(@event); } } public Fixed24 DeltaY { get { return GetDY(@event); } } public Fixed24 X { get { return GetAbsX(@event); } } @@ -305,11 +305,11 @@ namespace OpenTK.Platform.Linux [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)] static extern ButtonState GetButtonState(IntPtr @event); - [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis", CallingConvention = CallingConvention.Cdecl)] - static extern PointerAxis GetAxis(IntPtr @event); + [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_has_axis", CallingConvention = CallingConvention.Cdecl)] + static extern int HasAxis(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis_value", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAxisValue(IntPtr @event); + static extern double GetAxisValue(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)] static extern Fixed24 GetDX(IntPtr @event); From 9a0fa50b3a6e9b6c278d1aec547beb21e5859898 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:15:45 +0000 Subject: [PATCH 03/24] Pointer coordinate query functions now return doubles. --- .../Platform/Linux/Bindings/LibInput.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 53381939..d6ab8e98 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -280,12 +280,12 @@ namespace OpenTK.Platform.Linux public ButtonState ButtonState { get { return GetButtonState(@event); } } public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; } public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); } - public Fixed24 DeltaX { get { return GetDX(@event); } } - public Fixed24 DeltaY { get { return GetDY(@event); } } - public Fixed24 X { get { return GetAbsX(@event); } } - public Fixed24 Y { get { return GetAbsY(@event); } } - public Fixed24 TransformedX(int width) { return GetAbsXTransformed(@event, width); } - public Fixed24 TransformedY(int height) { return GetAbsYTransformed(@event, height); } + public double DeltaX { get { return GetDX(@event); } } + public double DeltaY { get { return GetDY(@event); } } + public double X { get { return GetAbsX(@event); } } + public double Y { get { return GetAbsY(@event); } } + public double TransformedX(int width) { return GetAbsXTransformed(@event, width); } + public double TransformedY(int height) { return GetAbsYTransformed(@event, height); } [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)] static extern uint GetTime(IntPtr @event); @@ -312,22 +312,22 @@ namespace OpenTK.Platform.Linux static extern double GetAxisValue(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetDX(IntPtr @event); + static extern double GetDX(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dy", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetDY(IntPtr @event); + static extern double GetDY(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsX(IntPtr @event); + static extern double GetAbsX(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsY(IntPtr @event); + static extern double GetAbsY(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x_transformed", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsXTransformed(IntPtr @event, int width); + static extern double GetAbsXTransformed(IntPtr @event, int width); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y_transformed", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsYTransformed(IntPtr @event, int height); + static extern double GetAbsYTransformed(IntPtr @event, int height); } } From 60a5315e32bf304fd30995c9f78d33eb9a2d32d2 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:17:52 +0000 Subject: [PATCH 04/24] Removed @ symbol from IntPtr name --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index d6ab8e98..d45f55de 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -50,7 +50,7 @@ namespace OpenTK.Platform.Linux IntPtr user_data, IntPtr udev); [DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)] - public static extern int AssignSeat(IntPtr @libinput, string seat_id); + public static extern int AssignSeat(IntPtr libinput, string seat_id); [DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)] public static extern void DestroyContext(IntPtr libinput); From 72f1e433b4389c7ecf516ebc2c8f7800e52122ff Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:30:08 +0000 Subject: [PATCH 05/24] Use new Libinput.CreateContext and Libinput.AssignSeat functions in Setup(). --- src/OpenTK/Platform/Linux/LinuxInput.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 8b7a02ee..5e42712b 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -314,7 +314,7 @@ namespace OpenTK.Platform.Linux } Debug.Print("[Input] Udev.New() = {0:x}", udev); - input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev, "seat0"); + input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev); if (input_context == IntPtr.Zero) { Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev); @@ -323,6 +323,16 @@ namespace OpenTK.Platform.Linux } Debug.Print("[Input] LibInput.CreateContext({0:x}) = {1:x}", udev, input_context); + string seat_id = "seat0"; + int seat_assignment = LibInput.AssignSeat(input_context, seat_id); + if (seat_assignment == -1) + { + Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1} failed.", input_context, seat_id); + Interlocked.Increment(ref exit); + return; + } + Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1}", input_context, seat_id); + fd = LibInput.GetFD(input_context); if (fd < 0) { From a7ca0921df33736b8e73023c2ee8ca2d7ce08a09 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:31:58 +0000 Subject: [PATCH 06/24] Use new axis querying functions to update mouse scroll state. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 5e42712b..efa45c70 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -485,21 +485,15 @@ namespace OpenTK.Platform.Linux { mouse.State.SetIsConnected(true); - double value = e.AxisValue; - PointerAxis axis = e.Axis; - switch (axis) + if (e.HasAxis(PointerAxis.HorizontalScroll)) { - case PointerAxis.HorizontalScroll: - mouse.State.SetScrollRelative((float)value, 0); - break; - case PointerAxis.VerticalScroll: - mouse.State.SetScrollRelative(0, (float)value); - break; - - default: - Debug.Print("[Input] Unknown scroll axis {0}.", axis); - break; + mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0); + } + if (e.HasAxis(PointerAxis.VerticalScroll)) + { + Debug.Print(e.AxisValue(PointerAxis.VerticalScroll)); + mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll)); } } } From ee69d2354f594d144ea465ea605a38acd87e7e5b Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:34:11 +0000 Subject: [PATCH 07/24] Relative pointer motion should use the relative (Delta) query functions. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index efa45c70..894a258e 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -512,7 +512,7 @@ namespace OpenTK.Platform.Linux void HandlePointerMotion(MouseDevice mouse, PointerEvent e) { - Vector2 delta = new Vector2((float)e.X, (float)e.Y); + Vector2 delta = new Vector2((float)e.DeltaX, (float)e.DeltaY); if (mouse != null) { mouse.State.SetIsConnected(true); From c5f6af87d0f86a9bc30718ab57e484e2c3f5b601 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:37:14 +0000 Subject: [PATCH 08/24] Mistake in change. The Debug.Print statement should not be there. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 894a258e..b68753b0 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -487,12 +487,10 @@ namespace OpenTK.Platform.Linux if (e.HasAxis(PointerAxis.HorizontalScroll)) { - mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0); } if (e.HasAxis(PointerAxis.VerticalScroll)) { - Debug.Print(e.AxisValue(PointerAxis.VerticalScroll)); mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll)); } } From 5eb42f0e3808630853bed5009245d660fae9f3a3 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:40:18 +0000 Subject: [PATCH 09/24] Some casts required in the absolute motion handler now that the query functions return doubles. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index b68753b0..ce5457c3 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -528,12 +528,12 @@ namespace OpenTK.Platform.Linux if (mouse != null) { mouse.State.SetIsConnected(true); - mouse.State.Position = new Vector2(e.X, e.Y); + mouse.State.Position = new Vector2((float)e.X, (float)e.Y); } CursorPosition = new Vector2( - e.TransformedX(bounds.Width), - e.TransformedY(bounds.Height)); + (float)e.TransformedX(bounds.Width), + (float)e.TransformedY(bounds.Height)); UpdateCursor(); } From 3c71e9b96fcc53e50180c806acbecbbcf4c77d0c Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Wed, 11 Jan 2017 21:30:33 +0000 Subject: [PATCH 10/24] Moving the LockSurface after waiting for the page flip stops the rendering glitches on Linux/KMS. --- src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs b/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs index d6959544..779fd36d 100644 --- a/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs +++ b/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs @@ -67,9 +67,6 @@ namespace OpenTK.Platform.Linux { base.SwapBuffers(); - bo_next = LockSurface(); - int fb = GetFramebuffer(bo_next); - if (is_flip_queued) { // Todo: if we don't wait for the page flip, @@ -84,6 +81,8 @@ namespace OpenTK.Platform.Linux } } + bo_next = LockSurface(); + int fb = GetFramebuffer(bo_next); QueueFlip(fb); } From 77f3c7528c2d894f3dba524e3be0c4bb3c8ff2bc Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Thu, 12 Jan 2017 16:58:48 +0000 Subject: [PATCH 11/24] Remove DRM cursor on Dispose. --- src/OpenTK/Platform/Linux/LinuxNativeWindow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs b/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs index 200b8e09..46ff13be 100644 --- a/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs +++ b/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs @@ -366,6 +366,7 @@ namespace OpenTK.Platform.Linux if (disposing) { Debug.Print("[KMS] Destroying window {0}.", window.Handle); + Drm.SetCursor(window.FD, window.DisplayDevice.Id, 0, 0, 0, 0, 0); window.Dispose(); Gbm.DestroySurface(window.Handle); } From 79bccee53548484c58315e185d22e4d8272f39c1 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Tue, 13 Jun 2017 16:19:50 -0500 Subject: [PATCH 12/24] Remove Fixed24 struct --- .../Platform/Linux/Bindings/LibInput.cs | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index d45f55de..2ca8da45 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -195,31 +195,6 @@ namespace OpenTK.Platform.Linux HorizontalScroll = 1 } - struct Fixed24 - { - internal readonly int Value; - - public static implicit operator double(Fixed24 n) - { - long l = ((1023L + 44L) << 52) + (1L << 51) + n.Value; - unsafe - { - double d = *(double*)&l; - return d - (3L << 43); - } - } - - public static implicit operator float(Fixed24 n) - { - return (float)(double)n; - } - - public static explicit operator int(Fixed24 n) - { - return n.Value >> 8; - } - } - [StructLayout(LayoutKind.Sequential)] class InputInterface { From 17a7464793f8dbe0f040b1b3e1fb9111d85de8bd Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:06:10 +0000 Subject: [PATCH 13/24] libinput v0.4 removed libinput_udev_create_for_seat and replaced with two functions libinput_udev_create_context and libinput_udev_assign_seat to separately create a context and assign it a seat name. --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 8dd2b69d..79911251 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -45,9 +45,12 @@ namespace OpenTK.Platform.Linux { internal const string lib = "libinput"; - [DllImport(lib, EntryPoint = "libinput_udev_create_for_seat", CallingConvention = CallingConvention.Cdecl)] + [DllImport(lib, EntryPoint = "libinput_udev_create_context", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr CreateContext(InputInterface @interface, - IntPtr user_data, IntPtr udev, string seat_id); + IntPtr user_data, IntPtr udev); + + [DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)] + public static extern int AssignSeat(IntPtr @libinput, string seat_id); [DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)] public static extern void DestroyContext(IntPtr libinput); From 0f65acc1651aa05c99d59a7b9c88d793a790df35 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:13:37 +0000 Subject: [PATCH 14/24] libinput v0.8 removed libinput_event_pointer_get_axis and replace with libinput_event_pointer_has_axis and libinput_event_pointer_get_axis_value now takes a specified PointerAxis --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 79911251..53381939 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -278,8 +278,8 @@ namespace OpenTK.Platform.Linux public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } } public uint ButtonCount { get { return GetButtonCount(@event); } } public ButtonState ButtonState { get { return GetButtonState(@event); } } - public PointerAxis Axis { get { return GetAxis(@event); } } - public Fixed24 AxisValue { get { return GetAxisValue(@event); } } + public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; } + public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); } public Fixed24 DeltaX { get { return GetDX(@event); } } public Fixed24 DeltaY { get { return GetDY(@event); } } public Fixed24 X { get { return GetAbsX(@event); } } @@ -305,11 +305,11 @@ namespace OpenTK.Platform.Linux [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)] static extern ButtonState GetButtonState(IntPtr @event); - [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis", CallingConvention = CallingConvention.Cdecl)] - static extern PointerAxis GetAxis(IntPtr @event); + [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_has_axis", CallingConvention = CallingConvention.Cdecl)] + static extern int HasAxis(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis_value", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAxisValue(IntPtr @event); + static extern double GetAxisValue(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)] static extern Fixed24 GetDX(IntPtr @event); From 5db38956d60f09117f20955873320980d31264e6 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:15:45 +0000 Subject: [PATCH 15/24] Pointer coordinate query functions now return doubles. --- .../Platform/Linux/Bindings/LibInput.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index 53381939..d6ab8e98 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -280,12 +280,12 @@ namespace OpenTK.Platform.Linux public ButtonState ButtonState { get { return GetButtonState(@event); } } public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; } public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); } - public Fixed24 DeltaX { get { return GetDX(@event); } } - public Fixed24 DeltaY { get { return GetDY(@event); } } - public Fixed24 X { get { return GetAbsX(@event); } } - public Fixed24 Y { get { return GetAbsY(@event); } } - public Fixed24 TransformedX(int width) { return GetAbsXTransformed(@event, width); } - public Fixed24 TransformedY(int height) { return GetAbsYTransformed(@event, height); } + public double DeltaX { get { return GetDX(@event); } } + public double DeltaY { get { return GetDY(@event); } } + public double X { get { return GetAbsX(@event); } } + public double Y { get { return GetAbsY(@event); } } + public double TransformedX(int width) { return GetAbsXTransformed(@event, width); } + public double TransformedY(int height) { return GetAbsYTransformed(@event, height); } [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)] static extern uint GetTime(IntPtr @event); @@ -312,22 +312,22 @@ namespace OpenTK.Platform.Linux static extern double GetAxisValue(IntPtr @event, PointerAxis axis); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dx", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetDX(IntPtr @event); + static extern double GetDX(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_dy", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetDY(IntPtr @event); + static extern double GetDY(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsX(IntPtr @event); + static extern double GetAbsX(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsY(IntPtr @event); + static extern double GetAbsY(IntPtr @event); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_x_transformed", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsXTransformed(IntPtr @event, int width); + static extern double GetAbsXTransformed(IntPtr @event, int width); [DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_absolute_y_transformed", CallingConvention = CallingConvention.Cdecl)] - static extern Fixed24 GetAbsYTransformed(IntPtr @event, int height); + static extern double GetAbsYTransformed(IntPtr @event, int height); } } From 8558e86e81bf181f297df1abd41d316fd4774801 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:17:52 +0000 Subject: [PATCH 16/24] Removed @ symbol from IntPtr name --- src/OpenTK/Platform/Linux/Bindings/LibInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index d6ab8e98..d45f55de 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -50,7 +50,7 @@ namespace OpenTK.Platform.Linux IntPtr user_data, IntPtr udev); [DllImport(lib, EntryPoint = "libinput_udev_assign_seat", CallingConvention = CallingConvention.Cdecl)] - public static extern int AssignSeat(IntPtr @libinput, string seat_id); + public static extern int AssignSeat(IntPtr libinput, string seat_id); [DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)] public static extern void DestroyContext(IntPtr libinput); From fa8f19a40afb2311442480f587846470d21300fd Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:30:08 +0000 Subject: [PATCH 17/24] Use new Libinput.CreateContext and Libinput.AssignSeat functions in Setup(). --- src/OpenTK/Platform/Linux/LinuxInput.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 8b7a02ee..5e42712b 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -314,7 +314,7 @@ namespace OpenTK.Platform.Linux } Debug.Print("[Input] Udev.New() = {0:x}", udev); - input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev, "seat0"); + input_context = LibInput.CreateContext(input_interface, IntPtr.Zero, udev); if (input_context == IntPtr.Zero) { Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev); @@ -323,6 +323,16 @@ namespace OpenTK.Platform.Linux } Debug.Print("[Input] LibInput.CreateContext({0:x}) = {1:x}", udev, input_context); + string seat_id = "seat0"; + int seat_assignment = LibInput.AssignSeat(input_context, seat_id); + if (seat_assignment == -1) + { + Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1} failed.", input_context, seat_id); + Interlocked.Increment(ref exit); + return; + } + Debug.Print("[Input] LibInput.AssignSeat({0:x}) = {1}", input_context, seat_id); + fd = LibInput.GetFD(input_context); if (fd < 0) { From 9494457c26231ea2743b5e506c1e0741ab250e89 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:31:58 +0000 Subject: [PATCH 18/24] Use new axis querying functions to update mouse scroll state. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 5e42712b..efa45c70 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -485,21 +485,15 @@ namespace OpenTK.Platform.Linux { mouse.State.SetIsConnected(true); - double value = e.AxisValue; - PointerAxis axis = e.Axis; - switch (axis) + if (e.HasAxis(PointerAxis.HorizontalScroll)) { - case PointerAxis.HorizontalScroll: - mouse.State.SetScrollRelative((float)value, 0); - break; - case PointerAxis.VerticalScroll: - mouse.State.SetScrollRelative(0, (float)value); - break; - - default: - Debug.Print("[Input] Unknown scroll axis {0}.", axis); - break; + mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0); + } + if (e.HasAxis(PointerAxis.VerticalScroll)) + { + Debug.Print(e.AxisValue(PointerAxis.VerticalScroll)); + mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll)); } } } From bbbbc75e75c3aabdce406b14dbb07958f8e1f385 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:34:11 +0000 Subject: [PATCH 19/24] Relative pointer motion should use the relative (Delta) query functions. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index efa45c70..894a258e 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -512,7 +512,7 @@ namespace OpenTK.Platform.Linux void HandlePointerMotion(MouseDevice mouse, PointerEvent e) { - Vector2 delta = new Vector2((float)e.X, (float)e.Y); + Vector2 delta = new Vector2((float)e.DeltaX, (float)e.DeltaY); if (mouse != null) { mouse.State.SetIsConnected(true); From 64e6346ac48013f77a39dc10957bafaf14e2fdbb Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:37:14 +0000 Subject: [PATCH 20/24] Mistake in change. The Debug.Print statement should not be there. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index 894a258e..b68753b0 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -487,12 +487,10 @@ namespace OpenTK.Platform.Linux if (e.HasAxis(PointerAxis.HorizontalScroll)) { - mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0); } if (e.HasAxis(PointerAxis.VerticalScroll)) { - Debug.Print(e.AxisValue(PointerAxis.VerticalScroll)); mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll)); } } From f08d210ba3409aaf196f14c3eecb7704f1972fb0 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Fri, 6 Jan 2017 15:40:18 +0000 Subject: [PATCH 21/24] Some casts required in the absolute motion handler now that the query functions return doubles. --- src/OpenTK/Platform/Linux/LinuxInput.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxInput.cs b/src/OpenTK/Platform/Linux/LinuxInput.cs index b68753b0..ce5457c3 100644 --- a/src/OpenTK/Platform/Linux/LinuxInput.cs +++ b/src/OpenTK/Platform/Linux/LinuxInput.cs @@ -528,12 +528,12 @@ namespace OpenTK.Platform.Linux if (mouse != null) { mouse.State.SetIsConnected(true); - mouse.State.Position = new Vector2(e.X, e.Y); + mouse.State.Position = new Vector2((float)e.X, (float)e.Y); } CursorPosition = new Vector2( - e.TransformedX(bounds.Width), - e.TransformedY(bounds.Height)); + (float)e.TransformedX(bounds.Width), + (float)e.TransformedY(bounds.Height)); UpdateCursor(); } From 612b86bd5a5ff6e3c6309b20db3a23e0a9978d3a Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Wed, 11 Jan 2017 21:30:33 +0000 Subject: [PATCH 22/24] Moving the LockSurface after waiting for the page flip stops the rendering glitches on Linux/KMS. --- src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs b/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs index d6959544..779fd36d 100644 --- a/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs +++ b/src/OpenTK/Platform/Linux/LinuxGraphicsContext.cs @@ -67,9 +67,6 @@ namespace OpenTK.Platform.Linux { base.SwapBuffers(); - bo_next = LockSurface(); - int fb = GetFramebuffer(bo_next); - if (is_flip_queued) { // Todo: if we don't wait for the page flip, @@ -84,6 +81,8 @@ namespace OpenTK.Platform.Linux } } + bo_next = LockSurface(); + int fb = GetFramebuffer(bo_next); QueueFlip(fb); } From d360026dfe09d110c0614478b695ca2246af8fa9 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Thu, 12 Jan 2017 16:58:48 +0000 Subject: [PATCH 23/24] Remove DRM cursor on Dispose. --- src/OpenTK/Platform/Linux/LinuxNativeWindow.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs b/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs index 200b8e09..46ff13be 100644 --- a/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs +++ b/src/OpenTK/Platform/Linux/LinuxNativeWindow.cs @@ -366,6 +366,7 @@ namespace OpenTK.Platform.Linux if (disposing) { Debug.Print("[KMS] Destroying window {0}.", window.Handle); + Drm.SetCursor(window.FD, window.DisplayDevice.Id, 0, 0, 0, 0, 0); window.Dispose(); Gbm.DestroySurface(window.Handle); } From 543bdc107c82fa11ea49cee9aef694aaecb12c91 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Tue, 13 Jun 2017 16:19:50 -0500 Subject: [PATCH 24/24] Remove Fixed24 struct --- .../Platform/Linux/Bindings/LibInput.cs | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs index d45f55de..2ca8da45 100644 --- a/src/OpenTK/Platform/Linux/Bindings/LibInput.cs +++ b/src/OpenTK/Platform/Linux/Bindings/LibInput.cs @@ -195,31 +195,6 @@ namespace OpenTK.Platform.Linux HorizontalScroll = 1 } - struct Fixed24 - { - internal readonly int Value; - - public static implicit operator double(Fixed24 n) - { - long l = ((1023L + 44L) << 52) + (1L << 51) + n.Value; - unsafe - { - double d = *(double*)&l; - return d - (3L << 43); - } - } - - public static implicit operator float(Fixed24 n) - { - return (float)(double)n; - } - - public static explicit operator int(Fixed24 n) - { - return n.Value >> 8; - } - } - [StructLayout(LayoutKind.Sequential)] class InputInterface {