using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.VisualTree;
using StarterNG.Controls;
namespace StarterNG.Tests;
/// Windows under gamescope, which gives them no title bar, no close button and no maximizing.
[Collection(AvaloniaControls.Name)]
public class GamescopeWindowsTests
{
static GamescopeWindowsTests()
{
HeadlessDrawing.Ensure();
DialogKeyboard.Install();
GamescopeWindows.Install(false, () => "Zamknij");
}
[Theory]
[InlineData("gamescope", null, true)]
[InlineData("Gamescope", null, true)]
[InlineData("KDE", "gamescope-0", true)]
[InlineData(null, "gamescope-0", true)]
[InlineData("KDE", null, false)]
[InlineData("KDE", "", false)]
[InlineData(null, null, false)]
public void Gamescope_is_told_by_its_session_or_by_its_display(string? desktop, string? display, bool expected)
{
var variables = new Dictionary
{
["XDG_CURRENT_DESKTOP"] = desktop,
["GAMESCOPE_WAYLAND_DISPLAY"] = display,
// Big Picture on a desktop, whose window manager still draws the bars.
["SteamGamepadUI"] = "1"
};
Assert.Equal(expected, GamescopeWindows.IsGamescope(name => variables.GetValueOrDefault(name)));
}
private static (Window Owner, Window Window) Open(Control content, bool gamescope, bool escapeCloses = true)
{
GamescopeWindows.Active = gamescope;
var owner = new Window();
owner.Show();
var window = new Window { Title = "Taśmy", Width = 300, Height = 200, Content = content };
DialogKeyboard.SetEscapeCloses(window, escapeCloses);
window.Show(owner);
// Headless a window says it opened before it is given its owner; it says so again once it has one.
Assert.Same(owner, window.Owner);
window.RaiseEvent(new RoutedEventArgs(Window.WindowOpenedEvent));
Controls.Settle();
return (owner, window);
}
private static Button? CloseButton(Window window) =>
window.GetVisualDescendants().OfType