From 51b3953cfc3b440aa0b7b1b06d33626426e54556 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Mon, 9 Jan 2023 04:55:37 +0100 Subject: [Headless] Add missing arguments & Fix typos (#4193) * headless: Fix typos in command line options * Remove nullable from command line options Add EnableMacroHLE option Add HideCursorOnIdle option * headless: Adjust enable-ptc help text * headless: Use switch statement instead of if-else chain * headless: Improve formatting for long constructors * headless: Remove discards from SDL_ShowCursor() * headless: Add window icon * Fix hiding cursor on idle At least on Wayland, SDL2 doesn't produce any mouse motion events. * Add new command line args: BaseDataDir and UserProfile * headless: Read icon from embedded resource * headless: Skip SetWindowIcon() on Windows if dll isn't present * headless: Fix division by zero * headless: Fix command line options not working correctly * headless: Fix crash when viewing command line options * headless: Load window icon bmp from memory * Add comment to the workaround for SDL_LoadBMP_RW * headless: Enable logging to file by default * headless: Add 3 options for --hide-cursor Replaces --disable-hide-cursor-on-idle --- Ryujinx.Headless.SDL2/WindowBase.cs | 55 ++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Headless.SDL2/WindowBase.cs') diff --git a/Ryujinx.Headless.SDL2/WindowBase.cs b/Ryujinx.Headless.SDL2/WindowBase.cs index 88b0d573..db6c8ec4 100644 --- a/Ryujinx.Headless.SDL2/WindowBase.cs +++ b/Ryujinx.Headless.SDL2/WindowBase.cs @@ -14,13 +14,16 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using static SDL2.SDL; using Switch = Ryujinx.HLE.Switch; namespace Ryujinx.Headless.SDL2 { - abstract class WindowBase : IHostUiHandler, IDisposable + abstract partial class WindowBase : IHostUiHandler, IDisposable { protected const int DefaultWidth = 1280; protected const int DefaultHeight = 720; @@ -29,6 +32,10 @@ namespace Ryujinx.Headless.SDL2 private static ConcurrentQueue MainThreadActions = new ConcurrentQueue(); + [LibraryImport("SDL2")] + // TODO: Remove this as soon as SDL2-CS was updated to expose this method publicly + private static partial IntPtr SDL_LoadBMP_RW(IntPtr src, int freesrc); + public static void QueueMainThreadAction(Action action) { MainThreadActions.Enqueue(action); @@ -66,9 +73,14 @@ namespace Ryujinx.Headless.SDL2 private AspectRatio _aspectRatio; private bool _enableMouse; - public WindowBase(InputManager inputManager, GraphicsDebugLevel glLogLevel, AspectRatio aspectRatio, bool enableMouse) + public WindowBase( + InputManager inputManager, + GraphicsDebugLevel glLogLevel, + AspectRatio aspectRatio, + bool enableMouse, + HideCursor hideCursor) { - MouseDriver = new SDL2MouseDriver(); + MouseDriver = new SDL2MouseDriver(hideCursor); _inputManager = inputManager; _inputManager.SetMouseDriver(MouseDriver); NpadManager = _inputManager.CreateNpadManager(); @@ -103,6 +115,34 @@ namespace Ryujinx.Headless.SDL2 TouchScreenManager.Initialize(device); } + private void SetWindowIcon() + { + Stream iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Ryujinx.Headless.SDL2.Ryujinx.bmp"); + byte[] iconBytes = new byte[iconStream!.Length]; + + if (iconStream.Read(iconBytes, 0, iconBytes.Length) != iconBytes.Length) + { + Logger.Error?.Print(LogClass.Application, "Failed to read icon to byte array."); + iconStream.Close(); + + return; + } + + iconStream.Close(); + + unsafe + { + fixed (byte* iconPtr = iconBytes) + { + IntPtr rwOpsStruct = SDL_RWFromConstMem((IntPtr)iconPtr, iconBytes.Length); + IntPtr iconHandle = SDL_LoadBMP_RW(rwOpsStruct, 1); + + SDL_SetWindowIcon(WindowHandle, iconHandle); + SDL_FreeSurface(iconHandle); + } + } + } + private void InitializeWindow() { string titleNameSection = string.IsNullOrWhiteSpace(Device.Application.TitleName) ? string.Empty @@ -127,6 +167,8 @@ namespace Ryujinx.Headless.SDL2 throw new Exception(errorMessage); } + SetWindowIcon(); + _windowId = SDL_GetWindowID(WindowHandle); SDL2Driver.Instance.RegisterWindow(_windowId, HandleWindowEvent); @@ -146,9 +188,11 @@ namespace Ryujinx.Headless.SDL2 Renderer?.Window.SetSize(Width, Height); MouseDriver.SetClientSize(Width, Height); break; + case SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE: Exit(); break; + default: break; } @@ -331,6 +375,9 @@ namespace Ryujinx.Headless.SDL2 Device.Hid.DebugPad.Update(); + // TODO: Replace this with MouseDriver.CheckIdle() when mouse motion events are received on every supported platform. + MouseDriver.UpdatePosition(); + return true; } @@ -451,4 +498,4 @@ namespace Ryujinx.Headless.SDL2 } } } -} +} \ No newline at end of file -- cgit v1.2.3