diff --git a/Ryujinx.Core/Hid.cs b/Ryujinx.Core/Hid.cs index bd83e92d4..fec7d9e54 100644 --- a/Ryujinx.Core/Hid.cs +++ b/Ryujinx.Core/Hid.cs @@ -183,7 +183,7 @@ namespace Ryujinx.Core Marshal.StructureToPtr(ControllerInputEntry, HidPtr, false); } - public void SendTouchPoint(HidTouchScreenEntryTouch TouchPoint) + public void SendTouchCoordinates(Touches TouchPoints) { uint InnerOffset = (uint)Marshal.SizeOf(typeof(HidSharedMemHeader)); @@ -203,21 +203,38 @@ namespace Ryujinx.Core Marshal.StructureToPtr(TouchScreenHeader, HidPtr, false); InnerOffset += (uint)Marshal.SizeOf(typeof(HidTouchScreenHeader)) - + (uint)((uint)(OldTouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry))); - HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset); + + (uint)((uint)(TouchScreenHeader.LatestEntry) * Marshal.SizeOf(typeof(HidTouchScreenEntry))); + HidPtr = new IntPtr(Ns.Ram.ToInt64() + (uint)SharedMemOffset + InnerOffset); + + //Truncate number of touches + TouchPoints.NumberOfTouches = TouchPoints.NumberOfTouches > 16 ? 16 : TouchPoints.NumberOfTouches; HidTouchScreenEntry hidTouchScreenEntry = new HidTouchScreenEntry() { Header = new HidTouchScreenEntryHeader() { Timestamp = (ulong)Environment.TickCount, - NumTouches = 1 + NumTouches = TouchPoints.NumberOfTouches }, Touches = new HidTouchScreenEntryTouch[16] }; - //Only supports single touch - hidTouchScreenEntry.Touches[0] = TouchPoint; + //Fill the touch buffer. + for (uint index = 0; index < TouchPoints.NumberOfTouches; index++) + { + hidTouchScreenEntry.Touches[index] = new HidTouchScreenEntryTouch() + { + Timestamp = (uint)Environment.TickCount, + X = TouchPoints.XTouches[index], + Y = TouchPoints.YTouches[index], + TouchIndex = index, + + //Placeholder values till more data is acquired + DiameterX = 10, + DiameterY = 10, + Angle = 90, + }; + } Marshal.StructureToPtr(hidTouchScreenEntry, HidPtr, false); } diff --git a/Ryujinx.Core/Hid/HidTouchScreen.cs b/Ryujinx.Core/Hid/HidTouchScreen.cs index 755ebadca..4a1a21fde 100644 --- a/Ryujinx.Core/Hid/HidTouchScreen.cs +++ b/Ryujinx.Core/Hid/HidTouchScreen.cs @@ -52,4 +52,11 @@ namespace Ryujinx.Core public byte[] Padding; } + public struct Touches + { + public uint[] XTouches; + public uint[] YTouches; + public uint NumberOfTouches; + } + } \ No newline at end of file diff --git a/Ryujinx.Core/Switch.cs b/Ryujinx.Core/Switch.cs index 8fd7979e4..333940f2e 100644 --- a/Ryujinx.Core/Switch.cs +++ b/Ryujinx.Core/Switch.cs @@ -52,9 +52,9 @@ namespace Ryujinx.Core Hid.SendControllerButtons(ControllerId, Layout, Buttons, LeftJoystick, RightJoystick); } - public void SendTouchScreenEntry(HidTouchScreenEntryTouch TouchPoint) + public void SendTouchCoordinates(Touches TouchPoints) { - Hid.SendTouchPoint(TouchPoint); + Hid.SendTouchCoordinates(TouchPoints); } internal virtual void OnFinish(EventArgs e) diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 3219303eb..53cd5b1aa 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -36,6 +36,11 @@ namespace Ryujinx JoystickPosition LeftJoystick; JoystickPosition RightJoystick; + Touches CurrentTouchPoints = new Touches() + { + XTouches = new uint[16], + YTouches = new uint[16] + }; if (Keyboard[OpenTK.Input.Key.Escape]) this.Exit(); @@ -89,26 +94,18 @@ namespace Ryujinx //Get screen touch position from left mouse click //Opentk always captures mouse events, even if out of focus, so check if window is focused. - if (Mouse != null && Focused) - if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed) + if (Mouse != null) + { + if (Mouse.GetState().LeftButton == OpenTK.Input.ButtonState.Pressed && Focused) { - HidTouchScreenEntryTouch CurrentPoint = new HidTouchScreenEntryTouch - { - Timestamp = (uint)Environment.TickCount, - X = (uint)Mouse.X, - Y = (uint)Mouse.Y, - - //Placeholder values till more data is acquired - DiameterX = 10, - DiameterY = 10, - Angle = 90, - - //Only support single touch - TouchIndex = 0, - }; - if (Mouse.X > -1 && Mouse.Y > -1) - Ns.SendTouchScreenEntry(CurrentPoint); + CurrentTouchPoints.XTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.X; + CurrentTouchPoints.YTouches[CurrentTouchPoints.NumberOfTouches] = (uint)Mouse.Y; + CurrentTouchPoints.NumberOfTouches++; } + } + + //Send current touches + Ns.SendTouchCoordinates(CurrentTouchPoints); //We just need one pair of JoyCon because it's emulate by the keyboard. Ns.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick);