Added a toggle fullscreen button (default F11) (#20272)

* Added a toggle fullscreen button (default F11)

* Removed un-needed comments

* Review Requested Changes

* Fixed Acidental Spacing Change

* bwoink, removed extraneous code

* nothing, litterally
This commit is contained in:
Miro Kavaliou
2023-09-28 19:55:10 -04:00
committed by GitHub
parent 3477349dfe
commit c06586f942
11 changed files with 82 additions and 9 deletions

View File

@@ -0,0 +1,43 @@
using Content.Shared.Input;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Players;
namespace Content.Client.Fullscreen;
public sealed class FullscreenHook
{
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILogManager _logManager = default!;
private ISawmill _sawmill = default!;
public void Initialize()
{
_inputManager.SetInputCommand(ContentKeyFunctions.ToggleFullscreen, InputCmdHandler.FromDelegate(ToggleFullscreen));
_sawmill = _logManager.GetSawmill("fullscreen");
}
private void ToggleFullscreen(ICommonSession? session)
{
var currentWindowMode = _cfg.GetCVar(CVars.DisplayWindowMode);
switch (currentWindowMode)
{
case (int) WindowMode.Windowed:
_cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Fullscreen);
_sawmill.Info("Switched to Fullscreen mode");
break;
case (int) WindowMode.Fullscreen:
_cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Windowed);
_sawmill.Info("Switched to Windowed mode");
break;
default:
throw new InvalidOperationException($"Unexpected WindowMode value: {currentWindowMode}");
}
}
}