Merge pull request #541 from varon/malcomstill-pr-471v2
Updated Linux/KMS platform to work with recent versions of libinput / Fix for Linux/KMS rendering glitches
This commit is contained in:
commit
b207829e80
4 changed files with 46 additions and 66 deletions
|
@ -45,9 +45,12 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
internal const string lib = "libinput";
|
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,
|
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)]
|
[DllImport(lib, EntryPoint = "libinput_destroy", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern void DestroyContext(IntPtr libinput);
|
public static extern void DestroyContext(IntPtr libinput);
|
||||||
|
@ -192,31 +195,6 @@ namespace OpenTK.Platform.Linux
|
||||||
HorizontalScroll = 1
|
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)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
class InputInterface
|
class InputInterface
|
||||||
{
|
{
|
||||||
|
@ -275,14 +253,14 @@ namespace OpenTK.Platform.Linux
|
||||||
public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } }
|
public EvdevButton Button { get { return (EvdevButton)GetButton(@event); } }
|
||||||
public uint ButtonCount { get { return GetButtonCount(@event); } }
|
public uint ButtonCount { get { return GetButtonCount(@event); } }
|
||||||
public ButtonState ButtonState { get { return GetButtonState(@event); } }
|
public ButtonState ButtonState { get { return GetButtonState(@event); } }
|
||||||
public PointerAxis Axis { get { return GetAxis(@event); } }
|
public bool HasAxis(PointerAxis axis) { return HasAxis(@event, axis) != 0; }
|
||||||
public Fixed24 AxisValue { get { return GetAxisValue(@event); } }
|
public double AxisValue(PointerAxis axis) { return GetAxisValue(@event, axis); }
|
||||||
public Fixed24 DeltaX { get { return GetDX(@event); } }
|
public double DeltaX { get { return GetDX(@event); } }
|
||||||
public Fixed24 DeltaY { get { return GetDY(@event); } }
|
public double DeltaY { get { return GetDY(@event); } }
|
||||||
public Fixed24 X { get { return GetAbsX(@event); } }
|
public double X { get { return GetAbsX(@event); } }
|
||||||
public Fixed24 Y { get { return GetAbsY(@event); } }
|
public double Y { get { return GetAbsY(@event); } }
|
||||||
public Fixed24 TransformedX(int width) { return GetAbsXTransformed(@event, width); }
|
public double TransformedX(int width) { return GetAbsXTransformed(@event, width); }
|
||||||
public Fixed24 TransformedY(int height) { return GetAbsYTransformed(@event, height); }
|
public double TransformedY(int height) { return GetAbsYTransformed(@event, height); }
|
||||||
|
|
||||||
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_time", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern uint GetTime(IntPtr @event);
|
static extern uint GetTime(IntPtr @event);
|
||||||
|
@ -302,29 +280,29 @@ namespace OpenTK.Platform.Linux
|
||||||
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_button_state", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern ButtonState GetButtonState(IntPtr @event);
|
static extern ButtonState GetButtonState(IntPtr @event);
|
||||||
|
|
||||||
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_has_axis", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern PointerAxis GetAxis(IntPtr @event);
|
static extern int HasAxis(IntPtr @event, PointerAxis axis);
|
||||||
|
|
||||||
[DllImport(LibInput.lib, EntryPoint = "libinput_event_pointer_get_axis_value", CallingConvention = CallingConvention.Cdecl)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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)]
|
[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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,6 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
base.SwapBuffers();
|
base.SwapBuffers();
|
||||||
|
|
||||||
bo_next = LockSurface();
|
|
||||||
int fb = GetFramebuffer(bo_next);
|
|
||||||
|
|
||||||
if (is_flip_queued)
|
if (is_flip_queued)
|
||||||
{
|
{
|
||||||
// Todo: if we don't wait for the page flip,
|
// 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);
|
QueueFlip(fb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -314,7 +314,7 @@ namespace OpenTK.Platform.Linux
|
||||||
}
|
}
|
||||||
Debug.Print("[Input] Udev.New() = {0:x}", udev);
|
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)
|
if (input_context == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
Debug.Print("[Input] LibInput.CreateContext({0:x}) failed.", udev);
|
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);
|
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);
|
fd = LibInput.GetFD(input_context);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
|
@ -475,21 +485,13 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
mouse.State.SetIsConnected(true);
|
mouse.State.SetIsConnected(true);
|
||||||
|
|
||||||
double value = e.AxisValue;
|
if (e.HasAxis(PointerAxis.HorizontalScroll))
|
||||||
PointerAxis axis = e.Axis;
|
|
||||||
switch (axis)
|
|
||||||
{
|
{
|
||||||
case PointerAxis.HorizontalScroll:
|
mouse.State.SetScrollRelative((float)e.AxisValue(PointerAxis.HorizontalScroll), 0);
|
||||||
mouse.State.SetScrollRelative((float)value, 0);
|
}
|
||||||
break;
|
if (e.HasAxis(PointerAxis.VerticalScroll))
|
||||||
|
{
|
||||||
case PointerAxis.VerticalScroll:
|
mouse.State.SetScrollRelative(0, (float)e.AxisValue(PointerAxis.VerticalScroll));
|
||||||
mouse.State.SetScrollRelative(0, (float)value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
Debug.Print("[Input] Unknown scroll axis {0}.", axis);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,7 +510,7 @@ namespace OpenTK.Platform.Linux
|
||||||
|
|
||||||
void HandlePointerMotion(MouseDevice mouse, PointerEvent e)
|
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)
|
if (mouse != null)
|
||||||
{
|
{
|
||||||
mouse.State.SetIsConnected(true);
|
mouse.State.SetIsConnected(true);
|
||||||
|
@ -526,12 +528,12 @@ namespace OpenTK.Platform.Linux
|
||||||
if (mouse != null)
|
if (mouse != null)
|
||||||
{
|
{
|
||||||
mouse.State.SetIsConnected(true);
|
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(
|
CursorPosition = new Vector2(
|
||||||
e.TransformedX(bounds.Width),
|
(float)e.TransformedX(bounds.Width),
|
||||||
e.TransformedY(bounds.Height));
|
(float)e.TransformedY(bounds.Height));
|
||||||
UpdateCursor();
|
UpdateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -366,6 +366,7 @@ namespace OpenTK.Platform.Linux
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
Debug.Print("[KMS] Destroying window {0}.", window.Handle);
|
Debug.Print("[KMS] Destroying window {0}.", window.Handle);
|
||||||
|
Drm.SetCursor(window.FD, window.DisplayDevice.Id, 0, 0, 0, 0, 0);
|
||||||
window.Dispose();
|
window.Dispose();
|
||||||
Gbm.DestroySurface(window.Handle);
|
Gbm.DestroySurface(window.Handle);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue