FullscreenHook.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Shared.Input;
  2. using Robust.Client.Graphics;
  3. using Robust.Client.Input;
  4. using Robust.Shared.Input.Binding;
  5. using Robust.Shared;
  6. using Robust.Shared.Configuration;
  7. using Robust.Shared.Player;
  8. namespace Content.Client.Fullscreen;
  9. public sealed class FullscreenHook
  10. {
  11. [Dependency] private readonly IInputManager _inputManager = default!;
  12. [Dependency] private readonly IConfigurationManager _cfg = default!;
  13. [Dependency] private readonly ILogManager _logManager = default!;
  14. private ISawmill _sawmill = default!;
  15. public void Initialize()
  16. {
  17. _inputManager.SetInputCommand(ContentKeyFunctions.ToggleFullscreen, InputCmdHandler.FromDelegate(ToggleFullscreen));
  18. _sawmill = _logManager.GetSawmill("fullscreen");
  19. }
  20. private void ToggleFullscreen(ICommonSession? session)
  21. {
  22. var currentWindowMode = _cfg.GetCVar(CVars.DisplayWindowMode);
  23. switch (currentWindowMode)
  24. {
  25. case (int) WindowMode.Windowed:
  26. _cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Fullscreen);
  27. _sawmill.Info("Switched to Fullscreen mode");
  28. break;
  29. case (int) WindowMode.Fullscreen:
  30. _cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Windowed);
  31. _sawmill.Info("Switched to Windowed mode");
  32. break;
  33. default:
  34. throw new InvalidOperationException($"Unexpected WindowMode value: {currentWindowMode}");
  35. }
  36. }
  37. }