-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Window.CanMinimize/CanMaximize #18117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the linked issue really resolved? CaptionButtons are still visible.
We're just supporting what the various platforms are exposing here. On Windows, if Maximize and Minimize are both disabled, the system automatically hides both buttons. To do more, it's always possible for users to use a custom chrome. |
You can test this PR using the following package version. |
I think hint in the name makes more sense and follows the existing pattern of things that may or may not work. |
Couple thoughts:
|
Public API for review: namespace Avalonia.Controls
{
public class Window : WindowBase, IFocusScope, ILayoutRoot
{
+ public static readonly StyledProperty<bool> CanMinimizeProperty;
+ public static readonly StyledProperty<bool> CanMaximizeProperty;
+ public bool CanMinimize { get; set; }
+ public bool CanMaximize { get; set; }
}
}
namespace Avalonia.Platform
{
[Unstable]
public interface IWindowImpl : IWindowBaseImpl
{
+ void SetCanMinimize(bool value);
+ void SetCanMaximize(bool value);
}
} |
During the API review meeting, it was noted that all 3 desktop platforms each provide some minimize and maximize flags directly. This new API maps to those perfectly and we decided not to add a higher level concept, that might require users to fiddle with several properties to set a single flag. We focused mostly on the fact that However, after some debate on the naming, The API is accepted. |
Note: this PR still needs integration tests. |
# Conflicts: # tests/Avalonia.Controls.UnitTests/WindowTests.cs
Integration tests have been added. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
* Add CanMinimize and CanMaximize to Window * Win32 impl for CanMinimize/CanMaximize * Add CanResize/CanMinimize/CanMaximize samples to control catalog * X11 impl for CanMinimize/CanMaximize * macOS impl for CanMinimize/CanMaximize * Win32: don't allow restore when the window isn't resizable * Additional documentation for CanMinimize/CanMaximize * Add CanMinimize/CanMaximize logic to CaptionButtons * Use START_COM_ARP_CALL * Added CanMinimize/CanMaximize integration tests * Fixed CanMaximize tests on macOS
What does the pull request do?
This PR adds two new properties to
Window
to enable or disable the minimize (CanMinimize
) and maximize (CanMaximize
) buttons of a window.They're implemented on all three desktop platforms: Windows, macOS and X11.
Notes
General
true
by default.CanMaximize
is automatically coerced tofalse
whenCanResize
isfalse
.CanMaximize
is false, the restore button stays enabled if the window is somehow already maximized (and is resizable).Both Qt and Wine have been used as reference implementations for X11 and macOS.
Windows
On Windows, the two properties work exactly as one would expect. They map to the
WS_MINIMIZEBOX
andWS_MAXIMIZEBOX
window styles.Linux
On X11, the two properties are effectively hints (
_MOTIF_WM_HINTS
).Maybe we should prefer names such as
CanMinimizeHint
andCanMaximizeHint
?In my tests, GNOME respects them, and while the buttons aren't visually disabled (at least on Ubuntu 24.04 with the default theme), they aren't clickable.
KDE (KWin) completely ignores them.
macOS
CanMinimize
disables the minimize button, as expected.CanMaximize
disables both the zoom/maximize gesture (titlebar double click) and the green full screen button.I went this route because I believe that's what most users would expect: that each property effectively corresponds to one traffic light button. Plus, clicking the green button with ⌥ pressed effectively zooms so the two behaviors aren't easily dissociated.
If that isn't acceptable, we could easily split that into
CanMaximize
andCanSwitchToFullScreen
(naming TBD).New API
Fixed issues