mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-07 16:50:43 +00:00
[Linux] Improve checks for TTY
This commit is contained in:
parent
9e73358dd7
commit
e7bd311fbd
|
@ -37,6 +37,12 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
const string lib = "libc";
|
const string lib = "libc";
|
||||||
|
|
||||||
|
[DllImport(lib)]
|
||||||
|
public static extern int dup(int file);
|
||||||
|
|
||||||
|
[DllImport(lib)]
|
||||||
|
public static extern int dup2(int file1, int file2);
|
||||||
|
|
||||||
[DllImport(lib)]
|
[DllImport(lib)]
|
||||||
public static extern int ioctl(int d, JoystickIoctlCode request, ref int data);
|
public static extern int ioctl(int d, JoystickIoctlCode request, ref int data);
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,10 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
const string lib = "libc";
|
const string lib = "libc";
|
||||||
|
|
||||||
|
[DllImport(lib, EntryPoint = "isatty", CallingConvention = CallingConvention.Cdecl)]
|
||||||
|
[return: MarshalAs(UnmanagedType.I4)]
|
||||||
|
public static extern bool IsTerminal(int fd);
|
||||||
|
|
||||||
[DllImport(lib, EntryPoint = "tcgetattr", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport(lib, EntryPoint = "tcgetattr", CallingConvention = CallingConvention.Cdecl)]
|
||||||
public static extern int GetAttributes(int fd, out TerminalState state);
|
public static extern int GetAttributes(int fd, out TerminalState state);
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,12 @@ namespace OpenTK.Platform.Linux
|
||||||
TerminalState current_state;
|
TerminalState current_state;
|
||||||
|
|
||||||
IntPtr original_mode = new IntPtr(-1);
|
IntPtr original_mode = new IntPtr(-1);
|
||||||
|
int original_stdin;
|
||||||
|
|
||||||
public LinuxKeyboardTTY()
|
public LinuxKeyboardTTY()
|
||||||
{
|
{
|
||||||
|
Debug.Print("[Linux] Using TTY keyboard input.");
|
||||||
|
|
||||||
if (!SetupTTY(stdin))
|
if (!SetupTTY(stdin))
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
|
@ -64,6 +67,16 @@ namespace OpenTK.Platform.Linux
|
||||||
|
|
||||||
bool SetupTTY(int stdin)
|
bool SetupTTY(int stdin)
|
||||||
{
|
{
|
||||||
|
// Ensure that we are using a real terminal,
|
||||||
|
// rather than some short of file redirection.thing.
|
||||||
|
if (!Terminal.IsTerminal(stdin))
|
||||||
|
{
|
||||||
|
Debug.Print("[Linux] Terminal.IsTerminal({0}) returned false.", stdin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//original_stdin = Libc.dup(stdin);
|
||||||
|
|
||||||
int ret = Terminal.GetAttributes(stdin, out original_state);
|
int ret = Terminal.GetAttributes(stdin, out original_state);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +96,7 @@ namespace OpenTK.Platform.Linux
|
||||||
|
|
||||||
// Update terminal state
|
// Update terminal state
|
||||||
current_state = original_state;
|
current_state = original_state;
|
||||||
current_state.LocalMode &= ~(LocalFlags.ECHO | LocalFlags.ICANON | LocalFlags.ISIG);
|
current_state.LocalMode &= ~(/*LocalFlags.ECHO |*/ LocalFlags.ICANON | LocalFlags.ISIG);
|
||||||
current_state.InputMode &= ~(
|
current_state.InputMode &= ~(
|
||||||
InputFlags.ISTRIP | InputFlags.IGNCR | InputFlags.ICRNL |
|
InputFlags.ISTRIP | InputFlags.IGNCR | InputFlags.ICRNL |
|
||||||
InputFlags.INLCR | InputFlags.IXOFF | InputFlags.IXON);
|
InputFlags.INLCR | InputFlags.IXOFF | InputFlags.IXON);
|
||||||
|
@ -113,6 +126,8 @@ namespace OpenTK.Platform.Linux
|
||||||
{
|
{
|
||||||
if (original_mode != new IntPtr(-1))
|
if (original_mode != new IntPtr(-1))
|
||||||
{
|
{
|
||||||
|
Debug.Print("[Linux] Exiting TTY keyboard input.");
|
||||||
|
|
||||||
Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, ref original_mode);
|
Libc.ioctl(stdin, KeyboardIoctlCode.SetMode, ref original_mode);
|
||||||
Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref original_state);
|
Terminal.SetAttributes(stdin, OptionalActions.FLUSH, ref original_state);
|
||||||
original_mode = new IntPtr(-1);
|
original_mode = new IntPtr(-1);
|
||||||
|
|
Loading…
Reference in a new issue