From 380b95bc59e7dc419f89df951cdc086e792cb0ff Mon Sep 17 00:00:00 2001 From: Caian Benedicto Date: Tue, 12 Oct 2021 16:54:21 -0300 Subject: Inline software keyboard without input pop up dialog (#2180) * Initial implementation * Refactor dynamic text input keys out to facilitate configuration via UI * Fix code styling * Add per applet indirect layer handles * Remove static functions from SoftwareKeyboardRenderer * Remove inline keyboard reset delay * Remove inline keyboard V2 responses * Add inline keyboard soft-lock recovering * Add comments * Forward accept and cancel key names to the keyboard and add soft-lock prevention line * Add dummy window to handle paste events * Rework inline keyboard state machine and graphics * Implement IHostUiHandler interfaces on headless WindowBase class * Add inline keyboard assets * Fix coding style * Fix coding style * Change mode cycling shortcut to F6 * Fix invalid calc size error in games using extended calc * Remove unnecessary namespaces --- .../Applets/SoftwareKeyboard/InlineResponses.cs | 59 ++++++++++++---------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs') diff --git a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs index 50e77b74..d48227a0 100644 --- a/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs +++ b/Ryujinx.HLE/HOS/Applets/SoftwareKeyboard/InlineResponses.cs @@ -38,9 +38,20 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard return (uint)text.Length; // Return the cursor position at the end of the text } - private static void WriteStringWithCursor(string text, BinaryWriter writer, uint maxSize, Encoding encoding) + private static void WriteStringWithCursor(string text, uint cursor, BinaryWriter writer, uint maxSize, Encoding encoding, bool padMiddle) { - uint cursor = WriteString(text, writer, maxSize, encoding); + uint length = WriteString(text, writer, maxSize, encoding); + + if (cursor > length) + { + cursor = length; + } + + if (padMiddle) + { + writer.Write((int)-1); // ? + writer.Write((int)-1); // ? + } writer.Write(cursor); // Cursor position } @@ -72,7 +83,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard } } - public static byte[] ChangedString(string text, InlineKeyboardState state) + public static byte[] ChangedString(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF16; @@ -80,15 +91,13 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.ChangedString, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF16, Encoding.Unicode); - writer.Write((int)0); // ? - writer.Write((int)0); // ? + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); return stream.ToArray(); } } - public static byte[] MovedCursor(string text, InlineKeyboardState state) + public static byte[] MovedCursor(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF16; @@ -96,13 +105,13 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.MovedCursor, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF16, Encoding.Unicode); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); return stream.ToArray(); } } - public static byte[] MovedTab(string text, InlineKeyboardState state) + public static byte[] MovedTab(string text, uint cursor, InlineKeyboardState state) { // Should be the same as MovedCursor. @@ -112,7 +121,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.MovedTab, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF16, Encoding.Unicode); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); return stream.ToArray(); } @@ -145,7 +154,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard } } - public static byte[] ChangedStringUtf8(string text, InlineKeyboardState state) + public static byte[] ChangedStringUtf8(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF8; @@ -153,15 +162,13 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF8, Encoding.UTF8); - writer.Write((int)0); // ? - writer.Write((int)0); // ? + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); return stream.ToArray(); } } - public static byte[] MovedCursorUtf8(string text, InlineKeyboardState state) + public static byte[] MovedCursorUtf8(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF8; @@ -169,7 +176,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF8, Encoding.UTF8); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); return stream.ToArray(); } @@ -228,7 +235,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard } } - public static byte[] ChangedStringV2(string text, InlineKeyboardState state) + public static byte[] ChangedStringV2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF16 + 0x1; @@ -236,16 +243,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.ChangedStringV2, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF16, Encoding.Unicode); - writer.Write((int)0); // ? - writer.Write((int)0); // ? + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, true); writer.Write((byte)0); // Flag == 0 return stream.ToArray(); } } - public static byte[] MovedCursorV2(string text, InlineKeyboardState state) + public static byte[] MovedCursorV2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF16 + 0x1; @@ -253,14 +258,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.MovedCursorV2, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF16, Encoding.Unicode); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF16, Encoding.Unicode, false); writer.Write((byte)0); // Flag == 0 return stream.ToArray(); } } - public static byte[] ChangedStringUtf8V2(string text, InlineKeyboardState state) + public static byte[] ChangedStringUtf8V2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 6 * sizeof(uint) + MaxStrLenUTF8 + 0x1; @@ -268,16 +273,14 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.ChangedStringUtf8V2, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF8, Encoding.UTF8); - writer.Write((int)0); // ? - writer.Write((int)0); // ? + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, true); writer.Write((byte)0); // Flag == 0 return stream.ToArray(); } } - public static byte[] MovedCursorUtf8V2(string text, InlineKeyboardState state) + public static byte[] MovedCursorUtf8V2(string text, uint cursor, InlineKeyboardState state) { uint resSize = 4 * sizeof(uint) + MaxStrLenUTF8 + 0x1; @@ -285,7 +288,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard using (BinaryWriter writer = new BinaryWriter(stream)) { BeginResponse(state, InlineKeyboardResponse.MovedCursorUtf8V2, writer); - WriteStringWithCursor(text, writer, MaxStrLenUTF8, Encoding.UTF8); + WriteStringWithCursor(text, cursor, writer, MaxStrLenUTF8, Encoding.UTF8, false); writer.Write((byte)0); // Flag == 0 return stream.ToArray(); -- cgit v1.2.3