mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-02-02 20:01:14 +00:00
[Linux] Added stub TTY and libinput IKeyboardDriver2
This commit is contained in:
parent
9bc774f78c
commit
97a539258b
|
@ -815,6 +815,10 @@
|
|||
<Compile Include="Platform\Linux\LinuxWindowInfo.cs" />
|
||||
<Compile Include="Platform\Linux\LinuxGraphicsContext.cs" />
|
||||
<Compile Include="Platform\Linux\Bindings\Poll.cs" />
|
||||
<Compile Include="Platform\Linux\LinuxKeyboardTTY.cs" />
|
||||
<Compile Include="Platform\Linux\Bindings\Udev.cs" />
|
||||
<Compile Include="Platform\Linux\LinuxKeyboardLibInput.cs" />
|
||||
<Compile Include="Platform\Linux\Bindings\LibInput.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
|
92
Source/OpenTK/Platform/Linux/Bindings/LibInput.cs
Normal file
92
Source/OpenTK/Platform/Linux/Bindings/LibInput.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
#region License
|
||||
//
|
||||
// LibInput.cs
|
||||
//
|
||||
// Author:
|
||||
// Stefanos A. <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
#pragma warning disable 0169
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.Platform.Linux
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate int OpenRestrictedCallback(IntPtr path, int flags, IntPtr data);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate void CloseRestrictedCallback(int fd, IntPtr data);
|
||||
|
||||
class LibInput
|
||||
{
|
||||
const string lib = "libinput";
|
||||
|
||||
[DllImport(lib, EntryPoint = "libinput_udev_create_for_seat", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr CreateContext(InputInterface @interface,
|
||||
IntPtr user_data, IntPtr udev, string seat_id);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
class InputInterface
|
||||
{
|
||||
IntPtr open;
|
||||
IntPtr close;
|
||||
|
||||
public InputInterface(
|
||||
OpenRestrictedCallback open_restricted,
|
||||
CloseRestrictedCallback close_restricted)
|
||||
{
|
||||
if (open_restricted == null || close_restricted == null)
|
||||
throw new ArgumentNullException();
|
||||
|
||||
open = Marshal.GetFunctionPointerForDelegate(open_restricted);
|
||||
close = Marshal.GetFunctionPointerForDelegate(close_restricted);
|
||||
}
|
||||
|
||||
#region Default implementation
|
||||
|
||||
static CloseRestrictedCallback CloseRestricted = CloseRestrictedHandler;
|
||||
static void CloseRestrictedHandler(int fd, IntPtr data)
|
||||
{
|
||||
Debug.Print("[Input] Closing fd {0}", fd);
|
||||
Libc.close(fd);
|
||||
}
|
||||
|
||||
static OpenRestrictedCallback OpenRestricted = OpenRestrictedHandler;
|
||||
static int OpenRestrictedHandler(IntPtr path, int flags, IntPtr data)
|
||||
{
|
||||
Debug.Print("[Input] Opening path '{0}'", Marshal.PtrToStringAnsi(path));
|
||||
return Libc.open(path, (OpenFlags)flags);
|
||||
}
|
||||
|
||||
public static readonly InputInterface Default = new InputInterface(
|
||||
OpenRestricted, CloseRestricted);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -49,11 +49,18 @@ namespace OpenTK.Platform.Linux
|
|||
[DllImport(lib)]
|
||||
public static extern int open([MarshalAs(UnmanagedType.LPStr)]string pathname, OpenFlags flags);
|
||||
|
||||
[DllImport(lib)]
|
||||
public static extern int open(IntPtr pathname, OpenFlags flags);
|
||||
|
||||
[DllImport(lib)]
|
||||
public static extern int close(int fd);
|
||||
|
||||
[DllImport(lib)]
|
||||
unsafe public static extern IntPtr read(int fd, void* buffer, UIntPtr count);
|
||||
|
||||
[DllImport(lib)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool isatty(int fd);
|
||||
}
|
||||
|
||||
[Flags]
|
||||
|
|
43
Source/OpenTK/Platform/Linux/Bindings/Udev.cs
Normal file
43
Source/OpenTK/Platform/Linux/Bindings/Udev.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
#region License
|
||||
//
|
||||
// Udev.cs
|
||||
//
|
||||
// Author:
|
||||
// Stefanos A. <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK.Platform.Linux
|
||||
{
|
||||
class Udev
|
||||
{
|
||||
const string lib = "libudev";
|
||||
|
||||
[DllImport(lib, EntryPoint = "udev_new")]
|
||||
public static extern IntPtr New();
|
||||
}
|
||||
}
|
||||
|
77
Source/OpenTK/Platform/Linux/LinuxKeyboardLibInput.cs
Normal file
77
Source/OpenTK/Platform/Linux/LinuxKeyboardLibInput.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
#region License
|
||||
//
|
||||
// LinuxKeyboardLibInput.cs
|
||||
//
|
||||
// Author:
|
||||
// thefiddler <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.Linux
|
||||
{
|
||||
class LinuxKeyboardLibInput : IKeyboardDriver2
|
||||
{
|
||||
IntPtr udev;
|
||||
IntPtr input_context;
|
||||
InputInterface input_interface = InputInterface.Default;
|
||||
|
||||
public LinuxKeyboardLibInput()
|
||||
{
|
||||
// Todo: add static path fallback when udev is not installed.
|
||||
udev = Udev.New();
|
||||
if (udev == IntPtr.Zero)
|
||||
throw new NotSupportedException("[Input] Udev.New() failed.");
|
||||
|
||||
input_context = LibInput.CreateContext(input_interface,
|
||||
IntPtr.Zero, udev, "seat0");
|
||||
if (input_context == IntPtr.Zero)
|
||||
throw new NotSupportedException("[Input] Udev.New() failed.");
|
||||
|
||||
|
||||
}
|
||||
|
||||
#region IKeyboardDriver2 implementation
|
||||
|
||||
public KeyboardState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public KeyboardState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
64
Source/OpenTK/Platform/Linux/LinuxKeyboardTTY.cs
Normal file
64
Source/OpenTK/Platform/Linux/LinuxKeyboardTTY.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
#region License
|
||||
//
|
||||
// LinuxKeyboardTTY.cs
|
||||
//
|
||||
// Author:
|
||||
// thefiddler <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace OpenTK.Platform.Linux
|
||||
{
|
||||
class LinuxKeyboardTTY : IKeyboardDriver2
|
||||
{
|
||||
public LinuxKeyboardTTY()
|
||||
{
|
||||
}
|
||||
|
||||
#region IKeyboardDriver2 implementation
|
||||
|
||||
public KeyboardState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public KeyboardState GetState(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetDeviceName(int index)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -146,6 +146,11 @@ namespace OpenTK.Platform.Linux
|
|||
|
||||
#region INativeWindow Members
|
||||
|
||||
public override void ProcessEvents()
|
||||
{
|
||||
base.ProcessEvents();
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
exists = false;
|
||||
|
|
Loading…
Reference in a new issue