GtkHostUiHandler.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Gtk;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE;
  4. using Ryujinx.HLE.HOS.Applets;
  5. using System;
  6. using System.Threading;
  7. namespace Ryujinx.Ui
  8. {
  9. internal class GtkHostUiHandler : IHostUiHandler
  10. {
  11. private readonly Window _parent;
  12. public GtkHostUiHandler(Window parent)
  13. {
  14. _parent = parent;
  15. }
  16. public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
  17. {
  18. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  19. bool okPressed = false;
  20. bool error = false;
  21. string inputText = args.InitialText ?? "";
  22. Application.Invoke(delegate
  23. {
  24. try
  25. {
  26. var swkbdDialog = new InputDialog(_parent)
  27. {
  28. Title = "Software Keyboard",
  29. Text = args.HeaderText,
  30. SecondaryText = args.SubtitleText
  31. };
  32. swkbdDialog.InputEntry.Text = inputText;
  33. swkbdDialog.InputEntry.PlaceholderText = args.GuideText;
  34. swkbdDialog.OkButton.Label = args.SubmitText;
  35. swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
  36. if (swkbdDialog.Run() == (int)ResponseType.Ok)
  37. {
  38. inputText = swkbdDialog.InputEntry.Text;
  39. okPressed = true;
  40. }
  41. swkbdDialog.Dispose();
  42. }
  43. catch (Exception e)
  44. {
  45. error = true;
  46. Logger.Error?.Print(LogClass.Application, $"Error displaying Software Keyboard: {e}");
  47. }
  48. finally
  49. {
  50. dialogCloseEvent.Set();
  51. }
  52. });
  53. dialogCloseEvent.WaitOne();
  54. userText = error ? null : inputText;
  55. return error || okPressed;
  56. }
  57. }
  58. }