GtkHostUiHandler.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using Gtk;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE;
  4. using Ryujinx.HLE.HOS.Applets;
  5. using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
  6. using System;
  7. using System.Threading;
  8. namespace Ryujinx.Ui
  9. {
  10. internal class GtkHostUiHandler : IHostUiHandler
  11. {
  12. private readonly Window _parent;
  13. public GtkHostUiHandler(Window parent)
  14. {
  15. _parent = parent;
  16. }
  17. public bool DisplayMessageDialog(ControllerAppletUiArgs args)
  18. {
  19. string playerCount = args.PlayerCountMin == args.PlayerCountMax
  20. ? $"exactly {args.PlayerCountMin}"
  21. : $"{args.PlayerCountMin}-{args.PlayerCountMax}";
  22. string message =
  23. $"Application requests <b>{playerCount}</b> player(s) with:\n\n"
  24. + $"<tt><b>TYPES:</b> {args.SupportedStyles}</tt>\n\n"
  25. + $"<tt><b>PLAYERS:</b> {string.Join(", ", args.SupportedPlayers)}</tt>\n\n"
  26. + (args.IsDocked ? "Docked mode set. <tt>Handheld</tt> is also invalid.\n\n" : "")
  27. + "<i>Please reconfigure Input now and then press OK.</i>";
  28. return DisplayMessageDialog("Controller Applet", message);
  29. }
  30. public bool DisplayMessageDialog(string title, string message)
  31. {
  32. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  33. bool okPressed = false;
  34. Application.Invoke(delegate
  35. {
  36. MessageDialog msgDialog = null;
  37. try
  38. {
  39. msgDialog = new MessageDialog(_parent, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
  40. {
  41. Title = title,
  42. Text = message,
  43. UseMarkup = true
  44. };
  45. msgDialog.SetDefaultSize(400, 0);
  46. msgDialog.Response += (object o, ResponseArgs args) =>
  47. {
  48. if (args.ResponseId == ResponseType.Ok) okPressed = true;
  49. dialogCloseEvent.Set();
  50. msgDialog?.Dispose();
  51. };
  52. msgDialog.Show();
  53. }
  54. catch (Exception e)
  55. {
  56. Logger.Error?.Print(LogClass.Application, $"Error displaying Message Dialog: {e}");
  57. dialogCloseEvent.Set();
  58. }
  59. });
  60. dialogCloseEvent.WaitOne();
  61. return okPressed;
  62. }
  63. public bool DisplayInputDialog(SoftwareKeyboardUiArgs args, out string userText)
  64. {
  65. ManualResetEvent dialogCloseEvent = new ManualResetEvent(false);
  66. bool okPressed = false;
  67. bool error = false;
  68. string inputText = args.InitialText ?? "";
  69. Application.Invoke(delegate
  70. {
  71. try
  72. {
  73. var swkbdDialog = new InputDialog(_parent)
  74. {
  75. Title = "Software Keyboard",
  76. Text = args.HeaderText,
  77. SecondaryText = args.SubtitleText
  78. };
  79. swkbdDialog.InputEntry.Text = inputText;
  80. swkbdDialog.InputEntry.PlaceholderText = args.GuideText;
  81. swkbdDialog.OkButton.Label = args.SubmitText;
  82. swkbdDialog.SetInputLengthValidation(args.StringLengthMin, args.StringLengthMax);
  83. if (swkbdDialog.Run() == (int)ResponseType.Ok)
  84. {
  85. inputText = swkbdDialog.InputEntry.Text;
  86. okPressed = true;
  87. }
  88. swkbdDialog.Dispose();
  89. }
  90. catch (Exception e)
  91. {
  92. error = true;
  93. Logger.Error?.Print(LogClass.Application, $"Error displaying Software Keyboard: {e}");
  94. }
  95. finally
  96. {
  97. dialogCloseEvent.Set();
  98. }
  99. });
  100. dialogCloseEvent.WaitOne();
  101. userText = error ? null : inputText;
  102. return error || okPressed;
  103. }
  104. public void ExecuteProgram(HLE.Switch device, ProgramSpecifyKind kind, ulong value)
  105. {
  106. device.UserChannelPersistence.ExecuteProgram(kind, value);
  107. MainWindow.GlWidget?.Exit();
  108. }
  109. }
  110. }