PreferredBackBufferWidth/Height not working on Linux Wayland after Initialize()
Prerequisites
- [X] I have verified this issue is present in the
developbranch - [X] I have searched open and closed issues to ensure it has not already been reported.
MonoGame Version
MonoGame 3.8.2.1105
Which MonoGame platform are you using?
MonoGame Cross-Platform Desktop Application (mgdesktopgl)
Operating System
Linux Nobara (Fedora) 40 - KDE Wayland
Description
When PreferredBackBufferWidth/PreferredBackBufferHeight is changed and then _graphics.ApplyChanges() is run the window is not resized on Linux.
If a minimum width/height is set by code to avoid the user to resize the window to too small sizes the viewport stops resizing (and becomes visible crop out) but the window can still be resized to be smaller.
Steps to Reproduce
using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace dev.dobon.ataraxia;
public class Game : Microsoft.Xna.Framework.Game
{
private const int DefaultWindowWidth = 1280;
private const int DefaultWindowHeight = 720;
private GraphicsDeviceManager _graphics;
public Game()
{
Window.AllowUserResizing = true;
Window.ClientSizeChanged += OnClientSizeChanged;
_graphics = new GraphicsDeviceManager(this);
_graphics.PreferredBackBufferWidth = DefaultWindowWidth;
_graphics.PreferredBackBufferHeight = DefaultWindowHeight;
Content.RootDirectory = "Content";
IsMouseVisible = false;
}
public void OnClientSizeChanged(object? sender, EventArgs e)
{
_graphics.PreferredBackBufferWidth = Window.ClientBounds.Width < LowResWidth ? LowResWidth : Window.ClientBounds.Width;
_graphics.PreferredBackBufferHeight = Window.ClientBounds.Height < LowResHeight ? LowResHeight : Window.ClientBounds.Height;
_graphics.ApplyChanges();
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}
Minimal Example Repo
No response
Expected Behavior
The window should be resized without issues.
Resulting Behavior
The window can become smaller but the image is crop out.
Files
The square is crop out and the window can still be resized further.
The PreferredBackBuffer... cannot override control the window manager's resizing of a window, while the resize is in progress. You cannot override the mouse while resizing a window
The event of "OnClientSizeChanged" is designed to allow resizing/reorienting of Sprite assets upon notification of a Window size change, including changes initiated via _graphics.ApplyChanges();
The _graphics.ApplyChanges(); has a static flag variable suppressing additional calls while the current call is in progress.
Had this not been the case, your recursive calls would have resulted in a stack overflow due to infinite recursion.
You could set a class level timer variable in OnClientSizeChanged for say 1 to 2 game steps later and run your code in Update() if the current size is below the minimums at that time.
I prefer to offer main menu sub-options for fixed window sizes, rather than having to provide accommodations for all combinations of position, scale, and aspect ratio variables possible at runtime.
I have no plans to support the possibility of a 7,680x720 window size for most of my games.