Skip to content

Conversation

MrJul
Copy link
Member

@MrJul MrJul commented Feb 4, 2025

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

  • Both properties are true by default.
  • CanMaximize is automatically coerced to false when CanResize is false.
  • Even if 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 and WS_MAXIMIZEBOX window styles.

Linux

On X11, the two properties are effectively hints (_MOTIF_WM_HINTS).
Maybe we should prefer names such as CanMinimizeHint and CanMaximizeHint?

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 and CanSwitchToFullScreen (naming TBD).

New API

namespace Avalonia.Controls
{
    public class Window
    {
        public static readonly StyledProperty<bool> CanMinimizeProperty;
        public static readonly StyledProperty<bool> CanMaximizeProperty;
        public bool CanMinimize { get; set; }
        public bool CanMaximize { get; set; }
    }
}

Fixed issues

@MrJul MrJul added feature os-macos os-linux os-windows needs-api-review The PR adds new public APIs that should be reviewed. labels Feb 4, 2025
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054759-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Contributor

@rabbitism rabbitism left a 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.

@MrJul
Copy link
Member Author

MrJul commented Feb 4, 2025

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.
On macOS, the traffic lights are kept, but disabled (see the "about this mac" system window).
On Linux, it totally depends on the window manager and its configuration.

To do more, it's always possible for users to use a custom chrome.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0054781-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@thevortexcloud
Copy link
Contributor

I think hint in the name makes more sense and follows the existing pattern of things that may or may not work.

@robloo
Copy link
Contributor

robloo commented Feb 7, 2025

Couple thoughts:

  1. Have you considered a higher level of abstraction like with WPF? WPF has the WindowStyle enum to control this. It might help here in some cases:
    • Do we really need to support maximize but not minimize? Usually a window is resisable or it is not.
    • A WindowStyle could have a value such as NotResizeable. On windows that would remove the minimize/maximize buttons completely but on macOS would just disable them. So this generic naming doesn't imply how the actual buttons are shown which allows the platforms to handle it natively.
  2. For some reason I'm not a fan of "Hint" in this context. But I also agree it is more of a "Hint" on the platforms such as Linux that don't support all cases. I guess my justification is the main platforms support these properties just fine so its a shame to use less-than-ideal naming just because of limitations of a minor platform.

@MrJul
Copy link
Member Author

MrJul commented Mar 5, 2025

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);
    }
}

@MrJul
Copy link
Member Author

MrJul commented Mar 6, 2025

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 CanMinimize/CanMaximize aren't technically correct. The actual use case is to disable/hide the title bar buttons, but the OS or a third party application might still be able to minimize/maximize the window, making the "Can" part technically wrong.

However, after some debate on the naming, CanMinimize/Maximize is still the winner, as it's simple enough and probably what the user would look for. Hint didn't get much traction.

The API is accepted.

@MrJul MrJul added api-approved The new public APIs have been approved. and removed needs-api-review The PR adds new public APIs that should be reviewed. labels Mar 6, 2025
@MrJul
Copy link
Member Author

MrJul commented Mar 6, 2025

Note: this PR still needs integration tests.

@MrJul MrJul changed the title [RFC] Add Window.CanMinimize/CanMaximize Add Window.CanMinimize/CanMaximize Mar 8, 2025
@MrJul MrJul added the backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch label Aug 4, 2025
@MrJul
Copy link
Member Author

MrJul commented Aug 4, 2025

Integration tests have been added.

@MrJul MrJul requested a review from maxkatz6 August 4, 2025 12:29
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058006-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0058014-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added this pull request to the merge queue Aug 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 13, 2025
@MrJul MrJul added this pull request to the merge queue Aug 13, 2025
Merged via the queue into AvaloniaUI:master with commit 1f8701a Aug 13, 2025
11 checks passed
@MrJul MrJul deleted the feature/window-can-min-max branch August 13, 2025 09:41
MrJul added a commit that referenced this pull request Aug 15, 2025
* 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
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to hide Minimize / Maximize window buttons
7 participants