mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-12-01 01:17:05 +01:00
e1800a20b9
Gamescope, SteamOS's game mode, is no window manager: it gives no window a title bar or a close button and does not answer a request to maximize, so it stretched the starter's first size over the screen, and the tapes window and the black box opened from them could not be closed at all. Under gamescope the main window now takes the size of the screen itself, and every window over another gets a bar with its title and a close button, takes the screen's size too and closes on Esc, even the tapes, which otherwise stay open beside the starter. Steam's Big Picture on a desktop keeps its window manager's bars and is only maximized, as before.
156 lines
5.1 KiB
C#
156 lines
5.1 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.VisualTree;
|
|
using StarterNG.Controls;
|
|
|
|
namespace StarterNG.Tests;
|
|
|
|
/// <summary>Windows under gamescope, which gives them no title bar, no close button and no maximizing.</summary>
|
|
[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<string, string?>
|
|
{
|
|
["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<Button>().FirstOrDefault(b => Equals(b.Content, "Zamknij"));
|
|
|
|
[Fact]
|
|
public void Under_gamescope_a_window_over_another_gets_its_title_and_a_close_button()
|
|
{
|
|
var content = new TextBlock { Text = "zawartość" };
|
|
var (owner, window) = Open(content, gamescope: true);
|
|
try
|
|
{
|
|
bool closed = false;
|
|
window.Closed += (_, _) => closed = true;
|
|
|
|
Assert.Contains(window.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Taśmy");
|
|
Assert.Same(content, window.GetVisualDescendants().OfType<TextBlock>().First(t => t.Text == "zawartość"));
|
|
var close = CloseButton(window);
|
|
Assert.NotNull(close);
|
|
|
|
close.RaiseEvent(Controls.Click());
|
|
Assert.True(closed);
|
|
}
|
|
finally
|
|
{
|
|
GamescopeWindows.Active = false;
|
|
owner.Close();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Under_gamescope_esc_closes_even_a_window_that_stays_open_beside_the_starter()
|
|
{
|
|
var (owner, window) = Open(new TextBox(), gamescope: true, escapeCloses: false);
|
|
try
|
|
{
|
|
bool closed = false;
|
|
window.Closed += (_, _) => closed = true;
|
|
|
|
Assert.True(Controls.Press(window, Key.Escape));
|
|
Assert.True(closed);
|
|
}
|
|
finally
|
|
{
|
|
GamescopeWindows.Active = false;
|
|
owner.Close();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void The_window_shows_what_it_had_first_and_the_bar_after_it_in_tab_order()
|
|
{
|
|
var first = new Button { Content = "Pierwszy" };
|
|
var (owner, window) = Open(new StackPanel { Children = { first } }, gamescope: true);
|
|
try
|
|
{
|
|
var grid = Assert.IsType<Grid>(window.Content);
|
|
Assert.IsType<StackPanel>(grid.Children[0]);
|
|
Assert.True(first.IsFocused);
|
|
}
|
|
finally
|
|
{
|
|
GamescopeWindows.Active = false;
|
|
owner.Close();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void A_window_that_says_twice_it_opened_gets_one_bar()
|
|
{
|
|
var (owner, window) = Open(new TextBlock { Text = "zawartość" }, gamescope: true);
|
|
try
|
|
{
|
|
window.RaiseEvent(new RoutedEventArgs(Window.WindowOpenedEvent));
|
|
Controls.Settle();
|
|
|
|
Assert.Single(window.GetVisualDescendants().OfType<Button>(), b => Equals(b.Content, "Zamknij"));
|
|
}
|
|
finally
|
|
{
|
|
GamescopeWindows.Active = false;
|
|
owner.Close();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Elsewhere_a_window_keeps_what_it_shows_and_esc_keeps_its_choice()
|
|
{
|
|
var content = new TextBox();
|
|
var (owner, window) = Open(content, gamescope: false, escapeCloses: false);
|
|
try
|
|
{
|
|
Assert.Same(content, window.Content);
|
|
Assert.Null(CloseButton(window));
|
|
Assert.False(Controls.Press(window, Key.Escape));
|
|
}
|
|
finally
|
|
{
|
|
owner.Close();
|
|
}
|
|
}
|
|
}
|